Files
ailine/frontend/config.py
root 626bae54ff
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 18s
前端修改
2026-04-16 03:21:38 +08:00

62 lines
1.8 KiB
Python
Raw 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.

"""
前端配置管理模块
集中管理所有配置项,支持环境变量覆盖
"""
import os
from dataclasses import dataclass
from dotenv import load_dotenv
# 加载 .env 文件
load_dotenv()
@dataclass
class FrontendConfig:
"""前端配置类 - 统一管理所有配置项"""
# ==================== API 配置 ====================
api_base: str = ""
# ==================== 页面配置 ====================
page_title: str = "AI 个人助手"
page_icon: str = "🤖"
layout: str = "wide"
# ==================== 模型配置 ====================
default_model: str = "zhipu"
model_options: dict = None
# ==================== 用户配置 ====================
default_user_id: str = "default_user"
# ==================== 历史记录配置 ====================
history_limit: int = 50
summary_max_length: int = 30
# ==================== 流式响应配置 ====================
stream_timeout: int = 120
def __post_init__(self):
"""初始化后处理 - 设置默认值和加载环境变量"""
if self.model_options is None:
self.model_options = {
"zhipu": "智谱 GLM-4.7-Flash在线",
"deepseek": "DeepSeek V3.2(在线)",
"local": "本地 llama.cppGemma-4"
}
# 从环境变量加载配置
self._load_from_env()
def _load_from_env(self):
"""从环境变量加载配置(优先级最高)"""
# API 地址(移除 /chat 后缀)
# 优先级:环境变量 API_URL > 默认值
api_url = os.getenv("API_URL", "http://localhost:8083")
self.api_base = api_url.replace("/chat", "").rstrip("/")
# 全局配置实例(单例模式)
config = FrontendConfig()