Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of promises package inside vetiver api #252

Closed
joscani opened this issue Oct 24, 2023 · 3 comments
Closed

Use of promises package inside vetiver api #252

joscani opened this issue Oct 24, 2023 · 3 comments
Labels
feature a feature request or enhancement

Comments

@joscani
Copy link

joscani commented Oct 24, 2023

Is there any way of use promises::future_promise in an endpoint of vetiver api?

In my regular plumbers api I have something like that

library(brms)
library(plumber)
library(tidybayes)

library(future)
library(promises)

future::plan(multicore, workers = 6, .cleanup = FALSE)

brms_model <- readRDS("brms_model.rds")

## more get and post endpoint ----
# ------
#---------------------------------------
#* @post /predict_async
function(req, res) {


  promises::future_promise({
    data <- tryCatch(
      RcppSimdJson::fparse(req$postBody),
      error = function(e)
        NULL
    )
    if (is.null(data)) {
      res$status <- 400
      return(list(error = "No data submitted"))
    }

    res <- predict(brms_model, data) |>
      as.data.frame()
    return(res)
  })
}
@juliasilge
Copy link
Member

I haven't tried this myself, but we do provide a lot of hooks into the deployment process for more advanced use cases so I would be interested in hearing about how it goes for you. I think I would try a process like:

  • Create vetiver model object
  • Version model on the appropriate board for you
  • Create a default plumber.R and then edit it

Maybe something like this?

# Generated by the vetiver package; edit with care

library(pins)
library(plumber)
library(rapidoc)
library(vetiver)
library(future)
library(promises)

b <- board_connect(auth = "envvar")
v <- vetiver_pin_read(b, "user.name/model-name", version = "version-number")

#* @plumber
function(pr) {
    promises::future_promise({ pr %>% vetiver_api(v) })
}

Have you tried anything like this before?

Once you have your plumber file, you can deploy it in whatever way it appropriate for your infrastructure, like rsconnect::deployAPI() or using Docker or similar.

@joscani
Copy link
Author

joscani commented Oct 26, 2023

Interestint. I'll try this weekend.

Thanks @juliasilge

@juliasilge juliasilge added the feature a feature request or enhancement label Oct 31, 2023
@juliasilge
Copy link
Member

Let us know if you have further questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants