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§
Sourcetype Response: WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned
type Response: WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned
The raw response type returned by the underlying completion model.
Sourcetype StreamingResponse: Clone + Unpin + WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned + GetTokenUsage
type StreamingResponse: Clone + Unpin + WasmCompatSend + WasmCompatSync + Serialize + DeserializeOwned + GetTokenUsage
The raw response type returned by the underlying completion model when streaming.
Required Methods§
Sourcefn make(client: &Self::Client, model: impl Into<String>) -> Self
fn make(client: &Self::Client, model: impl Into<String>) -> Self
Construct a model handle from a provider client and model identifier.
Sourcefn completion(
&self,
request: CompletionRequest,
) -> impl Future<Output = Result<CompletionResponse<Self::Response>, CompletionError>> + WasmCompatSend
fn completion( &self, request: CompletionRequest, ) -> impl Future<Output = Result<CompletionResponse<Self::Response>, CompletionError>> + WasmCompatSend
Generates a completion response for the given completion request.
fn stream( &self, request: CompletionRequest, ) -> impl Future<Output = Result<StreamingCompletionResponse<Self::StreamingResponse>, CompletionError>> + WasmCompatSend
Provided Methods§
Sourcefn completion_request(
&self,
prompt: impl Into<Message>,
) -> CompletionRequestBuilder<Self>
fn completion_request( &self, prompt: impl Into<Message>, ) -> CompletionRequestBuilder<Self>
Generates a completion request builder for the given prompt.
Sourcefn composes_native_output_with_tools(&self) -> bool
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.
impl CompletionModel for MockCompletionModel
test-utils only.