返回首页

🏷️ 标签(3)

🗂️ 分类(2)

第7章 配置详解 - config 文件逐项说明

第7章 配置详解 - config 文件逐项说明

完整的配置文件说明,包括模型接入、渠道设置、人设编写、记忆系统等。

🎯 本章目标

  • 目标 1

  • 目标 2

  • 目标 3

  • 目标 4


主要内容

配置文件结构

OpenClaw 的配置文件位于 ~/.openclaw/config.json,采用 JSON 格式。

完整配置示例

{
  "model": {
    "provider": "openai",
    "name": "gpt-4o",
    "apiKey": "sk-proj-xxxxx",
    "baseURL": "https://api.openai.com/v1",
    "temperature": 0.7,
    "maxTokens": 4096,
    "topP": 1.0,
    "frequencyPenalty": 0.0,
    "presencePenalty": 0.0
  },
  "agent": {
    "name": "OpenClaw Assistant",
    "systemPrompt": "你是一个专业的AI助手...",
    "maxHistoryLength": 10,
    "thinkingMode": "normal"
  },
  "memory": {
    "enabled": true,
    "type": "vector",
    "provider": "pinecone",
    "apiKey": "xxxxx",
    "indexName": "openclaw",
    "dimension": 1536,
    "maxResults": 5
  },
  "skills": {
    "enabled": ["web_search", "web_fetch"],
    "disabled": ["shell"],
    "config": {
      "web_search": {
        "engine": "google",
        "maxResults": 5
      }
    }
  },
  "channels": {
    "qq": {
      "enabled": true,
      "protocol": "napcat",
      "host": "localhost",
      "port": 3001
    },
    "feishu": {
      "enabled": false,
      "appId": "xxxxx",
      "appSecret": "xxxxx"
    }
  },
  "server": {
    "port": 3000,
    "host": "0.0.0.0",
    "cors": true
  },
  "log": {
    "level": "info",
    "file": "~/.openclaw/logs/openclaw.log",
    "maxSize": "10m",
    "maxFiles": 5
  },
  "security": {
    "sandbox": {
      "enabled": true,
      "type": "docker",
      "timeout": 30000
    },
    "rateLimit": {
      "enabled": true,
      "maxRequests": 100,
      "windowMs": 60000
    }
  }
}

模型配置详解

OpenAI 配置

{
  "model": {
    "provider": "openai",
    "name": "gpt-4o",
    "apiKey": "sk-proj-xxxxx",
    "baseURL": "https://api.openai.com/v1",
    "temperature": 0.7
  }
}

参数说明:

  • provider: 模型提供商,固定为 “openai”

  • name: 模型名称,可选值:

    • gpt-4o - 最新旗舰模型(推荐)
    • gpt-4o-mini - 轻量级模型(便宜)
    • gpt-4-turbo - 上一代旗舰
    • gpt-3.5-turbo - 经济型
  • apiKey: OpenAI API Key

  • baseURL: API 端点(可选,用于代理)

  • temperature: 温度参数(0-2),越高越随机

Anthropic Claude 配置

{
  "model": {
    "provider": "anthropic",
    "name": "claude-3-5-sonnet-20241022",
    "apiKey": "sk-ant-xxxxx",
    "baseURL": "https://api.anthropic.com",
    "temperature": 0.7,
    "maxTokens": 4096
  }
}

推荐模型:

  • claude-3-5-sonnet-20241022 - 最新版本(推荐)

  • claude-3-opus-20240229 - 最强模型

  • claude-3-haiku-20240307 - 最快模型

阿里通义千问配置

{
  "model": {
    "provider": "alibaba",
    "name": "qwen-max",
    "apiKey": "sk-xxxxx",
    "baseURL": "https://dashscope.aliyuncs.com/api/v1"
  }
}

本地 Ollama 配置

{
  "model": {
    "provider": "ollama",
    "name": "llama3.3",
    "baseURL": "http://localhost:11434",
    "temperature": 0.7
  }
}

使用 Ollama:

# 安装 Ollama
curl -fsSL https://ollama.ai/install.sh | sh

# 启动服务
ollama serve

# 拉取模型
ollama pull llama3.3
ollama pull qwen2.5
ollama pull deepseek-coder

最佳实践

  1. 实践 1 - 说明

  2. 实践 2 - 说明

  3. 实践 3 - 说明

常见问题

问题 1

症状:错误描述

解决方案

# 解决命令

下一步


📚 本章小结

✅ 完成了主要学习目标
✅ 掌握了核心概念
✅ 实践了示例代码
✅ 了解了最佳实践


返回目录 | 上一章 | 下一章