A simple protocol adapter layer for LLM services.
Overview
llm-connector is a lightweight protocol adapter for connecting various LLM services. It handles protocol conversion and standardization without caring about specific API endpoints.
- Zero Hardcoded URLs: No default endpoints. You provide the
base_url - Protocol Agnostic: Support multiple LLM providers with unified interface
- Lightweight & Standalone: No external configuration management or database dependencies
Protocol Architecture
The src/protocols/ module uses adapter pattern to convert different vendor APIs into unified internal interface:
formats/: Protocol-agnostic data structuresadapters/: Vendor-specific protocol adapterscommon/: Shared utility functions
Installation
Minimum Rust Version: 1.85+
[]
= "1.0.2"
= { = "1", = ["full"] }
Usage
Basic Chat
use ;
let client = openai?;
let request = new
.add_message;
let response = client.chat.await?;
println!;
Streaming Response
use ;
use StreamExt;
let client = anthropic?;
let request = new.with_stream;
let mut stream = client.chat_stream.await?;
while let Some = stream.next.await
Builder Pattern
let client = builder
.openai
.base_url // Required
.timeout
.build?;
Advanced Features
Reasoning Models
Support for reasoning models like OpenAI o1/o3 and Claude 3.7 Sonnet.
use ReasoningEffort;
let request = new
.add_message
.with_thinking_budget // Enable thinking with 16k token budget
.with_max_tokens; // Ensure max_tokens > thinking_budget
let response = client.chat.await?;
File Upload
Support for uploading local files (images, PDFs, etc.) with automatic Base64 encoding and MIME type detection.
use MessageBlock;
let request = new
.add_message
.add_message_block;
let response = client.chat.await?;
License
MIT