Skip to content

Commit 13849c0

Browse files
committed
Linting.
1 parent be1443e commit 13849c0

File tree

12 files changed

+84
-120
lines changed

12 files changed

+84
-120
lines changed

packages/core/ldai/__init__.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,21 @@
55
# to extend ldai.providers.* even though ldai itself has an __init__.py
66
import sys
77
from pkgutil import extend_path
8+
89
__path__ = extend_path(__path__, __name__)
910

11+
# Export chat
12+
from ldai.chat import TrackedChat
1013
# Export main client
1114
from ldai.client import LDAIClient
12-
13-
# Export models for convenience
14-
from ldai.models import (
15-
AIAgentConfig,
16-
AIAgentConfigDefault,
17-
AIAgentConfigRequest,
18-
AIAgents,
19-
AICompletionConfig,
20-
AICompletionConfigDefault,
21-
AIJudgeConfig,
22-
AIJudgeConfigDefault,
23-
JudgeConfiguration,
24-
LDMessage,
25-
ModelConfig,
26-
ProviderConfig,
27-
# Deprecated aliases for backward compatibility
28-
AIConfig,
29-
LDAIAgent,
30-
LDAIAgentConfig,
31-
LDAIAgentDefaults,
32-
)
33-
3415
# Export judge
3516
from ldai.judge import AIJudge
36-
37-
# Export chat
38-
from ldai.chat import TrackedChat
39-
17+
# Export models for convenience
18+
from ldai.models import ( # Deprecated aliases for backward compatibility
19+
AIAgentConfig, AIAgentConfigDefault, AIAgentConfigRequest, AIAgents,
20+
AICompletionConfig, AICompletionConfigDefault, AIConfig, AIJudgeConfig,
21+
AIJudgeConfigDefault, JudgeConfiguration, LDAIAgent, LDAIAgentConfig,
22+
LDAIAgentDefaults, LDMessage, ModelConfig, ProviderConfig)
4023
# Export judge types
4124
from ldai.providers.types import EvalScore, JudgeResponse
4225

packages/core/ldai/chat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
from ldai.chat.tracked_chat import TrackedChat
44

55
__all__ = ['TrackedChat']
6-

packages/core/ldai/chat/tracked_chat.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
import asyncio
44
from typing import Any, Dict, List, Optional
55

6+
from ldai.judge import AIJudge
67
from ldai.models import AICompletionConfig, LDMessage
78
from ldai.providers.ai_provider import AIProvider
89
from ldai.providers.types import ChatResponse, JudgeResponse
9-
from ldai.judge import AIJudge
1010
from ldai.tracker import LDAIConfigTracker
1111

1212

1313
class TrackedChat:
1414
"""
1515
Concrete implementation of TrackedChat that provides chat functionality
1616
by delegating to an AIProvider implementation.
17-
17+
1818
This class handles conversation management and tracking, while delegating
1919
the actual model invocation to the provider.
2020
"""
@@ -29,7 +29,7 @@ def __init__(
2929
):
3030
"""
3131
Initialize the TrackedChat.
32-
32+
3333
:param ai_config: The completion AI configuration
3434
:param tracker: The tracker for the completion configuration
3535
:param provider: The AI provider to use for chat
@@ -46,9 +46,9 @@ def __init__(
4646
async def invoke(self, prompt: str) -> ChatResponse:
4747
"""
4848
Invoke the chat model with a prompt string.
49-
49+
5050
This method handles conversation management and tracking, delegating to the provider's invoke_model method.
51-
51+
5252
:param prompt: The user prompt to send to the chat model
5353
:return: ChatResponse containing the model's response and metrics
5454
"""
@@ -83,9 +83,9 @@ def _start_judge_evaluations(
8383
) -> List[asyncio.Task[Optional[JudgeResponse]]]:
8484
"""
8585
Start judge evaluations as async tasks without awaiting them.
86-
86+
8787
Returns a list of async tasks that can be awaited later.
88-
88+
8989
:param messages: Array of messages representing the conversation history
9090
:param response: The AI response to be evaluated
9191
:return: List of async tasks that will return judge evaluation results
@@ -119,60 +119,60 @@ async def evaluate_judge(judge_config):
119119
asyncio.create_task(evaluate_judge(judge_config))
120120
for judge_config in judge_configs
121121
]
122-
122+
123123
return tasks
124124

125125
def get_config(self) -> AICompletionConfig:
126126
"""
127127
Get the underlying AI configuration used to initialize this TrackedChat.
128-
128+
129129
:return: The AI completion configuration
130130
"""
131131
return self._ai_config
132132

