Skip to content

Commit 11750d2

Browse files
committed
fixes
1 parent 5a2d2dc commit 11750d2

File tree

9 files changed

+124
-106
lines changed

9 files changed

+124
-106
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
from ldai.chat import ChatResponse, TrackedChat
1313
# Export main client
1414
from ldai.client import LDAIClient
15+
from ldai.config import LDMessage, ModelConfig, ProviderConfig
1516
# Export judge
1617
from ldai.judge import AIJudge, EvalScore, JudgeResponse, StructuredResponse
1718
# Export models for convenience
1819
from ldai.models import ( # Deprecated aliases for backward compatibility
1920
AIAgentConfig, AIAgentConfigDefault, AIAgentConfigRequest, AIAgents,
2021
AICompletionConfig, AICompletionConfigDefault, AIConfig, AIJudgeConfig,
2122
AIJudgeConfigDefault, JudgeConfiguration, LDAIAgent, LDAIAgentConfig,
22-
LDAIAgentDefaults, LDMessage, ModelConfig, ProviderConfig)
23+
LDAIAgentDefaults)
2324

2425
__all__ = [
2526
'LDAIClient',

packages/sdk/server-ai/src/ldai/chat/tracked_chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from typing import Dict, List, Optional
66

77
from ldai.chat.types import ChatResponse
8+
from ldai.config.types import LDMessage
89
from ldai.judge import AIJudge
910
from ldai.judge.types import JudgeResponse
10-
from ldai.models import AICompletionConfig, LDMessage
11+
from ldai.models import AICompletionConfig
1112
from ldai.providers.ai_provider import AIProvider
1213
from ldai.tracker import LDAIConfigTracker
1314

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from dataclasses import dataclass
44
from typing import Any, List, Optional
55

6+
from ldai.config.types import LDMessage
67
from ldai.metrics import LDAIMetrics
7-
from ldai.models import LDMessage
88

99

1010
@dataclass

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from ldclient.client import LDClient
88

99
from ldai.chat import TrackedChat
10+
from ldai.config import LDMessage, ModelConfig, ProviderConfig
1011
from ldai.judge import AIJudge
1112
from ldai.models import (AIAgentConfig, AIAgentConfigDefault,
1213
AIAgentConfigRequest, AIAgents, AICompletionConfig,
1314
AICompletionConfigDefault, AIJudgeConfig,
14-
AIJudgeConfigDefault, JudgeConfiguration, LDMessage,
15-
ModelConfig, ProviderConfig)
15+
AIJudgeConfigDefault, JudgeConfiguration)
1616
from ldai.providers.ai_provider_factory import (AIProviderFactory,
1717
SupportedAIProvider)
1818
from ldai.tracker import LDAIConfigTracker
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Config module for LaunchDarkly AI SDK."""
2+
3+
from ldai.config.types import LDMessage, ModelConfig, ProviderConfig
4+
5+
__all__ = ['LDMessage', 'ModelConfig', 'ProviderConfig']
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"""Types for configuration."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
from typing import Any, Dict, Literal, Optional
7+
8+
9+
@dataclass
10+
class LDMessage:
11+
role: Literal['system', 'user', 'assistant']
12+
content: str
13+
14+
def to_dict(self) -> dict:
15+
"""
16+
Render the given message as a dictionary object.
17+
"""
18+
return {
19+
'role': self.role,
20+
'content': self.content,
21+
}
22+
23+
24+
class ModelConfig:
25+
"""
26+
Configuration related to the model.
27+
"""
28+
29+
def __init__(self, name: str, parameters: Optional[Dict[str, Any]] = None, custom: Optional[Dict[str, Any]] = None):
30+
"""
31+
:param name: The name of the model.
32+
:param parameters: Additional model-specific parameters.
33+
:param custom: Additional customer provided data.
34+
"""
35+
self._name = name
36+
self._parameters = parameters
37+
self._custom = custom
38+
39+
@property
40+
def name(self) -> str:
41+
"""
42+
The name of the model.
43+
"""
44+
return self._name
45+
46+
def get_parameter(self, key: str) -> Any:
47+
"""
48+
Retrieve model-specific parameters.
49+
50+
Accessing a named, typed attribute (e.g. name) will result in the call
51+
being delegated to the appropriate property.
52+
"""
53+
if key == 'name':
54+
return self.name
55+
56+
if self._parameters is None:
57+
return None
58+
59+
return self._parameters.get(key)
60+
61+
def get_custom(self, key: str) -> Any:
62+
"""
63+
Retrieve customer provided data.
64+
"""
65+
if self._custom is None:
66+
return None
67+
68+
return self._custom.get(key)
69+
70+
def to_dict(self) -> dict:
71+
"""
72+
Render the given model config as a dictionary object.
73+
"""
74+
return {
75+
'name': self._name,
76+
'parameters': self._parameters,
77+
'custom': self._custom,
78+
}
79+
80+
81+
class ProviderConfig:
82+
"""
83+
Configuration related to the provider.
84+
"""
85+
86+
def __init__(self, name: str):
87+
self._name = name
88+
89+
@property
90+
def name(self) -> str:
91+
"""
92+
The name of the provider.
93+
"""
94+
return self._name
95+
96+
def to_dict(self) -> dict:
97+
"""
98+
Render the given provider config as a dictionary object.
99+
"""
100+
return {
101+
'name': self._name,
102+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import chevron
88

99
from ldai.chat.types import ChatResponse
10+
from ldai.config.types import LDMessage
1011
from ldai.judge.evaluation_schema_builder import EvaluationSchemaBuilder
1112
from ldai.judge.types import EvalScore, JudgeResponse, StructuredResponse
12-
from ldai.models import AIJudgeConfig, LDMessage
13+
from ldai.models import AIJudgeConfig
1314
from ldai.providers.ai_provider import AIProvider
1415
from ldai.tracker import LDAIConfigTracker
1516

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

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,17 @@
1+
from __future__ import annotations
2+
13
import warnings
24
from dataclasses import dataclass, field
3-
from typing import Any, Dict, List, Literal, Optional, Union
5+
from typing import Any, Dict, List, Optional, Union
46

7+
from ldai.config.types import LDMessage, ModelConfig, ProviderConfig
58
from ldai.tracker import LDAIConfigTracker
69

7-
8-
@dataclass
9-
class LDMessage:
10-
role: Literal['system', 'user', 'assistant']
11-
content: str
12-
13-
def to_dict(self) -> dict:
14-
"""
15-
Render the given message as a dictionary object.
16-
"""
17-
return {
18-
'role': self.role,
19-
'content': self.content,
20-
}
21-
22-
23-
class ModelConfig:
24-
"""
25-
Configuration related to the model.
26-
"""
27-
28-
def __init__(self, name: str, parameters: Optional[Dict[str, Any]] = None, custom: Optional[Dict[str, Any]] = None):
29-
"""
30-
:param name: The name of the model.
31-
:param parameters: Additional model-specific parameters.
32-
:param custom: Additional customer provided data.
33-
"""
34-
self._name = name
35-
self._parameters = parameters
36-
self._custom = custom
37-
38-
@property
39-
def name(self) -> str:
40-
"""
41-
The name of the model.
42-
"""
43-
return self._name
44-
45-
def get_parameter(self, key: str) -> Any:
46-
"""
47-
Retrieve model-specific parameters.
48-
49-
Accessing a named, typed attribute (e.g. name) will result in the call
50-
being delegated to the appropriate property.
51-
"""
52-
if key == 'name':
53-
return self.name
54-
55-
if self._parameters is None:
56-
return None
57-
58-
return self._parameters.get(key)
59-
60-
def get_custom(self, key: str) -> Any:
61-
"""
62-
Retrieve customer provided data.
63-
"""
64-
if self._custom is None:
65-
return None
66-
67-
return self._custom.get(key)
68-
69-
def to_dict(self) -> dict:
70-
"""
71-
Render the given model config as a dictionary object.
72-
"""
73-
return {
74-
'name': self._name,
75-
'parameters': self._parameters,
76-
'custom': self._custom,
77-
}
78-
79-
80-
class ProviderConfig:
81-
"""
82-
Configuration related to the provider.
83-
"""
84-
85-
def __init__(self, name: str):
86-
self._name = name
87-
88-
@property
89-
def name(self) -> str:
90-
"""
91-
The name of the provider.
92-
"""
93-
return self._name
94-
95-
def to_dict(self) -> dict:
96-
"""
97-
Render the given provider config as a dictionary object.
98-
"""
99-
return {
100-
'name': self._name,
101-
}
102-
103-
10410
# ============================================================================
10511
# Judge Types
10612
# ============================================================================
10713

14+
10815
@dataclass(frozen=True)
10916
class JudgeConfiguration:
11017
"""
@@ -128,7 +35,7 @@ def to_dict(self) -> dict:
12835
'samplingRate': self.sampling_rate,
12936
}
13037

131-
judges: List['JudgeConfiguration.Judge']
38+
judges: List[JudgeConfiguration.Judge]
13239

13340
def to_dict(self) -> dict:
13441
"""

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from typing import Any, Dict, List, Optional
66

77
from ldai.chat.types import ChatResponse
8+
from ldai.config.types import LDMessage
89
from ldai.judge.types import StructuredResponse
910
from ldai.metrics import LDAIMetrics
10-
from ldai.models import AIConfigKind, LDMessage
11+
from ldai.models import AIConfigKind
1112

1213

1314
class AIProvider(ABC):

0 commit comments

Comments
 (0)