mod request#
- module request#
LLM request codec types and trait.
This module defines the
AnnotatedLlmRequesttype system for structured LLM request representation and thecrate::codec::traits::LlmCodectrait for bidirectional translation between opaquecrate::api::llm::LlmRequestpayloads and typed form.Enums
- enum ContentPart#
A single content part within a multimodal message.
v1 supports text only. Future versions may add
ImageUrl,Audio, etc.
- enum Message#
A single message in a conversation, tagged by role.
- System#
A system instruction message.
- content: MessageContent#
The message content.
- name: Option<String>#
Optional sender name.
- User#
A user message.
- content: MessageContent#
The message content.
- name: Option<String>#
Optional sender name.
- Assistant#
An assistant response, optionally containing tool calls.
- content: Option<MessageContent>#
The message content (optional — may be absent when tool calls are present).
- name: Option<String>#
Optional sender name.
- Tool#
A tool result message.
- content: MessageContent#
The tool execution result.
- tool_call_id: String#
The ID of the tool call this result corresponds to.
- enum MessageContent#
Message content: either a plain string or multimodal parts array.
- Text(String)#
Plain text content.
- Parts(Vec<ContentPart>)#
Multimodal content parts.
- enum ToolChoice#
Tool choice control: how the model should use available tools.
- Auto#
Let the model decide whether to call a tool.
- None#
Do not call any tools.
- Required#
The model must call at least one tool.
- Specific(ToolChoiceFunction)#
Force a specific function by name.
Structs and Unions
- struct AnnotatedLlmRequest#
Structured view of an LLM request, produced by a Codec from opaque
LlmRequestcontent.The
extrafield captures any provider-specific keys not modeled by the known fields, ensuring lossless round-trip throughdecode/encode.- model: Option<String>#
Model identifier (e.g.,
"gpt-4","claude-sonnet-4-20250514").
- params: Option<GenerationParams>#
Common generation parameters, normalized.
- tools: Option<Vec<ToolDefinition>>#
Tool definitions (function schemas) available to the model.
- tool_choice: Option<ToolChoice>#
Tool choice control.
- extra: serde_json::Map<String, Json>#
Extensible key-value pairs for unmodeled provider-specific fields. Merged back into the request body during encode via
serde(flatten).
Implementations
- impl AnnotatedLlmRequest#
Functions
- fn has_tool_calls(&self) -> bool#
Check if any assistant message in the conversation contains tool calls.
Returns
trueif at least oneMessage::Assistantvariant has a non-emptytool_callsfield.
- fn last_user_message(&self) -> Option<&str>#
Get the text content of the last user message, if any.
Searches messages in reverse order and returns the first user message found. For
MessageContent::Parts, returns the text of the firstContentPart::Textpart.
- fn system_prompt(&self) -> Option<&str>#
Extract the text content of the first system message, if any.
For
MessageContent::Text, returns the string directly. ForMessageContent::Parts, returns the text of the firstContentPart::Textpart.
- struct FunctionCall#
A function call within a tool call.
- name: String#
The name of the function to call.
- arguments: String#
The function arguments as a JSON string (per OpenAI convention).
- struct FunctionDefinition#
A function definition within a tool definition.
- name: String#
The name of the function.
- description: Option<String>#
A description of what the function does.
- struct GenerationParams#
Normalized generation parameters across providers.
- temperature: Option<f64>#
Sampling temperature.
- max_tokens: Option<u64>#
Maximum number of tokens to generate.
- top_p: Option<f64>#
Nucleus sampling probability.
- stop: Option<Vec<String>>#
Stop sequences.
- struct ToolCall#
A tool call requested by the assistant.
- id: String#
Unique identifier for this tool call.
- call_type: String#
The type of tool call (typically
"function").
- function: FunctionCall#
The function to call.
- struct ToolChoiceFunction#
A specific tool choice that forces a named function.
- choice_type: String#
The type (typically
"function").
- function: ToolChoiceFunctionName#
The function to call.
- struct ToolChoiceFunctionName#
The name component of a specific tool choice.
- name: String#
The function name.
- struct ToolDefinition#
A tool definition (function schema) available to the model.
- tool_type: String#
The type of tool (typically
"function").
- function: FunctionDefinition#
The function definition.