pub struct GenericCompletionModel<Ext = OpenAICompletionsExt, H = Client> {
pub model: String,
/* private fields */
}Expand description
A chat-completions model over any OpenAICompatibleProvider extension.
This is the advertised path for OpenAI-compatible providers; see the
provider checklist in crate::providers.
Fields§
§model: StringImplementations§
Source§impl<Ext, H> GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + 'static,
Ext: Provider + OpenAICompatibleProvider + Clone + WasmCompatSend + 'static,
impl<Ext, H> GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + 'static,
Ext: Provider + OpenAICompatibleProvider + Clone + WasmCompatSend + 'static,
Sourcepub async fn raw_stream(
&self,
completion_request: CompletionRequest,
) -> Result<RawStreamingResult<StreamingCompletionResponse<Ext::StreamingUsage>>, CompletionError>
pub async fn raw_stream( &self, completion_request: CompletionRequest, ) -> Result<RawStreamingResult<StreamingCompletionResponse<Ext::StreamingUsage>>, CompletionError>
Open a chat-completions stream whose terminal record stays provider-native.
This is the escape hatch for provider-specific terminal fields rig does
not normalize. It shares the request builder, transport, telemetry, and
error handling with
CompletionModel::stream,
which calls it and normalizes the terminal record — one network request
either way.
Source§impl<Ext, H> GenericCompletionModel<Ext, H>
impl<Ext, H> GenericCompletionModel<Ext, H>
pub fn new(client: Client<Ext, H>, model: impl Into<String>) -> Self
Sourcepub fn with_strict_tools(self) -> Self
pub fn with_strict_tools(self) -> Self
Enable strict mode for tool schemas.
When enabled, tool schemas are automatically sanitized to meet OpenAI’s strict mode requirements:
additionalProperties: falseis added to all objects- All properties are marked as required
strict: trueis set on each function definition
This allows OpenAI to guarantee that the model’s tool calls will match the schema exactly.
pub fn with_tool_result_array_content(self) -> Self
Source§impl<Ext, H> GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
Ext: Provider + OpenAICompatibleProvider + DebugExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,
impl<Ext, H> GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
Ext: Provider + OpenAICompatibleProvider + DebugExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,
Sourcepub async fn raw_completion(
&self,
completion_request: CoreCompletionRequest,
) -> Result<Ext::Response, CompletionError>
pub async fn raw_completion( &self, completion_request: CoreCompletionRequest, ) -> Result<Ext::Response, CompletionError>
Execute a chat completion and return the provider’s own wire response.
This is the escape hatch for provider-specific fields rig does not
normalize. It shares the request builder, transport, telemetry, and
error handling with
CompletionModel::completion,
which calls it and then applies the provider-local mapping — one
network request either way.
The transport request id is not on the wire type and is dropped here;
use Self::raw_completion_with_request_id when the typed route must
reproduce everything completion returns.
Sourcepub async fn raw_completion_with_request_id(
&self,
completion_request: CoreCompletionRequest,
) -> Result<(Ext::Response, Option<String>), CompletionError>
pub async fn raw_completion_with_request_id( &self, completion_request: CoreCompletionRequest, ) -> Result<(Ext::Response, Option<String>), CompletionError>
Self::raw_completion plus the transport request id from the
provider’s request-id response header (OpenAICompatibleProvider::REQUEST_ID_HEADER).
The pair exists because the wire type is substitutable — Ext::Response
is whatever the compatible provider parses — so the transport id cannot
live on it, while the normalized completion::CompletionResponse
carries one. Without this method, raw_completion(..) followed by
normalize
would silently lack the provider_request_id that
CompletionModel::completion
reports — the typed escape hatch would not reproduce the normalized
path. Reassemble with
with_optional_provider_request_id.
Source§impl<H> GenericCompletionModel<OpenRouterExt, H>
impl<H> GenericCompletionModel<OpenRouterExt, H>
Sourcepub fn with_prompt_caching(self) -> Self
pub fn with_prompt_caching(self) -> Self
Enable explicit prompt caching for supported OpenRouter models.
Adds cache_control: {"type": "ephemeral"} to the system-prompt
block so subsequent turns that share the same system prefix can be
billed at the cache-hit rate when the selected model/provider supports
explicit cache breakpoints.
Trait Implementations§
Source§impl<Ext: Clone, H: Clone> Clone for GenericCompletionModel<Ext, H>
impl<Ext: Clone, H: Clone> Clone for GenericCompletionModel<Ext, H>
Source§fn clone(&self) -> GenericCompletionModel<Ext, H>
fn clone(&self) -> GenericCompletionModel<Ext, H>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Ext, H> CompletionModel for GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
Ext: Provider + OpenAICompatibleProvider + DebugExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,
impl<Ext, H> CompletionModel for GenericCompletionModel<Ext, H>where
Client<Ext, H>: HttpClientExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
Ext: Provider + OpenAICompatibleProvider + DebugExt + Clone + WasmCompatSend + WasmCompatSync + 'static,
H: Clone + Default + Debug + WasmCompatSend + WasmCompatSync + 'static,
Source§fn capabilities(&self) -> ProviderCapabilities
fn capabilities(&self) -> ProviderCapabilities
Source§async fn completion(
&self,
completion_request: CoreCompletionRequest,
) -> Result<CompletionResponse, CompletionError>
async fn completion( &self, completion_request: CoreCompletionRequest, ) -> Result<CompletionResponse, CompletionError>
Source§async fn stream(
&self,
request: CoreCompletionRequest,
) -> Result<StreamingCompletionResponse, CompletionError>
async fn stream( &self, request: CoreCompletionRequest, ) -> Result<StreamingCompletionResponse, CompletionError>
Source§fn completion_request(
&self,
prompt: impl Into<Message>,
) -> CompletionRequestBuilder<Self>
fn completion_request( &self, prompt: impl Into<Message>, ) -> CompletionRequestBuilder<Self>
prompt.Source§impl<Ext, H> ConstructCompletionModel<Client<Ext, H>> for GenericCompletionModel<Ext, H>
impl<Ext, H> ConstructCompletionModel<Client<Ext, H>> for GenericCompletionModel<Ext, H>
Auto Trait Implementations§
impl<Ext, H> Freeze for GenericCompletionModel<Ext, H>
impl<Ext, H> RefUnwindSafe for GenericCompletionModel<Ext, H>where
H: RefUnwindSafe,
Ext: RefUnwindSafe,
impl<Ext, H> Send for GenericCompletionModel<Ext, H>
impl<Ext, H> Sync for GenericCompletionModel<Ext, H>
impl<Ext, H> Unpin for GenericCompletionModel<Ext, H>
impl<Ext, H> UnsafeUnpin for GenericCompletionModel<Ext, H>where
H: UnsafeUnpin,
Ext: UnsafeUnpin,
impl<Ext, H> UnwindSafe for GenericCompletionModel<Ext, H>where
H: UnwindSafe,
Ext: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more