ferrous-llm-core
Core traits and types for the ferrous-llm ecosystem. This crate provides the foundational abstractions that all LLM providers implement, including traits for chat, completion, streaming, and tool calling, as well as standardized request/response types and error handling.
Overview
ferrous-llm-core
is the foundation crate that defines the common interface for all LLM providers in the ferrous-llm ecosystem. It follows the Interface Segregation Principle, allowing providers to implement only the capabilities they support.
Features
- Core Traits: Foundational traits for chat, completion, streaming, and specialized capabilities
- Standardized Types: Common request/response types across all providers
- Error Handling: Unified error types and handling patterns
- Configuration: Base configuration traits and utilities
- Type Safety: Leverages Rust's type system for safe LLM interactions
- Async Support: Full async/await support with proper trait bounds
Installation
Add this to your Cargo.toml
:
[]
= "0.2.0"
Core Traits
ChatProvider
The primary trait for chat-based LLM interactions:
use ;
StreamingProvider
Extends ChatProvider
with streaming capabilities:
use ;
use Stream;
Specialized Traits
CompletionProvider
- Text completion (non-chat) capabilitiesToolProvider
- Function/tool calling supportEmbeddingProvider
- Text embedding generationImageProvider
- Image generation capabilitiesSpeechToTextProvider
- Speech transcriptionTextToSpeechProvider
- Speech synthesis
Core Types
ChatRequest
Standard request structure for chat interactions:
use ;
let request = ChatRequest ;
Message Types
Role
- System, User, Assistant, ToolMessageContent
- Text, Image, or Mixed contentParameters
- Generation parameters (temperature, max_tokens, etc.)Metadata
- Request metadata and extensions
Response Types
All providers implement standardized response traits:
use ChatResponse;
// Common response interface
Error Handling
Unified error handling across all providers:
use ;
Configuration
Base configuration trait for all providers:
use ProviderConfig;
Usage Example
use ;
// This example shows how to use the core types
// Actual provider implementations are in separate crates
async
Provider Implementation
To implement a new provider, create a struct that implements the relevant traits:
use ;
use async_trait;
Testing
The core crate includes utilities for testing provider implementations:
cargo test
Contributing
This crate is part of the ferrous-llm workspace. See the main repository for contribution guidelines.
License
Licensed under the Apache License 2.0. See LICENSE for details.