Skip to main content

统一的LLM调用库,支持多种LLM提供商

Project description

LLM Hub - Unified LLM Calling Library

中文

A unified calling library supporting multiple LLM providers, providing consistent API interfaces, command-line tools, and graphical interface.

Project Structure

llm-hub/
│
├── 📄 Root configuration files
│   ├── LICENSE                          # GPL-3.0 license file
│   ├── requirements.txt                 # Python dependencies list
│   ├── setup.py                         # Project installation script
│   ├── pyproject.toml                   # Project configuration
│   ├── MANIFEST.in                      # Packaging manifest
│   ├── config.json                      # Default configuration example
│   ├── pytest.ini                       # pytest configuration
│   ├── Makefile                         # Build automation script
│   ├── Dockerfile                       # Docker containerization config
│   ├── .gitignore                       # Git ignore file
│   ├── run_ui.py                        # UI launcher script
│   └── README.md                        # Project documentation
│
├── 📁 llm_hub/                          # Core code directory
│   ├── __init__.py                      # Module initialization
│   ├── py.typed                         # Type marking file
│   │
│   ├── 📁 cli/                          # CLI module
│   │   ├── __init__.py
│   │   └── main.py                      # CLI main program
│   │
│   ├── 📁 core/                         # Core functionality
│   │   ├── __init__.py
│   │   ├── client.py                    # LLMClient main class
│   │   ├── config.py                    # Configuration management
│   │   ├── config_manager.py            # Config manager with profiles
│   │   └── enums.py                     # Enum definitions
│   │
│   ├── 📁 models/                       # Data models
│   │   ├── __init__.py
│   │   ├── message.py                   # Message and Conversation models
│   │   └── response.py                  # Response models
│   │
│   ├── 📁 providers/                    # LLM provider implementations
│   │   ├── __init__.py
│   │   ├── base.py                      # Base provider class
│   │   ├── openai_compatible.py         # OpenAI-compatible providers
│   │   ├── ollama.py                    # Ollama local provider
│   │   ├── llama_cpp.py                 # llama.cpp local provider
│   │   ├── deepseek.py                  # DeepSeek API provider
│   │   ├── kimi.py                      # Kimi API provider
│   │   ├── gemini.py                    # Google Gemini API provider
│   │   ├── anthropic.py                 # Anthropic Claude API provider
│   │   └── custom.py                    # Custom API provider
│   │
│   └── 📁 utils/                        # Utility functions
│       ├── __init__.py
│       ├── logger.py                    # Logging system
│       ├── token_counter.py             # Token counter
│       └── helpers.py                   # Helper functions
│
├── 📁 ui/                               # GUI module
│   ├── __init__.py
│   └── app.py                           # Main UI application
│
├── 📁 tests/                            # Test module
│   ├── __init__.py
│   ├── test_client.py
│   └── test_providers.py
│
└── 📁 examples/                         # Example code
    ├── basic_usage.py
    ├── streaming.py
    ├── multi_turn_chat.py
    ├── environment_aware.py
    └── json_config_usage.py

Quick Start

Installation

# Basic installation
pip install gracefox-llm-hub

# Install all dependencies (including UI)
pip install gracefox-llm-hub[all]

# Install UI only
pip install gracefox-llm-hub[ui]

Use as Library

from llm_hub import LLMClient, LLMConfig, Provider

# Create client
client = LLMClient(LLMConfig(
    provider=Provider.DEEPSEEK,
    model="deepseek-chat",
    api_key="your-api-key"
))

# Chat
response = client.chat("Hello")
print(response.content)

# Streaming output
for chunk in client.stream_chat("Tell a story"):
    print(chunk, end="")

Command Line Usage

# Basic usage
llm-hub --provider deepseek --api-key YOUR_KEY "Hello"

# Use JSON config string
llm-hub --json '{"provider": "deepseek", "model": "deepseek-chat", "api_key": "xxx"}' "Hello"

# Use config file
llm-hub --config-file config.json "Hello"

# Use config profile
llm-hub --profile my-deepseek "Hello"

# Interactive mode
llm-hub --provider ollama --interactive

