#[non_exhaustive]pub struct ChatRequest {
pub model: ModelId,
pub system: Option<String>,
pub messages: Vec<Message>,
pub tools: Vec<ToolSchema>,
pub generation: Generation,
pub thinking: Thinking,
pub response_schema: Option<Value>,
pub cache_breakpoints: Vec<usize>,
}Expand description
One request to one model.
Build it with ChatRequest::new and the with_ methods. The struct is marked
non exhaustive, so fields can be added without breaking your code, and constructing it
with a literal will not compile from outside this crate.
use llmr::{ChatRequest, Message};
let request = ChatRequest::new("claude-sonnet-5", vec![Message::user("Hello")])
.with_system("You answer in one sentence.")
.with_max_tokens(256);
assert_eq!(request.model.as_str(), "claude-sonnet-5");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.model: ModelIdWhich model.
system: Option<String>Instructions that are not part of the conversation.
messages: Vec<Message>The conversation so far, oldest first.
tools: Vec<ToolSchema>Tools the model may call.
generation: GenerationSampling settings.
thinking: ThinkingWhether to reason before answering.
response_schema: Option<Value>A JSON Schema the reply must match.
Providers that cannot do this say so through
crate::ModelCapabilities::structured_output. Check before you set it.
cache_breakpoints: Vec<usize>Where to place cache breakpoints, counted in messages from the start.
A provider without prompt caching ignores this. It costs money to get wrong in either direction, so it is explicit rather than inferred.
Implementations§
Source§impl ChatRequest
impl ChatRequest
Sourcepub fn new(model: impl Into<ModelId>, messages: Vec<Message>) -> Self
pub fn new(model: impl Into<ModelId>, messages: Vec<Message>) -> Self
A request with nothing set beyond the model and the conversation.
Sourcepub fn with_system(self, system: impl Into<String>) -> Self
pub fn with_system(self, system: impl Into<String>) -> Self
Sets the system instructions.
Sourcepub fn with_tools(self, tools: Vec<ToolSchema>) -> Self
pub fn with_tools(self, tools: Vec<ToolSchema>) -> Self
Offers the model a set of tools.
Sourcepub fn with_max_tokens(self, max: u32) -> Self
pub fn with_max_tokens(self, max: u32) -> Self
Caps the reply length.
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Sets the sampling temperature.
Sourcepub fn with_thinking(self, thinking: Thinking) -> Self
pub fn with_thinking(self, thinking: Thinking) -> Self
Asks the model to reason before answering.
Sourcepub fn with_response_schema(self, schema: Value) -> Self
pub fn with_response_schema(self, schema: Value) -> Self
Requires the reply to match a schema.
Sourcepub fn with_cache_breakpoint(self, after_message: usize) -> Self
pub fn with_cache_breakpoint(self, after_message: usize) -> Self
Places a cache breakpoint after the message at this index.
Sourcepub fn needs(&self) -> Needs
pub fn needs(&self) -> Needs
What this request needs a model to support.
Compare it against crate::Provider::capabilities to find out what will be
dropped before you send anything.
Trait Implementations§
Source§impl Clone for ChatRequest
impl Clone for ChatRequest
Source§fn clone(&self) -> ChatRequest
fn clone(&self) -> ChatRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more