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§
Provided Methods§
Sourcefn normalize_model(&self, model: String) -> String
fn normalize_model(&self, model: String) -> String
Normalize model name from Responses API to provider’s format.
Sourcefn chat_completions_path(&self) -> String
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.
Sourcefn transform_request(&self, _request: &mut ChatRequest)
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.
Sourcefn transform_response(&self, _response: &mut ChatResponse)
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.
Sourcefn transform_stream_chunk(&self, _chunk: &mut ChatStreamChunk)
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.