handler_startup: Model handler functions for API endpoint

Description Usage Arguments Details Value Examples

View source: R/handlers.R

Description

These are developer-facing functions, useful for supporting new model types. Each model supported by vetiver_model() uses two handler functions in vetiver_pr_predict():

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## S3 method for class 'train'
handler_startup(vetiver_model)

## S3 method for class 'train'
handler_predict(vetiver_model, ...)

handler_startup(vetiver_model)

## Default S3 method:
handler_startup(vetiver_model)

handler_predict(vetiver_model, ...)

## Default S3 method:
handler_predict(vetiver_model, ...)

## S3 method for class 'lm'
handler_predict(vetiver_model, ...)

## S3 method for class 'Learner'
handler_startup(vetiver_model)

## S3 method for class 'Learner'
handler_predict(vetiver_model, ...)

## S3 method for class 'workflow'
handler_startup(vetiver_model)

## S3 method for class 'workflow'
handler_predict(vetiver_model, ...)

## S3 method for class 'xgb.Booster'
handler_startup(vetiver_model)

## S3 method for class 'xgb.Booster'
handler_predict(vetiver_model, ...)

Arguments

vetiver_model

A deployable vetiver_model() object

...

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

Details

These are two generics that use the class of vetiver_model$model for dispatch.

Value

A handler_startup function should return invisibly, while a handler_predict function should return a function with the signature function(req). The request body (req$body) consists of the new data at prediction time; this function should return predictions either as a tibble or as a list coercable to a tibble via tibble::as_tibble().

Examples

1
2
3
4
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")
handler_startup(v)
handler_predict(v)

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