本教程基于实际部署经验,涵盖 DeepSeek、硅基流动、Ollama 本地模型,以及阿里云千问、腾讯云混元、智谱AI 等主流云端模型的配置。每一步都包含可能出现的问题及解决方案。
目录
-
一、前置条件检查
-
二、安装 Ollama 本地模型
-
三、配置云端模型 API
-
3.1 DeepSeek
-
3.2 硅基流动(SiliconFlow)
-
3.3 阿里云千问
-
3.4 腾讯云混元
-
3.5 智谱AI(ChatGLM)
-
3.6 OpenAI(备选)
-
-
四、验证模型配置
-
五、设置默认模型和切换方式
-
六、常见问题汇总
一、前置条件检查
1.1 确认 OpenClaw 服务运行状态
bash
# 查看服务状态
systemctl --user status openclaw-gateway
# 如果未运行,启动服务
systemctl --user start openclaw-gateway
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
Unit openclaw-gateway.service could not be found |
服务未安装 | 执行 openclaw onboard --install-daemon 安装服务 |
| 服务启动失败 | systemd 未启用 | 确保 WSL2 中 systemd 已启用(检查 /etc/wsl.conf) |
1.2 确认 OpenClaw 版本
bash
openclaw --version
要求:2026.3.x 或更高版本
二、安装 Ollama 本地模型
2.1 安装 Ollama
bash
# 一键安装
curl -fsSL https://ollama.com/install.sh | sh
# 或使用国内镜像(推荐)
curl -fsSL https://mirrors.aliyun.com/ollama/install.sh | sh
2.2 启动 Ollama 服务
bash
# 后台启动
ollama serve &
# 验证服务运行
curl -s http://localhost:11434/api/tags | python3 -m json.tool
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
Error: listen tcp 127.0.0.1:11434: bind: address already in use |
Ollama 已在运行 | 无需重复启动,直接使用 |
ollama: command not found |
安装未完成 | 重新执行安装脚本,或重启终端 |
2.3 下载本地模型
bash
# 下载千问系列(推荐)
ollama pull qwen2.5:7b # 约 4.7GB
ollama pull qwen2.5:1.5b # 约 1GB,轻量级
ollama pull qwen3.5:4b # 约 3.4GB
# 下载 DeepSeek 系列
ollama pull deepseek-r1:7b # DeepSeek 推理模型
# 下载 Llama 系列
ollama pull llama3.2:3b # Meta Llama 轻量版
# 查看已下载模型
ollama list
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
| 下载速度极慢 | 网络问题 | 配置代理,或使用国内镜像 |
| 磁盘空间不足 | 模型较大 | 清理磁盘,或只下载轻量模型(1.5B/3B) |
| 下载中断 | 网络不稳定 | 重新执行 ollama pull 会断点续传 |
三、配置云端模型 API
3.1 DeepSeek
获取 API Key:
-
注册/登录 → API Keys → 创建 API Key
-
复制保存(格式:
sk-xxxxxxxxxxxxxxxx)
配置命令:
bash
openclaw config set 'models.providers.deepseek' --json '{
"baseUrl": "https://api.deepseek.com/v1",
"apiKey": "sk-你的DeepSeek-API-Key",
"api": "openai-completions",
"models": [
{"id": "deepseek-chat", "name": "DeepSeek Chat"},
{"id": "deepseek-reasoner", "name": "DeepSeek Reasoner"}
]
}'
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
401 Unauthorized |
API Key 无效 | 检查 API Key 是否正确,重新生成 |
| 模型调用超时 | 网络问题 | 增加 timeout 配置 |
3.2 硅基流动(SiliconFlow)
硅基流动提供丰富的开源模型 API,包括千问、DeepSeek、Llama 等。
获取 API Key:
-
注册/登录 → API 密钥 → 创建 API 密钥
-
复制保存(格式:
sk-xxxxxxxxxxxxxxxx)
配置命令:
bash
openclaw config set 'models.providers.siliconflow' --json '{
"baseUrl": "https://api.siliconflow.cn/v1",
"apiKey": "sk-你的硅基流动API-Key",
"api": "openai-completions",
"models": [
{"id": "Qwen/Qwen2.5-7B-Instruct", "name": "硅基流动 Qwen 2.5 7B"},
{"id": "Qwen/Qwen2.5-14B-Instruct", "name": "硅基流动 Qwen 2.5 14B"},
{"id": "Qwen/Qwen2.5-72B-Instruct", "name": "硅基流动 Qwen 2.5 72B"},
{"id": "deepseek-ai/DeepSeek-V2.5", "name": "硅基流动 DeepSeek V2.5"},
{"id": "deepseek-ai/DeepSeek-V3", "name": "硅基流动 DeepSeek V3"},
{"id": "meta-llama/Meta-Llama-3.1-8B-Instruct", "name": "硅基流动 Llama 3.1 8B"},
{"id": "meta-llama/Meta-Llama-3.1-70B-Instruct", "name": "硅基流动 Llama 3.1 70B"}
]
}'
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
404 Not Found |
模型 ID 错误 | 检查模型 ID 格式是否正确(如 Qwen/Qwen2.5-7B-Instruct) |
| 账户余额不足 | 免费额度耗尽 | 在官网充值 |
| 部分模型不可用 | 模型已下线 | 查看官网支持的模型列表 |
3.3 阿里云千问
获取 API Key:
-
登录阿里云账号(需实名认证)
-
密钥管理 → 创建 API-Key
-
复制保存
配置命令:
bash
openclaw config set 'models.providers.qwen' --json '{
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"apiKey": "sk-你的千问API-Key",
"api": "openai-completions",
"models": [
{"id": "qwen-plus", "name": "千问 Plus"},
{"id": "qwen-max", "name": "千问 Max"},
{"id": "qwen-turbo", "name": "千问 Turbo"},
{"id": "qwen2.5-72b-instruct", "name": "千问 2.5 72B"},
{"id": "qwen2.5-32b-instruct", "name": "千问 2.5 32B"}
]
}'
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
Invalid API Key |
API Key 错误 | 确认是 DashScope 的 API Key,不是阿里云 AccessKey |
| 模型调用失败 | 服务未开通 | 在阿里云控制台开通模型服务 |
3.4 腾讯云混元
获取 API Key:
-
登录腾讯云账号(需实名认证)
-
接入管理 → 创建 API Key
-
复制保存
配置命令:
bash
openclaw config set 'models.providers.hunyuan' --json '{
"baseUrl": "https://api.hunyuan.cloud.tencent.com/v1",
"apiKey": "你的混元API-Key",
"api": "openai-completions",
"models": [
{"id": "hunyuan-turbos-latest", "name": "混元 Turbo"},
{"id": "hunyuan-t1-latest", "name": "混元 T1"},
{"id": "hunyuan-lite", "name": "混元 Lite"}
]
}'
3.5 智谱AI(ChatGLM)
获取 API Key:
-
注册/登录
-
API Keys → 创建 API Key
-
复制保存
配置命令:
bash
openclaw config set 'models.providers.zhipu' --json '{
"baseUrl": "https://open.bigmodel.cn/api/paas/v4",
"apiKey": "你的智谱API-Key",
"api": "openai-completions",
"models": [
{"id": "glm-4-plus", "name": "GLM-4 Plus"},
{"id": "glm-4-flash", "name": "GLM-4 Flash"},
{"id": "glm-4-air", "name": "GLM-4 Air"},
{"id": "glm-4-long", "name": "GLM-4 Long"}
]
}'
注意:智谱 API 的 baseUrl 可能需要根据文档调整。
3.6 OpenAI(备选)
获取 API Key:
-
注册/登录 → API Keys → Create new secret key
-
复制保存
配置命令:
bash
openclaw config set 'models.providers.openai' --json '{
"baseUrl": "https://api.openai.com/v1",
"apiKey": "sk-你的OpenAI-API-Key",
"api": "openai-completions",
"models": [
{"id": "gpt-4o", "name": "GPT-4o"},
{"id": "gpt-4o-mini", "name": "GPT-4o Mini"},
{"id": "gpt-4-turbo", "name": "GPT-4 Turbo"},
{"id": "gpt-3.5-turbo", "name": "GPT-3.5 Turbo"}
]
}'
四、验证模型配置
4.1 设置模型合并模式
bash
openclaw config set models.mode merge
4.2 查看已配置的模型提供商
bash
openclaw config get models.providers | python3 -c "
import sys, json
data = json.load(sys.stdin)
print('已配置的模型提供商:')
for provider in data.keys():
print(f' - {provider}')
"
4.3 查看所有模型列表
bash
openclaw config get models.providers | python3 -c "
import sys, json
data = json.load(sys.stdin)
for provider, config in data.items():
print(f'\n{provider}:')
for model in config.get('models', []):
print(f' - {model[\"id\"]}')
"
4.4 重启服务使配置生效
bash
systemctl --user restart openclaw-gateway
sleep 3
可能遇到的问题:
| 问题 | 原因 | 解决办法 |
|---|---|---|
| 配置不生效 | 服务未重启 | 执行 systemctl --user restart openclaw-gateway |
| JSON 格式错误 | 配置中有语法错误 | 使用 python3 -m json.tool 验证配置 |
五、设置默认模型和切换方式
5.1 查看当前默认模型
bash
openclaw config get agents.defaults.model.primary
5.2 设置默认模型
bash
# 设置为硅基流动千问
openclaw config set agents.defaults.model.primary siliconflow/Qwen/Qwen2.5-7B-Instruct
# 设置为 DeepSeek
openclaw config set agents.defaults.model.primary deepseek/deepseek-chat
# 设置为本地 Ollama
openclaw config set agents.defaults.model.primary ollama/qwen2.5:7b
# 设置为阿里千问
openclaw config set agents.defaults.model.primary qwen/qwen-plus
# 设置为智谱 GLM-4
openclaw config set agents.defaults.model.primary zhipu/glm-4-flash
5.3 重启服务
bash
systemctl --user restart openclaw-gateway
5.4 测试不同模型
bash
# 使用默认模型
openclaw agent --session-id test --message "你好,请用一句话介绍自己"
# 临时使用其他模型(不修改配置)
OPENCLAW_MODEL_PRIMARY=siliconflow/Qwen/Qwen2.5-7B-Instruct openclaw agent --session-id test --message "你好"
OPENCLAW_MODEL_PRIMARY=ollama/qwen2.5:7b openclaw agent --session-id test --message "1+1等于几?"
OPENCLAW_MODEL_PRIMARY=deepseek/deepseek-chat openclaw agent --session-id test --message "你好"
六、常见问题汇总
6.1 配置不生效
| 问题 | 解决方案 |
|---|---|
| 修改配置后模型列表不变 | 重启服务:systemctl --user restart openclaw-gateway |
| 服务重启失败 | 检查配置 JSON 格式:python3 -m json.tool ~/.openclaw/openclaw.json |
| 默认模型未改变 | 确认配置路径:openclaw config get agents.defaults.model.primary |
6.2 模型调用失败
| 问题 | 原因 | 解决办法 |
|---|---|---|
401 Unauthorized |
API Key 无效 | 重新生成 API Key,更新配置 |
404 Not Found |
模型 ID 错误 | 检查模型 ID 格式,参考各平台文档 |
429 Too Many Requests |
触发限流 | 降低请求频率,检查账户余额 |
| 超时无响应 | 网络问题或模型响应慢 | 增加 timeout,或切换到更快的模型 |
| 本地模型无响应 | Ollama 未运行 | 执行 ollama serve & 启动服务 |
6.3 openclaw models list 只显示部分模型
说明 :这是正常现象。models list 可能只显示默认或已认证的模型,但配置的其他模型仍可通过环境变量或修改默认模型使用。
验证方法:
bash
# 直接测试模型是否可用
OPENCLAW_MODEL_PRIMARY=你的模型ID openclaw agent --session-id test --message "测试"
6.4 模型切换命令速查
bash
# 查看当前默认模型
openclaw config get agents.defaults.model.primary
# 切换默认模型(永久)
openclaw config set agents.defaults.model.primary 模型ID
systemctl --user restart openclaw-gateway
# 临时切换(单次使用)
OPENCLAW_MODEL_PRIMARY=模型ID openclaw agent --session-id test --message "你的问题"
附录:常用模型 ID 速查表
| 提供商 | 模型名称 | 模型 ID |
|---|---|---|
| DeepSeek | DeepSeek Chat | deepseek-chat |
| DeepSeek Reasoner | deepseek-reasoner |
|
| 硅基流动 | Qwen 2.5 7B | Qwen/Qwen2.5-7B-Instruct |
| Qwen 2.5 14B | Qwen/Qwen2.5-14B-Instruct |
|
| DeepSeek V3 | deepseek-ai/DeepSeek-V3 |
|
| Llama 3.1 8B | meta-llama/Meta-Llama-3.1-8B-Instruct |
|
| 阿里千问 | 千问 Plus | qwen-plus |
| 千问 Max | qwen-max |
|
| 千问 Turbo | qwen-turbo |
|
| 腾讯混元 | 混元 Turbo | hunyuan-turbos-latest |
| 混元 T1 | hunyuan-t1-latest |
|
| 智谱AI | GLM-4 Flash | glm-4-flash |
| GLM-4 Plus | glm-4-plus |
|
| Ollama | Qwen 2.5 7B | qwen2.5:7b |
| Qwen 3.5 4B | qwen3.5:4b |
|
| DeepSeek R1 7B | deepseek-r1:7b |
|
| Llama 3.2 3B | llama3.2:3b |
总结
配置完成后,你拥有以下模型资源:
| 类型 | 模型来源 | 特点 |
|---|---|---|
| 云端 | DeepSeek | 性价比高,速度快 |
| 云端 | 硅基流动 | 模型丰富,开源模型多 |
| 云端 | 阿里千问 | 国内稳定,中文能力强 |
| 云端 | 腾讯混元 | 腾讯生态,稳定可靠 |
| 云端 | 智谱AI | GLM 系列,中文优秀 |
| 本地 | Ollama | 完全免费,离线可用 |
使用建议:
-
日常对话:DeepSeek 或硅基流动 Qwen 7B
-
复杂推理:硅基流动 DeepSeek V3 或千问 Max
-
中文任务:阿里千问或智谱 GLM-4
-
离线环境:本地 Ollama 模型
遇到问题 :第一个命令永远是 openclaw doctor,它会自动检测并提示问题所在。
本回答由 AI 生成,内容仅供参考,请仔细甄别。