These functions read the parts of a result so you do not need to know its
structure. They work on results of run() with
.return_format = "structured", for single inputs and batches, and on
evaluate() results.
get_output()returns the outputs: the named list of output fields for a single result, a list of them for a batch, and the predictions of an evaluation.get_metadata()returns the call metadata: a list for a single result and one list per row for a batch or an evaluation.get_tokens()returnsinput_tokens,output_tokensandtotal_tokens.get_cost()returns the estimated cost in US dollars.
For run_dataset() results, use the result and .metadata columns
instead.
Arguments
- x
A result: a
dsprrr_resultordsprrr_batch_resultfromrun()with.return_format = "structured", or adsprrr_evaluationfromevaluate(). For other objects,get_output()returnsxitself and the other functions return empty or missing values.- ...
Not used.
Value
get_output(): the outputs, as described above.get_metadata(): a list, or a list of lists; an empty list whenxhas no metadata.get_tokens(): a list of the three counts for a single result, or a tibble with columnsindex,input_tokens,output_tokensandtotal_tokensfor a batch or an evaluation. Unknown counts areNA.get_cost(): a number (NAwhen unknown) for a single result. For a batch or an evaluation, a list of classdsprrr_cost_summarywithcosts(a tibble ofindexandcost),totalandn_missing; missing costs give a warning and maketotalNAinstead of counting as free.
See also
Other inspection:
clear_prompt_history(),
clear_traces(),
export_traces(),
get_last_prompt(),
inspect_history(),
session_cost(),
summarize_traces()
Examples
shout <- module_fn("text -> reply", function(text) toupper(text))
result <- run(shout, text = "hello", .return_format = "structured")
get_output(result)
#> $reply
#> [1] "HELLO"
#>
get_metadata(result)$latency_ms
#> [1] 0.0629425
# Function-backed modules make no model calls, so these are NA
get_tokens(result)
#> $input_tokens
#> [1] NA
#>
#> $output_tokens
#> [1] NA
#>
#> $total_tokens
#> [1] NA
#>
get_cost(result)
#> [1] NA
if (FALSE) { # \dontrun{
qa <- module(signature("question -> answer"))
batch <- run(
qa,
question = c("What is 2 + 2?", "What is 3 + 3?"),
.llm = ellmer::chat_openai(model = "gpt-6-luna"),
.return_format = "structured"
)
get_tokens(batch)
get_cost(batch)$total
} # }