|
8 | 8 | import time |
9 | 9 | import uuid |
10 | 10 | from collections import defaultdict, deque |
| 11 | +from dataclasses import replace |
11 | 12 | from pathlib import Path |
12 | 13 | from typing import TYPE_CHECKING |
13 | 14 |
|
@@ -254,29 +255,28 @@ def optimize_function(self) -> Result[BestOptimization, str]: |
254 | 255 | ) |
255 | 256 |
|
256 | 257 | if best_optimization: |
257 | | - logger.info("Best candidate:") |
258 | | - code_print(best_optimization.candidate.source_code) |
259 | | - console.print( |
260 | | - Panel( |
261 | | - best_optimization.candidate.explanation, title="Best Candidate Explanation", border_style="blue" |
262 | | - ) |
263 | | - ) |
264 | | - #could possibly have it in the best optimization dataclass |
265 | 258 | new_explanation = self.aiservice_client.get_new_explanation(source_code=code_context.read_writable_code, |
266 | 259 | dependency_code=code_context.read_only_context_code, |
267 | 260 | trace_id=self.function_trace_id, |
268 | 261 | num_candidates=1, |
269 | 262 | experiment_metadata=None, existing_explanation=best_optimization.candidate.explanation) |
| 263 | + best_optimization.candidate = replace(best_optimization.candidate, explanation=new_explanation if new_explanation!="" else best_optimization.candidate.explanation) |
270 | 264 | explanation = Explanation( |
271 | | - raw_explanation_message=new_explanation if new_explanation!="" else best_optimization.candidate.explanation, |
| 265 | + raw_explanation_message=best_optimization.candidate.explanation, |
272 | 266 | winning_behavioral_test_results=best_optimization.winning_behavioral_test_results, |
273 | 267 | winning_benchmarking_test_results=best_optimization.winning_benchmarking_test_results, |
274 | 268 | original_runtime_ns=original_code_baseline.runtime, |
275 | 269 | best_runtime_ns=best_optimization.runtime, |
276 | 270 | function_name=function_to_optimize_qualified_name, |
277 | 271 | file_path=self.function_to_optimize.file_path, |
278 | 272 | ) |
279 | | - |
| 273 | + logger.info("Best candidate:") |
| 274 | + code_print(best_optimization.candidate.source_code) |
| 275 | + console.print( |
| 276 | + Panel( |
| 277 | + best_optimization.candidate.explanation, title="Best Candidate Explanation", border_style="blue" |
| 278 | + ) |
| 279 | + ) |
280 | 280 | self.log_successful_optimization(explanation, generated_tests) |
281 | 281 |
|
282 | 282 | self.replace_function_and_helpers_with_optimized_code( |
|
0 commit comments