feat: multi-key strategy, configurable retention, response cleanup & resilience - #1
Open
cxk1993 wants to merge 2 commits into
Open
feat: multi-key strategy, configurable retention, response cleanup & resilience#1cxk1993 wants to merge 2 commits into
cxk1993 wants to merge 2 commits into
Conversation
…ence
- Key strategies: sticky(failover) / round_robin / random / first, per-provider configurable
- 429 cooldown raised 30s -> 180s, provider-level to avoid burning all keys
- Response model field: pure model name (no '{provider} · {model}' prefix)
- Removed hardcoded 🤖 prefix injection in stream & non-stream paths
- Usage retention days: configurable from panel (default 720, 1-7200)
- Call log persisted to call_log.jsonl, API supports hours filter
- sanitize_messages strips empty tool_calls arrays (SenseNova compat)
- classify_failure distinguishes request/auth/quota/server errors
- Removed dead code: call_log_lock, get_sticky_key wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为 model-gateway 增加多 Key 轮换策略选择、消耗数据保留天数配置,并修复响应 model 字段拼接、🤖 前缀注入等体验问题。所有改动已在本地 WSL 环境实测验证。
主要改动(本 PR 新增)
🎯 多 Key 轮换策略(核心)
sticky(默认):粘性 + 熔断,一直用同一 Key,429 或连续 3 次失败才切换(保缓存、降延迟)round_robin:每次请求顺序轮换random:每次请求随机选择first:永远只取第一个 Key🔥 稳定性提升
classify_failure()区分 请求参数错误(400/404/422,不切 Key)/ 认证错误(401/403,切 Key+熔断)/ 限流(429,冷却)/ 服务故障(5xx,熔断)sanitize_messages()自动移除上游拒绝的空tool_calls: []数组(SenseNova 兼容)✨ 响应净化
🤖 {提供商} · {模型名}前缀注入model字段从"SenseNova · deepseek-v4-flash"改为纯"deepseek-v4-flash"(与其他提供商行为一致)📊 面板与数据管理
usage_retention_days,默认 720 天,1-7200),前端直接可改,改完立即触发清理call_log.jsonl(原内存 100 条重启即丢),/api/call-log?hours=N支持按小时查询models_meta.json修正多个模型的 context_length 错误值(如 sensenova-6.7-flash-lite / sensenova-u1-fast 应为 256K)🧹 代码清理
call_log_lock死代码get_sticky_key()兼容包装,统一走select_key()测试验证
python -m py_compile通过安全说明
providers.json/config.json/usage.jsonl/history.jsonl/routers.json/call_log.jsonl等)均在.gitignore中,未包含任何真实 API Keyconfig.example.json/providers.example.json使用占位符