【最近实战】为Hermes双QQ Bot实例分别配置DeepSeek和千问模型并修复千问API端点认证失败
【问题描述】 我使用Hermes Agent框架搭建了两个QQ Bot实例,default实例使用DeepSeek、qq2实例需要使用阿里千问。但qq2启动后一直报错"Provider authentication failed",无法正常回复消息。
【适用场景】 一台服务器上运行多个Hermes Gateway实例,每个实例绑定不同的QQ Bot和LLM提供商。
【解决方案】
1. 环境搭建基础 我通过Wisdom SSH管理服务器,上面已安装Hermes中文版,Dashboard运行在端口,WordPress运行在端口。Hermes已在安装时同步了72个内置技能。
2. 创建多Profile架构 我向AI助手提出:配置两个QQ Bot,QQ1使用DeepSeek、QQ2使用阿里千问。关键架构是基于Hermes的profile机制:
default: AppID=***, model=deepseek-chat
qq2: AppID=***, model=qwen-plus, provider=dashscope
qq2的配置文件位于***/profiles/qq2/config.yaml,内容为:
model:
default: qwen-plus
provider: dashscope
base_url: ''
3. 问题根因分析 qq2启动后收到消息处理时报401认证错误,错误日志核心信息:
base_url=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
HTTP 401: Incorrect API key provided
AI助手定位到两个问题:
- 阿里千问provider的默认base_url是国际端点
dashscope-intl.aliyuncs.com - 我的API Key是国内版的,必须使用国内端点
dashscope.aliyuncs.com
通过curl直接测试确认:
# 国际端点 → 401失败
curl -s https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer ***" \
-d '{"model":"qwen-plus","messages":[{"role":"user","content":"hi"}],"max_tokens":10}'
# HTTP:401
# 国内端点 → 200成功
curl -s https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer ***" \
-d '{"model":"qwen-plus","messages":[{"role":"user","content":"hi"}],"max_tokens":10}'
# HTTP:200
4. 修复过程
AI助手首次尝试在config.yaml中直接写base_url,但重启后日志仍显示使用国际端点。进一步排查发现Hermes的alibaba provider是通过环境变量覆盖base_url的,需要设置DASHSCOPE_BASE_URL而非在config.yaml中配置。
在***/profiles/qq2/.env中添加:
DASHSCOPE_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
验证方法来自hermes_cli/providers.py:
"alibaba": HermesOverlay(
transport="openai_chat",
base_url_env_var="DASHSCOPE_BASE_URL",
),
修复后重启两个Gateway,通过hermes --profile qq2 send发送测试消息到QQ2成功。
5. 验证与收尾
最后通过hermes gateway restart和hermes --profile qq2 gateway restart同步重启两个实例,清空日志后重新测试,两个Bot均正常回复。
【注意事项】
- 阿里千问API Key分国内版和国际版,端点不通用,需要在阿里云控制台确认Key类型
- Hermes配置provider的base_url时,优先级是环境变量 > config.yaml,不能直接在config.yaml里写
- 多profile实例运行时要注意日志路径隔离,每个profile的日志在各自目录下
- 通过Wisdom SSH的终端工具执行命令和查看日志,当需要对比两个profile状态时,可以快速切换上下文定位差异
最终架构总结:
| Profile | QQ AppID | 模型 | 端点 | 状态 |
|---|---|---|---|---|
| default | *** | DeepSeek | api.deepseek.com | ✅ |
| qq2 | *** | 千问 qwen-plus | dashscope.aliyuncs.com(国内) | ✅ |