Skip to content

Commit eda3997

Browse files
Merge branch 'main' into lsp/init-flow
2 parents 702939d + c1250e8 commit eda3997

File tree

6 files changed

+485
-52
lines changed

6 files changed

+485
-52
lines changed

codeflash/api/aiservice.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def generate_regression_tests( # noqa: D417
532532
ph("cli-testgen-error-response", {"response_status_code": response.status_code, "error": response.text})
533533
return None
534534

535-
def get_optimization_impact(
535+
def get_optimization_review(
536536
self,
537537
original_code: dict[Path, str],
538538
new_code: dict[Path, str],
@@ -544,8 +544,9 @@ def get_optimization_impact(
544544
replay_tests: str,
545545
root_dir: Path,
546546
concolic_tests: str, # noqa: ARG002
547+
calling_fn_details: str,
547548
) -> str:
548-
"""Compute the optimization impact of current Pull Request.
549+
"""Compute the optimization review of current Pull Request.
549550
550551
Args:
551552
original_code: dict -> data structure mapping file paths to function definition for original code
@@ -558,10 +559,11 @@ def get_optimization_impact(
558559
replay_tests: str -> replay test table
559560
root_dir: Path -> path of git directory
560561
concolic_tests: str -> concolic_tests (not used)
562+
calling_fn_details: str -> filenames and definitions of functions which call the function_to_optimize
561563
562564
Returns:
563565
-------
564-
- 'high' or 'low' optimization impact
566+
- 'high', 'medium' or 'low' optimization review
565567
566568
"""
567569
diff_str = "\n".join(
@@ -577,14 +579,7 @@ def get_optimization_impact(
577579
]
578580
)
579581
code_diff = f"```diff\n{diff_str}\n```"
580-
# TODO get complexity metrics and fn call heuristics -> constructing a complete static call graph can be expensive for really large repos
581-
# 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
582-
# metric 1 -> call count - how many times the function is called in the codebase
583-
# metric 2 -> loop call count - how many times the function is called in a loop in the codebase
584-
# metric 3 -> presence of decorators like @profile, @cache -> this means the owner of the repo cares about the performance of this function
585-
# metric 4 -> cyclomatic complexity (https://en.wikipedia.org/wiki/Cyclomatic_complexity)
586-
# metric 5 (for future) -> halstead complexity (https://en.wikipedia.org/wiki/Halstead_complexity_measures)
587-
logger.info("!lsp|Computing Optimization Impact…")
582+
logger.info("!lsp|Computing Optimization Review…")
588583
payload = {
589584
"code_diff": code_diff,
590585
"explanation": explanation.raw_explanation_message,
@@ -598,22 +593,23 @@ def get_optimization_impact(
598593
"benchmark_details": explanation.benchmark_details if explanation.benchmark_details else None,
599594
"optimized_runtime": humanize_runtime(explanation.best_runtime_ns),
600595
"original_runtime": humanize_runtime(explanation.original_runtime_ns),
596+
"calling_fn_details": calling_fn_details,
601597
}
602598
console.rule()
603599
try:
604-
response = self.make_ai_service_request("/optimization_impact", payload=payload, timeout=600)
600+
response = self.make_ai_service_request("/optimization_review", payload=payload, timeout=600)
605601
except requests.exceptions.RequestException as e:
606602
logger.exception(f"Error generating optimization refinements: {e}")
607603
ph("cli-optimize-error-caught", {"error": str(e)})
608604
return ""
609605

610606
if response.status_code == 200:
611-
return cast("str", response.json()["impact"])
607+
return cast("str", response.json()["review"])
612608
try:
613609
error = cast("str", response.json()["error"])
614610
except Exception:
615611
error = response.text
616-
logger.error(f"Error generating impact candidates: {response.status_code} - {error}")
612+
logger.error(f"Error generating optimization review: {response.status_code} - {error}")
617613
ph("cli-optimize-error-response", {"response_status_code": response.status_code, "error": error})
618614
console.rule()
619615
return ""

codeflash/api/cfapi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def suggest_changes(
130130
coverage_message: str,
131131
replay_tests: str = "",
132132
concolic_tests: str = "",
133-
optimization_impact: str = "",
133+
optimization_review: str = "",
134134
) -> Response:
135135
"""Suggest changes to a pull request.
136136
@@ -156,7 +156,7 @@ def suggest_changes(
156156
"coverage_message": coverage_message,
157157
"replayTests": replay_tests,
158158
"concolicTests": concolic_tests,
159-
"optimizationImpact": optimization_impact,
159+
"optimizationImpact": optimization_review, # impact keyword left for legacy reasons, touches js/ts code
160160
}
161161
return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload)
162162

@@ -173,6 +173,7 @@ def create_pr(
173173
coverage_message: str,
174174
replay_tests: str = "",
175175
concolic_tests: str = "",
176+
optimization_review: str = "",
176177
) -> Response:
177178
"""Create a pull request, targeting the specified branch. (usually 'main').
178179
@@ -197,6 +198,7 @@ def create_pr(
197198
"coverage_message": coverage_message,
198199
"replayTests": replay_tests,
199200
"concolicTests": concolic_tests,
201+
"optimizationImpact": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
200202
}
201203
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
202204

@@ -212,6 +214,7 @@ def create_staging(
212214
replay_tests: str,
213215
concolic_tests: str,
214216
root_dir: Path,
217+
optimization_review: str = "",
215218
) -> Response:
216219
"""Create a staging pull request, targeting the specified branch. (usually 'staging').
217220
@@ -252,6 +255,7 @@ def create_staging(
252255
"coverage_message": coverage_message,
253256
"replayTests": replay_tests,
254257
"concolicTests": concolic_tests,
258+
"optimizationImpact": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase
255259
}
256260

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

0 commit comments

Comments
 (0)