Skip to content

Commit 520d87c

Browse files
saga4saga4
authored andcommitted
pass reference values to aiservices
1 parent ffb910b commit 520d87c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

codeflash/api/aiservice.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydantic.json import pydantic_encoder
1111

1212
from codeflash.cli_cmds.console import console, logger
13+
from codeflash.code_utils.config_consts import get_n_candidates, get_n_candidates_lp
1314
from codeflash.code_utils.env_utils import get_codeflash_api_key
1415
from codeflash.code_utils.git_utils import get_last_commit_author_if_pr_exists, get_repo_owner_and_name
1516
from codeflash.lsp.helpers import is_LSP_enabled
@@ -131,6 +132,7 @@ def optimize_python_code( # noqa: D417
131132
"current_username": get_last_commit_author_if_pr_exists(None),
132133
"repo_owner": git_repo_owner,
133134
"repo_name": git_repo_name,
135+
"n_candidates": get_n_candidates(),
134136
}
135137

136138
logger.info("Generating optimized candidates…")
@@ -192,6 +194,7 @@ def optimize_python_code_line_profiler( # noqa: D417
192194
"experiment_metadata": experiment_metadata,
193195
"codeflash_version": codeflash_version,
194196
"lsp_mode": is_LSP_enabled(),
197+
"n_candidates_lp": get_n_candidates_lp(),
195198
}
196199

197200
logger.info("Generating optimized candidates…")

codeflash/code_utils/config_consts.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
MIN_TESTCASE_PASSED_THRESHOLD = 6
1212
REPEAT_OPTIMIZATION_PROBABILITY = 0.1
1313
DEFAULT_IMPORTANCE_THRESHOLD = 0.001
14+
N_CANDIDATES_LP = 6
1415

1516
# LSP-specific
1617
N_CANDIDATES_LSP = 3
17-
N_TESTS_TO_GENERATE_LSP = 1
18+
N_TESTS_TO_GENERATE_LSP = 2
1819
TOTAL_LOOPING_TIME_LSP = 10.0 # Kept same timing for LSP mode to avoid in increase in performance reporting
20+
N_CANDIDATES_LP_LSP = 3
1921

2022

2123
def get_n_candidates() -> int:
@@ -24,6 +26,12 @@ def get_n_candidates() -> int:
2426
return N_CANDIDATES_LSP if is_LSP_enabled() else N_CANDIDATES
2527

2628

29+
def get_n_candidates_lp() -> int:
30+
from codeflash.lsp.helpers import is_LSP_enabled
31+
32+
return N_CANDIDATES_LP_LSP if is_LSP_enabled() else N_CANDIDATES_LP
33+
34+
2735
def get_n_tests_to_generate() -> int:
2836
from codeflash.lsp.helpers import is_LSP_enabled
2937

codeflash/optimization/function_optimizer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
INDIVIDUAL_TESTCASE_TIMEOUT,
4646
REPEAT_OPTIMIZATION_PROBABILITY,
4747
get_n_candidates,
48+
get_n_candidates_lp,
4849
get_n_tests_to_generate,
4950
get_total_looping_time,
5051
)
@@ -476,7 +477,7 @@ def determine_best_candidate(
476477
dependency_code=code_context.read_only_context_code,
477478
trace_id=self.function_trace_id[:-4] + exp_type if self.experiment_id else self.function_trace_id,
478479
line_profiler_results=original_code_baseline.line_profile_results["str_out"],
479-
num_candidates=10,
480+
num_candidates=get_n_candidates_lp(),
480481
experiment_metadata=ExperimentMetadata(
481482
id=self.experiment_id, group="control" if exp_type == "EXP0" else "experiment"
482483
)

0 commit comments

Comments
 (0)