unique_toolkit 0.5.26__py3-none-any.whl → 0.5.30__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/content/service.py +7 -0
- unique_toolkit/language_model/infos.py +50 -0
- unique_toolkit/language_model/schemas.py +13 -2
- unique_toolkit/language_model/service.py +4 -4
- {unique_toolkit-0.5.26.dist-info → unique_toolkit-0.5.30.dist-info}/METADATA +15 -1
- {unique_toolkit-0.5.26.dist-info → unique_toolkit-0.5.30.dist-info}/RECORD +8 -8
- {unique_toolkit-0.5.26.dist-info → unique_toolkit-0.5.30.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.5.26.dist-info → unique_toolkit-0.5.30.dist-info}/WHEEL +0 -0
@@ -204,6 +204,13 @@ class ContentService(BaseService):
|
|
204
204
|
|
205
205
|
return self._map_contents(contents)
|
206
206
|
|
207
|
+
def search_content_on_chat(
|
208
|
+
self,
|
209
|
+
) -> list[Content]:
|
210
|
+
where = {"ownerId": {"equals": self.event.payload.chat_id}}
|
211
|
+
|
212
|
+
return self.search_contents(where)
|
213
|
+
|
207
214
|
@staticmethod
|
208
215
|
def _map_content_chunk(content_chunk: dict):
|
209
216
|
return ContentChunk(
|
@@ -20,6 +20,35 @@ class LanguageModelName(StrEnum):
|
|
20
20
|
AZURE_GPT_4o_MINI_2024_0718 = "AZURE_GPT_4o_MINI_2024_0718"
|
21
21
|
|
22
22
|
|
23
|
+
class EncoderName(StrEnum):
|
24
|
+
O200K_BASE = "o200k_base"
|
25
|
+
CL100K_BASE = "cl100k_base"
|
26
|
+
|
27
|
+
|
28
|
+
def get_encoder_name(model_name: LanguageModelName) -> Optional[EncoderName]:
|
29
|
+
LMN = LanguageModelName
|
30
|
+
match model_name:
|
31
|
+
case (
|
32
|
+
LMN.AZURE_GPT_35_TURBO
|
33
|
+
| LMN.AZURE_GPT_35_TURBO_16K
|
34
|
+
| LMN.AZURE_GPT_35_TURBO_0613
|
35
|
+
):
|
36
|
+
return EncoderName.CL100K_BASE
|
37
|
+
case (
|
38
|
+
LMN.AZURE_GPT_4_0613
|
39
|
+
| LMN.AZURE_GPT_4_TURBO_1106
|
40
|
+
| LMN.AZURE_GPT_4_VISION_PREVIEW
|
41
|
+
| LMN.AZURE_GPT_4_32K_0613
|
42
|
+
| LMN.AZURE_GPT_4_TURBO_2024_0409
|
43
|
+
):
|
44
|
+
return EncoderName.CL100K_BASE
|
45
|
+
case LMN.AZURE_GPT_4o_2024_0513 | LMN.AZURE_GPT_4o_MINI_2024_0718:
|
46
|
+
return EncoderName.O200K_BASE
|
47
|
+
case _:
|
48
|
+
print(f"{model_name} is not supported. Please add encoder information.")
|
49
|
+
return None
|
50
|
+
|
51
|
+
|
23
52
|
class LanguageModelProvider(StrEnum):
|
24
53
|
AZURE = "AZURE"
|
25
54
|
CUSTOM = "CUSTOM"
|
@@ -30,6 +59,7 @@ class LanguageModelInfo(BaseModel):
|
|
30
59
|
version: str
|
31
60
|
provider: LanguageModelProvider
|
32
61
|
|
62
|
+
encoder_name: Optional[EncoderName] = None
|
33
63
|
token_limits: Optional[LanguageModelTokenLimits] = None
|
34
64
|
|
35
65
|
info_cutoff_at: Optional[date] = None
|
@@ -53,6 +83,7 @@ class LanguageModel:
|
|
53
83
|
- name
|
54
84
|
- version
|
55
85
|
- provider
|
86
|
+
- encoder_name
|
56
87
|
- token_limits
|
57
88
|
- info_cutoff_at
|
58
89
|
- published_at
|
@@ -86,6 +117,13 @@ class LanguageModel:
|
|
86
117
|
"""
|
87
118
|
return self._model_info.version
|
88
119
|
|
120
|
+
@property
|
121
|
+
def encoder_name(self) -> Optional[EncoderName]:
|
122
|
+
"""
|
123
|
+
Returns the encoder_name used for the model.
|
124
|
+
"""
|
125
|
+
return self._model_info.encoder_name
|
126
|
+
|
89
127
|
@property
|
90
128
|
def token_limit(self) -> Optional[int]:
|
91
129
|
"""
|
@@ -191,6 +229,7 @@ def create_language_model(
|
|
191
229
|
provider: LanguageModelProvider,
|
192
230
|
info_cutoff_at: date,
|
193
231
|
published_at: date,
|
232
|
+
encoder_name: Optional[EncoderName] = None,
|
194
233
|
token_limit: Optional[int] = None,
|
195
234
|
token_limit_input: Optional[int] = None,
|
196
235
|
token_limit_output: Optional[int] = None,
|
@@ -202,6 +241,7 @@ def create_language_model(
|
|
202
241
|
name=name,
|
203
242
|
version=version,
|
204
243
|
provider=provider,
|
244
|
+
encoder_name=encoder_name,
|
205
245
|
token_limits=LanguageModelTokenLimits(
|
206
246
|
token_limit=token_limit,
|
207
247
|
token_limit_input=token_limit_input,
|
@@ -229,6 +269,7 @@ AzureGpt35Turbo0613 = create_language_model(
|
|
229
269
|
name=LanguageModelName.AZURE_GPT_35_TURBO_0613,
|
230
270
|
provider=LanguageModelProvider.AZURE,
|
231
271
|
version="0613",
|
272
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO_0613),
|
232
273
|
token_limit=8192,
|
233
274
|
info_cutoff_at=date(2021, 9, 1),
|
234
275
|
published_at=date(2023, 6, 13),
|
@@ -239,6 +280,7 @@ AzureGpt35Turbo = create_language_model(
|
|
239
280
|
name=LanguageModelName.AZURE_GPT_35_TURBO,
|
240
281
|
provider=LanguageModelProvider.AZURE,
|
241
282
|
version="0301",
|
283
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO),
|
242
284
|
token_limit=4096,
|
243
285
|
info_cutoff_at=date(2021, 9, 1),
|
244
286
|
published_at=date(2023, 3, 1),
|
@@ -249,6 +291,7 @@ AzureGpt35Turbo16k = create_language_model(
|
|
249
291
|
name=LanguageModelName.AZURE_GPT_35_TURBO_16K,
|
250
292
|
provider=LanguageModelProvider.AZURE,
|
251
293
|
version="0613",
|
294
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_35_TURBO_16K),
|
252
295
|
token_limit=16382,
|
253
296
|
info_cutoff_at=date(2021, 9, 1),
|
254
297
|
published_at=date(2023, 6, 13),
|
@@ -260,6 +303,7 @@ AzureGpt40613 = create_language_model(
|
|
260
303
|
name=LanguageModelName.AZURE_GPT_4_0613,
|
261
304
|
provider=LanguageModelProvider.AZURE,
|
262
305
|
version="0613",
|
306
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_0613),
|
263
307
|
token_limit=8192,
|
264
308
|
info_cutoff_at=date(2021, 9, 1),
|
265
309
|
published_at=date(2023, 6, 13),
|
@@ -272,6 +316,7 @@ AzureGpt4Turbo1106 = create_language_model(
|
|
272
316
|
name=LanguageModelName.AZURE_GPT_4_TURBO_1106,
|
273
317
|
provider=LanguageModelProvider.AZURE,
|
274
318
|
version="1106-preview",
|
319
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_TURBO_1106),
|
275
320
|
token_limit_input=128000,
|
276
321
|
token_limit_output=4096,
|
277
322
|
info_cutoff_at=date(2023, 4, 1),
|
@@ -283,6 +328,7 @@ AzureGpt4VisionPreview = create_language_model(
|
|
283
328
|
name=LanguageModelName.AZURE_GPT_4_VISION_PREVIEW,
|
284
329
|
provider=LanguageModelProvider.AZURE,
|
285
330
|
version="vision-preview",
|
331
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_VISION_PREVIEW),
|
286
332
|
token_limit_input=128000,
|
287
333
|
token_limit_output=4096,
|
288
334
|
info_cutoff_at=date(2023, 4, 1),
|
@@ -293,6 +339,7 @@ AzureGpt432k0613 = create_language_model(
|
|
293
339
|
name=LanguageModelName.AZURE_GPT_4_32K_0613,
|
294
340
|
provider=LanguageModelProvider.AZURE,
|
295
341
|
version="1106-preview",
|
342
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_32K_0613),
|
296
343
|
token_limit=32768,
|
297
344
|
info_cutoff_at=date(2021, 9, 1),
|
298
345
|
published_at=date(2023, 6, 13),
|
@@ -302,6 +349,7 @@ AzureGpt432k0613 = create_language_model(
|
|
302
349
|
|
303
350
|
AzureGpt4Turbo20240409 = create_language_model(
|
304
351
|
name=LanguageModelName.AZURE_GPT_4_TURBO_2024_0409,
|
352
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4_TURBO_2024_0409),
|
305
353
|
provider=LanguageModelProvider.AZURE,
|
306
354
|
version="turbo-2024-04-09",
|
307
355
|
token_limit_input=128000,
|
@@ -312,6 +360,7 @@ AzureGpt4Turbo20240409 = create_language_model(
|
|
312
360
|
|
313
361
|
AzureGpt4o20240513 = create_language_model(
|
314
362
|
name=LanguageModelName.AZURE_GPT_4o_2024_0513,
|
363
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4o_2024_0513),
|
315
364
|
provider=LanguageModelProvider.AZURE,
|
316
365
|
version="2024-05-13",
|
317
366
|
token_limit_input=128000,
|
@@ -324,6 +373,7 @@ AzureGpt4oMini20240718 = create_language_model(
|
|
324
373
|
name=LanguageModelName.AZURE_GPT_4o_MINI_2024_0718,
|
325
374
|
provider=LanguageModelProvider.AZURE,
|
326
375
|
version="2024-07-18",
|
376
|
+
encoder_name=get_encoder_name(LanguageModelName.AZURE_GPT_4o_MINI_2024_0718),
|
327
377
|
token_limit_input=128000,
|
328
378
|
token_limit_output=16384,
|
329
379
|
info_cutoff_at=date(2023, 10, 1),
|
@@ -3,7 +3,14 @@ from enum import StrEnum
|
|
3
3
|
from typing import Any, Optional, Self
|
4
4
|
|
5
5
|
from humps import camelize
|
6
|
-
from pydantic import
|
6
|
+
from pydantic import (
|
7
|
+
BaseModel,
|
8
|
+
ConfigDict,
|
9
|
+
Field,
|
10
|
+
RootModel,
|
11
|
+
field_validator,
|
12
|
+
model_validator,
|
13
|
+
)
|
7
14
|
|
8
15
|
# set config to convert camelCase to snake_case
|
9
16
|
model_config = ConfigDict(
|
@@ -173,7 +180,11 @@ class LanguageModelToolParameters(BaseModel):
|
|
173
180
|
|
174
181
|
|
175
182
|
class LanguageModelTool(BaseModel):
|
176
|
-
name: str
|
183
|
+
name: str = Field(
|
184
|
+
...,
|
185
|
+
pattern=r"^[a-zA-Z1-9_-]+$",
|
186
|
+
description="Name must adhere to the pattern ^[a-zA-Z_-]+$",
|
187
|
+
)
|
177
188
|
description: str
|
178
189
|
parameters: LanguageModelToolParameters
|
179
190
|
returns: LanguageModelToolParameterProperty | LanguageModelToolParameters | None = (
|
@@ -52,6 +52,7 @@ class LanguageModelService(BaseService):
|
|
52
52
|
LanguageModelResponse: The LanguageModelResponse object.
|
53
53
|
"""
|
54
54
|
options = self._add_tools_to_options({}, tools)
|
55
|
+
options["temperature"] = temperature
|
55
56
|
messages = messages.model_dump(exclude_none=True)
|
56
57
|
model = (
|
57
58
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
@@ -67,7 +68,6 @@ class LanguageModelService(BaseService):
|
|
67
68
|
messages,
|
68
69
|
),
|
69
70
|
timeout=timeout,
|
70
|
-
temperature=temperature,
|
71
71
|
options=options, # type: ignore
|
72
72
|
)
|
73
73
|
return LanguageModelResponse(**response)
|
@@ -109,6 +109,7 @@ class LanguageModelService(BaseService):
|
|
109
109
|
Exception: If an error occurs during the request, an exception is raised and logged.
|
110
110
|
"""
|
111
111
|
options = cls._add_tools_to_options({}, tools)
|
112
|
+
options["temperature"] = temperature
|
112
113
|
messages = messages.model_dump(exclude_none=True, exclude={"tool_calls"})
|
113
114
|
model = (
|
114
115
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
@@ -122,7 +123,6 @@ class LanguageModelService(BaseService):
|
|
122
123
|
messages,
|
123
124
|
),
|
124
125
|
timeout=timeout,
|
125
|
-
temperature=temperature,
|
126
126
|
options=options, # type: ignore
|
127
127
|
)
|
128
128
|
return LanguageModelResponse(**response)
|
@@ -196,6 +196,7 @@ class LanguageModelService(BaseService):
|
|
196
196
|
The LanguageModelStreamResponse object once the stream has finished.
|
197
197
|
"""
|
198
198
|
options = self._add_tools_to_options({}, tools)
|
199
|
+
options["temperature"] = temperature
|
199
200
|
search_context = self._to_search_context(content_chunks)
|
200
201
|
messages = messages.model_dump(exclude_none=True)
|
201
202
|
model = (
|
@@ -217,7 +218,6 @@ class LanguageModelService(BaseService):
|
|
217
218
|
# TODO change or extend types in unique_sdk
|
218
219
|
model=model,
|
219
220
|
timeout=timeout,
|
220
|
-
temperature=temperature,
|
221
221
|
assistantId=self.event.payload.assistant_id,
|
222
222
|
debugInfo=debug_info,
|
223
223
|
options=options, # type: ignore
|
@@ -257,6 +257,7 @@ class LanguageModelService(BaseService):
|
|
257
257
|
"""
|
258
258
|
|
259
259
|
options = self._add_tools_to_options({}, tools)
|
260
|
+
options["temperature"] = temperature
|
260
261
|
search_context = self._to_search_context(content_chunks)
|
261
262
|
messages = messages.model_dump(exclude_none=True, exclude=["tool_calls"])
|
262
263
|
model = (
|
@@ -277,7 +278,6 @@ class LanguageModelService(BaseService):
|
|
277
278
|
searchContext=search_context,
|
278
279
|
model=model,
|
279
280
|
timeout=timeout,
|
280
|
-
temperature=temperature,
|
281
281
|
assistantId=self.event.payload.assistant_id,
|
282
282
|
debugInfo=debug_info,
|
283
283
|
# TODO change or extend types in unique_sdk
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.30
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
@@ -100,6 +100,20 @@ All notable changes to this project will be documented in this file.
|
|
100
100
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
101
101
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
102
102
|
|
103
|
+
## [0.5.30] - 2024-10-28
|
104
|
+
- Correctly use `temperature` parameter in `LanguageModelService.complete` and `LanguageModelService.complete_async` methods
|
105
|
+
|
106
|
+
## [0.5.29] - 2024-10-28
|
107
|
+
- Allow numbers in `LanguageModelTool` name
|
108
|
+
|
109
|
+
## [0.5.28] - 2024-10-23
|
110
|
+
- Correctly use `temperature` parameter in `LanguageModelService.stream_complete` and `LanguageModelService.stream_complete_async` methods
|
111
|
+
|
112
|
+
## [0.5.27] - 2024-10-22
|
113
|
+
- Add encoder_name to to language model info
|
114
|
+
- Verify tool name for `LanguageModelTool` to conform with frontent requirements.
|
115
|
+
- Add `search_on_chat` to `ContentService`
|
116
|
+
|
103
117
|
## [0.5.26] - 2024-10-16
|
104
118
|
- Bump `unique_sdk` version
|
105
119
|
|
@@ -17,7 +17,7 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
|
|
17
17
|
unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
|
18
18
|
unique_toolkit/content/__init__.py,sha256=MSH2sxjQyKD2Sef92fzE5Dt9SihdzivB6yliSwJfTmQ,890
|
19
19
|
unique_toolkit/content/schemas.py,sha256=zks_Pkki2VhxICJJgHZyc-LPmRuj5dLbw3pgcUT7SW8,2362
|
20
|
-
unique_toolkit/content/service.py,sha256=
|
20
|
+
unique_toolkit/content/service.py,sha256=ZGYWYTphXpcByXyMqr1VOVUHdmdnsR-XIS_YRX0Wyv4,14211
|
21
21
|
unique_toolkit/content/utils.py,sha256=Lake671plRsqNvO3pN_rmyVcpwbdED_KQpLcCnc4lv4,6902
|
22
22
|
unique_toolkit/embedding/__init__.py,sha256=dr8M9jvslQTxPpxgaGwzxY0FildiWf-DidN_cahPAWw,191
|
23
23
|
unique_toolkit/embedding/schemas.py,sha256=1GvKCaSk4jixzVQ2PKq8yDqwGEVY_hWclYtoAr6CC2g,96
|
@@ -36,11 +36,11 @@ unique_toolkit/evaluators/hallucination/utils.py,sha256=507BsX1mFTEne1-LdRCNMgBj
|
|
36
36
|
unique_toolkit/evaluators/output_parser.py,sha256=eI72qkzK1dZyUvnfP2SOAQCGBj_-PwX5wy_aLPMsJMY,883
|
37
37
|
unique_toolkit/evaluators/schemas.py,sha256=Jaue6Uhx75X1CyHKWj8sT3RE1JZXTqoLtfLt2xQNCX8,2507
|
38
38
|
unique_toolkit/language_model/__init__.py,sha256=YuhyczGPj6w9xX-sOVUhmozvzIFxcckHFEkeMBecr5s,1784
|
39
|
-
unique_toolkit/language_model/infos.py,sha256=
|
40
|
-
unique_toolkit/language_model/schemas.py,sha256=
|
41
|
-
unique_toolkit/language_model/service.py,sha256=
|
39
|
+
unique_toolkit/language_model/infos.py,sha256=Oxkr9_6s8gFubxjox-iCm1GSs1RCAQQ5t8oh20izlC0,12002
|
40
|
+
unique_toolkit/language_model/schemas.py,sha256=LYWsZcGEPNK9T-fTHC4V0VbtCTNd1Q16UVf1b6WQzrU,5038
|
41
|
+
unique_toolkit/language_model/service.py,sha256=dtC4I5iDDAJXsOwd_b2COj8tkKIp9LPaxTpGkuV2o3I,13411
|
42
42
|
unique_toolkit/language_model/utils.py,sha256=WBPj1XKkDgxy_-T8HCZvsfkkSzj_1w4UZzNmyvdbBLY,1081
|
43
|
-
unique_toolkit-0.5.
|
44
|
-
unique_toolkit-0.5.
|
45
|
-
unique_toolkit-0.5.
|
46
|
-
unique_toolkit-0.5.
|
43
|
+
unique_toolkit-0.5.30.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
44
|
+
unique_toolkit-0.5.30.dist-info/METADATA,sha256=Vd_xIuIoQ_lnZNQJUoPUT3XQ32zXeGuAtC7FJdZQXxQ,12670
|
45
|
+
unique_toolkit-0.5.30.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
46
|
+
unique_toolkit-0.5.30.dist-info/RECORD,,
|
File without changes
|
File without changes
|