Skip to content

Commit 8f14682

Browse files
Merge branch 'main' of github.com:codeflash-ai/codeflash into multi-language
2 parents ea079ce + 7bf9f99 commit 8f14682

4 files changed

Lines changed: 35 additions & 7 deletions

File tree

codeflash/api/cfapi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ def suggest_changes(
171171
replay_tests: str = "",
172172
concolic_tests: str = "",
173173
optimization_review: str = "",
174+
original_line_profiler: str | None = None,
175+
optimized_line_profiler: str | None = None,
174176
) -> Response:
175177
"""Suggest changes to a pull request.
176178
@@ -182,6 +184,8 @@ def suggest_changes(
182184
:param file_changes: A dictionary of file changes.
183185
:param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc.
184186
:param generated_tests: The generated tests.
187+
:param original_line_profiler: Line profiler results for original code (markdown format).
188+
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
185189
:return: The response object.
186190
"""
187191
payload = {
@@ -197,7 +201,10 @@ def suggest_changes(
197201
"replayTests": replay_tests,
198202
"concolicTests": concolic_tests,
199203
"optimizationReview": optimization_review, # impact keyword left for legacy reasons, touches js/ts code
204+
"originalLineProfiler": original_line_profiler,
205+
"optimizedLineProfiler": optimized_line_profiler,
200206
}
207+
201208
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
202209

203210

@@ -214,6 +221,8 @@ def create_pr(
214221
replay_tests: str = "",
215222
concolic_tests: str = "",
216223
optimization_review: str = "",
224+
original_line_profiler: str | None = None,
225+
optimized_line_profiler: str | None = None,
217226
) -> Response:
218227
"""Create a pull request, targeting the specified branch. (usually 'main').
219228
@@ -223,6 +232,8 @@ def create_pr(
223232
:param file_changes: A dictionary of file changes.
224233
:param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc.
225234
:param generated_tests: The generated tests.
235+
:param original_line_profiler: Line profiler results for original code (markdown format).
236+
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
226237
:return: The response object.
227238
"""
228239
# convert Path objects to strings
@@ -239,7 +250,10 @@ def create_pr(
239250
"replayTests": replay_tests,
240251
"concolicTests": concolic_tests,
241252
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
253+
"originalLineProfiler": original_line_profiler,
254+
"optimizedLineProfiler": optimized_line_profiler,
242255
}
256+
243257
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
244258

245259

@@ -269,6 +283,8 @@ def create_staging(
269283
concolic_tests: str,
270284
root_dir: Path,
271285
optimization_review: str = "",
286+
original_line_profiler: str | None = None,
287+
optimized_line_profiler: str | None = None,
272288
) -> Response:
273289
"""Create a staging pull request, targeting the specified branch. (usually 'staging').
274290
@@ -279,6 +295,8 @@ def create_staging(
279295
:param generated_original_test_source: Generated tests for the original function.
280296
:param function_trace_id: Unique identifier for this optimization trace.
281297
:param coverage_message: Coverage report or summary.
298+
:param original_line_profiler: Line profiler results for original code (markdown format).
299+
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
282300
:return: The response object from the backend.
283301
"""
284302
relative_path = explanation.file_path.relative_to(root_dir).as_posix()
@@ -310,6 +328,8 @@ def create_staging(
310328
"replayTests": replay_tests,
311329
"concolicTests": concolic_tests,
312330
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
331+
"originalLineProfiler": original_line_profiler,
332+
"optimizedLineProfiler": optimized_line_profiler,
313333
}
314334

315335
return make_cfapi_request(endpoint="/create-staging", method="POST", payload=payload)

codeflash/optimization/function_optimizer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,8 +1790,8 @@ def generate_optimizations(
17901790
self,
17911791
read_writable_code: CodeStringsMarkdown,
17921792
read_only_context_code: str,
1793-
run_experiment: bool = False, # noqa: FBT001, FBT002
1794-
is_numerical_code: bool | None = None, # noqa: FBT001
1793+
run_experiment: bool = False,
1794+
is_numerical_code: bool | None = None,
17951795
) -> Result[tuple[OptimizationSet, str], str]:
17961796
"""Generate optimization candidates for the function. Backend handles multi-model diversity."""
17971797
n_candidates = get_effort_value(EffortKeys.N_OPTIMIZER_CANDIDATES, self.effort)
@@ -2174,6 +2174,8 @@ def process_review(
21742174
"replay_tests": replay_tests,
21752175
"concolic_tests": concolic_tests,
21762176
"language": self.function_to_optimize.language,
2177+
"original_line_profiler": original_code_baseline.line_profile_results.get("str_out", ""),
2178+
"optimized_line_profiler": best_optimization.line_profiler_test_results.get("str_out", ""),
21772179
}
21782180

21792181
raise_pr = not self.args.no_pr

codeflash/result/create_pr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ def check_create_pr(
285285
root_dir: Path,
286286
git_remote: Optional[str] = None,
287287
optimization_review: str = "",
288+
original_line_profiler: str | None = None,
289+
optimized_line_profiler: str | None = None,
288290
) -> None:
289291
pr_number: Optional[int] = env_utils.get_pr_number()
290292
git_repo = git.Repo(search_parent_directories=True)
@@ -329,6 +331,8 @@ def check_create_pr(
329331
replay_tests=replay_tests,
330332
concolic_tests=concolic_tests,
331333
optimization_review=optimization_review,
334+
original_line_profiler=original_line_profiler,
335+
optimized_line_profiler=optimized_line_profiler,
332336
)
333337
if response.ok:
334338
logger.info(f"Suggestions were successfully made to PR #{pr_number}")
@@ -381,6 +385,8 @@ def check_create_pr(
381385
replay_tests=replay_tests,
382386
concolic_tests=concolic_tests,
383387
optimization_review=optimization_review,
388+
original_line_profiler=original_line_profiler,
389+
optimized_line_profiler=optimized_line_profiler,
384390
)
385391
if response.ok:
386392
pr_id = response.text

tests/test_languages/test_js_code_replacer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ def test_code_replacer_for_class_method(ts_support, temp_project):
16791679
16801680
/**
16811681
* Find duplicates in the data array.
1682-
* Intentionally inefficient O(n²) implementation.
1682+
* Intentionally inefficient implementation.
16831683
* @returns Array of duplicate values
16841684
*/
16851685
findDuplicates(): T[] {
@@ -1698,7 +1698,7 @@ def test_code_replacer_for_class_method(ts_support, temp_project):
16981698
16991699
/**
17001700
* Sort the data using bubble sort.
1701-
* Intentionally inefficient O(n²) implementation.
1701+
* Intentionally inefficient implementation.
17021702
* @returns Sorted copy of the data
17031703
*/
17041704
sortData(): T[] {
@@ -1718,7 +1718,7 @@ def test_code_replacer_for_class_method(ts_support, temp_project):
17181718
17191719
/**
17201720
* Get unique values from the data.
1721-
* Intentionally inefficient O(n²) implementation.
1721+
* Intentionally inefficient implementation.
17221722
* @returns Array of unique values
17231723
*/
17241724
getUnique(): T[] {
@@ -1843,7 +1843,7 @@ class DataProcessor<T> {
18431843
18441844
/**
18451845
* Sort the data using bubble sort.
1846-
* Intentionally inefficient O(n²) implementation.
1846+
* Intentionally inefficient implementation.
18471847
* @returns Sorted copy of the data
18481848
*/
18491849
sortData(): T[] {
@@ -1863,7 +1863,7 @@ class DataProcessor<T> {
18631863
18641864
/**
18651865
* Get unique values from the data.
1866-
* Intentionally inefficient O(n²) implementation.
1866+
* Intentionally inefficient implementation.
18671867
* @returns Array of unique values
18681868
*/
18691869
getUnique(): T[] {

0 commit comments

Comments
 (0)