unique_toolkit 0.5.14__py3-none-any.whl → 0.5.16__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 +74 -77
- {unique_toolkit-0.5.14.dist-info → unique_toolkit-0.5.16.dist-info}/METADATA +7 -1
- {unique_toolkit-0.5.14.dist-info → unique_toolkit-0.5.16.dist-info}/RECORD +5 -5
- {unique_toolkit-0.5.14.dist-info → unique_toolkit-0.5.16.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.5.14.dist-info → unique_toolkit-0.5.16.dist-info}/WHEEL +0 -0
@@ -2,7 +2,7 @@ import logging
|
|
2
2
|
import os
|
3
3
|
import tempfile
|
4
4
|
from pathlib import Path
|
5
|
-
from typing import Optional, cast
|
5
|
+
from typing import Optional, Union, cast
|
6
6
|
|
7
7
|
import requests
|
8
8
|
import unique_sdk
|
@@ -14,7 +14,6 @@ from unique_toolkit.content.schemas import (
|
|
14
14
|
ContentChunk,
|
15
15
|
ContentRerankerConfig,
|
16
16
|
ContentSearchType,
|
17
|
-
ContentUploadInput,
|
18
17
|
)
|
19
18
|
|
20
19
|
|
@@ -69,9 +68,11 @@ class ContentService(BaseService):
|
|
69
68
|
searchType=search_type.name,
|
70
69
|
scopeIds=scope_ids,
|
71
70
|
limit=limit,
|
72
|
-
reranker=
|
73
|
-
|
74
|
-
|
71
|
+
reranker=(
|
72
|
+
reranker_config.model_dump(by_alias=True)
|
73
|
+
if reranker_config
|
74
|
+
else None
|
75
|
+
),
|
75
76
|
language=search_language,
|
76
77
|
chatOnly=chat_only,
|
77
78
|
)
|
@@ -123,9 +124,11 @@ class ContentService(BaseService):
|
|
123
124
|
searchType=search_type.name,
|
124
125
|
scopeIds=scope_ids,
|
125
126
|
limit=limit,
|
126
|
-
reranker=
|
127
|
-
|
128
|
-
|
127
|
+
reranker=(
|
128
|
+
reranker_config.model_dump(by_alias=True)
|
129
|
+
if reranker_config
|
130
|
+
else None
|
131
|
+
),
|
129
132
|
language=search_language,
|
130
133
|
chatOnly=chat_only,
|
131
134
|
)
|
@@ -241,16 +244,43 @@ class ContentService(BaseService):
|
|
241
244
|
Content: The uploaded content.
|
242
245
|
"""
|
243
246
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
247
|
+
try:
|
248
|
+
return self._trigger_upload_content(
|
249
|
+
path_to_content=path_to_content,
|
250
|
+
content_name=content_name,
|
251
|
+
mime_type=mime_type,
|
252
|
+
scope_id=scope_id,
|
253
|
+
chat_id=chat_id,
|
254
|
+
)
|
255
|
+
except Exception as e:
|
256
|
+
self.logger.error(f"Error while uploading content: {e}")
|
257
|
+
raise e
|
252
258
|
|
253
|
-
|
259
|
+
def _trigger_upload_content(
|
260
|
+
self,
|
261
|
+
path_to_content: str,
|
262
|
+
content_name: str,
|
263
|
+
mime_type: str,
|
264
|
+
scope_id: Optional[str] = None,
|
265
|
+
chat_id: Optional[str] = None,
|
266
|
+
):
|
267
|
+
if not chat_id and not scope_id:
|
268
|
+
raise ValueError("chat_id or scope_id must be provided")
|
269
|
+
|
270
|
+
byte_size = os.path.getsize(path_to_content)
|
271
|
+
created_content = unique_sdk.Content.upsert(
|
272
|
+
user_id=self.event.user_id,
|
273
|
+
company_id=self.event.company_id,
|
274
|
+
input={
|
275
|
+
"key": content_name,
|
276
|
+
"title": content_name,
|
277
|
+
"mimeType": mime_type,
|
278
|
+
},
|
279
|
+
scopeId=scope_id,
|
280
|
+
chatId=chat_id,
|
281
|
+
) # type: ignore
|
282
|
+
|
283
|
+
write_url = created_content["writeUrl"]
|
254
284
|
|
255
285
|
if not write_url:
|
256
286
|
error_msg = "Write url for uploaded content is missing"
|
@@ -268,7 +298,7 @@ class ContentService(BaseService):
|
|
268
298
|
},
|
269
299
|
)
|
270
300
|
|
271
|
-
read_url = created_content
|
301
|
+
read_url = created_content["readUrl"]
|
272
302
|
|
273
303
|
if not read_url:
|
274
304
|
error_msg = "Read url for uploaded content is missing"
|
@@ -276,74 +306,40 @@ class ContentService(BaseService):
|
|
276
306
|
raise ValueError(error_msg)
|
277
307
|
|
278
308
|
if chat_id:
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
309
|
+
unique_sdk.Content.upsert(
|
310
|
+
user_id=self.event.user_id,
|
311
|
+
company_id=self.event.company_id,
|
312
|
+
input={
|
313
|
+
"key": content_name,
|
314
|
+
"title": content_name,
|
315
|
+
"mimeType": mime_type,
|
316
|
+
"byteSize": byte_size,
|
317
|
+
},
|
318
|
+
fileUrl=read_url,
|
319
|
+
chatId=chat_id,
|
320
|
+
) # type: ignore
|
289
321
|
else:
|
290
|
-
|
291
|
-
input=ContentUploadInput(
|
292
|
-
key=content_name,
|
293
|
-
title=content_name,
|
294
|
-
mime_type=mime_type,
|
295
|
-
byte_size=byte_size,
|
296
|
-
),
|
297
|
-
content_url=read_url,
|
298
|
-
scope_id=scope_id,
|
299
|
-
)
|
300
|
-
|
301
|
-
return created_content
|
302
|
-
|
303
|
-
def _trigger_upsert_content(
|
304
|
-
self,
|
305
|
-
input: ContentUploadInput,
|
306
|
-
scope_id: Optional[str] = None,
|
307
|
-
chat_id: Optional[str] = None,
|
308
|
-
content_url: Optional[str] = None,
|
309
|
-
):
|
310
|
-
if not chat_id and not scope_id:
|
311
|
-
raise ValueError("chat_id or scope_id must be provided")
|
312
|
-
|
313
|
-
try:
|
314
|
-
if input.byte_size:
|
315
|
-
input_json = {
|
316
|
-
"key": input.key,
|
317
|
-
"title": input.title,
|
318
|
-
"mimeType": input.mime_type,
|
319
|
-
"byteSize": input.byte_size,
|
320
|
-
}
|
321
|
-
else:
|
322
|
-
input_json = {
|
323
|
-
"key": input.key,
|
324
|
-
"title": input.title,
|
325
|
-
"mimeType": input.mime_type,
|
326
|
-
}
|
327
|
-
content = unique_sdk.Content.upsert(
|
322
|
+
unique_sdk.Content.upsert(
|
328
323
|
user_id=self.event.user_id,
|
329
324
|
company_id=self.event.company_id,
|
330
|
-
input=
|
331
|
-
|
325
|
+
input={
|
326
|
+
"key": content_name,
|
327
|
+
"title": content_name,
|
328
|
+
"mimeType": mime_type,
|
329
|
+
"byteSize": byte_size,
|
330
|
+
},
|
331
|
+
fileUrl=read_url,
|
332
332
|
scopeId=scope_id,
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
)
|
337
|
-
return Content(**content)
|
338
|
-
except Exception as e:
|
339
|
-
self.logger.error(f"Error while uploading content: {e}")
|
340
|
-
raise e
|
333
|
+
) # type: ignore
|
334
|
+
|
335
|
+
return Content(**created_content)
|
341
336
|
|
342
337
|
def download_content(
|
343
338
|
self,
|
344
339
|
content_id: str,
|
345
340
|
content_name: str,
|
346
341
|
chat_id: Optional[str] = None,
|
342
|
+
dir_path: Optional[Union[str, Path]] = "/tmp",
|
347
343
|
) -> Path:
|
348
344
|
"""
|
349
345
|
Downloads content to temporary directory
|
@@ -352,6 +348,7 @@ class ContentService(BaseService):
|
|
352
348
|
content_id (str): The id of the uploaded content.
|
353
349
|
content_name (str): The name of the uploaded content.
|
354
350
|
chat_id (Optional[str]): The chat_id, defaults to None.
|
351
|
+
dir_path (Optional[Union[str, Path]]): The directory path to download the content to, defaults to "/tmp". If not provided, the content will be downloaded to a random directory inside /tmp. Be aware that this directory won't be cleaned up automatically.
|
355
352
|
|
356
353
|
Returns:
|
357
354
|
content_path: The path to the downloaded content in the temporary directory.
|
@@ -365,7 +362,7 @@ class ContentService(BaseService):
|
|
365
362
|
url = f"{url}?chatId={chat_id}"
|
366
363
|
|
367
364
|
# Create a random directory inside /tmp
|
368
|
-
random_dir = tempfile.mkdtemp(dir=
|
365
|
+
random_dir = tempfile.mkdtemp(dir=dir_path)
|
369
366
|
|
370
367
|
# Create the full file path
|
371
368
|
content_path = Path(random_dir) / content_name
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.16
|
4
4
|
Summary:
|
5
5
|
License: MIT
|
6
6
|
Author: Martin Fadler
|
@@ -101,6 +101,12 @@ All notable changes to this project will be documented in this file.
|
|
101
101
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
102
102
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
103
103
|
|
104
|
+
## [0.5.16] - 2024-08-27
|
105
|
+
- Fix `ContentService.upload_content` function.
|
106
|
+
|
107
|
+
## [0.5.15] - 2024-08-27
|
108
|
+
- Possibility to specify root directory in `ContentService.download_content`
|
109
|
+
|
104
110
|
## [0.5.14] - 2024-08-26
|
105
111
|
- Add AZURE_GPT_4o_MINI_2024_0718 to language model infos
|
106
112
|
|
@@ -15,7 +15,7 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
|
|
15
15
|
unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
|
16
16
|
unique_toolkit/content/__init__.py,sha256=MSH2sxjQyKD2Sef92fzE5Dt9SihdzivB6yliSwJfTmQ,890
|
17
17
|
unique_toolkit/content/schemas.py,sha256=UlC5nBIaFkq9TD31LR6ioG9JRZ1ScmtABi0l06HZR70,2231
|
18
|
-
unique_toolkit/content/service.py,sha256=
|
18
|
+
unique_toolkit/content/service.py,sha256=NoH8FNP36Jt92RRswDZAfUV0UItrsrtokcqKP__ERRc,13656
|
19
19
|
unique_toolkit/content/utils.py,sha256=Lake671plRsqNvO3pN_rmyVcpwbdED_KQpLcCnc4lv4,6902
|
20
20
|
unique_toolkit/embedding/__init__.py,sha256=dr8M9jvslQTxPpxgaGwzxY0FildiWf-DidN_cahPAWw,191
|
21
21
|
unique_toolkit/embedding/schemas.py,sha256=1GvKCaSk4jixzVQ2PKq8yDqwGEVY_hWclYtoAr6CC2g,96
|
@@ -26,7 +26,7 @@ unique_toolkit/language_model/infos.py,sha256=JkugUAFFlrhTHXeM3A_R5QLkNSR9Ro85xW
|
|
26
26
|
unique_toolkit/language_model/schemas.py,sha256=h5zjZNk7O-wLKtRuiNtMCIbp5hEVXrAOviKonQcjFuI,4594
|
27
27
|
unique_toolkit/language_model/service.py,sha256=JjsOOcGDcR7db3yF3_oDXclEGfxqmwWpL5jor7Q42cU,10470
|
28
28
|
unique_toolkit/language_model/utils.py,sha256=WBPj1XKkDgxy_-T8HCZvsfkkSzj_1w4UZzNmyvdbBLY,1081
|
29
|
-
unique_toolkit-0.5.
|
30
|
-
unique_toolkit-0.5.
|
31
|
-
unique_toolkit-0.5.
|
32
|
-
unique_toolkit-0.5.
|
29
|
+
unique_toolkit-0.5.16.dist-info/LICENSE,sha256=bIeCWCYuoUU_MzNdg48-ubJSVm7qxakaRbzTiJ5uxrs,1065
|
30
|
+
unique_toolkit-0.5.16.dist-info/METADATA,sha256=h7bIucz9PpU2PCc6BLMlAkDQO4s9aBZB_sGsc69oMlc,10301
|
31
|
+
unique_toolkit-0.5.16.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
unique_toolkit-0.5.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|