This commit is contained in:
@@ -95,12 +95,28 @@ class BailianService:
|
||||
{'role': 'user', 'content': f"{prompt}\n\n以下是需要评估的内容:\n{content}{chapter_context}"}
|
||||
]
|
||||
|
||||
completion = self.client.chat.completions.create(
|
||||
model=evaluation.model_selection,
|
||||
messages=messages,
|
||||
response_format={"type": "json_object"}
|
||||
)
|
||||
# 增加重试机制 (最多重试3次)
|
||||
completion = None
|
||||
last_error = None
|
||||
import time
|
||||
|
||||
for attempt in range(3):
|
||||
try:
|
||||
completion = self.client.chat.completions.create(
|
||||
model=evaluation.model_selection,
|
||||
messages=messages,
|
||||
response_format={"type": "json_object"}
|
||||
)
|
||||
break # 成功则跳出循环
|
||||
except Exception as e:
|
||||
last_error = e
|
||||
logger.warning(f"AI Evaluation attempt {attempt+1}/3 failed for eval {evaluation.id}: {e}")
|
||||
if attempt < 2:
|
||||
time.sleep(2 * (attempt + 1)) # 简单的指数退避
|
||||
|
||||
if not completion:
|
||||
raise last_error or Exception("AI Service call failed after retries")
|
||||
|
||||
response_content = completion.choices[0].message.content
|
||||
# Convert to dict for storage
|
||||
raw_response = completion.model_dump()
|
||||
|
||||
Reference in New Issue
Block a user