fix: chat 端点必须传入 api_key 参数

This commit is contained in:
zhanggangyong
2026-02-05 15:26:27 +00:00
parent 6bc7873bc3
commit a115ee68b0
3 changed files with 9 additions and 12 deletions
@@ -38,7 +38,6 @@ USER_ID = os.getenv("USER_ID", "")
# LLM 配置
LLM_BASE_URL = os.getenv("LLM_BASE_URL", "https://litellm.graystone-fb459c5d.southeastasia.azurecontainerapps.io/v1")
LLM_API_KEY = os.getenv("LLM_API_KEY", "")
LLM_MODEL = os.getenv("LLM_MODEL", "taiji/gpt-4o-mini")
# FastAPI 应用
@@ -635,9 +634,9 @@ async def chat_with_llm(message: str, context: str, api_key: str) -> str:
@app.post("/chat", response_model=ChatResponse)
async def chat(request: ChatRequest):
"""智能对话 - 获取技术分析并提供投资建议"""
api_key = request.api_key or LLM_API_KEY
if not api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数或设置 LLM_API_KEY 环境变量")
if not request.api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数")
api_key = request.api_key
# 从消息中提取股票代码
import re
@@ -41,7 +41,6 @@ NEWS_API_KEY = os.getenv("NEWS_API_KEY", "")
# LLM 配置
LLM_BASE_URL = os.getenv("LLM_BASE_URL", "https://litellm.graystone-fb459c5d.southeastasia.azurecontainerapps.io/v1")
LLM_API_KEY = os.getenv("LLM_API_KEY", "")
LLM_MODEL = os.getenv("LLM_MODEL", "taiji/gpt-4o-mini")
# FastAPI 应用
@@ -461,9 +460,9 @@ async def chat_with_llm(message: str, context: str, api_key: str) -> str:
@app.post("/chat", response_model=ChatResponse)
async def chat(request: ChatRequest):
"""智能对话 - 获取新闻并提供分析"""
api_key = request.api_key or LLM_API_KEY
if not api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数或设置 LLM_API_KEY 环境变量")
if not request.api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数")
api_key = request.api_key
# 从消息中提取关键词
import re
@@ -42,7 +42,6 @@ YAHOO_FINANCE_HOST = "yahoo-finance15.p.rapidapi.com"
# LLM 配置
LLM_BASE_URL = os.getenv("LLM_BASE_URL", "https://litellm.graystone-fb459c5d.southeastasia.azurecontainerapps.io/v1")
LLM_API_KEY = os.getenv("LLM_API_KEY", "")
LLM_MODEL = os.getenv("LLM_MODEL", "taiji/gpt-4o-mini")
# FastAPI 应用
@@ -415,9 +414,9 @@ def extract_symbols_from_message(message: str) -> List[str]:
@app.post("/chat", response_model=ChatResponse)
async def chat(request: ChatRequest):
"""智能对话 - 支持自然语言查询股票信息"""
api_key = request.api_key or LLM_API_KEY
if not api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数或设置 LLM_API_KEY 环境变量")
if not request.api_key:
raise HTTPException(status_code=400, detail="请提供 api_key 参数")
api_key = request.api_key
# 从消息中提取股票代码
symbols = extract_symbols_from_message(request.message)