133133
def get_tracker(self) -> LDAIConfigTracker:
134134
"""
135135
Get the underlying AI configuration tracker used to initialize this TrackedChat.
136-
136+
137137
:return: The tracker instance
138138
"""
139139
return self._tracker
140140

141141
def get_provider(self) -> AIProvider:
142142
"""
143143
Get the underlying AI provider instance.
144-
144+
145145
This provides direct access to the provider for advanced use cases.
146-
146+
147147
:return: The AI provider instance
148148
"""
149149
return self._provider
150150

151151
def get_judges(self) -> Dict[str, AIJudge]:
152152
"""
153153
Get the judges associated with this TrackedChat.
154-
154+
155155
Returns a dictionary of judge instances keyed by their configuration keys.
156-
156+
157157
:return: Dictionary of judge instances
158158
"""
159159
return self._judges
160160

161161
def append_messages(self, messages: List[LDMessage]) -> None:
162162
"""
163163
Append messages to the conversation history.
164-
164+
165165
Adds messages to the conversation history without invoking the model,
166166
which is useful for managing multi-turn conversations or injecting context.
167-
167+
168168
:param messages: Array of messages to append to the conversation history
169169
"""
170170
self._messages.extend(messages)
171171

172172
def get_messages(self, include_config_messages: bool = False) -> List[LDMessage]:
173173
"""
174174
Get all messages in the conversation history.
175-
175+
176176
:param include_config_messages: Whether to include the config messages from the AIConfig.
177177
Defaults to False.
178178
:return: Array of messages. When include_config_messages is True, returns both config
@@ -183,4 +183,3 @@ def get_messages(self, include_config_messages: bool = False) -> List[LDMessage]
183183
config_messages = self._ai_config.messages or []
184184
return config_messages + self._messages
185185
return list(self._messages)
186-

packages/core/ldai/client.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77

88
from ldai.chat import TrackedChat
99
from ldai.judge import AIJudge
10-
from ldai.models import (
11-
AIAgentConfig,
12-
AIAgentConfigDefault,
13-
AIAgentConfigRequest,
14-
AIAgents,
15-
AICompletionConfig,
16-
AICompletionConfigDefault,
17-
AIJudgeConfig,
18-
AIJudgeConfigDefault,
19-
JudgeConfiguration,
20-
LDMessage,
21-
ModelConfig,
22-
ProviderConfig,
23-
)
24-
from ldai.providers.ai_provider_factory import AIProviderFactory, SupportedAIProvider
10+
from ldai.models import (AIAgentConfig, AIAgentConfigDefault,
11+
AIAgentConfigRequest, AIAgents, AICompletionConfig,
12+
AICompletionConfigDefault, AIJudgeConfig,
13+
AIJudgeConfigDefault, JudgeConfiguration, LDMessage,
14+
ModelConfig, ProviderConfig)
15+
from ldai.providers.ai_provider_factory import (AIProviderFactory,
16+
SupportedAIProvider)
2517
from ldai.tracker import LDAIConfigTracker
2618

2719

@@ -204,15 +196,15 @@ async def _initialize_judges(
204196
) -> Dict[str, AIJudge]:
205197
"""
206198
Initialize judges from judge configurations.
207-
199+
208200
:param judge_configs: List of judge configurations
209201
:param context: Standard Context used when evaluating flags
210202
:param variables: Dictionary of values for instruction interpolation
211203
:param default_ai_provider: Optional default AI provider to use
212204
:return: Dictionary of judge instances keyed by their configuration keys
213205
"""
214206
judges: Dict[str, AIJudge] = {}
215-
207+
216208
async def create_judge_for_config(judge_key: str):
217209
judge = await self.create_judge(
218210
judge_key,
@@ -222,22 +214,22 @@ async def create_judge_for_config(judge_key: str):
222214
default_ai_provider,
223215
)
224216
return judge_key, judge
225-
217+
226218
judge_promises = [
227219
create_judge_for_config(judge_config.key)
228220
for judge_config in judge_configs
229221
]
230-
222+
231223
import asyncio
232224
results = await asyncio.gather(*judge_promises, return_exceptions=True)
233-
225+
234226
for result in results:
235227
if isinstance(result, Exception):
236228
continue
237-
judge_key, judge = result
229+
judge_key, judge = result # type: ignore[misc]
238230
if judge:
239231
judges[judge_key] = judge
240-
232+
241233
return judges
242234

243235
async def create_chat(
@@ -275,7 +267,7 @@ async def create_chat(
275267
if chat:
276268
response = await chat.invoke("I need help with my order")
277269
print(response.message.content)
278-
270+
279271
# Access conversation history
280272
messages = chat.get_messages()
281273
print(f"Conversation has {len(messages)} messages")

packages/core/ldai/judge/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
from ldai.judge.ai_judge import AIJudge
44

55
__all__ = ['AIJudge']
6-
7-

packages/core/ldai/judge/ai_judge.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55

66
import chevron
77

8+
from ldai.judge.evaluation_schema_builder import EvaluationSchemaBuilder
89
from ldai.models import AIJudgeConfig, LDMessage
910
from ldai.providers.ai_provider import AIProvider
10-
from ldai.providers.types import ChatResponse, EvalScore, JudgeResponse, StructuredResponse
11+
from ldai.providers.types import (ChatResponse, EvalScore, JudgeResponse,
12+
StructuredResponse)
1113
from ldai.tracker import LDAIConfigTracker
12-
from ldai.judge.evaluation_schema_builder import EvaluationSchemaBuilder
1314

1415

1516
class AIJudge:
1617
"""
1718
Judge implementation that handles evaluation functionality and conversation management.
18-
19+
1920
According to the AIEval spec, judges are AI Configs with mode: "judge" that evaluate
2021
other AI Configs using structured output.
2122
"""
@@ -29,7 +30,7 @@ def __init__(
2930
):
3031
"""
3132
Initialize the Judge.
32-
33+
3334
:param ai_config: The judge AI configuration
3435
:param ai_config_tracker: The tracker for the judge configuration
3536
:param ai_provider: The AI provider to use for evaluation
@@ -51,7 +52,7 @@ async def evaluate(
5152
) -> Optional[JudgeResponse]:
5253
"""
5354
Evaluates an AI response using the judge's configuration.
54-
55+
5556
:param input_text: The input prompt or question that was provided to the AI
5657
:param output_text: The AI-generated response to be evaluated
5758
:param sampling_rate: Sampling rate (0-1) to determine if evaluation should be processed (defaults to 1)
@@ -113,7 +114,7 @@ async def evaluate_messages(
113114
) -> Optional[JudgeResponse]:
114115
"""
115116
Evaluates an AI response from chat messages and response.
116-
117+
117118
:param messages: Array of messages representing the conversation history
118119
:param response: The AI response to be evaluated
119120
:param sampling_ratio: Sampling ratio (0-1) to determine if evaluation should be processed (defaults to 1)
@@ -127,31 +128,31 @@ async def evaluate_messages(
127128
def get_ai_config(self) -> AIJudgeConfig:
128129
"""
129130
Returns the AI Config used by this judge.
130-
131+
131132
:return: The judge AI configuration
132133
"""
133134
return self._ai_config
134135

135136
def get_tracker(self) -> LDAIConfigTracker:
136137
"""
137138
Returns the tracker associated with this judge.
138-
139+
139140
:return: The tracker for the judge configuration
140141
"""
141142
return self._ai_config_tracker
142143

143144
def get_provider(self) -> AIProvider:
144145
"""
145146
Returns the AI provider used by this judge.
146-
147+
147148
:return: The AI provider
148149
"""
149150
return self._ai_provider
150151

151152
def _construct_evaluation_messages(self, input_text: str, output_text: str) -> list[LDMessage]:
152153
"""
153154
Constructs evaluation messages by combining judge's config messages with input/output.
154-
155+
155156
:param input_text: The input text
156157
:param output_text: The output text to evaluate
157158
:return: List of messages for evaluation
@@ -173,7 +174,7 @@ def _construct_evaluation_messages(self, input_text: str, output_text: str) -> l
173174
def _interpolate_message(self, content: str, variables: Dict[str, str]) -> str:
174175
"""
175176
Interpolates message content with variables using Mustache templating.
176-
177+
177178
:param content: The message content template
178179
:param variables: Variables to interpolate
179180
:return: Interpolated message content
@@ -184,7 +185,7 @@ def _interpolate_message(self, content: str, variables: Dict[str, str]) -> str:
184185
def _parse_evaluation_response(self, data: Dict[str, Any]) -> Dict[str, EvalScore]:
185186
"""
186187
Parses the structured evaluation response from the AI provider.
187-
188+
188189
:param data: The structured response data
189190
:return: Dictionary of evaluation scores keyed by metric key
190191
"""
@@ -227,4 +228,3 @@ def _parse_evaluation_response(self, data: Dict[str, Any]) -> Dict[str, EvalScor
227228
results[metric_key] = EvalScore(score=float(score), reasoning=reasoning)
228229

229230
return results
230-

0 commit comments

Comments
 (0)