H1W0XXX
commited on
Commit
·
d2a4c38
1
Parent(s):
03e172a
失败重试只发最近1次的文本
Browse files- run_eval.py +14 -4
run_eval.py
CHANGED
|
@@ -268,18 +268,25 @@ def main():
|
|
| 268 |
# --- AI Mode ---
|
| 269 |
else:
|
| 270 |
base64_image = encode_image(task['image_path'])
|
| 271 |
-
|
|
|
|
| 272 |
{"role": "system", "content": current_system_prompt},
|
| 273 |
{"role": "user", "content": [
|
| 274 |
{"type": "text", "text": "Analyze the structure in this image and output the JSON definition."},
|
| 275 |
{"type": "image_url", "image_url": {"url": base64_image}}
|
| 276 |
]}
|
| 277 |
]
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
for attempt in range(args.max_retries + 1):
|
| 280 |
attempts_used = attempt + 1
|
| 281 |
current_temp = 0.1 if attempt == 0 else 0.4
|
| 282 |
|
|
|
|
|
|
|
|
|
|
| 283 |
print(f"\n[Attempt {attempts_used}] Requesting API...")
|
| 284 |
response_text = run_chat_completion(client, args.model, messages, temperature=current_temp)
|
| 285 |
|
|
@@ -333,11 +340,14 @@ def main():
|
|
| 333 |
error_feedback = f"JSON Syntax Error: {e}"
|
| 334 |
fail_reason = "Syntax Error"
|
| 335 |
|
| 336 |
-
# Retry Logic
|
| 337 |
if attempt < args.max_retries and error_feedback:
|
| 338 |
print(f" -> Feedback: {error_feedback}")
|
| 339 |
-
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
# Final Score Calculation: Difficulty * Ratio
|
| 343 |
final_score = best_score * task.get("difficulty", 1)
|
|
|
|
| 268 |
# --- AI Mode ---
|
| 269 |
else:
|
| 270 |
base64_image = encode_image(task['image_path'])
|
| 271 |
+
# 基础对话历史 (System + User/Image)
|
| 272 |
+
base_messages = [
|
| 273 |
{"role": "system", "content": current_system_prompt},
|
| 274 |
{"role": "user", "content": [
|
| 275 |
{"type": "text", "text": "Analyze the structure in this image and output the JSON definition."},
|
| 276 |
{"type": "image_url", "image_url": {"url": base64_image}}
|
| 277 |
]}
|
| 278 |
]
|
| 279 |
+
|
| 280 |
+
# 用于重试的上下文 (Last Assistant Response + Error)
|
| 281 |
+
retry_context = []
|
| 282 |
|
| 283 |
for attempt in range(args.max_retries + 1):
|
| 284 |
attempts_used = attempt + 1
|
| 285 |
current_temp = 0.1 if attempt == 0 else 0.4
|
| 286 |
|
| 287 |
+
# 构造本次请求的消息列表
|
| 288 |
+
messages = base_messages + retry_context
|
| 289 |
+
|
| 290 |
print(f"\n[Attempt {attempts_used}] Requesting API...")
|
| 291 |
response_text = run_chat_completion(client, args.model, messages, temperature=current_temp)
|
| 292 |
|
|
|
|
| 340 |
error_feedback = f"JSON Syntax Error: {e}"
|
| 341 |
fail_reason = "Syntax Error"
|
| 342 |
|
| 343 |
+
# Retry Logic: 只保留最近一次的错误
|
| 344 |
if attempt < args.max_retries and error_feedback:
|
| 345 |
print(f" -> Feedback: {error_feedback}")
|
| 346 |
+
# 更新 retry_context,覆盖掉旧的错误历史
|
| 347 |
+
retry_context = [
|
| 348 |
+
{"role": "assistant", "content": response_text},
|
| 349 |
+
{"role": "user", "content": f"Error: {error_feedback} Fix the JSON."}
|
| 350 |
+
]
|
| 351 |
|
| 352 |
# Final Score Calculation: Difficulty * Ratio
|
| 353 |
final_score = best_score * task.get("difficulty", 1)
|