fix(streamlit_app): 修复DeepSeek API密钥验证逻辑

增加对默认API密钥值的检查,当密钥未配置或为默认值时显示警告并使用模拟响应
This commit is contained in:
你的姓名 2026-01-16 00:17:56 +08:00
parent 52c426b241
commit dbebd707ba

View File

@ -897,13 +897,15 @@ def call_deepseek_api(prompt, max_tokens=1000, temperature=0.7):
try: try:
import os import os
from dotenv import load_dotenv from dotenv import load_dotenv
# 重新加载环境变量确保使用最新的API密钥
load_dotenv() load_dotenv()
url = "https://api.deepseek.com/v1/chat/completions" url = "https://api.deepseek.com/v1/chat/completions"
api_key = os.getenv("DEEPSEEK_API_KEY", "") # 使用环境变量 api_key = os.getenv("DEEPSEEK_API_KEY", "") # 使用环境变量
if not api_key: # 检查API密钥是否为空或默认值
st.warning("DeepSeek API密钥未配置使用模拟响应") if not api_key or api_key == "your-key-here":
st.warning("DeepSeek API密钥未配置或无效使用模拟响应")
# 返回模拟响应 # 返回模拟响应
return """ return """
# 个性化关怀方案 # 个性化关怀方案