Skip to content

Commit c143fcc

Browse files
authored
Merge pull request #905 from codeflash-ai/cf-842
Add Optimization Review Label in VSC Extension
2 parents 0168944 + 35378a3 commit c143fcc

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

codeflash/api/aiservice.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
import platform
66
import time
7-
from pathlib import Path
87
from typing import TYPE_CHECKING, Any, cast
98

109
import requests
@@ -24,6 +23,8 @@
2423
from codeflash.version import __version__ as codeflash_version
2524

2625
if TYPE_CHECKING:
26+
from pathlib import Path
27+
2728
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
2829
from codeflash.models.ExperimentMetadata import ExperimentMetadata
2930
from codeflash.models.models import AIServiceRefinerRequest
@@ -557,7 +558,6 @@ def get_optimization_review(
557558
function_trace_id: str,
558559
coverage_message: str,
559560
replay_tests: str,
560-
root_dir: Path,
561561
concolic_tests: str, # noqa: ARG002
562562
calling_fn_details: str,
563563
) -> str:
@@ -583,18 +583,13 @@ def get_optimization_review(
583583
"""
584584
diff_str = "\n".join(
585585
[
586-
unified_diff_strings(
587-
code1=original_code[p],
588-
code2=new_code[p],
589-
fromfile=Path(p).relative_to(root_dir).as_posix(),
590-
tofile=Path(p).relative_to(root_dir).as_posix(),
591-
)
586+
unified_diff_strings(code1=original_code[p], code2=new_code[p])
592587
for p in original_code
593588
if not is_zero_diff(original_code[p], new_code[p])
594589
]
595590
)
596591
code_diff = f"```diff\n{diff_str}\n```"
597-
logger.info("!lsp|Computing Optimization Review…")
592+
logger.info("loading|Reviewing Optimization…")
598593
payload = {
599594
"code_diff": code_diff,
600595
"explanation": explanation.raw_explanation_message,

codeflash/lsp/features/perform_optimization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ def sync_perform_optimization(server: CodeflashLanguageServer, cancel_event: thr
134134
"patch_file": str(patch_path),
135135
"task_id": params.task_id,
136136
"explanation": best_optimization.explanation_v2,
137+
"optimizationReview": function_optimizer.optimization_review.capitalize(),
137138
}

codeflash/optimization/function_optimizer.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def __init__(
246246
self.executor = concurrent.futures.ThreadPoolExecutor(
247247
max_workers=n_tests + 3 if self.experiment_id is None else n_tests + 4
248248
)
249+
self.optimization_review = ""
249250

250251
def can_be_optimized(self) -> Result[tuple[bool, CodeOptimizationContext, dict[Path, str]], str]:
251252
should_run_experiment = self.experiment_id is not None
@@ -1517,17 +1518,17 @@ def process_review(
15171518
raise_pr = not self.args.no_pr
15181519
staging_review = self.args.staging_review
15191520
opt_review_response = ""
1520-
# Skip optimization review for async functions for now
1521-
if (raise_pr or staging_review) and not self.function_to_optimize.is_async:
1522-
data["root_dir"] = git_root_dir()
1523-
try:
1524-
opt_review_response = self.aiservice_client.get_optimization_review(
1525-
**data, calling_fn_details=function_references
1526-
)
1527-
except Exception as e:
1528-
logger.debug(f"optimization review response failed, investigate {e}")
1529-
# Always set optimization_review in data (empty string for async functions)
1521+
# this will now run regardless of pr, staging review flags
1522+
try:
1523+
opt_review_response = self.aiservice_client.get_optimization_review(
1524+
**data, calling_fn_details=function_references
1525+
)
1526+
except Exception as e:
1527+
logger.debug(f"optimization review response failed, investigate {e}")
15301528
data["optimization_review"] = opt_review_response
1529+
self.optimization_review = opt_review_response
1530+
if raise_pr or staging_review:
1531+
data["root_dir"] = git_root_dir()
15311532
if raise_pr and not staging_review and opt_review_response != "low":
15321533
# Ensure root_dir is set for PR creation (needed for async functions that skip opt_review)
15331534
if "root_dir" not in data:

0 commit comments

Comments
 (0)