复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-OPENCLAW

2026.04.08

OpenClaw模型配置完整指南

Echo HaoRan
Echo HaoRan
#技术手册
ANALYSIS

OpenClaw 模型配置完整指南#

概述#

OpenClaw 支持多种大语言模型,包括本地模型(Ollama)、云端模型(OpenAI、Claude、国产模型等)。本文档详细介绍如何配置各种模型,帮助你根据需求选择最适合的模型方案。


模型类型概述#

模型类型优点缺点适用场景
本地模型隐私安全、无网络依赖、成本低需要硬件支持、性能较弱隐私敏感、离线使用、成本控制
云端模型性能强大、更新及时、功能丰富需要网络、产生费用、数据上传复杂任务、高性能需求、最新功能
混合模式兼顾性能和成本配置复杂生产环境、成本优化

本地模型配置(Ollama)#

安装 Ollama#

Windows#

PRTCL // POWERSHELL
Terminal window
# 下载并安装 Ollama
# 访问 https://ollama.ai/download 下载 Windows 版本
# 运行安装程序
# 验证安装
ollama --version

macOS#

PRTCL // BASH
Terminal window
# 使用 Homebrew 安装
brew install ollama
# 验证安装
ollama --version

Linux#

PRTCL // BASH
Terminal window
# 安装 Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# 验证安装
ollama --version

下载模型#

PRTCL // BASH
Terminal window
# 下载常用模型
ollama pull qwen2.5:7b # 通义千问 7B
ollama pull llama3.2:3b # Llama 3.2 3B
ollama pull glm4:9b # 智谱 GLM-4 9B
ollama pull deepseek-coder:6.6b # DeepSeek Coder 6.6B
# 查看已下载的模型
ollama list
# 删除模型
ollama rm <model-name>

配置 OpenClaw 使用本地模型#

方法一:命令行配置#

PRTCL // BASH
Terminal window
# 添加本地模型提供商
openclaw model provider add ollama
# 设置默认模型
openclaw model default ollama/qwen2.5:7b
# 测试模型连接
openclaw model test ollama/qwen2.5:7b

方法二:配置文件#

PRTCL // YAML
~/.openclaw/config/models.yaml
providers:
- name: "ollama"
type: "local"
baseUrl: "http://localhost:11434"
api: "openai-completions"
models:
- id: "ollama/qwen2.5:7b"
name: "通义千问 7B"
capabilities:
- "text"
- "code"
- id: "ollama/llama3.2:3b"
name: "Llama 3.2 3B"
capabilities:
- "text"
- id: "ollama/glm4:9b"
name: "智谱 GLM-4 9B"
capabilities:
- "text"
- "code"
- "tool"
defaultModel: "ollama/qwen2.5:7b"

硬件要求#

模型大小显存需求内存需求推荐配置
3B4GB8GB入门级
7B8GB16GB中端
14B16GB32GB高端
32B32GB64GB专业级

性能优化#

PRTCL // BASH
Terminal window
# 启用 GPU 加速(如果有 NVIDIA GPU)
# 设置环境变量
export CUDA_VISIBLE_DEVICES=0
# 使用量化模型
ollama pull qwen2.5:7b-q4_K_M
# 调整上下文长度
# 在配置文件中设置
context:
maxTokens: 4096

云端模型配置#

OpenAI 模型#

获取 API Key#

  1. 访问 https://platform.openai.com/api-keys
  2. 登录或注册账户
  3. 创建新的 API Key
  4. 保存 API Key(只显示一次)

配置 OpenClaw#

PRTCL // YAML
~/.openclaw/config/models.yaml
providers:
- name: "openai"
type: "openai"
baseUrl: "https://api.openai.com/v1"
apiKey: "${OPENAI_API_KEY}" # 使用环境变量
models:
- id: "gpt-4o"
name: "GPT-4o"
capabilities:
- "text"
- "image"
- "audio"
- "code"
- "tool"
- id: "gpt-4o-mini"
name: "GPT-4o Mini"
capabilities:
- "text"
- "code"
- "tool"
- id: "o1-preview"
name: "o1 Preview"
capabilities:
- "text"
- "reasoning"

使用环境变量#

PRTCL // BASH
Terminal window
# 设置 API Key
export OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxx"
# 或在配置文件中引用

Anthropic Claude 模型#

获取 API Key#

  1. 访问 https://console.anthropic.com/
  2. 登录或注册账户
  3. 进入 API Keys 页面
  4. 创建新的 API Key
  5. 保存 API Key

配置 OpenClaw#

PRTCL // YAML
~/.openclaw/config/models.yaml
providers:
- name: "anthropic"
type: "anthropic"
baseUrl: "https://api.anthropic.com"
apiKey: "${ANTHROPIC_API_KEY}"
models:
- id: "claude-opus-4-20250514"
name: "Claude Opus 4"
capabilities:
- "text"
- "code"
- "tool"
- "vision"
- id: "claude-sonnet-4-20250514"
name: "Claude Sonnet 4"
capabilities:
- "text"
- "code"
- "tool"
- "vision"
- id: "claude-haiku-4-20250514"
name: "Claude Haiku 4"
capabilities:
- "text"
- "code"