# Streaming output
llm-hub --provider openai --stream "Tell a story"

Configuration File Formats

Support multiple configuration formats:

Flat format:

{
    "provider": "deepseek",
    "model": "deepseek-chat",
    "api_key": "your-api-key",
    "temperature": 0.7,
    "max_tokens": 2000
}

Nested format:

{
    "deepseek_config": {
        "provider": "deepseek",
        "model": "deepseek-chat",
        "api_key": "your-api-key"
    }
}

Multi-profile format:

{
    "current": "deepseek",
    "profiles": {
        "deepseek": {
            "provider": "deepseek",
            "model": "deepseek-chat",
            "api_key": "sk-ds"
        },
        "openai": {
            "provider": "openai",
            "model": "gpt-4",
            "api_key": "sk-oa"
        }
    }
}

GUI

# Launch UI
llm-hub-ui
# or
python run_ui.py

Supported Providers

Provider Type API Key Required Config Parameters
OpenAI Cloud api_key
DeepSeek Cloud api_key
Kimi Cloud api_key
Google Gemini Cloud api_key
Anthropic Claude Cloud api_key
Ollama Local ollama_url
llama.cpp Local model_path
Custom Optional Optional api_url

Configuration Management

Config Profiles

# Save config profile
llm-hub --provider deepseek --api-key xxx --save-profile my-ds

# List all profiles
llm-hub --list-profiles

# Use profile
llm-hub --profile my-ds "Hello"

# Delete profile
llm-hub --delete-profile my-ds

Environment Variables

export LLM_PROVIDER=deepseek
export LLM_MODEL=deepseek-chat
export LLM_API_KEY=your-key
export LLM_TEMPERATURE=0.7

llm-hub "Hello"

Configuration Priority

From low to high:

  1. Default configuration
  2. Environment variables
  3. Config profile
  4. Config file
  5. JSON string
  6. Command line arguments

Development Commands

# Install development dependencies
make install-dev

# Run tests
make test

# Format code
make format

# Lint code
make lint

# Clean temporary files
make clean

# Build distribution package
make build

# Run CLI
make run-cli

# Run UI
make run-ui

Extending Development

Adding a New Provider

  1. Add enum in core/enums.py:
class Provider(Enum):
    NEW_PROVIDER = "new_provider"
  1. Create providers/new_provider.py:
from llm_hub.providers.base import BaseProvider

class NewProvider(BaseProvider):
    def chat(self, conversation, **kwargs):
        # Implement chat logic
        pass
  1. Register in providers/__init__.py:
from llm_hub.providers.new_provider import NewProvider

providers = {
    Provider.NEW_PROVIDER: NewProvider,
}

License

GNU General Public License v3.0 - See LICENSE file for details

GPL-3.0 Core Requirements

  • Freedom to Use: Anyone can freely use this software
  • Source Code Availability: Source code must be provided when distributing
  • Same License: Modified versions must be released under the same GPL-3.0 license
  • Copyright Notice: Original copyright and license notices must be retained

Links

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

gracefox_llm_hub-0.1.3.tar.gz (74.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gracefox_llm_hub-0.1.3-py3-none-any.whl (65.6 kB view details)

Uploaded Python 3

File details

Details for the file gracefox_llm_hub-0.1.3.tar.gz.

File metadata

  • Download URL: gracefox_llm_hub-0.1.3.tar.gz
  • Upload date:
  • Size: 74.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for gracefox_llm_hub-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7a5802573b87d4b01864e955127852b9ebdabb6803b52c4eaacabbe08bbc044a
MD5 f91e167f522b6234325cfefd91d284a5
BLAKE2b-256 406e4f8053e218d645c6f226833d3d6cea68d24856c06eda009bd8e799d150b7

See more details on using hashes here.

File details

Details for the file gracefox_llm_hub-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gracefox_llm_hub-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 96c344809d1fa328b1ffaa1d451a9a47b3d78f9d62da075809358c2891d9de19
MD5 8e580fde82ac31afa0e4208c77a24ece
BLAKE2b-256 173fb7271af7dc599efb9618d4bc3ad62b6435d8d73ed82d94adbd7650b85c3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page