A parsnip model whose predictions a language model makes, from a description of the task. It fits and predicts like any parsnip model, so it goes in workflows, is resampled with rsample and tuned with tune, and its predictions are scored with yardstick.
Arguments
- mode
"classification"(a factor outcome) or"regression".- description
What the model is asked, in words: "Which team should answer this customer message?".
- examples
How many training rows the model sees as worked examples (default 0). Tunable:
worked_examples().- name
The function's name, which the model reads ("Function: team") and the call log files calls under. Default: the outcome's name.
- object
A model specification.
- parameters
A one-row tibble of new values (from tune).
- fresh
Replace every argument, rather than only the ones given.
- ...
Engine arguments to change.
- x
A model specification.
Details
What fitting does. No weights are estimated. Fitting reads the
outcome (its levels, for classification: they become the answers the
model may give) and the predictors (their names and types become the
function's inputs), and picks examples rows of the training data as
worked examples the model sees with every question. So fitting is free,
and a fit with examples = 0 has used no answer from the training data.
Fitting that learns the instruction. With method = "gepa", fitting
runs gepa() on the training rows: a model reads the function's mistakes
and rewrites its instruction, within budget calls. Fitting then costs
calls, and resampling repeats it on every fold, so the resampled score
measures the whole procedure, the search included. The fitted function's
instruction is what it learned: extract_fit_engine(fit) prints it.
Engine arguments (set_engine("functai", ...)): lm (the model,
"gpt-4.1-mini" by default from ai_config()), temperature, any
other setting of ai_config(); method ("labeled": training rows as
they are, the default; "bootstrap": rows the model got right, whole,
reasoning included; "gepa": the instruction rewritten from mistakes,
see below); budget (calls "gepa" may make, default 300); teacher (the
model that writes instructions or examples); samples (answers per row: with samples = 5,
predict(type = "prob") gives each level's share of the answers and the
class is the majority; costs 5 calls a row); seed.
Every prediction is a paid model call. Resampling and tuning multiply them: a grid of 3 values on 5 folds predicts every training row 3 times.
Examples
ai_model("classification", "Which team should answer this customer message?")
#> AI Model Specification (classification)
#>
#> Main Arguments:
#> description = Which team should answer this customer message?
#>
#> Computational engine: functai
#>
if (FALSE) { # \dontrun{
fitted <- ai_model("classification", "Which team should answer this customer message?") |>
parsnip::set_engine("functai", lm = "gpt-4.1-mini") |>
parsnip::fit(category ~ message, data = train)
predict(fitted, test)
} # }