统一的LLM调用库,支持多种LLM提供商
Project description
LLM Hub - Unified LLM Calling Library
A unified calling library supporting multiple LLM providers (International + Chinese AI), providing a consistent API interface.
✨ Features
- 🔌 Unified API - One interface for all LLM providers
- 🌍 Multi-Provider Support - OpenAI, DeepSeek, Kimi, Gemini, Claude, etc.
- 🇨🇳 Chinese AI Support - Qwen, GLM, ERNIE, MiniCPM
- 💻 Local Deployment - Ollama, llama.cpp
- 🤔 Reasoning Mode - Display thinking process (DeepSeek support)
- 📊 Accurate Token Counting - Official tokenizers for each provider
- 📡 Streaming Output - Real-time response generation
- 💾 Configuration Management - JSON/YAML config, profiles, environment variables
- 🔌 Plugin System - Support for third-party Provider extensions
📋 Supported Providers
| Provider | Type | Token Counting | Reasoning Mode |
|---|---|---|---|
| OpenAI | Cloud | ✅ tiktoken | ❌ |
| DeepSeek | Cloud | ✅ deepseek-tokenizer | ✅ |
| Kimi | Cloud | ✅ API | ❌ |
| Google Gemini | Cloud | ⚠️ Estimation | ❌ |
| Anthropic Claude | Cloud | ⚠️ Estimation | ❌ |
| Qwen | Cloud | ✅ qwen-tokenizer | ❌ |
| GLM | Cloud | ✅ transformers | ❌ |
| ERNIE | Cloud | ✅ transformers | ❌ |
| MiniCPM | Cloud/Local | ✅ transformers | ❌ |
| Ollama | Local | ✅ API tokenize | ❌ |
| llama.cpp | Local | ✅ Subprocess | ❌ |
🚀 Quick Start
Installation
# Basic installation
pip install gracefox-llm-hub
# Install environment sensing support (system resource monitoring)
pip install gracefox-llm-hub[env]
# Install accurate token counting
pip install gracefox-llm-hub[tokenizers]
# Install secure encryption support
pip install gracefox-llm-hub[secure]
# Install YAML config support
pip install gracefox-llm-hub[yaml]
# Install all features
pip install gracefox-llm-hub[all]
Basic Usage
from llm_hub import LLMClient, LLMConfig, Provider
# Create DeepSeek client
client = LLMClient(LLMConfig(
provider=Provider.DEEPSEEK,
model="deepseek-chat",
api_key="your-api-key"
))
# Single round conversation
response = client.chat("What is artificial intelligence?")
print(response.content)
📖 Complete API usage examples can be found in the docs/ directory
⚙️ Configuration
Configuration File Format
{
"provider": "deepseek",
"model": "deepseek-chat",
"api_key": "your-api-key",
"temperature": 0.7,
"max_tokens": 2000,
"reasoning": true,
"stream": true
}
Environment Variables
export LLM_PROVIDER=deepseek
export LLM_MODEL=deepseek-chat
export LLM_API_KEY=your-key
export LLM_TEMPERATURE=0.7
Configuration Priority (Low to High)
- Default configuration
- Environment variables
- Configuration profiles
- Configuration files
- JSON string
- Code parameters
📦 Project Structure
llm-hub/
├── llm_hub/
│ ├── core/ # Core functionality
│ │ ├── client.py # Main client
│ │ ├── enums.py # Enum definitions
│ │ └── exceptions.py # Exception definitions
│ ├── config/ # Configuration management
│ │ ├── config.py # Configuration class
│ │ ├── manager.py # Configuration manager
│ │ └── security.py # Encryption and security
│ ├── models/ # Data models
│ │ ├── message.py # Message and Conversation
│ │ └── response.py # Response models
│ ├── providers/ # Provider implementations
│ │ ├── base.py # Base classes
│ │ ├── factory.py # Factory and plugin system
│ │ ├── deepseek.py # DeepSeek
│ │ ├── qwen.py # Qwen
│ │ ├── glm.py # GLM
│ │ ├── ernie.py # ERNIE
│ │ ├── minicpm.py # MiniCPM
│ │ └── ...
│ ├── environment/ # Environment sensing (optional)
│ └── utils/ # Utility functions
│ ├── token_counter.py # Token counting
│ ├── stream_handler.py # Stream handling
│ ├── rate_limiter.py # Rate limiting
│ └── logger.py # Logging system
├── docs/ # API documentation and examples
├── examples/ # Example code
├── pyproject.toml # Project configuration
└── README.md # This document
🔧 Development Guide
# Clone repository
git clone https://gitee.com/SteHub/llm-hub.git
cd llm-hub
# Development installation
pip install -e .[dev,all]
# Code formatting
black llm_hub/
# Code linting
ruff check llm_hub/
# Type checking
mypy llm_hub/
🔌 Plugin System
LLM Hub supports third-party Provider extensions through the entry points mechanism.
Developing Third-party Providers
# setup.py
from setuptools import setup
setup(
name="my-llm-provider",
entry_points={
"llm_hub.providers": [
"my_provider = my_package:MyProvider",
]
}
)
After installation, it will be automatically discovered without modifying llm_hub code.
🤝 Contributing
Contributions are welcome! Please feel free to submit Pull Requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
📄 License
GNU General Public License v3.0 - See LICENSE file for details
📧 Contact
- Author: GraceFox
- Email: 948743980@qq.com
- Homepage: https://gitee.com/SteHub/llm-hub
- Issues: https://gitee.com/SteHub/llm-hub/issues
Quick Reference
Installation Options
| Option | Description | Dependencies |
|---|---|---|
[env] |
Environment sensing | psutil |
[tokenizers] |
Accurate token counting | tiktoken, transformers |
[secure] |
Secure encryption | cryptography |
[yaml] |
YAML configuration | pyyaml |
[all] |
All features | All of the above |
Supported Providers
| Provider | Config Value | Example Model |
|---|---|---|
| OpenAI | openai |
gpt-3.5-turbo |
| DeepSeek | deepseek |
deepseek-chat |
| Kimi | kimi |
moonshot-v1-8k |
| Qwen | qwen |
qwen-turbo |
| GLM | glm |
glm-4-flash |
| ERNIE | ernie |
ernie-3.5-8k |
| MiniCPM | minicpm |
minicpm |
| Ollama | ollama |
llama2 |
| llama.cpp | llama_cpp |
llama-2-7b |
API Key Acquisition
📖 Complete API usage examples, streaming output, reasoning mode, token counting, and more detailed documentation can be found in the docs/ directory
⭐ If you find this useful, please give it a Star on Gitee!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gracefox_llm_hub-0.2.0.tar.gz.
File metadata
- Download URL: gracefox_llm_hub-0.2.0.tar.gz
- Upload date:
- Size: 83.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87f4f38d7907e47180a177af311099619024d155bb402afeb0ad34af1864c6e0
|
|
| MD5 |
19d2a738fd3234d045969d24d35bcc08
|
|
| BLAKE2b-256 |
6db18e639f72b528f1a3b92315169e8dafd2ba000dae4360e0c9ae16e903de19
|
File details
Details for the file gracefox_llm_hub-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gracefox_llm_hub-0.2.0-py3-none-any.whl
- Upload date:
- Size: 89.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a18070639a2544c0f02c4814a54900973b025cd240e2827b6fc327ea923c9f6
|
|
| MD5 |
ca99a0248cd8269401148b5051896fd0
|
|
| BLAKE2b-256 |
00e8f2490ddb091d372dfd46f9d0091167684691706b5c84bb92aa4f0dcc809f
|