config.py
1 # Copyright (c) 2024-2026 Tencent Zhuque Lab. All rights reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # Requirement: Any integration or derivative work must explicitly attribute 16 # Tencent Zhuque Lab (https://github.com/Tencent/AI-Infra-Guard) in its 17 # documentation or user interface, as detailed in the NOTICE file. 18 19 import os 20 from typing import Optional 21 from pathlib import Path 22 23 # Configuration settings 24 # 获取项目根目录(config.py 在 utils/ 目录下,所以需要获取父目录) 25 base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 26 27 # 自动加载 .env 文件 28 try: 29 from dotenv import load_dotenv 30 env_file = Path(base_dir) / ".env" 31 if env_file.exists(): 32 load_dotenv(env_file) 33 except ImportError: 34 # python-dotenv 未安装,跳过 35 pass 36 37 38 def get_env(key: str, default: Optional[str] = None) -> Optional[str]: 39 """获取环境变量,如果不存在则返回默认值""" 40 return os.environ.get(key, default) 41 42 43 # ===== 主要 LLM 配置 ===== 44 DEFAULT_MODEL = get_env("DEFAULT_MODEL", "deepseek/deepseek-v3.2-exp") 45 DEFAULT_BASE_URL = get_env("DEFAULT_BASE_URL", "https://openrouter.ai/api/v1") 46 47 # ===== 专用 LLM 配置 ===== 48 # Thinking 模型 49 THINKING_MODEL = get_env("THINKING_MODEL", "google/gemini-2.5-pro") 50 THINKING_BASE_URL = get_env("THINKING_BASE_URL", DEFAULT_BASE_URL) 51 THINKING_API_KEY = get_env("THINKING_API_KEY") # 可选,不设置则使用主 API Key 52 53 # Coding 模型 54 CODING_MODEL = get_env("CODING_MODEL", "anthropic/claude-sonnet-4.5") 55 CODING_BASE_URL = get_env("CODING_BASE_URL", DEFAULT_BASE_URL) 56 CODING_API_KEY = get_env("CODING_API_KEY") # 可选,不设置则使用主 API Key 57 58 # Fast 模型 59 FAST_MODEL = get_env("FAST_MODEL", "google/gemini-2.0-flash-exp") 60 FAST_BASE_URL = get_env("FAST_BASE_URL", DEFAULT_BASE_URL) 61 FAST_API_KEY = get_env("FAST_API_KEY") # 可选,不设置则使用主 API Key 62 63 # ===== Debug 和日志配置 ===== 64 LAMINAR_API_KEY = get_env("LAMINAR_API_KEY") 65 LOG_LEVEL = get_env("LOG_LEVEL", "INFO")