Skip to contents

The app's AI-translation prompts (from prompts.R, or your own prompts file), filled in for a model file, for a model description given as text, for a document attached to an AI chat, or for fixing code that did not compile. Use them with any AI model; mvp_translate() does the whole loop with an 'ellmer' chat, and the MCP tools give them to the assistant. Translations are to mrgsolve by default (the language MVPapp simulates with); the app's NONMEM and rxode2 prompts are used with target.

Usage

mvp_translation_prompt(
  file = NULL,
  code = NULL,
  error = NULL,
  ext_file = NULL,
  prompts_path = NULL,
  text = NULL,
  attachment = NULL,
  target = c("mrgsolve", "nonmem", "rxode2")
)

Arguments

file

Path to the model to translate: a NONMEM control stream, a PDF or text file describing the model.

code, error

For fixing code instead: the mrgsolve code and the compiler's error message (from mvp_model()). mrgsolve only.

ext_file

For a NONMEM model: its .ext file (default: found next to file). Its final estimates are added to the prompt, so the translation uses them instead of the initial estimates.

prompts_path

Path to an R file defining the prompts, as in run_mvp(). Default: the prompts installed with MVPapp.

text

Instead of file: the model description (or NONMEM code) as text, e.g. pasted from a paper.

attachment

Instead of file: the name of a document attached to the AI chat (e.g. "Smith2021.pdf"). The prompt then asks the AI model to translate that attachment, which it reads itself (tables and figures included); nothing is read from disk.

target

The language to translate to: "mrgsolve" (default), "nonmem" or "rxode2". MVPapp can only load and simulate mrgsolve models; NONMEM and rxode2 code is for use elsewhere.

Value

A list of class mvp_prompt with system (the system prompt), user (the user message, with the file contents or the code and error) and target.

See also

Examples

ctl <- tempfile(fileext = ".ctl")
writeLines(c("$PROBLEM one compartment", "$INPUT ID TIME AMT DV", "$SUBROUTINE ADVAN1 TRANS2",
             "$PK", "CL = THETA(1)*EXP(ETA(1))", "V = THETA(2)", "S1 = V",
             "$ERROR", "Y = F*(1 + EPS(1))", "$THETA 2 20", "$OMEGA 0.09", "$SIGMA 0.01"), ctl)
p <- mvp_translation_prompt(ctl)
cat(substr(p$user, 1, 200))
#> Convert the model described in this file into mrgsolve code.
#> 
#> <model_file name="file1cf54cd7af6.ctl">
#> $PROBLEM one compartment
#> $INPUT ID TIME AMT DV
#> $SUBROUTINE ADVAN1 TRANS2
#> $PK
#> CL = THETA(1)*EXP(ETA
p_rx <- mvp_translation_prompt(ctl, target = "rxode2")   # the app's rxode2 prompts