Skip to contents

pin_trace() saves a module's execution traces (timing, token use, cost and, optionally, prompts and outputs) to a pins board, together with a summary from summarize_traces(). Use it to keep a record of a run for later analysis.

Usage

pin_trace(
  board,
  name,
  module,
  include_prompts = FALSE,
  include_outputs = FALSE,
  description = NULL,
  ...
)

Arguments

board

A pins board.

name

Name of the pin.

module

A module that has been run.

include_prompts

Whether to include the full prompts (default FALSE).

include_outputs

Whether to include the full outputs (default FALSE).

description

Optional pin description.

...

Further arguments passed to pins::pin_write().

Value

name, invisibly.

Details

The pin is a list with traces (from export_traces()), summary and metadata (module class, number of traces, creation time and the include flags). A module without traces is not pinned; a warning is raised instead.

Examples

if (FALSE) { # \dontrun{
board <- pins::board_folder("pins")
classifier <- module(signature("text -> sentiment"))
run(
  classifier,
  text = c("Great!", "Terrible."),
  .llm = ellmer::chat_openai(model = "gpt-6-luna")
)

pin_trace(
  board,
  "sentiment-traces",
  classifier,
  include_prompts = TRUE,
  description = "Production run traces"
)
pins::pin_read(board, "sentiment-traces")$summary
} # }