Skip to main content

Provider

Trait Provider 

Source
pub trait Provider:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn clone_box(&self) -> Box<dyn Provider + Send + Sync>;
    fn as_any(&self) -> &dyn Any;

    // 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.

Required Methods§

Source

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

Get provider name.

Source

fn clone_box(&self) -> Box<dyn Provider + Send + Sync>

Clone the provider as a boxed trait object.

Source

fn as_any(&self) -> &dyn Any

Convert self to Any for downcasting.

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.

Trait Implementations§

Source§

impl Clone for Box<dyn Provider + Send + Sync>

Clone for Box uses downcasting (Rust object safety limitation).

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§