Skip to main content

CompletionModel

Trait CompletionModel 

Source
pub trait CompletionModel: WasmCompatSend + WasmCompatSync {
    // Required methods
    fn completion(
        &self,
        request: CompletionRequest,
    ) -> impl Future<Output = Result<CompletionResponse, CompletionError>> + WasmCompatSend;
    fn stream(
        &self,
        request: CompletionRequest,
    ) -> impl Future<Output = Result<StreamingCompletionResponse, CompletionError>> + WasmCompatSend;

    // Provided methods
    fn completion_request(
        &self,
        prompt: impl Into<Message>,
    ) -> CompletionRequestBuilder<Self>
       where Self: Sized + Clone { ... }
    fn capabilities(&self) -> ProviderCapabilities { ... }
}
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.

Implementations return Rig’s normalized CompletionResponse and StreamingCompletionResponse; a provider’s own wire types stay on the provider’s side of this boundary, reachable through its inherent raw_completion/raw_stream methods. Model construction belongs to crate::client::completion::CompletionClient, not to this trait.

The trait demands only async service behavior — no Clone supertrait, in the spirit of tower::Service: cloning or sharing a model is the caller’s concern (wrap it in an Arc if needed). The Self::completion_request convenience gates on Self: Clone individually, which every built-in provider model satisfies.

Required Methods§

Source

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

Generates a completion response for the given completion request.

Source

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

Streams a completion response for the given completion request.

Provided Methods§

Source

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

Generates a completion request builder for the given prompt.

Source

fn capabilities(&self) -> ProviderCapabilities

Provider behavior a runtime should account for when preparing requests.

The default is conservative — see ProviderCapabilities. Override this to declare the capabilities a provider actually supports.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<M: CompletionModel + ?Sized> CompletionModel for Arc<M>

A shared model is a model: Arc<M> forwards every method to M, so the “wrap it in an Arc if needed” guidance holds through the generic APIs (CompletionRequestBuilder, agent construction), not just at direct call sites. Arc<M>: Clone always holds, so CompletionModel::completion_request clones the Arc — never the model.

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 InteractionsCompletionModel<T>
where T: HttpClientExt + Clone + Debug + Default + 'static,