From 19e5745d6225b6581ebab9ab332f810e96f171c2 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 16:14:47 -0700 Subject: [PATCH 1/7] generated tests as multiple markdown blocks instead of a single block --- codeflash/optimization/function_optimizer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index d43198e68..d00954b45 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -1379,11 +1379,13 @@ def process_review( generated_tests, original_runtime_by_test, optimized_runtime_by_test ) - generated_tests_str = "\n#------------------------------------------------\n".join( - [test.generated_original_test_source for test in generated_tests.generated_tests] - ) + generated_tests_str = "" + for test in generated_tests.generated_tests: + generated_tests_str += f"```python\n{test.generated_original_test_source}\n```" + generated_tests_str += "\n\n" + if concolic_test_str: - generated_tests_str += "\n#------------------------------------------------\n" + concolic_test_str + generated_tests_str += f"```python\n{concolic_test_str}\n```\n\n" existing_tests, replay_tests, concolic_tests = existing_tests_source_for( self.function_to_optimize.qualified_name_with_modules_from_root(self.project_root), From 497da46a157cc47659d165bdaf9b69bc9f65dbc7 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:50:50 -0700 Subject: [PATCH 2/7] send codeflash cli version to backend for backwards compatibility --- codeflash/api/aiservice.py | 5 +++++ codeflash/optimization/function_optimizer.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index e15333d75..af4d7fd49 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -21,6 +21,7 @@ from codeflash.models.ExperimentMetadata import ExperimentMetadata from codeflash.models.models import AIServiceRefinerRequest, CodeStringsMarkdown, OptimizedCandidate from codeflash.telemetry.posthog_cf import ph +from codeflash.version import __version__ from codeflash.version import __version__ as codeflash_version if TYPE_CHECKING: @@ -308,6 +309,7 @@ def get_new_explanation( # noqa: D417 original_throughput: str | None = None, optimized_throughput: str | None = None, throughput_improvement: str | None = None, + codeflash_version: str | None = "0.17.2", ) -> str: """Optimize the given python code for performance by making a request to the Django endpoint. @@ -327,6 +329,7 @@ def get_new_explanation( # noqa: D417 - original_throughput: str | None - throughput for the baseline code (operations per second) - optimized_throughput: str | None - throughput for the optimized code (operations per second) - throughput_improvement: str | None - throughput improvement percentage + - current codeflash version Returns ------- @@ -349,6 +352,7 @@ def get_new_explanation( # noqa: D417 "original_throughput": original_throughput, "optimized_throughput": optimized_throughput, "throughput_improvement": throughput_improvement, + "codeflash_version": codeflash_version, } logger.info("loading|Generating explanation") console.rule() @@ -591,6 +595,7 @@ def get_optimization_impact( "benchmark_details": explanation.benchmark_details if explanation.benchmark_details else None, "optimized_runtime": humanize_runtime(explanation.best_runtime_ns), "original_runtime": humanize_runtime(explanation.original_runtime_ns), + "codeflash_version": __version__, } console.rule() try: diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index d00954b45..813df1c72 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -101,6 +101,7 @@ from codeflash.verification.test_runner import run_behavioral_tests, run_benchmarking_tests, run_line_profile_tests from codeflash.verification.verification_utils import get_test_file_path from codeflash.verification.verifier import generate_tests +from codeflash.version import __version__ if TYPE_CHECKING: from argparse import Namespace @@ -1427,6 +1428,7 @@ def process_review( original_throughput=original_throughput_str, optimized_throughput=optimized_throughput_str, throughput_improvement=throughput_improvement_str, + codeflash_version=__version__, ) new_explanation = Explanation( raw_explanation_message=new_explanation_raw_str or explanation.raw_explanation_message, From 7f1445beab115786a80943e05673359e9af8f280 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:52:21 -0700 Subject: [PATCH 3/7] Apply suggestion from @aseembits93 --- codeflash/api/aiservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index af4d7fd49..42314505a 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -309,7 +309,7 @@ def get_new_explanation( # noqa: D417 original_throughput: str | None = None, optimized_throughput: str | None = None, throughput_improvement: str | None = None, - codeflash_version: str | None = "0.17.2", + codeflash_version: str = codeflash_version, ) -> str: """Optimize the given python code for performance by making a request to the Django endpoint. From 786136ab96ff9c93d1064ef21f0ca810663c6dbb Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:52:47 -0700 Subject: [PATCH 4/7] Apply suggestion from @aseembits93 --- codeflash/api/aiservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index 42314505a..b17456b10 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -595,7 +595,7 @@ def get_optimization_impact( "benchmark_details": explanation.benchmark_details if explanation.benchmark_details else None, "optimized_runtime": humanize_runtime(explanation.best_runtime_ns), "original_runtime": humanize_runtime(explanation.original_runtime_ns), - "codeflash_version": __version__, + "codeflash_version": codeflash_version, } console.rule() try: From dc28e20b14a0d717d77208816948135f00d69803 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:53:05 -0700 Subject: [PATCH 5/7] Apply suggestion from @aseembits93 --- codeflash/api/aiservice.py | 1 - 1 file changed, 1 deletion(-) diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index b17456b10..e332c7cc6 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -21,7 +21,6 @@ from codeflash.models.ExperimentMetadata import ExperimentMetadata from codeflash.models.models import AIServiceRefinerRequest, CodeStringsMarkdown, OptimizedCandidate from codeflash.telemetry.posthog_cf import ph -from codeflash.version import __version__ from codeflash.version import __version__ as codeflash_version if TYPE_CHECKING: From cf219adf9c6dac7e29b7246592f595bd3ebf3ced Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:53:41 -0700 Subject: [PATCH 6/7] Apply suggestion from @aseembits93 --- codeflash/optimization/function_optimizer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index 813df1c72..301ec85fa 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -1428,7 +1428,6 @@ def process_review( original_throughput=original_throughput_str, optimized_throughput=optimized_throughput_str, throughput_improvement=throughput_improvement_str, - codeflash_version=__version__, ) new_explanation = Explanation( raw_explanation_message=new_explanation_raw_str or explanation.raw_explanation_message, From 317cad3c33747852556ebd41cdd461f1c052c1d2 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Wed, 8 Oct 2025 18:54:02 -0700 Subject: [PATCH 7/7] Apply suggestion from @aseembits93 --- codeflash/optimization/function_optimizer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index 301ec85fa..d00954b45 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -101,7 +101,6 @@ from codeflash.verification.test_runner import run_behavioral_tests, run_benchmarking_tests, run_line_profile_tests from codeflash.verification.verification_utils import get_test_file_path from codeflash.verification.verifier import generate_tests -from codeflash.version import __version__ if TYPE_CHECKING: from argparse import Namespace