|
|
@@ -16,6 +16,40 @@ from google import genai
|
|
|
from src.utils.logger import get_logger
|
|
|
from src.utils.json_extractor import JSONExtractor
|
|
|
|
|
|
+# 添加项目根目录到路径
|
|
|
+project_root = Path(__file__).parent.parent
|
|
|
+sys.path.insert(0, str(project_root))
|
|
|
+
|
|
|
+# 手动加载.env文件
|
|
|
+def load_env_file(env_path):
|
|
|
+ """手动加载.env文件"""
|
|
|
+ if not env_path.exists():
|
|
|
+ return False
|
|
|
+
|
|
|
+ with open(env_path, 'r') as f:
|
|
|
+ for line in f:
|
|
|
+ line = line.strip()
|
|
|
+ # 跳过注释和空行
|
|
|
+ if not line or line.startswith('#'):
|
|
|
+ continue
|
|
|
+ # 解析KEY=VALUE
|
|
|
+ if '=' in line:
|
|
|
+ key, value = line.split('=', 1)
|
|
|
+ os.environ[key.strip()] = value.strip()
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
+env_path = project_root / ".env"
|
|
|
+if load_env_file(env_path):
|
|
|
+ print(f"✅ 已加载环境变量从: {env_path}")
|
|
|
+ # 验证API密钥
|
|
|
+ api_key = os.environ.get("GEMINI_API_KEY", "")
|
|
|
+ if api_key:
|
|
|
+ print(f" GEMINI_API_KEY: {api_key[:10]}...")
|
|
|
+else:
|
|
|
+ print(f"⚠️ 未找到.env文件: {env_path}")
|
|
|
+
|
|
|
+
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
# Gemini 文件处理相关常量
|