Skip to contents

The app's AI translation from R: sends a model file (a NONMEM control stream, or a PDF or text file describing a model) to an AI model through an 'ellmer' chat, compiles the answer, and sends the compiler's errors back for fixing (up to max_retries times), with the app's prompts.

Usage

mvp_translate(
  file,
  chat,
  ext_file = NULL,
  max_retries = 3,
  params = NULL,
  prompts_path = NULL,
  quiet = FALSE
)

Arguments

file

Path to the model to translate.

chat

An 'ellmer' chat, e.g. ellmer::chat_anthropic() (with your API key set up as for 'ellmer'). It uses the provider's default model unless you choose one, e.g. ellmer::chat_anthropic(model = "..."); any temperature is set in the chat as well (params = ellmer::params(temperature = 0)).

ext_file

For a NONMEM model: its .ext file (default: found next to file), whose final estimates are used.

max_retries

Attempts to fix code that does not compile.

params

Optional parameter values to set after translating.

prompts_path

Path to your own prompts file (default: MVPapp's).

quiet

If FALSE, report each step.

Value

A compiled model, as from mvp_model(). The translated code is in attr(mod, "mrgsolve_code").

Details

Check the translation before using it: print mvp_params(mod) and the code (mrgsolve::see(mod)), and compare with the source. For a NONMEM model with an .ext file and the 'nonmem2mrgsolve' package installed, mvp_model() translates without an AI model.

Examples

# \donttest{
if (interactive() && requireNamespace("ellmer", quietly = TRUE)) {
  mod <- mvp_translate("run1.ctl", chat = ellmer::chat_anthropic())
  mvp_params(mod)
}
# }