@@ -574,19 +574,6 @@ def determine_best_candidate(
574574 if not len (self .valid_optimizations ):
575575 return None
576576 # need to figure out the best candidate here before we return best_optimization
577- # new_explanation = self.aiservice_client.get_new_explanation(
578- # source_code=code_context.read_writable_code,
579- # dependency_code=code_context.read_only_context_code,
580- # trace_id=self.function_trace_id,
581- # num_candidates=1,
582- # experiment_metadata=None,
583- # existing_explanation=best_optimization.candidate.explanation,
584- # )
585- #
586- # best_optimization.candidate = replace(
587- # best_optimization.candidate,
588- # explanation=new_explanation if new_explanation != "" else best_optimization.candidate.explanation,
589- # )
590577 diff_lens_list = [] # character level diff
591578 runtimes_list = []
592579 for valid_opt in self .valid_optimizations :
@@ -1134,11 +1121,30 @@ def find_and_process_best_optimization(
11341121 )
11351122 if concolic_test_str :
11361123 generated_tests_str += "\n \n " + concolic_test_str
1137-
1124+ new_explanation_raw_str = self .aiservice_client .get_new_explanation (
1125+ source_code = code_context .read_writable_code ,
1126+ dependency_code = code_context .read_only_context_code ,
1127+ trace_id = self .function_trace_id [:- 4 ] + exp_type ,
1128+ optimized_code = best_optimization .candidate .source_code ,
1129+ original_line_profiler_results = original_code_baseline .line_profile_results ["str_out" ],
1130+ optimized_line_profiler_results = best_optimization .line_profiler_test_results ["str_out" ],
1131+ original_code_runtime = humanize_runtime (original_code_baseline .runtime ),
1132+ optimized_code_runtime = humanize_runtime (best_optimization .runtime ),
1133+ speedup = f"{ int (performance_gain (original_runtime_ns = original_code_baseline .runtime , optimized_runtime_ns = best_optimization .runtime ) * 100 )} %" ,
1134+ annotated_tests = generated_tests_str ,
1135+ optimization_id = best_optimization .candidate .optimization_id ,
1136+ )
1137+ new_explanation = Explanation (raw_explanation_message = new_explanation_raw_str , winning_behavior_test_results = explanation .winning_behavior_test_results ,
1138+ winning_benchmarking_test_results = explanation .winning_benchmarking_test_results ,
1139+ original_runtime_ns = explanation .original_runtime_ns ,
1140+ best_runtime_ns = explanation .best_runtime_ns ,
1141+ function_name = explanation .function_name ,
1142+ file_path = explanation .file_path ,
1143+ benchmark_details = explanation .benchmark_details )
11381144 check_create_pr (
11391145 original_code = original_code_combined ,
11401146 new_code = new_code_combined ,
1141- explanation = explanation ,
1147+ explanation = new_explanation ,
11421148 existing_tests_source = existing_tests ,
11431149 generated_original_test_source = generated_tests_str ,
11441150 function_trace_id = self .function_trace_id [:- 4 ] + exp_type
0 commit comments