module() turns a signature into a prediction module: one structured model
call per input, whose output follows the signature. It is the usual
starting point:
signature() -> module() -> run() -> evaluate() -> compile().
Other kinds of program have their own constructors: chain_of_thought()
adds a reasoning step, react() calls tools, multi_chain_comparison()
compares several reasoning chains, and program_of_thought(),
code_act(), rlm_module() and flex() run code.
Arguments
- signature
A signature from
signature(). A string is not accepted here; wrap it insignature().- chat
An ellmer Chat stored on the module.
run()uses it unless you pass.llm; seeget_default_chat()for the full order.- template
A glue template for the input part of the prompt, with input fields in single braces, as in
"Review: {text}". The default ("") lists each input asname: value.- demos
Worked examples placed before the input in every prompt: a list of
list(inputs = list(...), output = list(...)).compile()sets demos for you.- config
Model settings applied to a copy of the chat on every call:
temperature,top_p,reasoning_effort,max_tokens,max_output_tokens,frequency_penalty,presence_penaltyandservice_tier, for exampleconfig = list(reasoning_effort = "low"). Reasoning models such as gpt-6-luna accepttemperatureandtop_ponly withreasoning_effort = "none". Chat settings such asmodelorproviderare an error here; set them on the chat instead.- ...
Must be empty. Arguments of other constructors, such as
toolsortype, give an error that names the constructor to use.
Value
A prediction module (an R6 object of class PredictModule) to use
with run(), run_dataset(), evaluate() and compile().
See also
Other program constructors:
chain_of_thought(),
code_act(),
flex(),
module_fn(),
multi_chain_comparison(),
program_of_thought(),
rag_module(),
react(),
rlm(),
rlm_module()
Examples
classifier <- module(
signature("text -> sentiment: enum('positive', 'negative', 'neutral')"),
template = "Classify the sentiment of this review:\n{text}",
demos = list(
list(
inputs = list(text = "Arrived broken."),
output = list(sentiment = "negative")
)
),
config = list(reasoning_effort = "low")
)
classifier
#>
#> ── PredictModule ──
#>
#> ── Signature
#>
#> ── Signature ──
#>
#> ── Inputs
#> • text: "string" - Input: text
#>
#> ── Output
#> Type: "object(sentiment: enum(positive, negative, neutral))"
#>
#> ── Instructions
#> Given the fields `text`, produce the fields `sentiment`.
#>
#> ── Template
#> Classify the sentiment of this review:
#> {text}
#>
#> ── Demos
#> 1 demonstration(s) loaded
if (FALSE) { # \dontrun{
run(
classifier,
text = "Great package!",
.llm = ellmer::chat_openai(model = "gpt-6-luna")
)
} # }