tingwu_new
All checks were successful
Deploy to Server / deploy (push) Successful in 17s

This commit is contained in:
jeremygan2021
2026-03-11 22:35:37 +08:00
parent c32522857e
commit 5a87105ec9
2 changed files with 49 additions and 8 deletions

View File

@@ -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()