llm-connector
- English | δΈζ
A lightweight Rust library for protocol adaptation across multiple LLM providers. This library focuses solely on converting between different LLM provider APIs and providing a unified OpenAI-compatible interface.
π― What llm-connector Does
Core Purpose: Protocol adaptation and API normalization
- β Protocol Conversion: Convert different LLM provider APIs to OpenAI-compatible format
- β Request/Response Standardization: Unified data structures across providers
- β Streaming Adaptation: Normalize SSE streams from different providers
- β Provider Abstraction: Extensible trait system for adding new providers
- β Simple Configuration: Basic API key and endpoint management
π« What llm-connector Does NOT Do
This library intentionally does not include:
- β Load balancing (use a reverse proxy or service mesh)
- β Health checking (use external monitoring)
- β Circuit breaking (use infrastructure-level solutions)
- β Complex routing strategies (keep it simple)
- β Built-in metrics collection (use tracing/metrics crates)
- β Request queuing or rate limiting
Features
- Provider-agnostic types: Unified request/response structures
- Simple provider trait: Easy to implement new providers
- Streaming support: Unified SSE handling across providers
- Minimal dependencies: Focused on core functionality
- OpenAI compatibility: Drop-in replacement for OpenAI client
Supported Providers
- OpenAI - GPT models (gpt-4, gpt-3.5-turbo, etc.)
- Anthropic - Claude models (claude-3-5-sonnet, claude-3-haiku, etc.)
- DeepSeek - DeepSeek models (deepseek-chat, deepseek-coder, etc.)
- Zhipu GLM - GLM models (glm-4, glm-3-turbo, etc.)
- Alibaba Qwen - Qwen models (qwen-turbo, qwen-plus, etc.)
- Moonshot Kimi - Kimi models (moonshot-v1-8k, moonshot-v1-32k, etc.)
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Basic Usage
use ;
async
Configuration
Environment Variables (Recommended)
Set environment variables for the providers you want to use:
# OpenAI
# optional
# DeepSeek
# optional
# Anthropic
# optional
# Add other providers as needed...
Explicit Configuration
use ;
let config = Config ;
let client = with_config;
Streaming
use StreamExt;
use ;
async
Model Naming Convention
Use the format provider/model for explicit provider selection:
// Explicit provider selection (recommended)
"openai/gpt-4"
"anthropic/claude-3-5-sonnet-20241022"
"deepseek/deepseek-chat"
"glm/glm-4"
"qwen/qwen-turbo"
"kimi/moonshot-v1-8k"
// Direct model names (auto-detected)
"gpt-4" // -> openai/gpt-4
"claude-3-haiku" // -> anthropic/claude-3-haiku
"deepseek-chat" // -> deepseek/deepseek-chat
Error Handling
The library provides structured error types:
use ;
match client.chat.await
Extending with New Providers
Implement the Provider trait to add support for new LLM providers:
use ;
use async_trait;
Design Philosophy
llm-connector follows the Unix philosophy: "Do one thing and do it well."
- Single Responsibility: Only handles protocol adaptation between LLM providers
- Minimal Dependencies: Keeps the dependency tree small and focused
- Composable: Designed to be used as a building block in larger systems
- No Magic: Explicit configuration and clear error messages
- Provider Agnostic: Treats all providers equally, no special cases
What's NOT Included (By Design)
If you need these features, consider these alternatives:
- Load Balancing: Use nginx, HAProxy, or a service mesh
- Rate Limiting: Use Redis-based rate limiters or API gateways
- Caching: Use Redis, Memcached, or HTTP caching proxies
- Monitoring: Use Prometheus, Grafana, or APM solutions
- Circuit Breaking: Use Hystrix-style libraries or service mesh features
- Request Queuing: Use message queues like RabbitMQ or Apache Kafka
Contributing
We welcome contributions! Please focus on:
- Adding new providers - Implement the
Providertrait - Improving protocol compatibility - Better OpenAI API compliance
- Bug fixes - Especially around streaming and error handling
- Documentation - Examples and provider-specific notes
Please avoid adding features outside the core scope (load balancing, complex routing, etc.).
License
MIT