Skip to contents

chain_of_thought() is module(with_reasoning(x)): a prediction module whose output starts with a reasoning field, so the model reasons step by step before it gives the other outputs.

Usage

chain_of_thought(
  x,
  prefix = "Let's think step by step in order to",
  chat = NULL,
  template = "",
  demos = list(),
  config = list(),
  ...
)

Arguments

x

A signature from signature(), or a signature string.

prefix

Start of the reasoning field's description; see with_reasoning().

chat, template, demos, config

As in module().

...

Must be empty.

Value

A prediction module, as from module(). run() returns the reasoning along with the other outputs, for example list(reasoning = "...", answer = "...").

Examples

solver <- chain_of_thought("question -> answer: float")
solver
#> 
#> ── PredictModule ──
#> 
#> ── Signature 
#> 
#> ── Signature ──
#> 
#> ── Inputs 
#> • question: "string" - Input: question
#> 
#> ── Output 
#> Type: "object(reasoning: string, answer: number)"
#> 
#> ── Instructions 
#> Given the fields `question`, produce the fields `answer`. Think through your
#> reasoning step by step before providing the answer.

if (FALSE) { # \dontrun{
result <- run(
  solver,
  question = "What is 15 * 24?",
  .llm = ellmer::chat_openai(model = "gpt-6-luna")
)
result$reasoning
result$answer
} # }