-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 多模型池支持 - 私聊场景智能模型选择 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
40631b1
feat: 多模型池功能 - 默认关闭、防竞态、解耦设计
69gg c69e4a5
refactor: 多模型池仅保留私聊,移除群聊实现
69gg 7ffa2c2
refactor: 多模型池解耦 - 拆出 ModelPoolService
69gg ca2b574
fix: model_pool WebUI 兼容性优化
69gg 9556864
fix: 完善多模型相关文档
69gg 63c52ea
feat: WebUI 支持模型池配置
69gg 341f85f
refactor: 拆分 WebUI 大文件,降低维护难度
69gg a3fde90
chore: 添加 Biome/Stylelint 检查,修复2处JS代码风格
69gg 2708a13
test(ModelPool): 为多模型添加测试
69gg 9a7a9b6
ci: 在 CI 和 Release 工作流中添加测试环节
69gg e11a19c
fix(ModelPool): 修复多模型池的多个关键问题
69gg 2c4a544
fix(HotReload): 修复池模型配置热重载时队列间隔不更新
69gg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", | ||
| "files": { | ||
| "include": ["src/Undefined/webui/static/js/**/*.js"] | ||
| }, | ||
| "linter": { | ||
| "rules": { | ||
| "correctness": { | ||
| "noUnusedVariables": "off" | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # 多模型池功能 | ||
|
|
||
| ## 功能概述 | ||
|
|
||
| - **Chat 模型池(私聊)**:轮询/随机自动切换,或在私聊中通过「选X」指定模型 | ||
| - **Agent 模型池**:按策略(轮询/随机)自动分配,无需用户干预 | ||
|
|
||
| > 仅私聊支持用户手动切换 Chat 模型;群聊始终使用主模型。 | ||
|
|
||
| ## 配置方式 | ||
|
|
||
| ### 方式一:WebUI | ||
|
|
||
| 启动 `uv run Undefined-webui`,登录后进入「配置修改」页: | ||
|
|
||
| - **全局开关**:`features` → `pool_enabled` 设为 `true` | ||
| - **Chat 模型池**:`models` → `chat` → `pool`,设置 `enabled`、`strategy`,在 `models` 列表中添加/移除条目 | ||
| - **Agent 模型池**:`models` → `agent` → `pool`,同上 | ||
|
|
||
| 每次修改自动保存并热更新,无需重启。 | ||
|
|
||
| ### 方式二:直接编辑 config.toml | ||
|
|
||
| ## 配置 | ||
|
|
||
| ### 1. 全局开关 | ||
|
|
||
| ```toml | ||
| [features] | ||
| pool_enabled = true # 默认 false,需显式开启 | ||
| ``` | ||
|
|
||
| ### 2. Chat 模型池 | ||
|
|
||
| ```toml | ||
| [models.chat.pool] | ||
| enabled = true | ||
| strategy = "round_robin" # "default" | "round_robin" | "random" | ||
|
|
||
| [[models.chat.pool.models]] | ||
| model_name = "claude-sonnet-4-20250514" | ||
| api_url = "https://api.anthropic.com/v1" | ||
| api_key = "sk-ant-xxx" | ||
| # 其他字段(max_tokens, thinking_* 等)可选,缺省继承主模型 | ||
|
|
||
| [[models.chat.pool.models]] | ||
| model_name = "deepseek-chat" | ||
| api_url = "https://api.deepseek.com/v1" | ||
| api_key = "sk-ds-xxx" | ||
| ``` | ||
|
|
||
| ### 3. Agent 模型池 | ||
|
|
||
| ```toml | ||
| [models.agent.pool] | ||
| enabled = true | ||
| strategy = "round_robin" # "default" | "round_robin" | "random" | ||
|
|
||
| [[models.agent.pool.models]] | ||
| model_name = "claude-sonnet-4-20250514" | ||
| api_url = "https://api.anthropic.com/v1" | ||
| api_key = "sk-ant-xxx" | ||
| ``` | ||
|
|
||
| ### strategy 说明 | ||
|
|
||
| | 值 | 行为 | | ||
| |----|------| | ||
| | `default` | 只使用主模型,忽略池中模型 | | ||
| | `round_robin` | 按顺序轮流使用池中模型 | | ||
| | `random` | 每次随机选择池中模型 | | ||
|
|
||
| > `pool.models` 中只有 `model_name` 必填,其余字段缺省时继承主模型配置。 | ||
|
|
||
| ## 私聊使用方法 | ||
|
|
||
| ### 自动轮换 | ||
|
|
||
| 配置 `strategy = "round_robin"` 或 `"random"` 后,私聊请求会自动在池中模型间切换,无需任何操作。 | ||
|
|
||
| ### 手动指定模型(私聊) | ||
|
|
||
| 1. 私聊发送 `/compare <问题>` 或 `/pk <问题>`,bot 并发请求所有模型并编号返回: | ||
|
|
||
| ``` | ||
| 你: /compare 写一首关于春天的诗 | ||
|
|
||
| bot: | ||
| 正在向 3 个模型发送问题,请稍候... | ||
|
|
||
| 问题: 写一首关于春天的诗 | ||
|
|
||
| 【1】gpt-4o | ||
| 春风拂面暖如酥... | ||
|
|
||
| 【2】claude-sonnet-4-20250514 | ||
| 春日融融暖意浓... | ||
|
|
||
| 【3】deepseek-chat | ||
| 春回大地万象新... | ||
|
|
||
| 回复「选X」可切换到该模型并继续对话 | ||
| ``` | ||
|
|
||
| 2. 5 分钟内回复 `选2`,后续私聊固定使用第 2 个模型继续对话。 | ||
|
|
||
| 3. 偏好持久化保存在 `data/model_preferences.json`,重启后保留。 | ||
|
|
||
| ## 开关层级 | ||
|
|
||
| ``` | ||
| features.pool_enabled ← 全局总开关(false 时完全不生效) | ||
| └─ models.chat.pool.enabled ← Chat 模型池开关 | ||
| └─ models.agent.pool.enabled ← Agent 模型池开关 | ||
| ``` | ||
|
|
||
| ## 注意事项 | ||
|
|
||
| - 不同模型使用独立队列,互不影响 | ||
| - 所有模型的 Token 使用均会被统计 | ||
| - 「选X」状态 5 分钟后过期 | ||
| - 群聊不受多模型池影响,始终使用主模型 | ||
|
|
||
| ## 代码结构 | ||
|
|
||
| | 文件 | 职责 | | ||
| |------|------| | ||
| | `config/models.py` | `ModelPool`, `ModelPoolEntry` 数据类 | | ||
| | `config/loader.py` | 解析 pool 配置,字段缺省继承主模型 | | ||
| | `ai/model_selector.py` | 纯选择逻辑:策略、偏好存储、compare 状态 | | ||
| | `services/model_pool.py` | 私聊交互服务:`/compare`、「选X」、`select_chat_config` | | ||
| | `services/ai_coordinator.py` | 持有 `ModelPoolService`,私聊队列投递时选模型 | | ||
| | `handlers.py` | 私聊消息委托给 `model_pool.handle_private_message()` | | ||
| | `skills/agents/runner.py` | Agent 执行时调用 `model_selector.select_agent_config()` | | ||
| | `utils/queue_intervals.py` | 注册 pool 模型的队列间隔 | |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.