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§
- Completion
Request - A request to complete a conversation
- Usage
- Token usage statistics
Enums§
- Provider
Error - Errors that can occur when using a provider
- Stop
Reason - Why the model stopped generating
- Stream
Event - Events emitted by a completion stream
Traits§
- Provider
- An LLM provider that can complete conversations
Type Aliases§
- Completion
Stream - A stream of completion events