pub struct Request { /* private fields */ }
Expand description
A request to a language model.
Contains the conversation messages, available tools, and generation parameters. This is the primary input structure for language model interactions.
§Examples
use ai_types::llm::{Request, Message, model::Parameters};
// Simple request with messages
let messages = [
Message::system("You are a helpful assistant"),
Message::user("Hello!")
];
let request = Request::new(messages);
// Request with custom parameters - create new messages
let other_messages = [Message::user("Another message")];
let request = Request::new(other_messages)
.with_parameters(Parameters::default().temperature(0.7));
Implementations§
Source§impl Request
impl Request
Sourcepub const fn parameters(&self) -> &Parameters
pub const fn parameters(&self) -> &Parameters
Return parameters controlling model behavior and generation.
Source§impl Request
impl Request
Sourcepub fn new(messages: impl Into<Vec<Message>>) -> Self
pub fn new(messages: impl Into<Vec<Message>>) -> Self
Creates a new request with the given messages.
The request is initialized with default tools and parameters.
§Arguments
messages
- The conversation messages (can beVec<Message>
, array, etc.)
§Examples
use ai_types::llm::{Request, Message};
let messages = [Message::user("Hello, world!")];
let request = Request::new(messages);
Sourcepub fn oneshot(system: impl Into<String>, user: impl Into<String>) -> Self
pub fn oneshot(system: impl Into<String>, user: impl Into<String>) -> Self
Creates a request for a simple system/user conversation.
This is a convenience method that creates a two-message conversation with a system prompt and user message.
§Arguments
system
- The system message contentuser
- The user message content
§Examples
use ai_types::llm::Request;
let request = Request::oneshot(
"You are a helpful assistant",
"What is the capital of France?"
);
Sourcepub fn with_parameters(self, parameters: Parameters) -> Self
pub fn with_parameters(self, parameters: Parameters) -> Self
Sourcepub fn with_tool(self, tool: impl Tool) -> Self
pub fn with_tool(self, tool: impl Tool) -> Self
Adds a tool that the model can use.
§Arguments
tool
- The tool to add to this request
§Examples
use ai_types::llm::{Request, Message, Tool};
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(JsonSchema, Deserialize)]
struct MyToolArgs {
input: String,
}
struct MyTool;
impl Tool for MyTool {
const NAME: &str = "my_tool";
const DESCRIPTION: &str = "A test tool";
type Arguments = MyToolArgs;
async fn call(&mut self, args: Self::Arguments) -> ai_types::Result {
Ok(format!("Processed: {}", args.input))
}
}
let tool = MyTool;
let request = Request::new([Message::user("Hello")])
.with_tool(tool);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Request
impl !RefUnwindSafe for Request
impl Send for Request
impl !Sync for Request
impl Unpin for Request
impl !UnwindSafe for Request
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
Mutably borrows from an owned value. Read more