Skip to content

Commit a386a27

Browse files
committed
chore: update types for lint
1 parent 7074cfa commit a386a27

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

packages/optimization/src/ldai_optimization/dataclasses.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def handle_llm_call(
119119
key: str,
120120
config: LLMCallConfig,
121121
context: LLMCallContext,
122+
is_evaluation: bool,
122123
) -> OptimizationResponse:
123124
model_name = config.model.name if config.model else "gpt-4o"
124125
instructions = config.instructions or ""
@@ -132,9 +133,12 @@ async def handle_llm_call(
132133
)
133134
"""
134135

135-
key: str
136-
model: Optional[ModelConfig]
137-
instructions: Optional[str]
136+
@property
137+
def key(self) -> str: ...
138+
@property
139+
def model(self) -> Optional[ModelConfig]: ...
140+
@property
141+
def instructions(self) -> Optional[str]: ...
138142

139143

140144
class LLMCallContext(Protocol):
@@ -144,8 +148,10 @@ class LLMCallContext(Protocol):
144148
``handle_agent_call`` and ``handle_judge_call``.
145149
"""
146150

147-
user_input: Optional[str]
148-
current_variables: Dict[str, Any]
151+
@property
152+
def user_input(self) -> Optional[str]: ...
153+
@property
154+
def current_variables(self) -> Dict[str, Any]: ...
149155

150156

151157
@dataclass

packages/optimization/src/ldai_optimization/util.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import logging
66
import re
7-
from typing import Any, Awaitable, Dict, List, Optional, Tuple, Union
7+
from typing import Any, Awaitable, Dict, List, Optional, Tuple, TypeVar, Union
88

99
from ldai_optimization.dataclasses import ToolDefinition
1010

@@ -156,18 +156,19 @@ def restore_variable_placeholders(
156156
return text, warnings
157157

158158

159-
async def await_if_needed(
160-
result: Union[str, Awaitable[str]]
161-
) -> str:
159+
_T = TypeVar("_T")
160+
161+
162+
async def await_if_needed(result: Union[_T, Awaitable[_T]]) -> _T:
162163
"""
163164
Handle both sync and async callable results.
164165
165-
:param result: Either a string or an awaitable that returns a string
166-
:return: The string result
166+
:param result: Either a value or an awaitable that returns a value
167+
:return: The resolved value
167168
"""
168-
if isinstance(result, str):
169-
return result
170-
return await result
169+
if inspect.isawaitable(result):
170+
return await result # type: ignore[return-value]
171+
return result # type: ignore[return-value]
171172

172173

173174
def create_evaluation_tool() -> ToolDefinition:

packages/optimization/tests/test_ld_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
from ldai_optimization.ld_api_client import (
1313
AgentOptimizationConfig,
14+
AgentOptimizationResultPost as OptimizationResultPayload,
1415
LDApiClient,
1516
LDApiError,
16-
OptimizationResultPayload,
1717
_parse_agent_optimization,
1818
)
1919

0 commit comments

Comments
 (0)