Skip to main content

RequestAdapter

Trait RequestAdapter 

Source
pub trait RequestAdapter {
Show 13 methods // Required methods fn messages(&self) -> &[MessageNum]; fn messages_mut(&mut self) -> &mut Vec<MessageNum>; fn system_instructions(&self) -> Vec<&MessageNum>; fn response_json_schema(&self) -> Option<&Value>; fn preprend_system_instructions( &mut self, messages: Vec<MessageNum>, ) -> Result<(), TypeError>; fn get_py_system_instructions<'py>( &self, py: Python<'py>, ) -> Result<Bound<'py, PyList>, TypeError>; fn model_settings<'py>( &self, py: Python<'py>, ) -> Result<Bound<'py, PyAny>, TypeError>; fn to_request_body(&self) -> Result<Value, TypeError>; fn match_provider(&self, provider: &Provider) -> bool; fn build_provider_enum( messages: Vec<MessageNum>, system_instructions: Vec<MessageNum>, model: String, settings: ModelSettings, response_json_schema: Option<Value>, ) -> Result<ProviderRequest, TypeError>; fn set_response_json_schema(&mut self, response_json_schema: Option<Value>); fn add_tools( &mut self, tools: Vec<AgentToolDefinition>, ) -> Result<(), TypeError>; // Provided method fn insert_message(&mut self, message: MessageNum, idx: Option<usize>) { ... }
}
Expand description

Core trait that must be implemented for all request types

Required Methods§

Source

fn messages(&self) -> &[MessageNum]

Returns all messages in the request

Source

fn messages_mut(&mut self) -> &mut Vec<MessageNum>

Returns a mutable reference to the messages in the request

Source

fn system_instructions(&self) -> Vec<&MessageNum>

Returns all system instructions in the request

Source

fn response_json_schema(&self) -> Option<&Value>

Returns the response JSON schema if set

Source

fn preprend_system_instructions( &mut self, messages: Vec<MessageNum>, ) -> Result<(), TypeError>

Prepends system instructions to the messages

Source

fn get_py_system_instructions<'py>( &self, py: Python<'py>, ) -> Result<Bound<'py, PyList>, TypeError>

Returns the system instructions as a Python list

§Arguments
  • py - The Python GIL token
§Returns

Returns a Python list of system instruction messages

Source

fn model_settings<'py>( &self, py: Python<'py>, ) -> Result<Bound<'py, PyAny>, TypeError>

Returns the model settings for the request (python object)

Source

fn to_request_body(&self) -> Result<Value, TypeError>

Converts the request to a JSON value for sending to the provider

Source

fn match_provider(&self, provider: &Provider) -> bool

Checks if the request matches the given provider

Source

fn build_provider_enum( messages: Vec<MessageNum>, system_instructions: Vec<MessageNum>, model: String, settings: ModelSettings, response_json_schema: Option<Value>, ) -> Result<ProviderRequest, TypeError>

Builds a provider-specific request enum from the given parameters The ProviderRequest enum encapsulates all supported provider request types and is an attribute of the Prompt struct. ProviderRequest is built on instantiation of the Prompt

Source

fn set_response_json_schema(&mut self, response_json_schema: Option<Value>)

Sets the response JSON schema for the request Typically used as part of workflows when adding tasks

Source

fn add_tools( &mut self, tools: Vec<AgentToolDefinition>, ) -> Result<(), TypeError>

Adds tools to the request

Provided Methods§

Source

fn insert_message(&mut self, message: MessageNum, idx: Option<usize>)

Inserts a message at the specified index (or at the start if None)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§