@@ -129,8 +129,7 @@ def optimize_code(
129129 experiment_metadata : ExperimentMetadata | None = None ,
130130 * ,
131131 language : str = "python" ,
132- language_version : str
133- | None = None , # TODO:{claude} add language version to the language support and it should be cached
132+ language_version : str | None = None ,
134133 module_system : str | None = None ,
135134 is_async : bool = False ,
136135 n_candidates : int = 5 ,
@@ -177,16 +176,12 @@ def optimize_code(
177176 "is_numerical_code" : is_numerical_code ,
178177 }
179178
180- # Add language-specific version fields
181- # Always include python_version for backward compatibility with older backend
182- payload ["python_version" ] = platform .python_version ()
183- if is_python ():
184- pass # python_version already set
185- elif is_java ():
186- payload ["language_version" ] = language_version or "17" # Default Java version
187- else :
188- payload ["language_version" ] = language_version or "ES2022"
189- # Add module system for JavaScript/TypeScript (esm or commonjs)
179+ # Add language version (canonical for all languages)
180+ payload ["language_version" ] = language_version
181+ # Backward compat: backend still expects python_version
182+ payload ["python_version" ] = language_version if is_python () else platform .python_version ()
183+
184+ if not is_python ():
190185 if module_system :
191186 payload ["module_system" ] = module_system
192187
@@ -262,7 +257,8 @@ def get_jit_rewritten_code(self, source_code: str, trace_id: str) -> list[Optimi
262257 "source_code" : source_code ,
263258 "trace_id" : trace_id ,
264259 "dependency_code" : "" , # dummy value to please the api endpoint
265- "python_version" : "3.12.1" , # dummy value to please the api endpoint
260+ "language_version" : platform .python_version (),
261+ "python_version" : platform .python_version (), # backward compat
266262 "current_username" : get_last_commit_author_if_pr_exists (None ),
267263 "repo_owner" : git_repo_owner ,
268264 "repo_name" : git_repo_name ,
@@ -329,18 +325,15 @@ def optimize_python_code_line_profiler(
329325 logger .info ("Generating optimized candidates with line profiler…" )
330326 console .rule ()
331327
332- # Set python_version for backward compatibility with Python, or use language_version
333- python_version = language_version if language_version else platform .python_version ()
334-
335328 payload = {
336329 "source_code" : source_code ,
337330 "dependency_code" : dependency_code ,
338331 "n_candidates" : n_candidates ,
339332 "line_profiler_results" : line_profiler_results ,
340333 "trace_id" : trace_id ,
341- "python_version" : python_version ,
342334 "language" : language ,
343335 "language_version" : language_version ,
336+ "python_version" : language_version if is_python () else platform .python_version (), # backward compat
344337 "experiment_metadata" : experiment_metadata ,
345338 "codeflash_version" : codeflash_version ,
346339 "call_sequence" : self .get_next_sequence (),
@@ -434,14 +427,10 @@ def optimize_code_refinement(self, request: list[AIServiceRefinerRequest]) -> li
434427 "language" : opt .language ,
435428 }
436429
437- # Add language version - always include python_version for backward compatibility
438- item ["python_version" ] = platform .python_version ()
439- if is_python ():
440- pass # python_version already set
441- elif opt .language_version :
442- item ["language_version" ] = opt .language_version
443- else :
444- item ["language_version" ] = "ES2022" # Default for JS/TS
430+ # Add language version (canonical for all languages)
431+ item ["language_version" ] = opt .language_version
432+ # Backward compat: backend still expects python_version
433+ item ["python_version" ] = opt .language_version if is_python () else platform .python_version ()
445434
446435 # Add multi-file context if provided
447436 if opt .additional_context_files :
@@ -649,7 +638,8 @@ def generate_ranking(
649638 "diffs" : diffs ,
650639 "speedups" : speedups ,
651640 "optimization_ids" : optimization_ids ,
652- "python_version" : platform .python_version (),
641+ "language_version" : platform .python_version (),
642+ "python_version" : platform .python_version (), # backward compat
653643 "function_references" : function_references ,
654644 }
655645 logger .info ("loading|Generating ranking" )
@@ -785,18 +775,16 @@ def generate_regression_tests(
785775 "is_async" : function_to_optimize .is_async ,
786776 "call_sequence" : self .get_next_sequence (),
787777 "is_numerical_code" : is_numerical_code ,
778+ "class_name" : function_to_optimize .class_name ,
779+ "qualified_name" : function_to_optimize .qualified_name ,
788780 }
789781
790- # Add language-specific version fields
791- # Always include python_version for backward compatibility with older backend
792- payload ["python_version" ] = platform .python_version ()
793- if is_python ():
794- pass # python_version already set
795- elif is_java ():
796- payload ["language_version" ] = language_version or "17" # Default Java version
797- else :
798- payload ["language_version" ] = language_version or "ES2022"
799- # Add module system for JavaScript/TypeScript (esm or commonjs)
782+ # Add language version (canonical for all languages)
783+ payload ["language_version" ] = language_version
784+ # Backward compat: backend still expects python_version
785+ payload ["python_version" ] = language_version if is_python () else platform .python_version ()
786+
787+ if not is_python ():
800788 if module_system :
801789 payload ["module_system" ] = module_system
802790
@@ -884,7 +872,8 @@ def get_optimization_review(
884872 "codeflash_version" : codeflash_version ,
885873 "calling_fn_details" : calling_fn_details ,
886874 "language" : language ,
887- "python_version" : platform .python_version () if is_python () else None ,
875+ "language_version" : platform .python_version () if is_python () else None ,
876+ "python_version" : platform .python_version () if is_python () else None , # backward compat
888877 "call_sequence" : self .get_next_sequence (),
889878 }
890879 console .rule ()
0 commit comments