Skip to main content

CompletionModel

Trait CompletionModel 

Source
pub trait CompletionModel:
    Clone
    + WasmCompatSend
    + WasmCompatSync {
    type Response: WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned;
    type StreamingResponse: Clone + Unpin + WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned + GetTokenUsage;
    type Client;

    // Required methods
    fn make(client: &Self::Client, model: impl Into<String>) -> Self;
    fn completion(
        &self,
        request: CompletionRequest,
    ) -> impl Future<Output = Result<CompletionResponse<Self::Response>, CompletionError>> + WasmCompatSend;
    fn stream(
        &self,
        request: CompletionRequest,
    ) -> impl Future<Output = Result<StreamingCompletionResponse<Self::StreamingResponse>, CompletionError>> + WasmCompatSend;

    // Provided methods
    fn completion_request(
        &self,
        prompt: impl Into<Message>,
    ) -> CompletionRequestBuilder<Self> { ... }
    fn composes_native_output_with_tools(&self) -> bool { ... }
}
Expand description

Trait defining a completion model that can be used to generate completion responses. This trait is meant to be implemented by the user to define a custom completion model, either from a third party provider (e.g.: OpenAI) or a local model.

Required Associated Types§

Source

type Response: WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned

The raw response type returned by the underlying completion model.

Source

type StreamingResponse: Clone + Unpin + WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned + GetTokenUsage

The raw response type returned by the underlying completion model when streaming.

Source

type Client

Provider client type used to construct this model.

Required Methods§

Source

fn make(client: &Self::Client, model: impl Into<String>) -> Self

Construct a model handle from a provider client and model identifier.

Source

fn completion( &self, request: CompletionRequest, ) -> impl Future<Output = Result<CompletionResponse<Self::Response>, CompletionError>> + WasmCompatSend

Generates a completion response for the given completion request.

Source

fn stream( &self, request: CompletionRequest, ) -> impl Future<Output = Result<StreamingCompletionResponse<Self::StreamingResponse>, CompletionError>> + WasmCompatSend

Provided Methods§

Source

fn completion_request( &self, prompt: impl Into<Message>, ) -> CompletionRequestBuilder<Self>

Generates a completion request builder for the given prompt.

Source

fn composes_native_output_with_tools(&self) -> bool

Whether this provider’s native structured output (output_schema -> format/response_format) composes with tool calls in the same multi-turn request without suppressing them.

Defaults to false (the safe assumption: the native constraint may make the model emit schema JSON instead of calling its tools — see issue #1928). Providers that enforce structured output and tool use together (e.g. OpenAI, Anthropic) override this to true, which lets the agent’s OutputMode::Auto keep using guaranteed native structured output even when the agent has tools.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl CompletionModel for MockCompletionModel

Available on crate feature test-utils only.
Source§

impl<Ext, H> CompletionModel for GenericCompletionModel<Ext, H>

Source§

impl<H> CompletionModel for rig_core::providers::copilot::CompletionModel<H>
where Client<H>: HttpClientExt + Clone + Debug + 'static, H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,

Source§

impl<H> CompletionModel for ResponsesCompletionModel<H>
where Client<H>: HttpClientExt + Clone + Debug + 'static, H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,

Source§

impl<T> CompletionModel for rig_core::providers::cohere::completion::CompletionModel<T>
where T: HttpClientExt + Clone + 'static,

Source§

impl<T> CompletionModel for rig_core::providers::gemini::completion::CompletionModel<T>
where T: HttpClientExt + Clone + 'static,

Source§

impl<T> CompletionModel for rig_core::providers::ollama::CompletionModel<T>
where T: HttpClientExt + Clone + Default + Debug + Send + 'static,

Source§

impl<T> CompletionModel for rig_core::providers::xai::completion::CompletionModel<T>
where T: HttpClientExt + Clone + Default + Debug + Send + 'static,

Source§

impl<T> CompletionModel for InteractionsCompletionModel<T>
where T: HttpClientExt + Clone + Debug + Default + 'static,