Skip to main content

Provider

Trait Provider 

Source
pub trait Provider:
    Send
    + Sync
    + 'static {
    // Required method
    fn name(&self) -> &'static str;

    // Provided methods
    fn normalize_model(&self, model: String) -> String { ... }
    fn chat_completions_path(&self) -> String { ... }
    fn transform_request(&self, _request: &mut ChatRequest) { ... }
    fn transform_response(&self, _response: &mut ChatResponse) { ... }
    fn transform_stream_chunk(&self, _chunk: &mut ChatStreamChunk) { ... }
}
Expand description

Provider trait for LLM provider-specific transformations.

Each Chinese LLM provider may have slightly different API requirements or model name formats that need to be normalized.

Implementations are expected to be stateless so a single instance can be shared across all requests via Arc<dyn Provider>.

Required Methods§

Source

fn name(&self) -> &'static str

Get provider name.

Provided Methods§

Source

fn normalize_model(&self, model: String) -> String

Normalize model name from Responses API to provider’s format.

Source

fn chat_completions_path(&self) -> String

Get the chat completions path for this provider. Only returns the endpoint path, e.g., “/chat/completions”. The version prefix (e.g., “/v1”) should come from the backend URL’s base_path.

Source

fn transform_request(&self, _request: &mut ChatRequest)

Transform request before sending to provider.

This is called after the standard conversion but before sending to the upstream provider. Providers can modify the request to handle API differences.

Source

fn transform_response(&self, _response: &mut ChatResponse)

Transform response after receiving from provider.

This is called after receiving the response but before converting to Responses API format. Providers can normalize response format.

Source

fn transform_stream_chunk(&self, _chunk: &mut ChatStreamChunk)

Transform streaming chunk in real-time.

This is called for each SSE chunk received from the provider. Providers can modify chunk content before event conversion.

Implementors§