MND-IA/CONFIG_GUIDE.md
2025-12-31 19:58:09 +08:00

3.0 KiB
Raw Blame History

Configuration Example

配置文件使用说明

这是 MND-IA 系统的配置文件模板。

配置项说明

LLM 配置

"llm": {
  "model_name": "gpt-4",              // 模型名称(支持 gpt-4, gpt-3.5-turbo, glm-4, claude-3.5-sonnet 等)
  "api_base": "https://api.openai.com/v1",  // API 地址
  "api_key": "your-api-key-here",     // API Key必填
  "temperature": 0.7,                  // 生成温度0-1
  "max_tokens": 2000,                  // 最大生成长度
  "timeout": 60                        // 超时时间(秒)
}

系统配置

"system": {
  "data_dir": "data",                  // 数据存储目录
  "cache_dir": "data/news_cache",      // 新闻缓存目录
  "log_level": "INFO"                  // 日志级别
}

爬虫配置

"crawler": {
  "max_retries": 3,                    // 最大重试次数
  "retry_delay": 5,                    // 重试间隔(秒)
  "cache_days": 7                      // 缓存保留天数
}

交易配置

"trading": {
  "max_position_ratio": 0.2,           // 单个资产最大仓位比例
  "risk_free_rate": 0.02               // 无风险利率
}

使用不同的 LLM 提供商

OpenAI

"llm": {
  "model_name": "gpt-4",
  "api_base": "https://api.openai.com/v1",
  "api_key": "sk-xxxxxxxxxxxx"
}

智谱 GLM

"llm": {
  "model_name": "glm-4",
  "api_base": "https://open.bigmodel.cn/api/paas/v4",
  "api_key": "xxxxxxxxxxxx.xxxxxxxxxxxx"
}

Claude (Anthropic)

"llm": {
  "model_name": "claude-3-5-sonnet-20241022",
  "api_base": "https://api.anthropic.com/v1",
  "api_key": "sk-ant-xxxxxxxxxxxx"
}

本地部署Ollama

"llm": {
  "model_name": "qwen2.5:14b",
  "api_base": "http://localhost:11434/v1",
  "api_key": "ollama"
}

代码中使用配置

方式 1直接访问配置属性

from core.config import config

# 获取模型名称
model = config.model_name

# 获取 API Key
api_key = config.api_key

# 获取完整 LLM 配置
llm_config = config.llm_config

方式 2使用统一的 LLM 调用接口

from core.config import llm_call

# 直接调用 LLM
response = llm_call(
    messages=[
        {"role": "system", "content": "你是 A 股分析师"},
        {"role": "user", "content": "分析这条新闻..."}
    ],
    temperature=0.5  # 可以覆盖配置文件中的默认值
)

方式 3获取配置好的客户端

from core.config import get_llm_client

client = get_llm_client()
if client:
    response = client.chat.completions.create(...)

环境变量支持TODO

未来版本将支持环境变量覆盖:

export MND_IA_API_KEY="sk-xxxxxxxxxxxx"
export MND_IA_MODEL_NAME="gpt-4"

安全提示

⚠️ 重要

  1. 不要将包含真实 API Key 的 config.json 提交到 Git
  2. 建议将 config.json 添加到 .gitignore
  3. 团队协作时,提供 config.example.json 模板
  4. 生产环境使用环境变量或密钥管理服务