Skip to contents

Convenience function that creates a PredictModule with chain-of-thought reasoning enabled. This is equivalent to calling with_reasoning() on a signature and then creating a module from it.

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 object created by signature(), or string notation.

prefix

Character. The prefix for the reasoning field.

chat

Optional ellmer Chat object.

template

Optional glue template.

demos

Optional demonstration examples.

config

Optional prediction configuration.

...

Must be empty.

Value

A PredictModule with reasoning enabled

Examples

# Create a chain-of-thought QA module
mod <- chain_of_thought("question -> answer")

# Use it like any other module
# result <- run(mod, question = "What is 15 * 24?", .llm = llm)
# result$reasoning contains step-by-step reasoning
# result$answer contains the final answer