unique_toolkit 1.11.1__py3-none-any.whl → 1.11.2__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/functions.py +20 -7
- unique_toolkit/content/schemas.py +16 -3
- unique_toolkit/knowledge_base.py +81 -2
- {unique_toolkit-1.11.1.dist-info → unique_toolkit-1.11.2.dist-info}/METADATA +4 -1
- {unique_toolkit-1.11.1.dist-info → unique_toolkit-1.11.2.dist-info}/RECORD +7 -7
- {unique_toolkit-1.11.1.dist-info → unique_toolkit-1.11.2.dist-info}/LICENSE +0 -0
- {unique_toolkit-1.11.1.dist-info → unique_toolkit-1.11.2.dist-info}/WHEEL +0 -0
@@ -16,7 +16,8 @@ from unique_toolkit.content.schemas import (
|
|
16
16
|
ContentInfo,
|
17
17
|
ContentRerankerConfig,
|
18
18
|
ContentSearchType,
|
19
|
-
|
19
|
+
FolderInfo,
|
20
|
+
PaginatedContentInfos,
|
20
21
|
)
|
21
22
|
from unique_toolkit.content.utils import map_contents, map_to_content_chunks
|
22
23
|
|
@@ -590,21 +591,33 @@ def get_content_info(
|
|
590
591
|
file_path: str | None = None,
|
591
592
|
):
|
592
593
|
"""Gets the info of a content."""
|
594
|
+
|
593
595
|
get_info_params = unique_sdk.Content.ContentInfoParams(
|
594
|
-
metadataFilter=metadata_filter,
|
595
|
-
skip=skip,
|
596
|
-
take=take,
|
597
|
-
filePath=file_path,
|
596
|
+
metadataFilter=metadata_filter or None, # Dict cannot be empty
|
598
597
|
)
|
598
|
+
if skip:
|
599
|
+
get_info_params["skip"] = skip
|
600
|
+
if take:
|
601
|
+
get_info_params["take"] = take
|
602
|
+
if file_path:
|
603
|
+
get_info_params["filePath"] = file_path
|
599
604
|
|
600
|
-
content_info = unique_sdk.Content.
|
605
|
+
content_info = unique_sdk.Content.get_infos(
|
601
606
|
user_id=user_id, company_id=company_id, **get_info_params
|
602
607
|
)
|
603
|
-
return
|
608
|
+
return PaginatedContentInfos.model_validate(
|
604
609
|
content_info, by_alias=True, by_name=True
|
605
610
|
)
|
606
611
|
|
607
612
|
|
613
|
+
def get_folder_info(user_id: str, company_id: str, scope_id: str) -> FolderInfo:
|
614
|
+
info = unique_sdk.Folder.get_info(
|
615
|
+
user_id=user_id, company_id=company_id, scopeId=scope_id
|
616
|
+
)
|
617
|
+
|
618
|
+
return FolderInfo.model_validate(info, by_alias=True, by_name=True)
|
619
|
+
|
620
|
+
|
608
621
|
def update_content(
|
609
622
|
user_id: str,
|
610
623
|
company_id: str,
|
@@ -154,12 +154,13 @@ class ContentRerankerConfig(BaseModel):
|
|
154
154
|
class ContentInfo(BaseModel):
|
155
155
|
model_config = model_config
|
156
156
|
id: str
|
157
|
+
object: str
|
157
158
|
key: str
|
158
159
|
url: str | None = None
|
159
160
|
title: str | None = None
|
160
161
|
metadata: dict[str, Any] | None = None
|
161
|
-
mime_type: str
|
162
162
|
byte_size: int
|
163
|
+
mime_type: str
|
163
164
|
owner_id: str
|
164
165
|
created_at: datetime
|
165
166
|
updated_at: datetime
|
@@ -168,7 +169,19 @@ class ContentInfo(BaseModel):
|
|
168
169
|
expired_at: datetime | None = None
|
169
170
|
|
170
171
|
|
171
|
-
class
|
172
|
+
class PaginatedContentInfos(BaseModel):
|
172
173
|
model_config = model_config
|
173
|
-
|
174
|
+
object: str
|
175
|
+
content_infos: list[ContentInfo]
|
174
176
|
total_count: int
|
177
|
+
|
178
|
+
|
179
|
+
class FolderInfo(BaseModel):
|
180
|
+
model_config = model_config
|
181
|
+
id: str
|
182
|
+
name: str
|
183
|
+
ingestion_config: dict[str, Any]
|
184
|
+
createdAt: str | None
|
185
|
+
updatedAt: str | None
|
186
|
+
parentId: str | None
|
187
|
+
externalId: str | None
|
unique_toolkit/knowledge_base.py
CHANGED
@@ -14,6 +14,7 @@ from unique_toolkit.content.functions import (
|
|
14
14
|
download_content_to_bytes,
|
15
15
|
download_content_to_file_by_id,
|
16
16
|
get_content_info,
|
17
|
+
get_folder_info,
|
17
18
|
search_content_chunks,
|
18
19
|
search_content_chunks_async,
|
19
20
|
search_contents,
|
@@ -28,7 +29,8 @@ from unique_toolkit.content.schemas import (
|
|
28
29
|
ContentInfo,
|
29
30
|
ContentRerankerConfig,
|
30
31
|
ContentSearchType,
|
31
|
-
|
32
|
+
FolderInfo,
|
33
|
+
PaginatedContentInfos,
|
32
34
|
)
|
33
35
|
|
34
36
|
_LOGGER = logging.getLogger(f"toolkit.knowledge_base.{__name__}")
|
@@ -483,7 +485,7 @@ class KnowledgeBaseService:
|
|
483
485
|
skip: int | None = None,
|
484
486
|
take: int | None = None,
|
485
487
|
file_path: str | None = None,
|
486
|
-
) ->
|
488
|
+
) -> PaginatedContentInfos:
|
487
489
|
return get_content_info(
|
488
490
|
user_id=self._user_id,
|
489
491
|
company_id=self._company_id,
|
@@ -493,6 +495,17 @@ class KnowledgeBaseService:
|
|
493
495
|
file_path=file_path,
|
494
496
|
)
|
495
497
|
|
498
|
+
def get_folder_info(
|
499
|
+
self,
|
500
|
+
*,
|
501
|
+
scope_id: str,
|
502
|
+
) -> FolderInfo:
|
503
|
+
return get_folder_info(
|
504
|
+
user_id=self._user_id,
|
505
|
+
company_id=self._company_id,
|
506
|
+
scope_id=scope_id,
|
507
|
+
)
|
508
|
+
|
496
509
|
def replace_content_metadata(
|
497
510
|
self,
|
498
511
|
*,
|
@@ -506,6 +519,72 @@ class KnowledgeBaseService:
|
|
506
519
|
metadata=metadata,
|
507
520
|
)
|
508
521
|
|
522
|
+
def _resolve_visible_file_tree(self, content_infos: list[ContentInfo]) -> list[str]:
|
523
|
+
# collect all scope ids
|
524
|
+
folder_id_paths: set[str] = set()
|
525
|
+
known_folder_paths: set[str] = set()
|
526
|
+
for content_info in content_infos:
|
527
|
+
if (
|
528
|
+
content_info.metadata
|
529
|
+
and content_info.metadata.get(r"{FullPath}") is not None
|
530
|
+
):
|
531
|
+
known_folder_paths.add(str(content_info.metadata.get(r"{FullPath}")))
|
532
|
+
continue
|
533
|
+
|
534
|
+
if (
|
535
|
+
content_info.metadata
|
536
|
+
and content_info.metadata.get("folderIdPath") is not None
|
537
|
+
):
|
538
|
+
folder_id_paths.add(str(content_info.metadata.get("folderIdPath")))
|
539
|
+
|
540
|
+
scope_ids: set[str] = set()
|
541
|
+
for fp in folder_id_paths:
|
542
|
+
scope_ids_list = set(fp.replace("uniquepathid://", "").split("/"))
|
543
|
+
scope_ids.update(scope_ids_list)
|
544
|
+
|
545
|
+
scope_id_to_folder_name: dict[str, str] = {}
|
546
|
+
for scope_id in scope_ids:
|
547
|
+
folder_info = self.get_folder_info(
|
548
|
+
scope_id=scope_id,
|
549
|
+
)
|
550
|
+
scope_id_to_folder_name[scope_id] = folder_info.name
|
551
|
+
|
552
|
+
folder_paths: set[str] = set()
|
553
|
+
for folder_id_path in folder_id_paths:
|
554
|
+
scope_ids_list = folder_id_path.replace("uniquepathid://", "").split("/")
|
555
|
+
|
556
|
+
if all(scope_id in scope_id_to_folder_name for scope_id in scope_ids_list):
|
557
|
+
folder_path = [
|
558
|
+
scope_id_to_folder_name[scope_id] for scope_id in scope_ids_list
|
559
|
+
]
|
560
|
+
folder_paths.add("/".join(folder_path))
|
561
|
+
|
562
|
+
return [
|
563
|
+
p if p.startswith("/") else f"/{p}"
|
564
|
+
for p in folder_paths.union(known_folder_paths)
|
565
|
+
]
|
566
|
+
|
567
|
+
def resolve_visible_file_tree(
|
568
|
+
self, *, metadata_filter: dict[str, Any] | None = None
|
569
|
+
) -> list[str]:
|
570
|
+
"""
|
571
|
+
Resolves the visible file tree for the knowledge base for the current user.
|
572
|
+
|
573
|
+
Args:
|
574
|
+
metadata_filter (dict[str, Any] | None): The metadata filter to use. Defaults to None.
|
575
|
+
|
576
|
+
Returns:
|
577
|
+
list[str]: The visible file tree.
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
"""
|
582
|
+
info = self.get_paginated_content_infos(
|
583
|
+
metadata_filter=metadata_filter,
|
584
|
+
)
|
585
|
+
|
586
|
+
return self._resolve_visible_file_tree(content_infos=info.content_infos)
|
587
|
+
|
509
588
|
|
510
589
|
if __name__ == "__main__":
|
511
590
|
kb_service = KnowledgeBaseService.from_settings()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 1.11.
|
3
|
+
Version: 1.11.2
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Cedric Klinkert
|
@@ -118,6 +118,9 @@ All notable changes to this project will be documented in this file.
|
|
118
118
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
119
119
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
120
120
|
|
121
|
+
## [1.11.2] - 2025-10-07
|
122
|
+
- Fix for empty metadata filter at info retrieval
|
123
|
+
|
121
124
|
## [1.11.1] - 2025-10-07
|
122
125
|
- Fix bug where hallucination check was taking all of the chunks as input instead of only the referenced ones.
|
123
126
|
|
@@ -112,8 +112,8 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
|
|
112
112
|
unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
|
113
113
|
unique_toolkit/content/__init__.py,sha256=EdJg_A_7loEtCQf4cah3QARQreJx6pdz89Rm96YbMVg,940
|
114
114
|
unique_toolkit/content/constants.py,sha256=1iy4Y67xobl5VTnJB6SxSyuoBWbdLl9244xfVMUZi5o,60
|
115
|
-
unique_toolkit/content/functions.py,sha256=
|
116
|
-
unique_toolkit/content/schemas.py,sha256=
|
115
|
+
unique_toolkit/content/functions.py,sha256=6Z9fOEsngJaT1R5DgoeRl5z06RavYgCxiAAPjkw-NKI,21100
|
116
|
+
unique_toolkit/content/schemas.py,sha256=YmZa6ddjf6_RvDFGPovamLd0YX99am9nzWYrKHo8-Hg,5579
|
117
117
|
unique_toolkit/content/service.py,sha256=i7wN_wYjF8NBZHBcpcA5XRlMRGntuw3mlVoudAoGQRk,23293
|
118
118
|
unique_toolkit/content/utils.py,sha256=qNVmHTuETaPNGqheg7TbgPr1_1jbNHDc09N5RrmUIyo,7901
|
119
119
|
unique_toolkit/embedding/__init__.py,sha256=uUyzjonPvuDCYsvXCIt7ErQXopLggpzX-MEQd3_e2kE,250
|
@@ -129,7 +129,7 @@ unique_toolkit/framework_utilities/openai/__init__.py,sha256=CrHYoC7lv2pBscitLer
|
|
129
129
|
unique_toolkit/framework_utilities/openai/client.py,sha256=ct1cqPcIK1wPl11G9sJV39ZnLJwKr2kDUDSra0FjvtM,2007
|
130
130
|
unique_toolkit/framework_utilities/openai/message_builder.py,sha256=VU6mJm_upLcarJQKFft_t1RlLRncWDxDuLC5LIJ5lQQ,4339
|
131
131
|
unique_toolkit/framework_utilities/utils.py,sha256=JK7g2yMfEx3eMprug26769xqNpS5WJcizf8n2zWMBng,789
|
132
|
-
unique_toolkit/knowledge_base.py,sha256=
|
132
|
+
unique_toolkit/knowledge_base.py,sha256=SHAFs68zDQuHJZdrFcdU7wnkUdfNQlNzpSLNckx3Scg,20167
|
133
133
|
unique_toolkit/language_model/__init__.py,sha256=lRQyLlbwHbNFf4-0foBU13UGb09lwEeodbVsfsSgaCk,1971
|
134
134
|
unique_toolkit/language_model/builder.py,sha256=4OKfwJfj3TrgO1ezc_ewIue6W7BCQ2ZYQXUckWVPPTA,3369
|
135
135
|
unique_toolkit/language_model/constants.py,sha256=B-topqW0r83dkC_25DeQfnPk3n53qzIHUCBS7YJ0-1U,119
|
@@ -148,7 +148,7 @@ unique_toolkit/short_term_memory/schemas.py,sha256=OhfcXyF6ACdwIXW45sKzjtZX_gkcJ
|
|
148
148
|
unique_toolkit/short_term_memory/service.py,sha256=5PeVBu1ZCAfyDb2HLVvlmqSbyzBBuE9sI2o9Aajqjxg,8884
|
149
149
|
unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
150
150
|
unique_toolkit/smart_rules/compile.py,sha256=cxWjb2dxEI2HGsakKdVCkSNi7VK9mr08w5sDcFCQyWI,9553
|
151
|
-
unique_toolkit-1.11.
|
152
|
-
unique_toolkit-1.11.
|
153
|
-
unique_toolkit-1.11.
|
154
|
-
unique_toolkit-1.11.
|
151
|
+
unique_toolkit-1.11.2.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
152
|
+
unique_toolkit-1.11.2.dist-info/METADATA,sha256=IdERxyqJO7c7OzqAkm1CrB5sXxC2Wu96_VAXakkjvgo,35670
|
153
|
+
unique_toolkit-1.11.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
154
|
+
unique_toolkit-1.11.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|