Struct Request

Source
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

Source

pub const fn tools(&self) -> &Tools

Return available tools that the model can call.

Source

pub const fn parameters(&self) -> &Parameters

Return parameters controlling model behavior and generation.

Source

pub const fn messages(&self) -> &[Message]

Return the conversation messages to send to the model.

Source§

impl Request

Source

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 be Vec<Message>, array, etc.)
§Examples
use ai_types::llm::{Request, Message};

let messages = [Message::user("Hello, world!")];
let request = Request::new(messages);
Source

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 content
  • user - 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?"
);
Source

pub fn with_parameters(self, parameters: Parameters) -> Self

Sets the generation parameters for this request.

§Arguments
  • parameters - The model parameters to use
§Examples
use ai_types::llm::{Request, Message, model::Parameters};

let request = Request::new([Message::user("Hello")])
    .with_parameters(Parameters::default().temperature(0.7));
Source

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§

Source§

impl Debug for Request

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Request

Source§

fn default() -> Request

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,