Skip to content

Commit 769815c

Browse files
committed
refactor: remove deprecated ModelResponse, StructuredResponse, AgentResult and compat shims
1 parent 1c0255f commit 769815c

11 files changed

Lines changed: 72 additions & 199 deletions

File tree

packages/sdk/server-ai/src/ldai/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from ldai.providers import (
3535
AgentGraphResult,
3636
AgentGraphRunner,
37-
AgentResult,
3837
AgentRunner,
3938
ManagedResult,
4039
Runner,
@@ -49,7 +48,6 @@
4948
'Evaluator',
5049
'AgentRunner',
5150
'AgentGraphRunner',
52-
'AgentResult',
5351
'AgentGraphResult',
5452
'ManagedResult',
5553
'Runner',

packages/sdk/server-ai/src/ldai/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def create_judge(
329329
if not provider:
330330
return None
331331

332-
return Judge(judge_config, provider) # type: ignore[arg-type]
332+
return Judge(judge_config, provider)
333333
except Exception as error:
334334
return None
335335

packages/sdk/server-ai/src/ldai/judge/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from ldai import log
99
from ldai.judge.evaluation_schema_builder import EvaluationSchemaBuilder
1010
from ldai.models import AIJudgeConfig, LDMessage
11-
from ldai.providers.model_runner import ModelRunner
12-
from ldai.providers.types import JudgeResult, ModelResponse
11+
from ldai.providers.runner import Runner
12+
from ldai.providers.types import JudgeResult, RunnerResult
1313

1414

1515
class Judge:
@@ -23,13 +23,13 @@ class Judge:
2323
def __init__(
2424
self,
2525
ai_config: AIJudgeConfig,
26-
model_runner: ModelRunner,
26+
model_runner: Runner,
2727
):
2828
"""
2929
Initialize the Judge.
3030
3131
:param ai_config: The judge AI configuration
32-
:param model_runner: The model runner to use for evaluation
32+
:param model_runner: The runner to use for evaluation
3333
"""
3434
self._ai_config = ai_config
3535
self._model_runner = model_runner
@@ -76,10 +76,10 @@ async def evaluate(
7676

7777
response = await tracker.track_metrics_of_async(
7878
lambda result: result.metrics,
79-
lambda: self._model_runner.invoke_structured_model(messages, self._evaluation_response_structure),
79+
lambda: self._model_runner.run(messages, output_type=self._evaluation_response_structure),
8080
)
8181

82-
parsed = self._parse_evaluation_response(response.data)
82+
parsed = self._parse_evaluation_response(response.parsed)
8383

8484
if parsed is None:
8585
log.warning('Judge evaluation did not return the expected evaluation')
@@ -99,7 +99,7 @@ async def evaluate(
9999
async def evaluate_messages(
100100
self,
101101
messages: list[LDMessage],
102-
response: ModelResponse,
102+
response: RunnerResult,
103103
sampling_ratio: float = 1.0,
104104
) -> JudgeResult:
105105
"""
@@ -111,7 +111,7 @@ async def evaluate_messages(
111111
:return: The result of the judge evaluation.
112112
"""
113113
input_text = '\r\n'.join([msg.content for msg in messages]) if messages else ''
114-
output_text = response.message.content
114+
output_text = response.content
115115

116116
return await self.evaluate(input_text, output_text, sampling_ratio)
117117

@@ -123,11 +123,11 @@ def get_ai_config(self) -> AIJudgeConfig:
123123
"""
124124
return self._ai_config
125125

126-
def get_model_runner(self) -> ModelRunner:
126+
def get_model_runner(self) -> Runner:
127127
"""
128-
Returns the model runner used by this judge.
128+
Returns the runner used by this judge.
129129
130-
:return: The model runner
130+
:return: The runner
131131
"""
132132
return self._model_runner
133133

@@ -164,7 +164,7 @@ def _interpolate_message(self, content: str, variables: Dict[str, str]) -> str:
164164
# Use chevron (Mustache) for templating, with no escaping
165165
return chevron.render(content, variables)
166166

167-
def _parse_evaluation_response(self, data: Dict[str, Any]) -> Optional[Tuple[float, str]]:
167+
def _parse_evaluation_response(self, data: Optional[Dict[str, Any]]) -> Optional[Tuple[float, str]]:
168168
"""
169169
Parses the structured evaluation response. Expects {"score": n, "reasoning": "..."}.
170170

packages/sdk/server-ai/src/ldai/managed_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ldai import log
55
from ldai.models import AICompletionConfig, LDMessage
66
from ldai.providers.runner import Runner
7-
from ldai.providers.types import JudgeResult, ManagedResult
7+
from ldai.providers.types import JudgeResult, ManagedResult, RunnerResult
88
from ldai.tracker import LDAIConfigTracker
99

1010

@@ -46,7 +46,7 @@ async def run(self, prompt: str) -> ManagedResult:
4646
config_messages = self._ai_config.messages or []
4747
all_messages = config_messages + self._messages
4848

49-
result = await tracker.track_metrics_of_async(
49+
result: RunnerResult = await tracker.track_metrics_of_async(
5050
lambda r: r.metrics,
5151
lambda: self._model_runner.run(all_messages),
5252
)

packages/sdk/server-ai/src/ldai/providers/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,24 @@
66
from ldai.providers.runner_factory import RunnerFactory
77
from ldai.providers.types import (
88
AgentGraphResult,
9-
AgentResult,
109
JudgeResult,
1110
LDAIMetrics,
1211
ManagedResult,
13-
ModelResponse,
1412
RunnerResult,
15-
StructuredResponse,
1613
ToolRegistry,
1714
)
1815

1916
__all__ = [
2017
'AIProvider',
2118
'AgentGraphResult',
2219
'AgentGraphRunner',
23-
'AgentResult',
2420
'AgentRunner',
2521
'JudgeResult',
2622
'LDAIMetrics',
2723
'ManagedResult',
28-
'ModelResponse',
2924
'ModelRunner',
3025
'Runner',
3126
'RunnerFactory',
3227
'RunnerResult',
33-
'StructuredResponse',
3428
'ToolRegistry',
3529
]

packages/sdk/server-ai/src/ldai/providers/agent_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Protocol, runtime_checkable
22

3-
from ldai.providers.types import AgentResult
3+
from ldai.providers.types import RunnerResult
44

55

66
@runtime_checkable
@@ -18,11 +18,11 @@ class AgentRunner(Protocol):
1818
the caller just passes input.
1919
"""
2020

21-
async def run(self, input: Any) -> AgentResult:
21+
async def run(self, input: Any) -> RunnerResult:
2222
"""
2323
Run the agent with the given input.
2424
2525
:param input: The input to the agent (string prompt or structured input)
26-
:return: AgentResult containing the output, raw response, and metrics
26+
:return: RunnerResult containing the agent's content, metrics, and optional raw/parsed fields
2727
"""
2828
...

packages/sdk/server-ai/src/ldai/providers/ai_provider.py

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from abc import ABC
2-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Optional
33

44
from ldai import log
5-
from ldai.models import LDMessage
6-
from ldai.providers.types import ModelResponse, StructuredResponse, ToolRegistry
5+
from ldai.providers.types import ToolRegistry
76

87

98
class AIProvider(ABC):
@@ -16,51 +15,6 @@ class AIProvider(ABC):
1615
create_model(), create_agent(), and create_agent_graph().
1716
"""
1817

19-
async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
20-
"""
21-
Invoke the chat model with an array of messages.
22-
23-
Default implementation takes no action and returns a placeholder response.
24-
Provider implementations should override this method.
25-
26-
:param messages: Array of LDMessage objects representing the conversation
27-
:return: ModelResponse containing the model's response
28-
"""
29-
log.warning('invoke_model not implemented by this provider')
30-
31-
from ldai.models import LDMessage
32-
from ldai.providers.types import LDAIMetrics
33-
34-
return ModelResponse(
35-
message=LDMessage(role='assistant', content=''),
36-
metrics=LDAIMetrics(success=False, usage=None),
37-
)
38-
39-
async def invoke_structured_model(
40-
self,
41-
messages: List[LDMessage],
42-
response_structure: Dict[str, Any],
43-
) -> StructuredResponse:
44-
"""
45-
Invoke the chat model with structured output support.
46-
47-
Default implementation takes no action and returns a placeholder response.
48-
Provider implementations should override this method.
49-
50-
:param messages: Array of LDMessage objects representing the conversation
51-
:param response_structure: Dictionary of output configurations keyed by output name
52-
:return: StructuredResponse containing the structured data
53-
"""
54-
log.warning('invoke_structured_model not implemented by this provider')
55-
56-
from ldai.providers.types import LDAIMetrics
57-
58-
return StructuredResponse(
59-
data={},
60-
raw_response='',
61-
metrics=LDAIMetrics(success=False, usage=None),
62-
)
63-
6418
def create_model(self, config: Any) -> Optional[Any]:
6519
"""
6620
Create a configured model executor for the given AI config.
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Dict, List, Protocol, runtime_checkable
1+
from typing import List, Protocol, runtime_checkable
22

33
from ldai.models import LDMessage
4-
from ldai.providers.types import ModelResponse, StructuredResponse
4+
from ldai.providers.types import RunnerResult
55

66

77
@runtime_checkable
@@ -14,25 +14,11 @@ class ModelRunner(Protocol):
1414
and with what parameters — the caller just passes messages.
1515
"""
1616

17-
async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
17+
async def invoke_model(self, messages: List[LDMessage]) -> RunnerResult:
1818
"""
1919
Invoke the model with an array of messages.
2020
2121
:param messages: Array of LDMessage objects representing the conversation
22-
:return: ModelResponse containing the model's response and metrics
23-
"""
24-
...
25-
26-
async def invoke_structured_model(
27-
self,
28-
messages: List[LDMessage],
29-
response_structure: Dict[str, Any],
30-
) -> StructuredResponse:
31-
"""
32-
Invoke the model with structured output support.
33-
34-
:param messages: Array of LDMessage objects representing the conversation
35-
:param response_structure: Dictionary defining the JSON schema for output structure
36-
:return: StructuredResponse containing the structured data
22+
:return: RunnerResult containing the model's response and metrics
3723
"""
3824
...

packages/sdk/server-ai/src/ldai/providers/types.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from dataclasses import dataclass
77
from typing import Any, Callable, Dict, List, Optional
88

9-
from ldai.models import LDMessage
109
from ldai.tracker import LDAIMetricSummary, TokenUsage
1110

1211
# Type alias for a registry of tools available to an agent.
@@ -87,33 +86,6 @@ class ManagedResult:
8786
"""Optional asyncio Task that resolves to the list of :class:`JudgeResult` instances when awaited."""
8887

8988

90-
@dataclass
91-
class ModelResponse:
92-
"""
93-
Response from a model invocation.
94-
95-
.. deprecated::
96-
Use :class:`RunnerResult` (from a runner) and :class:`ManagedResult`
97-
(from the managed layer) instead.
98-
"""
99-
message: LDMessage
100-
metrics: LDAIMetrics
101-
evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None
102-
103-
104-
@dataclass
105-
class StructuredResponse:
106-
"""
107-
Structured response from AI models.
108-
109-
.. deprecated::
110-
Structured output is now represented by :attr:`RunnerResult.parsed`.
111-
"""
112-
data: Dict[str, Any]
113-
raw_response: str
114-
metrics: LDAIMetrics
115-
116-
11789
@dataclass
11890
class JudgeResult:
11991
"""Contains the result of a single judge evaluation."""
@@ -160,20 +132,6 @@ def to_dict(self) -> Dict[str, Any]:
160132
return result
161133

162134

163-
@dataclass
164-
class AgentResult:
165-
"""
166-
Result from a single-agent run.
167-
168-
.. deprecated::
169-
Use :class:`ManagedResult` (managed layer) or :class:`RunnerResult`
170-
(runner layer) instead.
171-
"""
172-
output: str
173-
raw: Any
174-
metrics: LDAIMetrics
175-
176-
177135
@dataclass
178136
class AgentGraphResult:
179137
"""Contains the result of an agent graph run."""

0 commit comments

Comments
 (0)