Update stock_analyzer.py
This commit is contained in:
@@ -237,8 +237,16 @@ class StockAnalyzer:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# OpenAI API 调用
|
# OpenAI API 调用
|
||||||
response = requests.post(
|
api_urls = [
|
||||||
f"{self.API_URL}/chat/completions",
|
f"{self.API_URL}/chat/completions",
|
||||||
|
f"{self.API_URL}/v1/chat/completions"
|
||||||
|
]
|
||||||
|
|
||||||
|
last_error = None
|
||||||
|
for api_url in api_urls:
|
||||||
|
try:
|
||||||
|
response = requests.post(
|
||||||
|
api_url,
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f"Bearer {self.API_KEY}",
|
"Authorization": f"Bearer {self.API_KEY}",
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@@ -253,8 +261,15 @@ class StockAnalyzer:
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()['choices'][0]['message']['content']
|
return response.json()['choices'][0]['message']['content']
|
||||||
else:
|
else:
|
||||||
print(f"API 错误: {response.status_code} - {response.text}")
|
last_error = f"API 错误: {response.status_code} - {response.text}"
|
||||||
return f"AI 分析暂时无法使用 (HTTP {response.status_code})"
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
last_error = str(e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"AI 分析暂时无法使用: {last_error}")
|
||||||
|
return f"AI 分析暂时无法使用: {last_error}"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"AI 分析发生错误: {str(e)}")
|
print(f"AI 分析发生错误: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user