Skip to main content

NormalizeCompletionResponse

Trait NormalizeCompletionResponse 

Source
pub trait NormalizeCompletionResponse {
    // Required method
    fn normalize(
        self,
        provider: &str,
    ) -> Result<CompletionResponse, CompletionError>;
}
Expand description

Convert a provider’s own completion payload into the normalized CompletionResponse.

The provider descriptor name is an input rather than something the conversion knows, because several providers share one wire shape — the OpenAI chat-completions payload is used by more than a dozen of them. A conversion that hardcoded a name would mislabel every provider but one, and a placeholder overwritten by the caller would be correct only by convention.

This is a trait rather than TryFrom<(&str, T)> for a concrete reason: a tuple is not a local type, so impl TryFrom<(&str, TheirResponse)> for CompletionResponse is rejected by the orphan rule in any crate other than rig-core. Implementing this trait on a provider’s own response type is allowed anywhere, which keeps provider extensions implementable outside this crate.

Required Methods§

Source

fn normalize( self, provider: &str, ) -> Result<CompletionResponse, CompletionError>

Normalize this payload, attributing it to provider.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::anthropic::completion::CompletionResponse

Normalize an Anthropic Messages response.

The provider descriptor name is an input rather than a constant: this same wire shape is served by every Anthropic-compatible provider (MiniMax, Z.ai, Moonshot, Xiaomi MiMo), so baking in "anthropic" here would mislabel all of them. Taking it as part of the conversion makes the correct name impossible to forget.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::deepseek::CompletionResponse

Normalize a DeepSeek chat completion response.

The provider descriptor name is an input rather than a constant so the shared OpenAI-compatible completion path labels the response with the descriptor that actually produced it, exactly as it does for the OpenAI wire type.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::mira::CompletionResponse

Normalize a Mira chat completion response.

The provider descriptor name is an input rather than a constant so the shared OpenAI-compatible completion path labels the response with the descriptor that actually produced it.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::mistral::CompletionResponse

Normalize a Mistral chat completion response.

The provider descriptor name is an input rather than a constant so the shared OpenAI-compatible completion path labels the response with the descriptor that actually produced it.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::openai::CompletionResponse

Normalize an OpenAI-compatible chat completion response.

The provider descriptor name is an input rather than a constant: this same wire shape is shared by every OpenAI-compatible provider, so baking in "openai" here would mislabel Groq, Together, DeepSeek and the rest. Taking it as part of the conversion makes the correct name impossible to forget.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::xai::CompletionResponse

Normalize an OpenAI Responses API completion.

The provider descriptor name is an input rather than a constant: ChatGPT and Copilot return this exact wire shape, so hardcoding "openai" here would mislabel them. Taking it as part of the conversion makes the correct name impossible to forget.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::openrouter::CompletionResponse

Normalize an OpenRouter chat completion response.

The provider descriptor name is an input because the message model is the shared OpenAI one; taking it as part of the conversion keeps the shape consistent with the OpenAI-compatible path even though only OpenRouter produces this envelope.

Source§

impl NormalizeCompletionResponse for rig_agent::core::providers::venice::CompletionResponse

Source§

impl NormalizeCompletionResponse for CopilotCompletionResponse

The forward direction for the route-tagged raw type, so CompletionModel::raw_completion followed by normalize is a complete typed route regardless of which route answered — each variant delegates to its wire type’s own conversion. This is also what completion::CompletionModel::completion uses, so the two cannot drift.