Skip to content
Merged
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
7 changes: 7 additions & 0 deletions codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,13 @@ def get_optimization_impact(
]
)
code_diff = f"```diff\n{diff_str}\n```"
# TODO get complexity metrics and fn call heuristics -> constructing a complete static call graph can be expensive for really large repos
# grep function name in codebase -> ast parser to get no of calls and no of calls in loop -> radon lib to get complexity metrics -> send as additional context to the AI service
# metric 1 -> call count - how many times the function is called in the codebase
# metric 2 -> loop call count - how many times the function is called in a loop in the codebase
# metric 3 -> presence of decorators like @profile, @cache -> this means the owner of the repo cares about the performance of this function
# metric 4 -> cyclomatic complexity (https://en.wikipedia.org/wiki/Cyclomatic_complexity)
# metric 5 (for future) -> halstead complexity (https://en.wikipedia.org/wiki/Halstead_complexity_measures)
logger.info("!lsp|Computing Optimization Impact…")
payload = {
"code_diff": code_diff,
Expand Down
2 changes: 2 additions & 0 deletions codeflash/api/cfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def suggest_changes(
coverage_message: str,
replay_tests: str = "",
concolic_tests: str = "",
optimization_impact: str = "",
) -> Response:
"""Suggest changes to a pull request.

Expand All @@ -155,6 +156,7 @@ def suggest_changes(
"coverage_message": coverage_message,
"replayTests": replay_tests,
"concolicTests": concolic_tests,
"optimizationImpact": optimization_impact,
}
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)

Expand Down
14 changes: 6 additions & 8 deletions codeflash/optimization/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,14 +1461,12 @@ def process_review(

if raise_pr or staging_review:
data["root_dir"] = git_root_dir()
# try:
# # modify argument of staging vs pr based on the impact
# opt_impact_response = self.aiservice_client.get_optimization_impact(**data)
# if opt_impact_response == "low":
# raise_pr = False
# staging_review = True
# except Exception as e:
# logger.debug(f"optimization impact response failed, investigate {e}")
opt_impact_response = ""
try:
opt_impact_response = self.aiservice_client.get_optimization_impact(**data)
except Exception as e:
logger.debug(f"optimization impact response failed, investigate {e}")
data["optimization_impact"] = opt_impact_response
if raise_pr and not staging_review:
data["git_remote"] = self.args.git_remote
check_create_pr(**data)
Expand Down
2 changes: 2 additions & 0 deletions codeflash/result/create_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def check_create_pr(
concolic_tests: str,
root_dir: Path,
git_remote: Optional[str] = None,
optimization_impact: str = "",
) -> None:
pr_number: Optional[int] = env_utils.get_pr_number()
git_repo = git.Repo(search_parent_directories=True)
Expand Down Expand Up @@ -226,6 +227,7 @@ def check_create_pr(
coverage_message=coverage_message,
replay_tests=replay_tests,
concolic_tests=concolic_tests,
optimization_impact=optimization_impact,
)
if response.ok:
logger.info(f"Suggestions were successfully made to PR #{pr_number}")
Expand Down
Loading