diff --git a/codeflash/api/aiservice.py b/codeflash/api/aiservice.py index e15333d75..6b478f148 100644 --- a/codeflash/api/aiservice.py +++ b/codeflash/api/aiservice.py @@ -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, diff --git a/codeflash/api/cfapi.py b/codeflash/api/cfapi.py index bd3e927d4..a0a5685b3 100644 --- a/codeflash/api/cfapi.py +++ b/codeflash/api/cfapi.py @@ -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. @@ -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) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index 8aaf11ec5..e54aac92d 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -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) diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index 7731c67f2..f9fbf84d7 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -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) @@ -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}")