Expand description
Cognate Core — HTTP client, traits, and base types for LLM providers.
This crate provides the foundational abstractions for building provider-agnostic LLM applications with type-safe interfaces and zero-cost abstractions.
§Quick start
use cognate_core::{Provider, Request, Message};
async fn run<P: Provider>(provider: &P) -> cognate_core::Result<()> {
let response = provider
.complete(
Request::new()
.with_model("gpt-4o-mini")
.with_message(Message::user("Hello!")),
)
.await?;
println!("{}", response.content());
Ok(())
}Re-exports§
pub use error::Error;pub use error::Result;pub use middleware::Layer;pub use middleware::Middleware;pub use middleware::ProviderExt;pub use mock::MockProvider;pub use ratelimit::TokenBucket;
Modules§
- error
- Error types for Cognate.
- middleware
- Tower-inspired middleware system for Cognate providers.
- mock
- Mock provider for use in tests.
- ratelimit
- Token bucket rate limiting implementation
- types
- Re-exports of core types for ergonomic imports.
Structs§
- Choice
- A single completion choice within a
Response. - Chunk
- A single chunk in a streaming response.
- Delta
- The incremental content delta inside a
Chunk. - Message
- A single message in a conversation.
- Provider
Config - Configuration shared by all provider clients.
- Request
- A completion request sent to a provider.
- Response
- A completed response from a provider.
- Response
Format - Structured output format specifier.
- Tool
Call - A tool invocation requested by the model.
- Tool
Call Function - The function component of a
ToolCall. - Usage
- Token usage statistics for a request.
Enums§
- Role
- The role of a message sender.
Traits§
- Embedding
Provider - Trait for providers that can generate embedding vectors.
- Provider
- Core trait for all LLM providers.