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.
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 = "...").
See also
Other program constructors:
code_act(),
flex(),
module(),
module_fn(),
multi_chain_comparison(),
program_of_thought(),
rag_module(),
react(),
rlm(),
rlm_module()
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
} # }