Skip to content

Commit 49cab09

Browse files
committed
precommit mypy fix
1 parent 08aed91 commit 49cab09

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

codeflash/api/aiservice.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def optimize_python_code_refinement(self, request: list[AIServiceRefinerRequest]
278278
console.rule()
279279
return []
280280

281-
def get_new_explanation(
281+
def get_new_explanation( # noqa: D417
282282
self,
283283
source_code: str,
284284
optimized_code: str,
@@ -297,11 +297,15 @@ def get_new_explanation(
297297
Parameters
298298
----------
299299
- source_code (str): The python code to optimize.
300+
- optimized_code (str): The python code generated by the AI service.
300301
- dependency_code (str): The dependency code used as read-only context for the optimization
301-
- trace_id (str): Trace id of optimization run
302-
- num_candidates (int): Number of optimization variants to generate. Default is 10.
303-
- experiment_metadata (Optional[ExperimentalMetadata, None]): Any available experiment metadata for this optimization
304-
- existing_explanation (str): Existing explanation from AIservice call
302+
- original_line_profiler_results: str - line profiler results for the baseline code
303+
- optimized_line_profiler_results: str - line profiler results for the optimized code
304+
- original_code_runtime: str - runtime for the baseline code
305+
- optimized_code_runtime: str - runtime for the optimized code
306+
- speedup: str - speedup of the optimized code
307+
- annotated_tests: str - test functions annotated with runtime
308+
- optimization_id: str - unique id of opt candidate
305309
306310
Returns
307311
-------
@@ -331,7 +335,7 @@ def get_new_explanation(
331335
return ""
332336

333337
if response.status_code == 200:
334-
explanation = response.json()["explanation"]
338+
explanation: str = response.json()["explanation"]
335339
logger.info(f"New Explanation: {explanation}")
336340
console.rule()
337341
return explanation
@@ -344,8 +348,7 @@ def get_new_explanation(
344348
console.rule()
345349
return ""
346350

347-
348-
def log_results(
351+
def log_results( # noqa: D417
349352
self,
350353
function_trace_id: str,
351354
speedup_ratio: dict[str, float | None] | None,

codeflash/optimization/function_optimizer.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import time
99
import uuid
1010
from collections import defaultdict, deque
11-
from dataclasses import replace
1211
from pathlib import Path
1312
from typing import TYPE_CHECKING
1413

@@ -1124,7 +1123,9 @@ def find_and_process_best_optimization(
11241123
new_explanation_raw_str = self.aiservice_client.get_new_explanation(
11251124
source_code=code_context.read_writable_code,
11261125
dependency_code=code_context.read_only_context_code,
1127-
trace_id=self.function_trace_id[:-4] + exp_type if self.experiment_id else self.function_trace_id,
1126+
trace_id=self.function_trace_id[:-4] + exp_type
1127+
if self.experiment_id
1128+
else self.function_trace_id,
11281129
optimized_code=best_optimization.candidate.source_code,
11291130
original_line_profiler_results=original_code_baseline.line_profile_results["str_out"],
11301131
optimized_line_profiler_results=best_optimization.line_profiler_test_results["str_out"],
@@ -1134,13 +1135,16 @@ def find_and_process_best_optimization(
11341135
annotated_tests=generated_tests_str,
11351136
optimization_id=best_optimization.candidate.optimization_id,
11361137
)
1137-
new_explanation = Explanation(raw_explanation_message=new_explanation_raw_str or explanation.raw_explanation_message, winning_behavior_test_results=explanation.winning_behavior_test_results,
1138-
winning_benchmarking_test_results=explanation.winning_benchmarking_test_results,
1139-
original_runtime_ns=explanation.original_runtime_ns,
1140-
best_runtime_ns=explanation.best_runtime_ns,
1141-
function_name=explanation.function_name,
1142-
file_path=explanation.file_path,
1143-
benchmark_details=explanation.benchmark_details)
1138+
new_explanation = Explanation(
1139+
raw_explanation_message=new_explanation_raw_str or explanation.raw_explanation_message,
1140+
winning_behavior_test_results=explanation.winning_behavior_test_results,
1141+
winning_benchmarking_test_results=explanation.winning_benchmarking_test_results,
1142+
original_runtime_ns=explanation.original_runtime_ns,
1143+
best_runtime_ns=explanation.best_runtime_ns,
1144+
function_name=explanation.function_name,
1145+
file_path=explanation.file_path,
1146+
benchmark_details=explanation.benchmark_details,
1147+
)
11441148
check_create_pr(
11451149
original_code=original_code_combined,
11461150
new_code=new_code_combined,

0 commit comments

Comments
 (0)