# Plan Manager - 多平台 Coding Plan 统一管理系统 统一管理 MiniMax、OpenAI、Google Gemini、智谱、Kimi 等多个 AI 平台的订阅计划,提供额度查询、刷新倒计时、API 代理转发、多媒体任务队列和 Web 仪表盘。 ## 功能 - **多 Plan 管理** -- 增删改查,支持任意数量的 AI 平台订阅 - **多维度额度追踪** -- 同一 Plan 可配置多条 QuotaRule(如 Kimi 的"周额度 + 5 小时滚动窗口") - **四种刷新策略** -- 固定间隔 / 自然周期 / API 同步 / 手动 - **API 代理** -- OpenAI (`/v1/chat/completions`) + Anthropic (`/v1/messages`) 兼容端点 - **智能路由** -- 按 model 名称自动路由到对应 Plan,额度耗尽自动 fallback - **任务队列** -- 支持图片、语音、视频等多媒体任务的异步提交和消费 - **插件化 Provider** -- 新增平台只需添加一个 Python 文件 - **Web 仪表盘** -- 额度进度条、刷新倒计时、队列管理、配置页 ## 快速开始 ### Docker 部署(推荐) ```bash # 1. 编辑配置文件,填入各平台 API Key vim config.yaml # 2. 启动 docker compose up -d # 3. 访问 http://localhost:8080 ``` ### 本地开发 ```bash # 安装依赖 pip install -r requirements.txt # 启动 uvicorn app.main:app --host 0.0.0.0 --port 8080 --reload ``` ## 配置说明 编辑 `config.yaml`: ```yaml server: host: "0.0.0.0" port: 8080 proxy_api_key: "your-proxy-key" # 代理端点鉴权 Key,留空则不鉴权 plans: - name: "Kimi Coding Plan" provider: kimi api_key: "sk-xxx" api_base: "https://api.moonshot.cn/v1" quota_rules: - rule_name: "周额度" quota_total: 500 quota_unit: requests refresh_type: calendar_cycle calendar_unit: weekly calendar_anchor: { weekday: 1, hour: 0 } - rule_name: "5小时滚动窗口" quota_total: 50 quota_unit: requests refresh_type: fixed_interval interval_hours: 5 ``` ### QuotaRule 刷新类型 | refresh_type | 说明 | 关键参数 | |---|---|---| | `fixed_interval` | 固定间隔刷新(如 5h、13h) | `interval_hours` | | `calendar_cycle` | 自然周期(日/周/月) | `calendar_unit` + `calendar_anchor` | | `api_sync` | 调用平台 API 查询真实余额 | 无 | | `manual` | 手动重置 | 无 | ## API 代理使用 配置好 Plan 和 Model 路由后,可将本系统作为统一网关: ```bash # OpenAI 兼容格式 curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer your-proxy-key" \ -H "Content-Type: application/json" \ -d '{"model": "moonshot-v1-8k", "messages": [{"role": "user", "content": "hello"}]}' # 指定 Plan(跳过 model 路由) curl http://localhost:8080/v1/chat/completions \ -H "Authorization: Bearer your-proxy-key" \ -H "X-Plan-Id: plan-id-here" \ -d '...' # Anthropic 兼容格式 curl http://localhost:8080/v1/messages \ -H "x-api-key: your-proxy-key" \ -d '{"model": "glm-4-plus", "messages": [{"role": "user", "content": "hello"}]}' ``` ## 扩展新平台 在 `app/providers/` 下新建文件即可,无需修改核心代码: ```python # app/providers/new_platform.py from app.providers.base import BaseProvider, Capability class NewPlatformProvider(BaseProvider): name = "new_platform" display_name = "New Platform" capabilities = [Capability.CHAT] async def chat(self, messages, model, plan, stream=True, **kwargs): # 实现 chat 逻辑... yield "data: ..." ``` 然后在 `config.yaml` 或 Web UI 中添加对应的 Plan 即可。 ## API 文档 启动后访问 `http://localhost:8080/docs` 查看自动生成的 OpenAPI 文档。