Babel
Babel is a Rust library designed to simplify interactions with various LLM (Large Language Model) providers. It provides a unified interface for making API calls to different LLM services while handling the variations in model naming conventions across providers.
Features
- Provider-agnostic API: Interact with different LLM providers using a consistent interface
- Enum-based model selection: Get IDE autocompletion for available models
- Streaming support: Process responses as they arrive for real-time applications
- Regular request support: Get complete responses in a single call
- Type-safe model mapping: Map Rust enums to provider-specific model strings
Installation
Add Babel to your Cargo.toml:
[]
= "0.0.3"
Supported Providers
Currently, Babel supports the following providers:
- Groq
- OpenRouter (API compatible)
- SambaNova
Quick Start
Here's a simple example of using Babel with Groq:
use ;
use tokio;
async
API Authentication
Babel supports two methods for API authentication:
- Direct API key: Pass your API key directly to the builder
- Environment variables: Store your API keys in environment variables following the pattern
{PROVIDER_NAME}_API_KEY(e.g.,GROQ_API_KEY)
Multi-turn Conversations
Babel makes it easy to maintain conversation history:
// Start a conversation
let mut conversation = vec!;
// Get first response
let response = llm.chat.await?;
// Add response to conversation history
conversation.push;
// Add next user message
conversation.push;
// Continue the conversation
let next_response = llm.chat.await?;
Streaming Responses
For applications that need to process responses as they arrive:
let mut stream = llm.stream_chat.await;
while let Some = stream.next.await
Adding New Providers
Babel is designed to be extensible. To add a new provider:
- Create a new module for your provider
- Define a provider struct and implement the
Providertrait - Define a model enum and use the
define_provider_models!macro to implement theModeltrait
Example:
use ;
// Define your provider
;
// Define models for your provider
define_provider_models!;
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.