使用 LLM as a Judge 判断是否应该停止优化 Args: task: 任务 current_code: 当前代码 current_reasoning: 当前推理 eval_result: 评测结果 model: 模型名称 round_num: 当前轮数 Returns: (should_stop, reason): 是否停止及原因
(
task: Task,
current_code: str,
current_reasoning: str,
eval_result: Dict[str, Any],
model: str,
round_num: int,
)
| 490 | |
| 491 | |
| 492 | async def llm_judge_should_stop( |
| 493 | task: Task, |
| 494 | current_code: str, |
| 495 | current_reasoning: str, |
| 496 | eval_result: Dict[str, Any], |
| 497 | model: str, |
| 498 | round_num: int, |
| 499 | ) -> tuple[bool, str]: |
| 500 | """ |
| 501 | 使用 LLM as a Judge 判断是否应该停止优化 |
| 502 | |
| 503 | Args: |
| 504 | task: 任务 |
| 505 | current_code: 当前代码 |
| 506 | current_reasoning: 当前推理 |
| 507 | eval_result: 评测结果 |
| 508 | model: 模型名称 |
| 509 | round_num: 当前轮数 |
| 510 | |
| 511 | Returns: |
| 512 | (should_stop, reason): 是否停止及原因 |
| 513 | """ |
| 514 | question_text = task.input |
| 515 | eval_result_text = format_evaluation_result(eval_result) |
| 516 | status = eval_result.get("status", "Unknown") |
| 517 | |
| 518 | # 构建 LLM Judge 的 prompt |
| 519 | judge_system_prompt = f"""You are an expert code reviewer and judge for LeetCode solutions. |
| 520 | Your task is to evaluate whether the current solution is satisfactory and whether optimization should stop. |
| 521 | |
| 522 | Current Round: {round_num}/{MAX_REFLECTION_ROUNDS} |
| 523 | |
| 524 | Evaluation Criteria: |
| 525 | 1. **Correctness**: Is the solution accepted by LeetCode? (This is the most important criterion) |
| 526 | 2. **Efficiency**: If accepted, is the runtime and memory performance acceptable? |
| 527 | 3. **Code Quality**: Is the code clean, readable, and well-structured? |
| 528 | 4. **Improvement Potential**: Is there significant room for improvement? |
| 529 | |
| 530 | Decision Guidelines: |
| 531 | - If the solution is NOT accepted (Wrong Answer, TLE, Runtime Error, etc.), you should NOT stop - we need to fix the bugs. |
| 532 | - If the solution is Accepted with good performance (beats > 50%), you can consider stopping. |
| 533 | - If the solution is Accepted but with poor performance, consider whether optimization is worth the effort. |
| 534 | - Consider the current round number - if we're at the last round, we might want to stop. |
| 535 | |
| 536 | Output format: |
| 537 | The output should be a JSON object with the following fields: |
| 538 | {{ |
| 539 | "should_stop": true/false, |
| 540 | "reasoning": "Your detailed reasoning for the decision", |
| 541 | "suggestion": "If should_stop is false, provide a brief suggestion for improvement" |
| 542 | }} |
| 543 | """ |
| 544 | |
| 545 | judge_user_prompt = f"""## Problem |
| 546 | {question_text} |
| 547 | |
| 548 | ## Current Solution (Round {round_num}) |
| 549 | ### Reasoning: |
no test coverage detected