保存结果,并过滤掉 prompt, answer (代码), extra 等冗余字段
(self, result: Result)
| 172 | |
| 173 | |
| 174 | async def save_result(self, result: Result) -> None: |
| 175 | """ |
| 176 | 保存结果,并过滤掉 prompt, answer (代码), extra 等冗余字段 |
| 177 | """ |
| 178 | try: |
| 179 | # [修改点] 使用 exclude 参数过滤不需要的字段 |
| 180 | # 1. 'prompt': 题目描述太长,且不需要保存 |
| 181 | # 2. 'answer': 你提到代码不保存在这里 |
| 182 | # 3. 'ground_truth': 通常为 null 或不重要 |
| 183 | # 4. 'extra': 这里面包含了重复的 result 信息,直接去掉以减少冗余 |
| 184 | json_line = result.model_dump_json( |
| 185 | exclude={ |
| 186 | 'prompt', |
| 187 | 'answer', |
| 188 | 'ground_truth', |
| 189 | 'extra' |
| 190 | } |
| 191 | ) |
| 192 | |
| 193 | # 使用 'a' (append) 模式写入 |
| 194 | with open(self.output_file, 'a', encoding='utf-8') as f: |
| 195 | f.write(json_line + "\n") |
| 196 | |
| 197 | logger.info(f"| 💾 Saved result for Task {result.task_id} (Score: {result.score})") |
| 198 | |
| 199 | except Exception as e: |
| 200 | logger.error(f"| ❌ Failed to save result to file: {e}") |
| 201 | |
| 202 | |
| 203 | async def _setup_git_repo(self): |
no test coverage detected