hyx/config.py

49 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""全局配置模块。
课程要求:不要把 API Key 写死在代码里。
- API Key 从环境变量读取(推荐用 .env + python-dotenv
- 若缺失,则给出清晰错误提示
"""
from __future__ import annotations
import logging
import os
from typing import Dict
logger = logging.getLogger(__name__)
# --- API 配置 ---
# API Endpoint 和模型 ID 仍从环境变量读取,或使用默认值
OPENAI_API_BASE: str = os.getenv("OPENAI_API_BASE", "https://api.deepseek.com/v1")
MODEL_ID: str = os.getenv("MODEL_ID", "deepseek-chat")
# --- 统一使用一个 API Key ---
# 从环境变量读取(建议用 .env + python-dotenv
# 兼容多种命名:优先 OPENAI_API_KEY其次 DEEPSEEK_API_KEY
API_KEY: str = os.getenv("OPENAI_API_KEY") or os.getenv("DEEPSEEK_API_KEY", "")
API_BASE: str = OPENAI_API_BASE
# 兼容旧代码:历史版本可能引用 ROLE_API_KEY_MAP
ROLE_API_KEY_MAP: Dict[str, str] = {"default": API_KEY}
# --- Agent 默认参数 ---
MAX_TOKENS: int = 1000
TEMPERATURE: float = 0.7
MAX_RETRIES: int = 3
RETRY_INITIAL_DELAY: float = 1.5 # 秒
RETRY_BACKOFF_FACTOR: float = 2.0
RETRY_MAX_DELAY: float = 10.0
# --- 角色系统提示 ---
AGENT_ROLES: Dict[str, str] = {
"product_manager": "你是一位经验丰富的产品经理,擅长从用户需求和市场角度分析方案,关注产品的价值和可行性。",
"tech_expert": "你是一位资深技术专家,擅长从技术实现角度分析方案,关注架构设计、技术风险和性能优化。",
"user_representative": "你是一位典型的终端用户,擅长从实际使用角度分析方案,关注用户体验、易用性和实用性。",
"business_analyst": "你是一位专业的商业分析师,擅长从商业价值角度分析方案,关注成本效益、投资回报率和市场竞争力。",
"designer": "你是一位优秀的设计师,擅长从设计角度分析方案,关注视觉效果、交互设计和用户体验。",
}
# --- 为兼容旧代码,保持部分常量导出 ---
API_BASE: str = OPENAI_API_BASE