Skip to main content

Module provider

Module provider 

Source
Expand description

Provider trait and types for LLM integrations

This module defines the abstraction layer for LLM providers (Anthropic, OpenAI, etc.). The key design principle is streaming-first: all completions return a stream of events.

§Architecture

CompletionRequest
       │
       ▼
┌─────────────┐
│  Provider   │  (Anthropic, OpenAI, etc.)
└─────────────┘
       │
       ▼
CompletionStream (StreamEvent, StreamEvent, ...)

§Example

ⓘ
use codive_core::provider::{Provider, CompletionRequest};
use tokio_stream::StreamExt;

async fn chat(provider: &dyn Provider) {
    let request = CompletionRequest::new("You are a helpful assistant")
        .with_message(Message::user("Hello!"));

    let mut stream = provider.complete(request).await?;
    while let Some(event) = stream.next().await {
        match event {
            StreamEvent::TextDelta { text } => print!("{}", text),
            StreamEvent::Done { .. } => break,
            _ => {}
        }
    }
}

Structs§

CompletionRequest
A request to complete a conversation
Usage
Token usage statistics

Enums§

ProviderError
Errors that can occur when using a provider
StopReason
Why the model stopped generating
StreamEvent
Events emitted by a completion stream

Traits§

Provider
An LLM provider that can complete conversations

Type Aliases§

CompletionStream
A stream of completion events