Enhance environment configuration and error handling in API server and backend. Implement dynamic loading of .env files for various execution contexts, improve schema file path resolution, and refine vector search error handling in the orchestrator. Update ChromaDB integration to support memory mode and add persistence options for few-shot learning. Include additional logging for better traceability.

This commit is contained in:
lasean.zhou
2026-04-14 18:21:50 +08:00
parent ca8bc5e7de
commit 4ea3056e95
8 changed files with 161 additions and 41 deletions
+33 -3
View File
@@ -100,19 +100,49 @@ def setup_environment():
logger.warning("未设置 DASHSCOPE_MODEL")
return False
# 检查Schema文件
schema_path = Path("./data/schemas/G3SB_MCDataDictionary_table_structure.json")
# 检查Schema文件(支持相对路径和绝对路径)
schema_path_str = os.getenv("SCHEMA_PATH", "./data/schemas/G3SB_MCDataDictionary_table_structure.json")
schema_path = Path(schema_path_str)
# 如果是相对路径,尝试从多个位置查找
if not schema_path.is_absolute():
# 尝试1: PyInstaller 临时目录(单文件模式)
import sys
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
meipass_schema = Path(sys._MEIPASS) / schema_path_str
if meipass_schema.exists():
schema_path = meipass_schema
# 尝试2: 当前工作目录
if not schema_path.exists():
schema_path = Path.cwd() / schema_path_str
# 尝试3: 脚本所在目录
if not schema_path.exists():
script_dir = Path(__file__).resolve().parent.parent
schema_path = script_dir / schema_path_str
# 尝试4: 可执行文件所在目录
if not schema_path.exists() and getattr(sys, 'frozen', False):
exe_dir = Path(sys.executable).parent
schema_path = exe_dir / schema_path_str
if not schema_path.exists():
logger.warning(f"Schema文件不存在: {schema_path}")
logger.info("请将G3SB Schema文件放置在 ./data/schemas/ 目录")
return False
# 检查API Key
if not os.getenv("DEEPSEEK_API_KEY"):
api_key = os.getenv("DEEPSEEK_API_KEY", "").strip()
if not api_key:
logger.warning("环境变量 DEEPSEEK_API_KEY 未设置")
logger.info("请在 .env 文件中配置,或 export DEEPSEEK_API_KEY=your_key")
return False
logger.info(f"[OK] 环境检查通过")
logger.info(f" - Schema: {schema_path}")
logger.info(f" - API Key: {'已配置' if api_key else '未配置'}")
return True