1313from typing import TYPE_CHECKING
1414
1515import libcst as cst
16+ import sentry_sdk
1617from rich .console import Group
1718from rich .panel import Panel
1819from rich .syntax import Syntax
@@ -583,6 +584,7 @@ def determine_best_candidate(
583584 baseline_results = original_code_baseline ,
584585 original_helper_code = original_helper_code ,
585586 file_path_to_helper_classes = file_path_to_helper_classes ,
587+ code_context = code_context ,
586588 )
587589 console .rule ()
588590 if not is_successful (run_results ):
@@ -672,21 +674,21 @@ def determine_best_candidate(
672674 async_throughput = candidate_result .async_throughput ,
673675 )
674676 valid_optimizations .append (best_optimization )
675- # queue corresponding refined optimization for best optimization
676- if not candidate .optimization_id .endswith ("refi" ):
677- future_all_refinements .append (
678- self .refine_optimizations (
679- valid_optimizations = [best_optimization ],
680- original_code_baseline = original_code_baseline ,
681- code_context = code_context ,
682- trace_id = self .function_trace_id [:- 4 ] + exp_type
683- if self .experiment_id
684- else self .function_trace_id ,
685- ai_service_client = ai_service_client ,
686- executor = self .executor ,
687- function_references = function_references ,
688- )
689- )
677+ # # queue corresponding refined optimization for best optimization
678+ # if not candidate.optimization_id.endswith("refi"):
679+ # future_all_refinements.append(
680+ # self.refine_optimizations(
681+ # valid_optimizations=[best_optimization],
682+ # original_code_baseline=original_code_baseline,
683+ # code_context=code_context,
684+ # trace_id=self.function_trace_id[:-4] + exp_type
685+ # if self.experiment_id
686+ # else self.function_trace_id,
687+ # ai_service_client=ai_service_client,
688+ # executor=self.executor,
689+ # function_references=function_references,
690+ # )
691+ # )
690692 else :
691693 # For async functions, prioritize throughput metrics over runtime even for slow candidates
692694 is_async = (
@@ -1813,6 +1815,7 @@ def run_optimized_candidate(
18131815 )
18141816 )
18151817 console .rule ()
1818+ # print(type(code_context), type(candidate))
18161819 match , diffs = compare_test_results (baseline_results .behavior_test_results , candidate_behavior_results )
18171820 if match :
18181821 logger .info ("h3|Test results matched ✅" )
@@ -1823,7 +1826,25 @@ def run_optimized_candidate(
18231826 # if the test unmatched percentage is greater than 50%, we can't fix it
18241827 return self .get_results_not_matched_error ()
18251828
1826- print (f"should try to fix it, diffs: { diffs } " )
1829+ logger .info ("running code repair..." )
1830+ # not sure if all return types will be convertible to string
1831+ diff_per_test_fn = {}
1832+ for diff in diffs :
1833+ try :
1834+ diff_per_test_fn .setdefault (diff .test_src_code , []).append (
1835+ f"Expected Value: { diff .original_value !s} \n Actual Value: { diff .candidate_value !s} \n Error String:{ diff .pytest_error } "
1836+ )
1837+ except Exception as e :
1838+ sentry_sdk .capture_exception (e )
1839+ logger .exception (e )
1840+ try :
1841+ test_issues = "\n " .join (
1842+ f"{ test_fn_def } \n { value } " for test_fn_def , value in diff_per_test_fn .items ()
1843+ )
1844+ except Exception as e :
1845+ sentry_sdk .capture_exception (e )
1846+ logger .exception (e )
1847+ print (type (diff_per_test_fn ), type (test_issues ))
18271848 # with the parsed test results diff ask the llm to fix the candidate to match the test results of the original code, and run again
18281849 # self.run_optimized_candidate(
18291850 # optimization_candidate_index=optimization_candidate_index,
0 commit comments