国产模型配置#

阿里云百炼#

PRTCL // YAML
~/.openclaw/config/models.yaml
providers:
- name: "qwen"
type: "openai"
baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1"
apiKey: "${DASHSCOPE_API_KEY}"
models:
- id: "qwen-max"
name: "通义千问 Max"
capabilities:
- "text"
- "code"
- "tool"
- id: "qwen-plus"
name: "通义千问 Plus"
capabilities:
- "text"
- "code"
- id: "qwen-turbo"
name: "通义千问 Turbo"
capabilities:
- "text"

智谱 AI#

PRTCL // YAML
providers:
- name: "zhipu"
type: "openai"
baseUrl: "https://open.bigmodel.cn/api/paas/v4"
apiKey: "${ZHIPU_API_KEY}"
models:
- id: "glm-4"
name: "GLM-4"
capabilities:
- "text"
- "code"
- "tool"
- id: "glm-4-flash"
name: "GLM-4 Flash"
capabilities:
- "text"
- "code"

DeepSeek#

PRTCL // YAML
providers:
- name: "deepseek"
type: "openai"
baseUrl: "https://api.deepseek.com"
apiKey: "${DEEPSEEK_API_KEY}"
models:
- id: "deepseek-chat"
name: "DeepSeek Chat"
capabilities:
- "text"
- "code"
- id: "deepseek-coder"
name: "DeepSeek Coder"
capabilities:
- "code"

月之暗面 Kimi#

PRTCL // YAML
providers:
- name: "kimi"
type: "openai"
baseUrl: "https://api.moonshot.cn/v1"
apiKey: "${KIMI_API_KEY}"
models:
- id: "moonshot-v1-128k"
name: "Kimi 128K"
capabilities:
- "text"
- "code"
- id: "moonshot-v1-32k"
name: "Kimi 32K"
capabilities:
- "text"
- "code"

自定义模型提供商#

通用配置模板#

如果使用第三方兼容 OpenAI/Anthropic 协议的模型,可以使用以下模板:

PRTCL // YAML
providers:
- name: "custom_provider"
type: "openai" # 或 "anthropic"
baseUrl: "https://api.custom-provider.com/v1"
apiKey: "${CUSTOM_API_KEY}"
models:
- id: "custom-model-id"
name: "Custom Model Name"
capabilities:
- "text"
- "code"

示例:硅基流动#

PRTCL // YAML
providers:
- name: "siliconflow"
type: "openai"
baseUrl: "https://api.siliconflow.cn/v1"
apiKey: "${SILICONFLOW_API_KEY}"
models:
- id: "deepseek-ai/DeepSeek-V3"
name: "DeepSeek V3"
capabilities:
- "text"
- "code"
- id: "Qwen/Qwen2.5-72B-Instruct"
name: "Qwen2.5 72B"
capabilities:
- "text"
- "code"

示例:OpenRouter#

PRTCL // YAML
providers:
- name: "openrouter"
type: "openai"
baseUrl: "https://openrouter.ai/api/v1"
apiKey: "${OPENROUTER_API_KEY}"
models:
- id: "anthropic/claude-3.5-sonnet"
name: "Claude 3.5 Sonnet"
capabilities:
- "text"
- "code"
- id: "google/gemini-pro-1.5"
name: "Gemini Pro 1.5"
capabilities:
- "text"
- "code"

模型路由策略#

基于任务类型的路由#

PRTCL // YAML
~/.openclaw/config/router.yaml
router:
enabled: true
rules:
- condition: "task.type == 'coding'"
model: "gpt-4o"
priority: 10
- condition: "task.type == 'writing'"
model: "claude-opus-4"
priority: 9
- condition: "task.type == 'analysis'"
model: "qwen-max"
priority: 8
- condition: "task.complexity < 3"
model: "gpt-4o-mini"
priority: 7
- default: "gpt-4o-mini"

基于成本的路由#

PRTCL // YAML
router:
enabled: true
strategy: "cost"
rules:
- condition: "budget.available < 10"
model: "ollama/qwen2.5:7b"
priority: 10
- condition: "budget.available >= 10"
model: "gpt-4o-mini"
priority: 5
- condition: "budget.available >= 50"
model: "gpt-4o"
priority: 3

基于性能的路由#

PRTCL // YAML
router:
enabled: true
strategy: "performance"
rules:
- condition: "task.urgency == 'high'"
model: "gpt-4o"
priority: 10
- condition: "task.urgency == 'medium'"
model: "claude-sonnet-4"
priority: 7
- condition: "task.urgency == 'low'"
model: "ollama/llama3.2:3b"
priority: 3

多模态模型配置#

GPT-4o Vision#

