vetiver_pr_predict: Create a Plumber API to predict with a deployable...

Description Usage Arguments Details Value Examples

View source: R/pr-predict.R

Description

Use vetiver_pr_predict() to add a POST endpoint for predictions from a trained vetiver_model() to a Plumber router.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
vetiver_pr_predict(
  pr,
  vetiver_model,
  path = "/predict",
  debug = is_interactive(),
  ...
)

vetiver_pr_post(
  pr,
  vetiver_model,
  path = "/predict",
  debug = is_interactive(),
  ...
)

vetiver_pr_docs(pr, vetiver_model, path = "/predict", all_docs = TRUE)

Arguments

pr

A Plumber router, such as from plumber::pr().

vetiver_model

A deployable vetiver_model() object

path

The endpoint path

debug

TRUE provides more insight into your API errors.

...

Other arguments passed to predict(), such as prediction type

all_docs

Should the interactive visual API documentation be created for all POST endpoints in the router pr? This defaults to TRUE, and assumes that all POST endpoints use the vetiver_model$ptype input data prototype.

Details

You can first store and version your vetiver_model() with vetiver_pin_write(), and then create an API endpoint with vetiver_pr_predict().

Setting debug = TRUE may expose any sensitive data from your model in API errors.

Two GET endpoints will also be added to the router pr, depending on the characteristics of the model object: a /pin-url endpoint to return the URL of the pinned model and a /ping endpoint for the API health.

The function vetiver_pr_predict() uses:

These modular functions are available for more advanced use cases.

Value

A Plumber router with the prediction endpoint added.

Examples

1
2
3
4
5
6
7
8
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")

library(plumber)
pr() %>% vetiver_pr_predict(v)
## is the same as:
pr() %>% vetiver_pr_post(v) %>% vetiver_pr_docs(v)
## for either, next, pipe to `pr_run()`

tidymodels/vetiver documentation built on Jan. 14, 2022, 7:32 p.m.