Sends one request per row, with every question batched into that request,
and performs the requests in parallel with httr2::req_perform_parallel().
Rate-limited and failed requests are retried as described in
typesafer_error.
Usage
system_one_df(
.data,
state,
...,
model = ts_default_model(),
probs = FALSE,
include_usage = FALSE,
max_active = 10,
on_error = c("stop", "continue"),
max_tries = 3,
timeout = ts_timeout(),
api_key = ts_api_key()
)Arguments
- .data
A data frame.
- state
<
data-masking> An expression evaluated in.datagiving the state for each row: usually a character column (state = text), an expression such aspaste(subject, body, sep = "\n\n"), or a list-column holding one structured state (a list) per row.- ...
Named questions created with
ts_noul(),ts_choice(), orts_score(). The names identify the answers and aren't shown to the model. You can also splice a named list of questions with!!!.- model
The model to use. Defaults to
ts_default_model(), which is"jev-latest", TypeSafe's flagship model, unless theTYPESAFE_DEFAULT_MODELenvironment variable says otherwise. Pin a versioned ID such as"jev-1.13.0"to keep answers stable. Seets_models().- probs
If
TRUE, also add a<name>_probslist-column for each choice and score question holding its full probability distribution.- include_usage
If
TRUE, also addinput_tokensandoutput_tokenscolumns with each row's token usage (NAfor failed rows).- max_active
Maximum number of requests in flight at once.
- on_error
What to do when a row's request fails after retries:
"stop"(default): stop sending requests and raise the error for the first failed row (see typesafer_error); the condition has arowfield."continue": finish every row, fill the answers of failed rows withNA, add a.errorlist-column holding each row's error (orNULL), and warn with a count of failed rows.
- max_tries
Maximum number of attempts per request, including the first. Requests that fail with 408, 429, 5xx, or a connection failure are retried with exponential backoff, within a 30 second retry budget. Use
1to disable retries.- timeout
Timeout for each attempt, in seconds. Defaults to the
typesafer.timeoutoption, or 10.- api_key
API key; defaults to
ts_api_key().
Value
.data as a tibble, with columns added for each question name:
noul:
name(probability of yes).choice:
name(the chosen option) andname_confidence, plusname_probs(named double vectors) whenprobs = TRUE.score:
name(0-based expected level) andname_confidence, plusname_probs(double vectors ordered by level) whenprobs = TRUE.
Plus input_tokens and output_tokens when include_usage = TRUE, and
.error when on_error = "continue".
See also
system_one() for a single request.
Examples
if (FALSE) { # \dontrun{
tickets <- tibble::tibble(
id = 1:3,
text = c(
"I was charged twice. Please help ASAP.",
"How do I export my data to CSV?",
"Your app crashed and I lost an hour of work!!"
)
)
system_one_df(
tickets,
state = text,
billing = ts_noul("Is this about billing?"),
tone = ts_choice("What is the tone?", c("calm", "angry")),
urgency = ts_score("How urgent is this?", c("low", "medium", "high"))
)
} # }
