H1W0XXX commited on
Commit ·
d2a4c38
1
Parent(s): 03e172a
失败重试只发最近1次的文本
Browse files267 unmodified lines26826927027127227327427527627727827928028128228328428547 unmodified lines333334335336337338339340341342343267 unmodified lines# --- AI Mode ---else:base64_image = encode_image(task['image_path'])messages = [{"role": "system", "content": current_system_prompt},{"role": "user", "content": [{"type": "text", "text": "Analyze the structure in this image and output the JSON definition."},{"type": "image_url", "image_url": {"url": base64_image}}]}]for attempt in range(args.max_retries + 1):attempts_used = attempt + 1current_temp = 0.1 if attempt == 0 else 0.4print(f"\n[Attempt {attempts_used}] Requesting API...")response_text = run_chat_completion(client, args.model, messages, temperature=current_temp)47 unmodified lineserror_feedback = f"JSON Syntax Error: {e}"fail_reason = "Syntax Error"# Retry Logicif attempt < args.max_retries and error_feedback:print(f" -> Feedback: {error_feedback}")messages.append({"role": "assistant", "content": response_text})messages.append({"role": "user", "content": f"Error: {error_feedback} Fix the JSON."})# Final Score Calculation: Difficulty * Ratiofinal_score = best_score * task.get("difficulty", 1)267 unmodified lines26826927027127227327427527627727827928028128228328428528628728828929029129247 unmodified lines340341342343344345346347348349350351352353267 unmodified lines# --- AI Mode ---else:base64_image = encode_image(task['image_path'])# 基础对话历史 (System + User/Image)base_messages = [{"role": "system", "content": current_system_prompt},{"role": "user", "content": [{"type": "text", "text": "Analyze the structure in this image and output the JSON definition."},{"type": "image_url", "image_url": {"url": base64_image}}]}]# 用于重试的上下文 (Last Assistant Response + Error)retry_context = []for attempt in range(args.max_retries + 1):attempts_used = attempt + 1current_temp = 0.1 if attempt == 0 else 0.4# 构造本次请求的消息列表messages = base_messages + retry_contextprint(f"\n[Attempt {attempts_used}] Requesting API...")response_text = run_chat_completion(client, args.model, messages, temperature=current_temp)47 unmodified lineserror_feedback = f"JSON Syntax Error: {e}"fail_reason = "Syntax Error"# Retry Logic: 只保留最近一次的错误if attempt < args.max_retries and error_feedback:print(f" -> Feedback: {error_feedback}")# 更新 retry_context,覆盖掉旧的错误历史retry_context = [{"role": "assistant", "content": response_text},{"role": "user", "content": f"Error: {error_feedback} Fix the JSON."}]# Final Score Calculation: Difficulty * Ratiofinal_score = best_score * task.get("difficulty", 1)
run_eval.py+14-4