Skip to main content

CompletionModel

Trait CompletionModel 

Source
pub trait CompletionModel {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn name(&self) -> &str;
    fn model(&self) -> &str;
    fn chat_stream<'life0, 'async_trait>(
        &'life0 self,
        req: ChatRequest,
    ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamChunk, Self::Error>>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Provider-agnostic streaming completion contract.

Implementors map ChatRequest to the provider’s wire format, open the streaming response, and translate per-chunk events into StreamChunks. Implementations must be Send + Sync because RetryingModel and the engine hold them across await boundaries; the trait does not declare these super-bounds yet — every use site adds them — but new implementations should satisfy them.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Error type for the model’s transport / setup failures. Implement crate::Retryable on it to make the model composable with RetryingModel.

Required Methods§

Source

fn name(&self) -> &str

Adapter family name used in telemetry, e.g. "anthropic" or "azure-openai". Stable across model ids — changing model name does not change this.

Source

fn model(&self) -> &str

Model identifier this handle is bound to: Anthropic model id ("claude-sonnet-4-5"), Azure deployment name, etc. The engine surfaces this in tracing and the JSON tracer envelope.

Source

fn chat_stream<'life0, 'async_trait>( &'life0 self, req: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamChunk, Self::Error>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Open a streaming completion. Returns a stream of Result<StreamChunk, Self::Error> so per-chunk transport errors can be surfaced mid-stream. Setup-time failures (auth, schema, transport open) return the outer Err.

Implementors§