PRTCL // YAML
providers:
- name: "openai"
models:
- id: "gpt-4o"
name: "GPT-4o"
capabilities:
- "text"
- "image"
- "audio"
- "video"
vision:
enabled: true
maxImageSize: 10485760 # 10MB
supportedFormats:
- "png"
- "jpeg"
- "gif"
- "webp"

Claude Vision#

PRTCL // YAML
providers:
- name: "anthropic"
models:
- id: "claude-opus-4"
name: "Claude Opus 4"
capabilities:
- "text"
- "vision"
vision:
enabled: true
maxImageSize: 20971520 # 20MB
supportedFormats:
- "png"
- "jpeg"
- "gif"
- "webp"

国产多模态模型#

PRTCL // YAML
providers:
- name: "qwen"
models:
- id: "qwen-vl-max"
name: "通义千问 VL Max"
capabilities:
- "text"
- "vision"
vision:
enabled: true
maxImageSize: 10485760

参数调优#

常用参数#

参数说明默认值推荐范围
temperature温度参数,控制随机性0.70.0-1.0
max_tokens最大生成 Token 数2000100-8000
top_p核采样概率1.00.8-1.0
frequency_penalty频率惩罚0.0-2.0-2.0
presence_penalty存在惩罚0.0-2.0-2.0

不同场景的参数配置#

创意写作#

PRTCL // YAML
creative_writing:
temperature: 0.9
top_p: 0.95
max_tokens: 4000
frequency_penalty: 0.5
presence_penalty: 0.3

代码生成#

PRTCL // YAML
code_generation:
temperature: 0.2
top_p: 0.95
max_tokens: 2000
frequency_penalty: 0.0
presence_penalty: 0.0

文档摘要#

PRTCL // YAML
summarization:
temperature: 0.3
top_p: 0.9
max_tokens: 1000
frequency_penalty: 0.1
presence_penalty: 0.1

问答系统#

PRTCL // YAML
qa_system:
temperature: 0.1
top_p: 0.85
max_tokens: 1500
frequency_penalty: 0.0
presence_penalty: 0.0

监控与优化#

Token 使用监控#

PRTCL // YAML
~/.openclaw/config/monitoring.yaml
monitoring:
tokenUsage:
enabled: true
alertThreshold: 10000
resetPeriod: "daily"
report: true
costTracking:
enabled: true
budget:
daily: 10
monthly: 300
alerts:
- level: "warning"
threshold: 0.8
- level: "critical"
threshold: 0.95

性能监控#

PRTCL // YAML
performance:
metrics:
- "response_time"
- "throughput"
- "error_rate"
- "success_rate"
logging:
enabled: true
level: "info"

优化建议#

  1. 使用缓存:对重复查询启用缓存
  2. 批量处理:将多个小请求合并处理
  3. 模型选择:根据任务复杂度选择合适的模型
  4. 上下文管理:合理控制上下文长度
  5. 并发控制:避免过度并发导致限流

故障排查#

连接问题#

症状:无法连接到模型 API

解决方案

PRTCL // BASH
Terminal window
# 测试网络连接
curl -I https://api.openai.com
# 检查 API Key
openclaw model test <model-id>
# 查看详细日志
openclaw logs -f --level=debug

认证问题#

症状:401 Unauthorized 错误

解决方案

PRTCL // BASH
Terminal window
# 验证 API Key
echo $OPENAI_API_KEY
# 重新设置 API Key
export OPENAI_API_KEY="new-key"
# 测试连接
openclaw model test <model-id>

限流问题#

症状:429 Too Many Requests 错误

解决方案

PRTCL // YAML
# 降低请求频率
rateLimit:
enabled: true
requestsPerMinute: 60
# 使用多个 API Key
providers:
- name: "openai"
apiKeys:
- "${OPENAI_API_KEY_1}"
- "${OPENAI_API_KEY_2}"

本地模型性能问题#

症状:本地模型响应缓慢

解决方案

PRTCL // BASH
Terminal window
# 检查硬件资源
nvidia-smi # GPU 使用情况
free -h # 内存使用情况
# 使用量化模型
ollama pull qwen2.5:7b-q4_K_M
# 减少上下文长度
context:
maxTokens: 2048

最佳实践#

安全建议#

  • 保护 API Key:使用环境变量或密钥管理服务
  • 限制访问:配置适当的权限和访问控制
  • 审计日志:记录所有模型调用
  • 定期轮换:定期更换 API Key

成本控制#

  • 设置预算:配置每日 / 每月预算限制
  • 使用缓存:避免重复调用
  • 选择合适模型:根据任务选择性价比高的模型
  • 监控使用:定期检查 Token 使用情况

性能优化#

  • 模型路由:根据任务类型自动选择模型
  • 批量处理:合并相似请求
  • 本地优先:简单任务使用本地模型
  • 异步处理:耗时任务异步执行

资源链接#


最后更新: 2026-03-12 作者: EchoHaoRan

R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

OpenClaw模型配置完整指南

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21