pub struct LLMRequest {
pub system: Option<String>,
pub messages: Vec<ChatMessage>,
pub temperature: f32,
pub max_tokens: Option<u32>,
pub model: Option<String>,
pub response_format: Option<ResponseFormat>,
pub tools: Option<Vec<ToolDefinition>>,
}Expand description
A chat completion request to an LLM provider.
This struct implements Default so callers can use struct-update syntax
to stay forward-compatible with future field additions:
let req = LLMRequest {
system: Some("...".into()),
messages: vec![ChatMessage::user("hi")],
..LLMRequest::default()
};New fields added to LLMRequest in future non-breaking releases are
absorbed by ..LLMRequest::default() and will not break such call sites
(unlike full struct literals, which must enumerate every field). For the
fluent equivalent, see LLMRequest::builder.
Fields§
§system: Option<String>Optional system prompt prepended to the conversation.
messages: Vec<ChatMessage>Ordered list of chat messages forming the conversation.
temperature: f32Sampling temperature (0.0–2.0).
max_tokens: Option<u32>Maximum tokens to generate. None uses the provider default.
model: Option<String>Model override for this request. None uses the client default.
response_format: Option<ResponseFormat>Desired response format. None uses the provider default.
Forwarded to the provider by OpenAIClient
(OpenAI response_format) and, for ResponseFormat::JsonSchema, by
AnthropicClient (Anthropic
output_config.format). ResponseFormat::Json without a schema has no
native Anthropic equivalent and is a no-op there.
tools: Option<Vec<ToolDefinition>>Tool definitions available to the model for this request.
Forwarded to both OpenAI (tools with type: "function") and Anthropic
(tools with input_schema). Any tool calls the model makes are returned
in LLMResponse::tool_calls.
Implementations§
Source§impl LLMRequest
impl LLMRequest
Sourcepub fn builder() -> LLMRequestBuilder
pub fn builder() -> LLMRequestBuilder
Create a new builder for constructing an LLMRequest.
Sourcepub fn into_openai_messages(self) -> Vec<(String, String)>
pub fn into_openai_messages(self) -> Vec<(String, String)>
Convert into OpenAI-format messages, consuming the request.
Prepends a system message if self.system is set.
Sourcepub fn into_anthropic_messages(self) -> Vec<(String, String)>
pub fn into_anthropic_messages(self) -> Vec<(String, String)>
Convert into Anthropic-format messages, consuming the request.
Returns only user/assistant messages (system is handled separately by Anthropic API).
Trait Implementations§
Source§impl Clone for LLMRequest
impl Clone for LLMRequest
Source§fn clone(&self) -> LLMRequest
fn clone(&self) -> LLMRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LLMRequest
impl Debug for LLMRequest
Source§impl Default for LLMRequest
impl Default for LLMRequest
Source§impl<'de> Deserialize<'de> for LLMRequest
impl<'de> Deserialize<'de> for LLMRequest
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for LLMRequest
impl RefUnwindSafe for LLMRequest
impl Send for LLMRequest
impl Sync for LLMRequest
impl Unpin for LLMRequest
impl UnsafeUnpin for LLMRequest
impl UnwindSafe for LLMRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.