Skip to main content

LLM Toolkit

一个 Python 命令行工具,统一调用多个大模型 API,支持流式输出、Token 统计、多 Provider 切换。

✨ 功能特性

  • 🚀 多 Provider 统一接口:支持 MiniMax、DeepSeek、Anthropic(Mock),新增 Provider 只需写一个类
  • 💬 流式输出:边生成边打印,字一个字出来
  • ⏱️ 超时 +错误重试:网络错误自动重试,超时 30 秒
  • 📝 日志:自动记录调用模型和耗时
  • 🔌 CLI 设计:基于 Click,支持参数和子命令

📁 项目结构

src/llm_toolkit/
├── __init__.py
├── cli/
│   ├── __init__.py
│   └── main.py             # CLI 入口
├── providers/              # 多 Provider 支持
│   ├── __init__.py         # 注册表
│   ├── base.py             # 抽象基类
│   ├── minimax.py          # MiniMax Provider
│   ├── deepseek.py         # DeepSeek Provider
│   └── anthropic.py        # Anthropic Provider(Mock)
├── client.py               # 预留:统一 LLMClient(Day 6+)
├── models.py               # 预留:请求/响应模型
└── config.py               # 预留:配置加载

🚀 安装

1. 克隆仓库

git clone <repo-url>
cd m1

2. 安装依赖

需要先安装 uv。

uv sync

⚙️ 配置

在项目根目录创建 .env 文件:

# MiniMax(国内节点)
MINIMAX_API_KEY=sk-cp-xxx

# DeepSeek
DEEPSEEK_API_KEY=sk-xxx# Anthropic(可选,目前未启用)
# ANTHROPIC_API_KEY=sk-ant-xxx

📖 使用

默认 Provider(MiniMax)

llm chat "你好"

切换 Provider

llm chat --provider deepseek "你好"

流式输出

llm chat --stream "写一首关于 Python 的诗"

通过环境变量设置默认 Provider

# PowerShell
$env:LLM_PROVIDER="deepseek"
llm chat "你好"

# Bash
LLM_PROVIDER=deepseek llm chat "你好"

查看帮助

llm --help
llm chat --help

🧪 开发

运行测试

uv run pytest

添加新 Provider

  1. 在 src/agent/providers/ 下新建 <provider>.py
  2. 继承 BaseProvider,实现 create_client()
  3. 在 providers/__init__.py 注册

示例:

from .base import BaseProvider
from openai import OpenAI

class MyProvider(BaseProvider):
    name = "myprovider"
    model = "my-model"
    
    def create_client(self) -> OpenAI:
        api_key = os.getenv("MY_API_KEY")
        return OpenAI(api_key=api_key, base_url="https://api.my.com/v1")

⚠️ 已知限制

  • Anthropic Provider 暂未实现(无 API Key,需要时再填真实代码)
  • OpenAI Provider 未集成(无 API Key,需要时按上面示例添加)
  • 当前只有 chat 命令,后续会加 conversation(历史)、prompt(模板)

📝许可证

MIT

Metadata

Release files for chujie-llm-toolkit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chujie-llm-toolkit 0.1.0
File Size Uploaded Provenance Actions
chujie_llm_toolkit-0.1.0.tar.gz 11.6 kB Without provenance Details for chujie_llm_toolkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chujie-llm-toolkit 0.1.0
File Interpreter ABI Platform Actions
chujie_llm_toolkit-0.1.0-py3-none-any.whl Python 3 none any Details for chujie_llm_toolkit-0.1.0-py3-none-any.whl

Total release size: 23.2 kB

Release files / chujie_llm_toolkit-0.1.0.tar.gz

Download URL chujie_llm_toolkit-0.1.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3a0843905bbdbe7dd1f8aa0e260725aaca092c9031c96e0af8348a47e5d1dcc7
BLAKE2b-256 checksum
How to use checksums
004a56aab9060f9d4e21d7f905c2dfeb3570b8ee01dda687088f78dff9018cc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / chujie_llm_toolkit-0.1.0-py3-none-any.whl

Download URL chujie_llm_toolkit-0.1.0-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a820b4771d899aa1111117adc1ca271a9017490f553a415844dbc71ca30636b
BLAKE2b-256 checksum
How to use checksums
79c219570a6f1c0d77ace87675c60f2c97d9fee5ccfb08f7f6d90e5baf6e72b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.12 {"installer":{"name":"uv","version":"0.12.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for chujie-llm-toolkit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page