配置说明

本文档详细介绍 Mindra 开源版本的 config.yaml 配置文件。

配置文件位置

配置文件 config.yaml 位于项目根目录:

Mindra-oa/
├── main.py
├── config.yaml    # 配置文件
└── ...

配置文件结构

database:
  host: "<database host>"
  database: "<database name>"
  user: "<username>"
  password: "<password>"

ai:
  api_key: "<api key>"
  base_url: "<base url>"

models:
  text_parsing: "<text parsing model>"
  image_parsing: "<image parsing model>"
  daily_conversation: "<daily conversation model>"

配置项详解

database 部分

数据库连接配置。

配置项 说明 示例
host 数据库主机地址 localhost127.0.0.1
database 数据库名称 mindra
user 数据库用户名 rootmindra_user
password 数据库密码 your_password

示例:

database:
  host: "localhost"
  database: "mindra"
  user: "root"
  password: "my_secret_password"

ai 部分

AI 服务配置。

配置项 说明 示例
api_key AI 服务 API 密钥 sk-xxxxxxxxxxxxxxxx
base_url AI 服务基础 URL https://api.openai.com/v1

示例:

ai:
  api_key: "sk-your-api-key-here"
  base_url: "https://api.openai.com/v1"

注意: 如果您使用兼容 OpenAI API 的其他服务(如本地部署的模型),请相应修改 base_url

models 部分

AI 模型配置,指定不同任务使用的模型。

配置项 说明 示例模型
text_parsing 文本解析模型 qwen-long-latest
image_parsing 图像分析模型 qwen3-vl-plus
daily_conversation 日常对话模型 deepseek-v3.1

示例:

models:
  text_parsing: "qwen-long-latest"
  image_parsing: "qwen3-vl-plus"
  daily_conversation: "deepseek-v3.1"

完整配置示例

使用 OpenAI 服务

database:
  host: "localhost"
  database: "mindra"
  user: "root"
  password: "password123"

ai:
  api_key: "sk-your-openai-api-key"
  base_url: "https://api.openai.com/v1"

models:
  text_parsing: "gpt-4-turbo-preview"
  image_parsing: "gpt-4-vision-preview"
  daily_conversation: "gpt-4-turbo-preview"

使用阿里云百炼服务

database:
  host: "localhost"
  database: "mindra"
  user: "root"
  password: "password123"

ai:
  api_key: "sk-your-dashscope-api-key"
  base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"

models:
  text_parsing: "qwen-long-latest"
  image_parsing: "qwen-vl-plus"
  daily_conversation: "qwen-max"

使用本地模型(如 Ollama)

database:
  host: "localhost"
  database: "mindra"
  user: "root"
  password: "password123"

ai:
  api_key: "ollama"  # 本地模型可使用任意值
  base_url: "http://localhost:11434/v1"

models:
  text_parsing: "llama3"
  image_parsing: "llava"
  daily_conversation: "llama3"

配置文件创建

如果项目中没有 config.yaml,请手动创建:

  1. 在项目根目录创建 config.yaml 文件
  2. 复制上面的配置模板
  3. 替换为您的实际配置

或使用命令行创建:

# 创建配置文件
cat > config.yaml << EOF
database:
  host: "localhost"
  database: "mindra"
  user: "root"
  password: "your_password"

ai:
  api_key: "your_api_key"
  base_url: "your_base_url"

models:
  text_parsing: "your_text_model"
  image_parsing: "your_image_model"
  daily_conversation: "your_conversation_model"
EOF

配置验证

创建测试脚本验证配置是否正确:

import yaml
from pathlib import Path

try:
    with open(Path("config.yaml"), 'r', encoding='utf-8') as f:
        config = yaml.safe_load(f)

    print("配置文件读取成功!")
    print(f"数据库主机: {config['database']['host']}")
    print(f"数据库名称: {config['database']['database']}")
    print(f"AI Base URL: {config['ai']['base_url']}")
    print(f"文本解析模型: {config['models']['text_parsing']}")

except FileNotFoundError:
    print("错误: 找不到 config.yaml 文件")
except KeyError as e:
    print(f"错误: 配置项缺失 {e}")
except Exception as e:
    print(f"错误: {e}")

安全注意事项

  1. 不要提交配置文件到版本控制

.gitignore 中添加:

config.yaml

  1. 保护 API 密钥

  2. 不要将 API 密钥分享给他人

  3. 不要将包含 API 密钥的配置文件上传到公开仓库

  4. 使用环境变量(可选)

为了更安全地管理配置,可以使用环境变量:

```python import os

api_key = os.getenv("MINRA_AI_API_KEY", "default_key") ```

常见问题

配置文件读取失败

错误信息: FileNotFoundError: No such file or directory: 'config.yaml'

解决方案: 确保在项目根目录创建 config.yaml 文件。

YAML 格式错误

错误信息: yaml.parser.ParserError

解决方案: 检查 YAML 文件格式,确保: - 使用空格缩进(不使用 Tab) - 冒号后有空格 - 字符串如包含特殊字符请用引号包裹

数据库连接失败

解决方案: 检查 database 部分配置是否正确,确保 MySQL 服务已启动。