Skip to content

Commit 1043272

Browse files
committed
refactor: move OptimizationReviewResult to models.py
Better placement with other data models and AI service request/response types.
1 parent 96cbf83 commit 1043272

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

codeflash/api/aiservice.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import platform
66
import time
77
from itertools import count
8-
from typing import TYPE_CHECKING, Any, NamedTuple, cast
8+
from typing import TYPE_CHECKING, Any, cast
99

1010
import requests
1111
from pydantic.json import pydantic_encoder
@@ -23,6 +23,7 @@
2323
CodeStringsMarkdown,
2424
OptimizedCandidate,
2525
OptimizedCandidateSource,
26+
OptimizationReviewResult,
2627
)
2728
from codeflash.telemetry.posthog_cf import ph
2829
from codeflash.version import __version__ as codeflash_version
@@ -40,13 +41,6 @@
4041
from codeflash.result.explanation import Explanation
4142

4243

43-
class OptimizationReviewResult(NamedTuple):
44-
"""Result from the optimization review API."""
45-
46-
review: str # "high", "medium", "low", or ""
47-
explanation: str
48-
49-
5044
class AiServiceClient:
5145
def __init__(self) -> None:
5246
self.base_url = self.get_aiservice_base_url()

codeflash/models/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from enum import Enum, IntEnum
2121
from pathlib import Path
2222
from re import Pattern
23-
from typing import Annotated, Optional, cast
23+
from typing import Annotated, NamedTuple, Optional, cast
2424

2525
from jedi.api.classes import Name
2626
from pydantic import AfterValidator, BaseModel, ConfigDict, Field, PrivateAttr, ValidationError
@@ -95,6 +95,13 @@ class AIServiceCodeRepairRequest:
9595
test_diffs: list[TestDiff]
9696

9797

98+
class OptimizationReviewResult(NamedTuple):
99+
"""Result from the optimization review API."""
100+
101+
review: str # "high", "medium", "low", or ""
102+
explanation: str
103+
104+
98105
# If the method spam is in the class Ham, which is at the top level of the module eggs in the package foo, the fully
99106
# qualified name of the method is foo.eggs.Ham.spam, its qualified name is Ham.spam, and its name is spam. The full name
100107
# of the module is foo.eggs.

codeflash/optimization/function_optimizer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@
1717
from rich.syntax import Syntax
1818
from rich.tree import Tree
1919

20-
from codeflash.api.aiservice import (
21-
AiServiceClient,
22-
AIServiceRefinerRequest,
23-
LocalAiServiceClient,
24-
OptimizationReviewResult,
25-
)
20+
from codeflash.api.aiservice import AiServiceClient, AIServiceRefinerRequest, LocalAiServiceClient
2621
from codeflash.api.cfapi import add_code_context_hash, create_staging, get_cfapi_base_urls, mark_optimization_success
2722
from codeflash.benchmarking.utils import process_benchmark_data
2823
from codeflash.cli_cmds.console import code_print, console, logger, lsp_log, progress_bar
@@ -90,6 +85,7 @@
9085
CodeOptimizationContext,
9186
GeneratedTests,
9287
GeneratedTestsList,
88+
OptimizationReviewResult,
9389
OptimizationSet,
9490
OptimizedCandidate,
9591
OptimizedCandidateResult,

0 commit comments

Comments
 (0)