unique_toolkit 0.6.1__py3-none-any.whl → 0.6.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unique_toolkit/__init__.py +17 -0
- unique_toolkit/evaluators/config.py +1 -1
- unique_toolkit/evaluators/context_relevancy/constants.py +1 -1
- unique_toolkit/language_model/builder.py +20 -5
- unique_toolkit/language_model/infos.py +146 -207
- unique_toolkit/language_model/schemas.py +54 -24
- {unique_toolkit-0.6.1.dist-info → unique_toolkit-0.6.4.dist-info}/METADATA +14 -1
- {unique_toolkit-0.6.1.dist-info → unique_toolkit-0.6.4.dist-info}/RECORD +10 -10
- {unique_toolkit-0.6.1.dist-info → unique_toolkit-0.6.4.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.6.1.dist-info → unique_toolkit-0.6.4.dist-info}/WHEEL +0 -0
unique_toolkit/__init__.py
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Re-export commonly used classes for easier imports
|
2
|
+
from unique_toolkit.chat import ChatService
|
3
|
+
from unique_toolkit.content import ContentService
|
4
|
+
from unique_toolkit.embedding import EmbeddingService
|
5
|
+
from unique_toolkit.language_model import LanguageModelMessages, LanguageModelService
|
6
|
+
from unique_toolkit.short_term_memory import ShortTermMemoryService
|
7
|
+
|
8
|
+
# You can add other classes you frequently use here as well
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"LanguageModelService",
|
12
|
+
"LanguageModelMessages",
|
13
|
+
"ChatService",
|
14
|
+
"ContentService",
|
15
|
+
"EmbeddingService",
|
16
|
+
"ShortTermMemoryService",
|
17
|
+
]
|
@@ -25,7 +25,7 @@ class EvaluationMetricConfig(BaseModel):
|
|
25
25
|
enabled: bool = False
|
26
26
|
name: EvaluationMetricName
|
27
27
|
language_model: LanguageModel = LanguageModel(
|
28
|
-
LanguageModelName.
|
28
|
+
LanguageModelName.AZURE_GPT_35_TURBO_0125
|
29
29
|
)
|
30
30
|
custom_prompts: dict[str, str] = {}
|
31
31
|
score_to_emoji: dict[str, str] = {}
|
@@ -23,7 +23,7 @@ context_relevancy_required_input_fields = [
|
|
23
23
|
default_config = EvaluationMetricConfig(
|
24
24
|
enabled=False,
|
25
25
|
name=EvaluationMetricName.CONTEXT_RELEVANCY,
|
26
|
-
language_model=LanguageModel(LanguageModelName.
|
26
|
+
language_model=LanguageModel(LanguageModelName.AZURE_GPT_35_TURBO_0125),
|
27
27
|
score_to_emoji={"LOW": "🟢", "MEDIUM": "🟡", "HIGH": "🔴"},
|
28
28
|
custom_prompts={
|
29
29
|
SYSTEM_MSG_KEY: CONTEXT_RELEVANCY_METRIC_SYSTEM_MSG,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
from typing_extensions import Self
|
2
|
+
|
1
3
|
from unique_toolkit.language_model import (
|
2
4
|
LanguageModelAssistantMessage,
|
3
5
|
LanguageModelMessage,
|
@@ -12,25 +14,38 @@ class MessagesBuilder:
|
|
12
14
|
def __init__(self):
|
13
15
|
self.messages: list[LanguageModelMessage] = []
|
14
16
|
|
15
|
-
def system_message_append(self, content):
|
16
|
-
"""Appends a
|
17
|
+
def system_message_append(self, content: str) -> Self:
|
18
|
+
"""Appends a system message to the messages list."""
|
17
19
|
message = LanguageModelSystemMessage(content=content)
|
18
20
|
self.messages.append(message)
|
19
21
|
return self # Return self to allow method chaining
|
20
22
|
|
21
|
-
def user_message_append(self, content):
|
23
|
+
def user_message_append(self, content: str) -> Self:
|
22
24
|
"""Appends a user message to the messages list."""
|
23
25
|
message = LanguageModelUserMessage(content=content)
|
24
26
|
self.messages.append(message)
|
25
27
|
return self # Return self to allow method chaining
|
26
28
|
|
27
|
-
def
|
29
|
+
def image_message_append(self, content: str, images: list[str]) -> Self:
|
30
|
+
message = LanguageModelUserMessage(
|
31
|
+
content=[
|
32
|
+
{"type": "text", "text": content},
|
33
|
+
*[
|
34
|
+
{"type": "image_url", "imageUrl": {"url": image}}
|
35
|
+
for image in images
|
36
|
+
],
|
37
|
+
]
|
38
|
+
)
|
39
|
+
self.messages.append(message)
|
40
|
+
return self
|
41
|
+
|
42
|
+
def assistant_message_append(self, content: str) -> Self:
|
28
43
|
"""Appends an assistant message to the messages list."""
|
29
44
|
message = LanguageModelAssistantMessage(content=content)
|
30
45
|
self.messages.append(message)
|
31
46
|
return self # Return self to allow method chaining
|
32
47
|
|
33
|
-
def tool_message_append(self, name: str, tool_call_id: str, content: str):
|
48
|
+
def tool_message_append(self, name: str, tool_call_id: str, content: str) -> Self:
|
34
49
|
"""Appends a tool message to the messages list."""
|
35
50
|
message = LanguageModelToolMessage(
|
36
51
|
name=name, tool_call_id=tool_call_id, content=content
|
@@ -1,16 +1,14 @@
|
|
1
1
|
from datetime import date
|
2
2
|
from enum import StrEnum
|
3
|
-
from typing import ClassVar, Optional
|
3
|
+
from typing import ClassVar, Optional
|
4
4
|
|
5
5
|
from pydantic import BaseModel
|
6
|
+
from typing_extensions import deprecated
|
6
7
|
|
7
8
|
from unique_toolkit.language_model.schemas import LanguageModelTokenLimits
|
8
9
|
|
9
10
|
|
10
11
|
class LanguageModelName(StrEnum):
|
11
|
-
AZURE_GPT_35_TURBO_0613 = "AZURE_GPT_35_TURBO_0613"
|
12
|
-
AZURE_GPT_35_TURBO = "AZURE_GPT_35_TURBO"
|
13
|
-
AZURE_GPT_35_TURBO_16K = "AZURE_GPT_35_TURBO_16K"
|
14
12
|
AZURE_GPT_35_TURBO_0125 = "AZURE_GPT_35_TURBO_0125"
|
15
13
|
AZURE_GPT_4_0613 = "AZURE_GPT_4_0613"
|
16
14
|
AZURE_GPT_4_TURBO_1106 = "AZURE_GPT_4_TURBO_1106"
|
@@ -30,12 +28,7 @@ class EncoderName(StrEnum):
|
|
30
28
|
def get_encoder_name(model_name: LanguageModelName) -> Optional[EncoderName]:
|
31
29
|
LMN = LanguageModelName
|
32
30
|
match model_name:
|
33
|
-
case
|
34
|
-
LMN.AZURE_GPT_35_TURBO
|
35
|
-
| LMN.AZURE_GPT_35_TURBO_16K
|
36
|
-
| LMN.AZURE_GPT_35_TURBO_0613
|
37
|
-
| LMN.AZURE_GPT_35_TURBO_0125
|
38
|
-
):
|
31
|
+
case LMN.AZURE_GPT_35_TURBO_0125:
|
39
32
|
return EncoderName.CL100K_BASE
|
40
33
|
case (
|
41
34
|
LMN.AZURE_GPT_4_0613
|
@@ -76,7 +69,147 @@ class LanguageModelInfo(BaseModel):
|
|
76
69
|
deprecated_at: Optional[date] = None
|
77
70
|
retirement_text: Optional[str] = None
|
78
71
|
|
72
|
+
@classmethod
|
73
|
+
def from_name(cls, model_name: LanguageModelName):
|
74
|
+
match model_name:
|
75
|
+
case LanguageModelName.AZURE_GPT_35_TURBO_0125:
|
76
|
+
return cls(
|
77
|
+
name=model_name,
|
78
|
+
provider=LanguageModelProvider.AZURE,
|
79
|
+
version="0125",
|
80
|
+
encoder_name=get_encoder_name(model_name),
|
81
|
+
token_limits=LanguageModelTokenLimits(
|
82
|
+
token_limit_input=16385, token_limit_output=4096
|
83
|
+
),
|
84
|
+
info_cutoff_at=date(2021, 9, 1),
|
85
|
+
published_at=date(2023, 1, 25),
|
86
|
+
retirement_at=date(5, 3, 31),
|
87
|
+
)
|
88
|
+
case LanguageModelName.AZURE_GPT_4_0613:
|
89
|
+
return cls(
|
90
|
+
name=model_name,
|
91
|
+
provider=LanguageModelProvider.AZURE,
|
92
|
+
version="0613",
|
93
|
+
encoder_name=get_encoder_name(model_name),
|
94
|
+
token_limits=LanguageModelTokenLimits(token_limit=8192),
|
95
|
+
info_cutoff_at=date(2021, 9, 1),
|
96
|
+
published_at=date(2023, 6, 13),
|
97
|
+
deprecated_at=date(2024, 10, 1),
|
98
|
+
retirement_at=date(2025, 6, 6),
|
99
|
+
)
|
100
|
+
case LanguageModelName.AZURE_GPT_4_TURBO_1106:
|
101
|
+
return cls(
|
102
|
+
name=model_name,
|
103
|
+
provider=LanguageModelProvider.AZURE,
|
104
|
+
version="1106-preview",
|
105
|
+
encoder_name=get_encoder_name(model_name),
|
106
|
+
token_limits=LanguageModelTokenLimits(
|
107
|
+
token_limit_input=128000, token_limit_output=4096
|
108
|
+
),
|
109
|
+
info_cutoff_at=date(2023, 4, 1),
|
110
|
+
published_at=date(2023, 11, 6),
|
111
|
+
)
|
112
|
+
case LanguageModelName.AZURE_GPT_4_VISION_PREVIEW:
|
113
|
+
return cls(
|
114
|
+
name=model_name,
|
115
|
+
provider=LanguageModelProvider.AZURE,
|
116
|
+
version="vision-preview",
|
117
|
+
encoder_name=get_encoder_name(model_name),
|
118
|
+
token_limits=LanguageModelTokenLimits(
|
119
|
+
token_limit_input=128000, token_limit_output=4096
|
120
|
+
),
|
121
|
+
info_cutoff_at=date(2023, 4, 1),
|
122
|
+
published_at=date(2023, 11, 6),
|
123
|
+
)
|
124
|
+
case LanguageModelName.AZURE_GPT_4_32K_0613:
|
125
|
+
return cls(
|
126
|
+
name=model_name,
|
127
|
+
provider=LanguageModelProvider.AZURE,
|
128
|
+
version="1106-preview",
|
129
|
+
encoder_name=get_encoder_name(model_name),
|
130
|
+
token_limits=LanguageModelTokenLimits(token_limit=32768),
|
131
|
+
info_cutoff_at=date(2021, 9, 1),
|
132
|
+
published_at=date(2023, 6, 13),
|
133
|
+
deprecated_at=date(2024, 10, 1),
|
134
|
+
retirement_at=date(2025, 6, 6),
|
135
|
+
)
|
136
|
+
case LanguageModelName.AZURE_GPT_4_TURBO_2024_0409:
|
137
|
+
return cls(
|
138
|
+
name=model_name,
|
139
|
+
encoder_name=get_encoder_name(model_name),
|
140
|
+
provider=LanguageModelProvider.AZURE,
|
141
|
+
version="turbo-2024-04-09",
|
142
|
+
token_limits=LanguageModelTokenLimits(
|
143
|
+
token_limit_input=128000, token_limit_output=4096
|
144
|
+
),
|
145
|
+
info_cutoff_at=date(2023, 12, 1),
|
146
|
+
published_at=date(2024, 4, 9),
|
147
|
+
)
|
148
|
+
case LanguageModelName.AZURE_GPT_4o_2024_0513:
|
149
|
+
return cls(
|
150
|
+
name=model_name,
|
151
|
+
encoder_name=get_encoder_name(model_name),
|
152
|
+
provider=LanguageModelProvider.AZURE,
|
153
|
+
version="2024-05-13",
|
154
|
+
token_limits=LanguageModelTokenLimits(
|
155
|
+
token_limit_input=128000, token_limit_output=4096
|
156
|
+
),
|
157
|
+
info_cutoff_at=date(2023, 10, 1),
|
158
|
+
published_at=date(2024, 5, 13),
|
159
|
+
)
|
160
|
+
case LanguageModelName.AZURE_GPT_4o_2024_0806:
|
161
|
+
return cls(
|
162
|
+
name=model_name,
|
163
|
+
encoder_name=get_encoder_name(model_name),
|
164
|
+
provider=LanguageModelProvider.AZURE,
|
165
|
+
version="2024-08-06",
|
166
|
+
token_limits=LanguageModelTokenLimits(
|
167
|
+
token_limit_input=128000, token_limit_output=16384
|
168
|
+
),
|
169
|
+
info_cutoff_at=date(2023, 10, 1),
|
170
|
+
published_at=date(2024, 8, 6),
|
171
|
+
)
|
172
|
+
case LanguageModelName.AZURE_GPT_4o_MINI_2024_0718:
|
173
|
+
return cls(
|
174
|
+
name=model_name,
|
175
|
+
provider=LanguageModelProvider.AZURE,
|
176
|
+
version="2024-07-18",
|
177
|
+
encoder_name=get_encoder_name(model_name),
|
178
|
+
token_limits=LanguageModelTokenLimits(
|
179
|
+
token_limit_input=128000, token_limit_output=16384
|
180
|
+
),
|
181
|
+
info_cutoff_at=date(2023, 10, 1),
|
182
|
+
published_at=date(2024, 7, 18),
|
183
|
+
)
|
184
|
+
case _:
|
185
|
+
if isinstance(model_name, LanguageModelName):
|
186
|
+
raise ValueError(
|
187
|
+
f"{model_name} is not supported. Please add model information in toolkit."
|
188
|
+
)
|
189
|
+
|
190
|
+
return cls(
|
191
|
+
name=model_name,
|
192
|
+
version="custom",
|
193
|
+
provider=LanguageModelProvider.CUSTOM,
|
194
|
+
)
|
195
|
+
|
196
|
+
@property
|
197
|
+
def display_name(self) -> str:
|
198
|
+
"""
|
199
|
+
Returns the name of the model as a string.
|
200
|
+
"""
|
201
|
+
|
202
|
+
if isinstance(self.name, LanguageModelName):
|
203
|
+
return self.name.value
|
204
|
+
else:
|
205
|
+
return self.name
|
206
|
+
|
79
207
|
|
208
|
+
@deprecated(
|
209
|
+
"""
|
210
|
+
Use `LanguageModelInfo` instead of `LanguageModel`
|
211
|
+
"""
|
212
|
+
)
|
80
213
|
class LanguageModel:
|
81
214
|
_info: ClassVar[LanguageModelInfo]
|
82
215
|
|
@@ -199,17 +332,8 @@ class LanguageModel:
|
|
199
332
|
|
200
333
|
@classmethod
|
201
334
|
def get_model_info(cls, model_name: LanguageModelName | str) -> LanguageModelInfo:
|
202
|
-
if
|
203
|
-
|
204
|
-
|
205
|
-
for subclass in cls.__subclasses__():
|
206
|
-
if hasattr(subclass, "info") and subclass._info.name == model_name:
|
207
|
-
# TODO find alternative solution for warning
|
208
|
-
# if subclass._info.retirement_at:
|
209
|
-
# warning_text = f"WARNING: {subclass._info.name} will be retired on {subclass._info.retirement_at.isoformat()} and from then on not accessible anymore. {subclass._info.retirement_text}"
|
210
|
-
# print(warning_text)
|
211
|
-
# warnings.warn(warning_text, DeprecationWarning, stacklevel=2)
|
212
|
-
return subclass._info
|
335
|
+
if isinstance(model_name, LanguageModelName):
|
336
|
+
return LanguageModelInfo.from_name(model_name)
|
213
337
|
|
214
338
|
return LanguageModelInfo(
|
215
339
|
name=model_name,
|
@@ -224,190 +348,5 @@ class LanguageModel:
|
|
224
348
|
"""
|
225
349
|
|
226
350
|
return [
|
227
|
-
|
228
|
-
for subclass in cls.__subclasses__()
|
229
|
-
if hasattr(subclass, "_info")
|
351
|
+
LanguageModelInfo.from_name(model_name=name) for name in LanguageModelName
|
230
352
|
]
|
231
|
-
|
232
|
-
|
233
|
-
def create_language_model(
|
234
|
-
name: LanguageModelName,
|
235
|
-
version: str,
|
236
|
-
provider: LanguageModelProvider,
|
237
|
-
info_cutoff_at: date,
|
238
|
-
published_at: date,
|
239
|
-
encoder_name: Optional[EncoderName] = None,
|
240
|
-
token_limit: Optional[int] = None,
|
241
|
-
token_limit_input: Optional[int] = None,
|
242
|
-
token_limit_output: Optional[int] = None,
|
243
|
-
retirement_at: Optional[date] = None,
|
244
|
-
deprecated_at: Optional[date] = None,
|
245
|
-
retirement_text: Optional[str] = None,
|
246
|
-
) -> Type[LanguageModel]:
|
247
|
-
info = LanguageModelInfo(
|
248
|
-
name=name,
|
249
|
-
version=version,
|
250
|
-
provider=provider,
|
251
|
-
encoder_name=encoder_name,
|
252
|
-
token_limits=LanguageModelTokenLimits(
|
253
|
-
token_limit=token_limit,
|
254
|
-
token_limit_input=token_limit_input,
|
255
|
-
token_limit_output=token_limit_output,
|
256
|
-
),
|
257
|
-
info_cutoff_at=info_cutoff_at,
|
258
|
-
published_at=published_at,
|
259
|
-
retirement_at=retirement_at,
|
260
|
-
deprecated_at=deprecated_at,
|
261
|
-
retirement_text=retirement_text,
|
262
|
-
)
|
263
|
-
|
264
|
-
class Model(LanguageModel):
|
265
|
-
_info = info
|
266
|
-
|
267
|
-
return Model
|
268
|
-
|
269
|
-
|
270
|
-
############################################################################################################
|
271
|
-
# Define the models here
|
272
|
-
############################################################################################################
|
273
|
-
|
274
|
-
|
275
|
-
AzureGpt35Turbo0613 = create_language_model(
|
276
|
-
name=LanguageModelName.AZURE_GPT_35_TURBO_0613,
|
277
|
-
provider=LanguageModelProvider.AZURE,
|
278
|
-
version="0613",
|
279
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO_0613),
|
280
|
-
token_limit=8192,
|
281
|
-
info_cutoff_at=date(2021, 9, 1),
|
282
|
-
published_at=date(2023, 6, 13),
|
283
|
-
retirement_at=date(2025, 2, 13),
|
284
|
-
)
|
285
|
-
|
286
|
-
AzureGpt35Turbo = create_language_model(
|
287
|
-
name=LanguageModelName.AZURE_GPT_35_TURBO,
|
288
|
-
provider=LanguageModelProvider.AZURE,
|
289
|
-
version="0301",
|
290
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO),
|
291
|
-
token_limit=4096,
|
292
|
-
info_cutoff_at=date(2021, 9, 1),
|
293
|
-
published_at=date(2023, 3, 1),
|
294
|
-
retirement_at=date(2025, 2, 13),
|
295
|
-
)
|
296
|
-
|
297
|
-
|
298
|
-
AzureGpt35Turbo16k = create_language_model(
|
299
|
-
name=LanguageModelName.AZURE_GPT_35_TURBO_16K,
|
300
|
-
provider=LanguageModelProvider.AZURE,
|
301
|
-
version="0613",
|
302
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO_16K),
|
303
|
-
token_limit=16382,
|
304
|
-
info_cutoff_at=date(2021, 9, 1),
|
305
|
-
published_at=date(2023, 6, 13),
|
306
|
-
retirement_at=date(2025, 2, 13),
|
307
|
-
)
|
308
|
-
|
309
|
-
|
310
|
-
AzureGpt35Turbo0125 = create_language_model(
|
311
|
-
name=LanguageModelName.AZURE_GPT_35_TURBO_0125,
|
312
|
-
provider=LanguageModelProvider.AZURE,
|
313
|
-
version="0125",
|
314
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO_0125),
|
315
|
-
token_limit_input=16385,
|
316
|
-
token_limit_output=4096,
|
317
|
-
info_cutoff_at=date(2021, 9, 1),
|
318
|
-
published_at=date(2023, 1, 25),
|
319
|
-
retirement_at=date(5, 3, 31),
|
320
|
-
)
|
321
|
-
|
322
|
-
|
323
|
-
AzureGpt40613 = create_language_model(
|
324
|
-
name=LanguageModelName.AZURE_GPT_4_0613,
|
325
|
-
provider=LanguageModelProvider.AZURE,
|
326
|
-
version="0613",
|
327
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_0613),
|
328
|
-
token_limit=8192,
|
329
|
-
info_cutoff_at=date(2021, 9, 1),
|
330
|
-
published_at=date(2023, 6, 13),
|
331
|
-
deprecated_at=date(2024, 10, 1),
|
332
|
-
retirement_at=date(2025, 6, 6),
|
333
|
-
)
|
334
|
-
|
335
|
-
|
336
|
-
AzureGpt4Turbo1106 = create_language_model(
|
337
|
-
name=LanguageModelName.AZURE_GPT_4_TURBO_1106,
|
338
|
-
provider=LanguageModelProvider.AZURE,
|
339
|
-
version="1106-preview",
|
340
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_TURBO_1106),
|
341
|
-
token_limit_input=128000,
|
342
|
-
token_limit_output=4096,
|
343
|
-
info_cutoff_at=date(2023, 4, 1),
|
344
|
-
published_at=date(2023, 11, 6),
|
345
|
-
)
|
346
|
-
|
347
|
-
|
348
|
-
AzureGpt4VisionPreview = create_language_model(
|
349
|
-
name=LanguageModelName.AZURE_GPT_4_VISION_PREVIEW,
|
350
|
-
provider=LanguageModelProvider.AZURE,
|
351
|
-
version="vision-preview",
|
352
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_VISION_PREVIEW),
|
353
|
-
token_limit_input=128000,
|
354
|
-
token_limit_output=4096,
|
355
|
-
info_cutoff_at=date(2023, 4, 1),
|
356
|
-
published_at=date(2023, 11, 6),
|
357
|
-
)
|
358
|
-
|
359
|
-
AzureGpt432k0613 = create_language_model(
|
360
|
-
name=LanguageModelName.AZURE_GPT_4_32K_0613,
|
361
|
-
provider=LanguageModelProvider.AZURE,
|
362
|
-
version="1106-preview",
|
363
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_32K_0613),
|
364
|
-
token_limit=32768,
|
365
|
-
info_cutoff_at=date(2021, 9, 1),
|
366
|
-
published_at=date(2023, 6, 13),
|
367
|
-
deprecated_at=date(2024, 10, 1),
|
368
|
-
retirement_at=date(2025, 6, 6),
|
369
|
-
)
|
370
|
-
|
371
|
-
AzureGpt4Turbo20240409 = create_language_model(
|
372
|
-
name=LanguageModelName.AZURE_GPT_4_TURBO_2024_0409,
|
373
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_TURBO_2024_0409),
|
374
|
-
provider=LanguageModelProvider.AZURE,
|
375
|
-
version="turbo-2024-04-09",
|
376
|
-
token_limit_input=128000,
|
377
|
-
token_limit_output=4096,
|
378
|
-
info_cutoff_at=date(2023, 12, 1),
|
379
|
-
published_at=date(2024, 4, 9),
|
380
|
-
)
|
381
|
-
|
382
|
-
AzureGpt4o20240513 = create_language_model(
|
383
|
-
name=LanguageModelName.AZURE_GPT_4o_2024_0513,
|
384
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4o_2024_0513),
|
385
|
-
provider=LanguageModelProvider.AZURE,
|
386
|
-
version="2024-05-13",
|
387
|
-
token_limit_input=128000,
|
388
|
-
token_limit_output=4096,
|
389
|
-
info_cutoff_at=date(2023, 10, 1),
|
390
|
-
published_at=date(2024, 5, 13),
|
391
|
-
)
|
392
|
-
|
393
|
-
AzureGpt4o20240806 = create_language_model(
|
394
|
-
name=LanguageModelName.AZURE_GPT_4o_2024_0806,
|
395
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4o_2024_0806),
|
396
|
-
provider=LanguageModelProvider.AZURE,
|
397
|
-
version="2024-08-06",
|
398
|
-
token_limit_input=128000,
|
399
|
-
token_limit_output=16384,
|
400
|
-
info_cutoff_at=date(2023, 10, 1),
|
401
|
-
published_at=date(2024, 8, 6),
|
402
|
-
)
|
403
|
-
|
404
|
-
AzureGpt4oMini20240718 = create_language_model(
|
405
|
-
name=LanguageModelName.AZURE_GPT_4o_MINI_2024_0718,
|
406
|
-
provider=LanguageModelProvider.AZURE,
|
407
|
-
version="2024-07-18",
|
408
|
-
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4o_MINI_2024_0718),
|
409
|
-
token_limit_input=128000,
|
410
|
-
token_limit_output=16384,
|
411
|
-
info_cutoff_at=date(2023, 10, 1),
|
412
|
-
published_at=date(2024, 7, 18),
|
413
|
-
)
|
@@ -9,11 +9,13 @@ from pydantic import (
|
|
9
9
|
BaseModel,
|
10
10
|
ConfigDict,
|
11
11
|
Field,
|
12
|
+
PrivateAttr,
|
12
13
|
RootModel,
|
13
14
|
field_validator,
|
14
15
|
model_serializer,
|
15
16
|
model_validator,
|
16
17
|
)
|
18
|
+
from typing_extensions import deprecated
|
17
19
|
|
18
20
|
from unique_toolkit.language_model.utils import format_message
|
19
21
|
|
@@ -163,6 +165,14 @@ class LanguageModelMessages(RootModel):
|
|
163
165
|
def __getitem__(self, item):
|
164
166
|
return self.root[item]
|
165
167
|
|
168
|
+
def builder(self):
|
169
|
+
"""Returns a MessagesBuilder instance pre-populated with existing messages."""
|
170
|
+
from unique_toolkit.language_model.builder import MessagesBuilder
|
171
|
+
|
172
|
+
builder = MessagesBuilder()
|
173
|
+
builder.messages = self.root.copy() # Start with existing messages
|
174
|
+
return builder
|
175
|
+
|
166
176
|
|
167
177
|
class LanguageModelCompletionChoice(BaseModel):
|
168
178
|
model_config = model_config
|
@@ -205,30 +215,50 @@ class LanguageModelStreamResponse(BaseModel):
|
|
205
215
|
|
206
216
|
|
207
217
|
class LanguageModelTokenLimits(BaseModel):
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
@
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
self.
|
228
|
-
self.
|
229
|
-
|
230
|
-
|
231
|
-
|
218
|
+
token_limit_input: int
|
219
|
+
token_limit_output: int
|
220
|
+
|
221
|
+
_fraction_adaptable = PrivateAttr(default=False)
|
222
|
+
|
223
|
+
@property
|
224
|
+
@deprecated("""
|
225
|
+
Deprecated: Use the more specific `token_limit_input` and `token_limit_output` instead.
|
226
|
+
""")
|
227
|
+
def token_limit(self):
|
228
|
+
return self.token_limit_input + self.token_limit_output
|
229
|
+
|
230
|
+
@token_limit.setter
|
231
|
+
@deprecated("""
|
232
|
+
Deprecated: Token limit can only be reduced
|
233
|
+
""")
|
234
|
+
def token_limit(self, token_limit, fraction_input=0.4):
|
235
|
+
if self.token_limit > token_limit:
|
236
|
+
self.token_limit_input = math.floor(fraction_input * token_limit)
|
237
|
+
self.token_limit_output = math.floor((1 - fraction_input) * token_limit)
|
238
|
+
self._fraction_adaptable = True
|
239
|
+
|
240
|
+
def adapt_fraction(self, fraction_input: float):
|
241
|
+
if self._fraction_adaptable:
|
242
|
+
token_limit = self.token_limit_input + self.token_limit_output
|
243
|
+
self.token_limit_input = math.floor(fraction_input * token_limit)
|
244
|
+
self.token_limit_output = math.floor((1 - fraction_input) * token_limit)
|
245
|
+
|
246
|
+
@model_validator(mode="before")
|
247
|
+
def check_required_fields(cls, data):
|
248
|
+
if isinstance(data, dict):
|
249
|
+
if {"token_limit_input", "token_limit_output"}.issubset(data.keys()):
|
250
|
+
return data
|
251
|
+
|
252
|
+
if {"token_limit"}.issubset(data.keys()):
|
253
|
+
token_limit = data.get("token_limit")
|
254
|
+
fraction_input = data.get("fraction_input", 0.4)
|
255
|
+
|
256
|
+
data["token_limit_input"] = math.floor(fraction_input * token_limit)
|
257
|
+
data["token_limit_output"] = math.floor(
|
258
|
+
(1 - fraction_input) * token_limit
|
259
|
+
)
|
260
|
+
data["_fraction_adaptpable"] = True
|
261
|
+
return data
|
232
262
|
|
233
263
|
raise ValueError(
|
234
264
|
'Either "token_limit_input" and "token_limit_output" must be provided together, or "token_limit" must be provided.'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.6.
|
3
|
+
Version: 0.6.4
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
@@ -111,6 +111,19 @@ All notable changes to this project will be documented in this file.
|
|
111
111
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
112
112
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
113
113
|
|
114
|
+
|
115
|
+
## [0.6.3] - 2025-02-27
|
116
|
+
- Simplified imports for services. `from unique_toolkit.language_model import LanguageModelService` -> `from unique_toolkit import LanguageModelService` to reduce number of import lines.
|
117
|
+
|
118
|
+
## [0.6.3] - 2025-02-26
|
119
|
+
- Add `builder` method to `LanguageModelMessages` class
|
120
|
+
|
121
|
+
## [0.6.2] - 2025-02-25
|
122
|
+
- Deprecate `LanguageModel` in favor of `LanguageModelInfo`
|
123
|
+
- `LanguageModelTokenLimits` properties become mandatory, initialization allows
|
124
|
+
- init with `token_limit` and `fraction_input` or `input_token_limit` and `output_token_limit`
|
125
|
+
- only `input_token_limit` and `output_token_limit` are members of model
|
126
|
+
|
114
127
|
## [0.6.1] - 2025-02-25
|
115
128
|
- [BREAKING] `LanguageModelService.stream_complete` and `LanguageModelService.stream_complete_async` are now moved to `ChatService.stream_complete` and `ChatService.stream_complete_async`. Correspondingly `assistant_message_id` and `user_message_id` are removed from `LanguageModelService`.
|
116
129
|
- Add `create_user_message` and `create_user_message_async` to `ChatService` (similar to `create_assistant_message` and `create_assistant_message_async`)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
unique_toolkit/__init__.py,sha256=
|
1
|
+
unique_toolkit/__init__.py,sha256=waK7W0EK3v2RJ26hawccwVz1i3yHGvHIIu5qgGjEGHQ,583
|
2
2
|
unique_toolkit/_common/_base_service.py,sha256=S8H0rAebx7GsOldA7xInLp3aQJt9yEPDQdsGSFRJsGg,276
|
3
3
|
unique_toolkit/_common/_time_utils.py,sha256=ztmTovTvr-3w71Ns2VwXC65OKUUh-sQlzbHdKTQWm-w,135
|
4
4
|
unique_toolkit/_common/exception.py,sha256=caQIE1btsQnpKCHqL2cgWUSbHup06enQu_Pt7uGUTTE,727
|
@@ -31,9 +31,9 @@ unique_toolkit/embedding/schemas.py,sha256=1GvKCaSk4jixzVQ2PKq8yDqwGEVY_hWclYtoA
|
|
31
31
|
unique_toolkit/embedding/service.py,sha256=sCMKeFjwNrWYQic1UUW2c1jnhjRQLcDYfsBgxmR70sY,2697
|
32
32
|
unique_toolkit/embedding/utils.py,sha256=v86lo__bCJbxZBQ3OcLu5SuwT6NbFfWlcq8iyk6BuzQ,279
|
33
33
|
unique_toolkit/evaluators/__init__.py,sha256=3Rfpnowm7MUXHWmeU4UV4s_3Hk-sw3V20oBwQCYlejQ,50
|
34
|
-
unique_toolkit/evaluators/config.py,sha256=
|
34
|
+
unique_toolkit/evaluators/config.py,sha256=iYiBi7M6u5MG9nVgpxl9dKfoS4j72stA6Hl-MQHmYp8,1056
|
35
35
|
unique_toolkit/evaluators/constants.py,sha256=1oI93jsh0R_TjX_8OenliiiywVe3vTooSnaMqtq6R18,27
|
36
|
-
unique_toolkit/evaluators/context_relevancy/constants.py,sha256=
|
36
|
+
unique_toolkit/evaluators/context_relevancy/constants.py,sha256=9mAGc23e5XjTYOBfeuZVbaqOyYrvRoXYjfUnsBOVShU,1126
|
37
37
|
unique_toolkit/evaluators/context_relevancy/prompts.py,sha256=gTlWP7fDuxhrXhCYNCqXMbCey_DalZMdi5l-a6RHgk0,713
|
38
38
|
unique_toolkit/evaluators/context_relevancy/service.py,sha256=9hzdMuF4A4T97-3X3zcXgrDISLn1bleZ6tTL1bHa9dQ,1722
|
39
39
|
unique_toolkit/evaluators/context_relevancy/utils.py,sha256=E9ljdRNbwYlx04fQDLvgF4SwxvlTJT0vE328PlUF6KA,5191
|
@@ -45,12 +45,12 @@ unique_toolkit/evaluators/hallucination/utils.py,sha256=4KTJH8low_fBzOcuVlcHB2FR
|
|
45
45
|
unique_toolkit/evaluators/output_parser.py,sha256=eI72qkzK1dZyUvnfP2SOAQCGBj_-PwX5wy_aLPMsJMY,883
|
46
46
|
unique_toolkit/evaluators/schemas.py,sha256=Jaue6Uhx75X1CyHKWj8sT3RE1JZXTqoLtfLt2xQNCX8,2507
|
47
47
|
unique_toolkit/language_model/__init__.py,sha256=jWko_vQj48wjnpTtlkg8iNdef0SMI3FN2kGywXRTMzg,1880
|
48
|
-
unique_toolkit/language_model/builder.py,sha256=
|
48
|
+
unique_toolkit/language_model/builder.py,sha256=qP1SlUnYJHLqT-fpXs4lgUixnekhx8IIfuoXnMHvRKE,2408
|
49
49
|
unique_toolkit/language_model/constants.py,sha256=B-topqW0r83dkC_25DeQfnPk3n53qzIHUCBS7YJ0-1U,119
|
50
50
|
unique_toolkit/language_model/functions.py,sha256=I5jHhHsKoq7GwEQyTrM8LXB2n_6dvMAk7UklenjuHSY,7945
|
51
|
-
unique_toolkit/language_model/infos.py,sha256
|
51
|
+
unique_toolkit/language_model/infos.py,sha256=-axWHj55mp6tZfX_3i-FSkfh8e9fwORXWMfi9xQ_UjA,12232
|
52
52
|
unique_toolkit/language_model/prompt.py,sha256=JSawaLjQg3VR-E2fK8engFyJnNdk21zaO8pPIodzN4Q,3991
|
53
|
-
unique_toolkit/language_model/schemas.py,sha256=
|
53
|
+
unique_toolkit/language_model/schemas.py,sha256=rrwzUgKANFOrdehCULW8Hh03uRW3tsE5dXpWqxmClfg,8618
|
54
54
|
unique_toolkit/language_model/service.py,sha256=GupYD4uDZjy1TfVQW3jichmgQwiSgQCj350FtL4O0W4,5569
|
55
55
|
unique_toolkit/language_model/utils.py,sha256=bPQ4l6_YO71w-zaIPanUUmtbXC1_hCvLK0tAFc3VCRc,1902
|
56
56
|
unique_toolkit/short_term_memory/__init__.py,sha256=2mI3AUrffgH7Yt-xS57EGqnHf7jnn6xquoKEhJqk3Wg,185
|
@@ -58,7 +58,7 @@ unique_toolkit/short_term_memory/constants.py,sha256=698CL6-wjup2MvU19RxSmQk3gX7
|
|
58
58
|
unique_toolkit/short_term_memory/functions.py,sha256=3WiK-xatY5nh4Dr5zlDUye1k3E6kr41RiscwtTplw5k,4484
|
59
59
|
unique_toolkit/short_term_memory/schemas.py,sha256=OhfcXyF6ACdwIXW45sKzjtZX_gkcJs8FEZXcgQTNenw,1406
|
60
60
|
unique_toolkit/short_term_memory/service.py,sha256=gdsVzoNqTXmLoBR_-p_lJlZDBo8L7Cr5EKchTNVJg1Q,5233
|
61
|
-
unique_toolkit-0.6.
|
62
|
-
unique_toolkit-0.6.
|
63
|
-
unique_toolkit-0.6.
|
64
|
-
unique_toolkit-0.6.
|
61
|
+
unique_toolkit-0.6.4.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
62
|
+
unique_toolkit-0.6.4.dist-info/METADATA,sha256=dSeB-ilRjS8PXAPrssjGar0aCsxTqBqqju2hPiDCYNw,19703
|
63
|
+
unique_toolkit-0.6.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
64
|
+
unique_toolkit-0.6.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|