pub struct UnifiedLLMRequest {
pub messages: Vec<UnifiedMessage>,
pub response_schema: Option<Value>,
pub config: Option<RequestConfig>,
}Expand description
A complete request to an LLM provider.
Bundles messages, optional response schema, and request configuration into a single structure that can be passed to any provider.
§Basic Usage
use multi_llm::{UnifiedLLMRequest, UnifiedMessage};
let messages = vec![
UnifiedMessage::system("You are a helpful assistant."),
UnifiedMessage::user("Hello!"),
];
let request = UnifiedLLMRequest::new(messages);§With Configuration
use multi_llm::{UnifiedLLMRequest, UnifiedMessage, RequestConfig};
let messages = vec![UnifiedMessage::user("Hello!")];
let config = RequestConfig {
temperature: Some(0.7),
max_tokens: Some(1000),
..Default::default()
};
let request = UnifiedLLMRequest::with_config(messages, config);§Structured Output
For JSON-structured responses (useful for data extraction):
use multi_llm::{UnifiedLLMRequest, UnifiedMessage};
let messages = vec![UnifiedMessage::user("Extract the name and age.")];
let schema = serde_json::json!({
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
},
"required": ["name", "age"]
});
let request = UnifiedLLMRequest::with_schema(messages, schema);§Message Ordering
Use sort_messages() to order by priority and timestamp:
use multi_llm::{UnifiedLLMRequest, UnifiedMessage};
let messages = vec![
UnifiedMessage::current_user("Hello!".to_string()), // priority 30
UnifiedMessage::system_instruction("Be helpful.".to_string(), None), // priority 0
];
let mut request = UnifiedLLMRequest::new(messages);
request.sort_messages(); // System instruction now firstFields§
§messages: Vec<UnifiedMessage>All messages for this request.
Use sort_messages() to order by priority.
response_schema: Option<Value>Optional JSON schema for structured output.
When provided, the LLM will attempt to return a response that conforms to this schema. Useful for data extraction tasks.
config: Option<RequestConfig>Optional configuration overrides for this request.
When None, the provider’s default configuration is used.
Implementations§
Source§impl UnifiedLLMRequest
impl UnifiedLLMRequest
Sourcepub fn new(messages: Vec<UnifiedMessage>) -> Self
pub fn new(messages: Vec<UnifiedMessage>) -> Self
Create a new request with messages
Sourcepub fn with_schema(messages: Vec<UnifiedMessage>, schema: Value) -> Self
pub fn with_schema(messages: Vec<UnifiedMessage>, schema: Value) -> Self
Create a new request with schema
Sourcepub fn with_config(messages: Vec<UnifiedMessage>, config: RequestConfig) -> Self
pub fn with_config(messages: Vec<UnifiedMessage>, config: RequestConfig) -> Self
Create a new request with config
Sourcepub fn sort_messages(&mut self)
pub fn sort_messages(&mut self)
Sort messages by priority and timestamp
Sourcepub fn get_sorted_messages(&self) -> Vec<&UnifiedMessage>
pub fn get_sorted_messages(&self) -> Vec<&UnifiedMessage>
Get messages sorted by priority (does not modify original)
Sourcepub fn get_system_messages(&self) -> Vec<&UnifiedMessage>
pub fn get_system_messages(&self) -> Vec<&UnifiedMessage>
Get system messages
Sourcepub fn get_conversation_messages(&self) -> Vec<&UnifiedMessage>
pub fn get_conversation_messages(&self) -> Vec<&UnifiedMessage>
Get non-system messages
Sourcepub fn get_cacheable_messages(&self) -> Vec<&UnifiedMessage>
pub fn get_cacheable_messages(&self) -> Vec<&UnifiedMessage>
Get cacheable messages
Trait Implementations§
Source§impl Clone for UnifiedLLMRequest
impl Clone for UnifiedLLMRequest
Source§fn clone(&self) -> UnifiedLLMRequest
fn clone(&self) -> UnifiedLLMRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more