glean/provider
Types
Everything the provider needs to make a generation call.
pub type GenerateRequest {
GenerateRequest(
messages: List(message.Message),
settings: ModelSettings,
tools: List(ToolSpec),
tool_choice: ToolChoice,
response_format: ResponseFormat,
)
}
Constructors
-
GenerateRequest( messages: List(message.Message), settings: ModelSettings, tools: List(ToolSpec), tool_choice: ToolChoice, response_format: ResponseFormat, )
The result of a generation call.
pub type GenerateResult {
GenerateResult(
content: List(GeneratedContent),
finish_reason: error.FinishReason,
usage: usage.Usage,
model_id: String,
)
}
Constructors
-
GenerateResult( content: List(GeneratedContent), finish_reason: error.FinishReason, usage: usage.Usage, model_id: String, )
Content generated by the model.
pub type GeneratedContent {
GeneratedText(text: String)
GeneratedReasoning(
text: String,
signature: option.Option(String),
)
GeneratedRedactedReasoning(data: String)
GeneratedToolCall(
tool_call_id: String,
tool_name: String,
arguments_json: String,
)
GeneratedFile(
media_type: String,
data: String,
signature: option.Option(String),
)
}
Constructors
-
GeneratedText(text: String) -
GeneratedReasoning( text: String, signature: option.Option(String), )Reasoning text.
signatureis set when the provider signs its reasoning (Claude) and must be sent back with it. -
GeneratedRedactedReasoning(data: String)Encrypted reasoning (Claude’s redacted thinking), to send back verbatim.
-
GeneratedToolCall( tool_call_id: String, tool_name: String, arguments_json: String, ) -
GeneratedFile( media_type: String, data: String, signature: option.Option(String), )A file the model produced, such as an image from one of Gemini’s image models: base64
dataof the given media type.signatureis the provider’s token for sending the file back on the next turn.
Model settings for controlling generation behavior.
pub type ModelSettings {
ModelSettings(
max_output_tokens: option.Option(Int),
temperature: option.Option(Float),
top_p: option.Option(Float),
top_k: option.Option(Int),
stop_sequences: option.Option(List(String)),
seed: option.Option(Int),
presence_penalty: option.Option(Float),
frequency_penalty: option.Option(Float),
reasoning_effort: option.Option(ReasoningEffort),
include_reasoning: Bool,
)
}
Constructors
-
ModelSettings( max_output_tokens: option.Option(Int), temperature: option.Option(Float), top_p: option.Option(Float), top_k: option.Option(Int), stop_sequences: option.Option(List(String)), seed: option.Option(Int), presence_penalty: option.Option(Float), frequency_penalty: option.Option(Float), reasoning_effort: option.Option(ReasoningEffort), include_reasoning: Bool, )Arguments
- reasoning_effort
-
How much a reasoning model should think before answering. Only sent by providers whose API has the parameter.
- include_reasoning
-
Ask for the model’s reasoning as text. Claude and Gemini think either way but only return the text (a summary of it) when asked; without this their reasoning content and
ReasoningDeltaevents are empty. Other providers return what they return, and ignore this.
The provider abstraction. Contains function fields for generation.
pub type Provider {
Provider(
name: String,
model_id: String,
generate: fn(GenerateRequest) -> Result(
GenerateResult,
error.GleanError,
),
stream: fn(GenerateRequest, fn(stream.StreamEvent) -> Nil) -> Result(
GenerateResult,
error.GleanError,
),
)
}
Constructors
-
Provider( name: String, model_id: String, generate: fn(GenerateRequest) -> Result( GenerateResult, error.GleanError, ), stream: fn(GenerateRequest, fn(stream.StreamEvent) -> Nil) -> Result( GenerateResult, error.GleanError, ), )Arguments
- name
-
Human-readable provider name (e.g., “openai”, “anthropic”)
- model_id
-
The model ID (e.g., “gpt-4o”, “claude-sonnet-4-20250514”)
- generate
-
Non-streaming generation
- stream
-
Streaming generation: calls callback for each event, returns final result
Reasoning effort for models that think before answering.
Providers map these onto their own scale (e.g. DeepSeek folds Medium
into high).
pub type ReasoningEffort {
LowEffort
MediumEffort
HighEffort
XHighEffort
MaxEffort
}
Constructors
-
LowEffort -
MediumEffort -
HighEffort -
XHighEffortAbove
high: Claude Opus 4.7 and later, and OpenAI’s newest GPT-5 models. Gemini has no such level and getshigh. -
MaxEffortThe most a model can think: current Claude models and DeepSeek. Gemini has no such level and gets
high.
The format the model should respond in.
pub type ResponseFormat {
TextFormat
JsonFormat(
schema: option.Option(schema.Schema),
name: option.Option(String),
)
}
Constructors
-
TextFormat -
JsonFormat( schema: option.Option(schema.Schema), name: option.Option(String), )
How the model should choose tools.
pub type ToolChoice {
Auto
Required
NoTools
SpecificTool(name: String)
}
Constructors
-
AutoModel decides whether to call tools
-
RequiredModel must call at least one tool
-
NoToolsModel must not call any tools
-
SpecificTool(name: String)Model must call this specific tool
A tool specification as sent to the provider API.
pub type ToolSpec {
ToolSpec(
name: String,
description: String,
input_schema: schema.Schema,
)
}
Constructors
-
ToolSpec( name: String, description: String, input_schema: schema.Schema, )
Values
pub fn default_settings() -> ModelSettings
Default model settings (all None — provider uses its defaults).
pub fn reasoning_effort_to_string(
effort: ReasoningEffort,
) -> String
The wire value most OpenAI-compatible APIs use for reasoning_effort,
and Claude for output_config.effort.
pub fn result_text(result: GenerateResult) -> String
Extract all text content from a generate result.
pub fn result_tool_calls(
result: GenerateResult,
) -> List(#(String, String, String))
Extract tool calls from generated content.