Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions codeflash/api/cfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def suggest_changes(
replay_tests: str = "",
concolic_tests: str = "",
optimization_review: str = "",
original_line_profiler: str = "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
original_line_profiler: str = "",
original_line_profiler: str | None = None,

optimized_line_profiler: str = "",
) -> Response:
"""Suggest changes to a pull request.

Expand All @@ -182,6 +184,8 @@ def suggest_changes(
:param file_changes: A dictionary of file changes.
:param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc.
:param generated_tests: The generated tests.
:param original_line_profiler: Line profiler results for original code (markdown format).
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
:return: The response object.
"""
payload = {
Expand All @@ -198,6 +202,13 @@ def suggest_changes(
"concolicTests": concolic_tests,
"optimizationReview": optimization_review, # impact keyword left for legacy reasons, touches js/ts code
}

# Add line profiler data if available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed if you default the argument to None

if original_line_profiler:
payload["originalLineProfiler"] = original_line_profiler
if optimized_line_profiler:
payload["optimizedLineProfiler"] = optimized_line_profiler

return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)


Expand All @@ -214,6 +225,8 @@ def create_pr(
replay_tests: str = "",
concolic_tests: str = "",
optimization_review: str = "",
original_line_profiler: str = "",
optimized_line_profiler: str = "",
) -> Response:
"""Create a pull request, targeting the specified branch. (usually 'main').

Expand All @@ -223,6 +236,8 @@ def create_pr(
:param file_changes: A dictionary of file changes.
:param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc.
:param generated_tests: The generated tests.
:param original_line_profiler: Line profiler results for original code (markdown format).
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
:return: The response object.
"""
# convert Path objects to strings
Expand All @@ -240,6 +255,13 @@ def create_pr(
"concolicTests": concolic_tests,
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
}

# Add line profiler data if available
if original_line_profiler:
payload["originalLineProfiler"] = original_line_profiler
if optimized_line_profiler:
payload["optimizedLineProfiler"] = optimized_line_profiler

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


Expand Down Expand Up @@ -269,6 +291,8 @@ def create_staging(
concolic_tests: str,
root_dir: Path,
optimization_review: str = "",
original_line_profiler: str = "",
optimized_line_profiler: str = "",
) -> Response:
"""Create a staging pull request, targeting the specified branch. (usually 'staging').

Expand All @@ -279,6 +303,8 @@ def create_staging(
:param generated_original_test_source: Generated tests for the original function.
:param function_trace_id: Unique identifier for this optimization trace.
:param coverage_message: Coverage report or summary.
:param original_line_profiler: Line profiler results for original code (markdown format).
:param optimized_line_profiler: Line profiler results for optimized code (markdown format).
:return: The response object from the backend.
"""
relative_path = explanation.file_path.relative_to(root_dir).as_posix()
Expand Down Expand Up @@ -312,6 +338,12 @@ def create_staging(
"optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
}

# Add line profiler data if available
if original_line_profiler:
payload["originalLineProfiler"] = original_line_profiler
if optimized_line_profiler:
payload["optimizedLineProfiler"] = optimized_line_profiler

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


Expand Down
2 changes: 2 additions & 0 deletions codeflash/optimization/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,8 @@ def process_review(
"coverage_message": coverage_message,
"replay_tests": replay_tests,
"concolic_tests": concolic_tests,
"original_line_profiler": original_code_baseline.line_profile_results.get("str_out", ""),
"optimized_line_profiler": best_optimization.line_profiler_test_results.get("str_out", ""),
}

raise_pr = not self.args.no_pr
Expand Down
6 changes: 6 additions & 0 deletions codeflash/result/create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def check_create_pr(
root_dir: Path,
git_remote: Optional[str] = None,
optimization_review: str = "",
original_line_profiler: str = "",
optimized_line_profiler: str = "",
) -> None:
pr_number: Optional[int] = env_utils.get_pr_number()
git_repo = git.Repo(search_parent_directories=True)
Expand Down Expand Up @@ -230,6 +232,8 @@ def check_create_pr(
replay_tests=replay_tests,
concolic_tests=concolic_tests,
optimization_review=optimization_review,
original_line_profiler=original_line_profiler,
optimized_line_profiler=optimized_line_profiler,
)
if response.ok:
logger.info(f"Suggestions were successfully made to PR #{pr_number}")
Expand Down Expand Up @@ -282,6 +286,8 @@ def check_create_pr(
replay_tests=replay_tests,
concolic_tests=concolic_tests,
optimization_review=optimization_review,
original_line_profiler=original_line_profiler,
optimized_line_profiler=optimized_line_profiler,
)
if response.ok:
pr_id = response.text
Expand Down
Loading