inst/test/structured.R

reprex::reprex({
  library(vitals)
  library(ellmer)
  library(tidyverse)

  type_answer <- type_object(
    answer = type_string(
      "The author's first name, with no other formatting."
    )
  )

  names <- tribble(
    ~input                                 , ~target  ,
    "Name's Josiah, how's it going?"       , "Josiah" ,
    "I'm Lin, what's your name?"           , "Lin"    ,
    "My name is Em Fields, how about you?" , "Em"
  )

  tsk <-
    Task$new(
      dataset = names,
      solver = generate_structured(
        solver_chat = chat_anthropic(model = "claude-sonnet-4-20250514"),
        type = type_answer
      ),
      scorer = detect_match("any")
    )

  tsk$eval()

  tsk$get_samples()$solver_chat[[1]]
})

Try the vitals package in your browser

Any scripts or data that you put into this service are public.

vitals documentation built on Sept. 3, 2026, 1:06 a.m.