unique_toolkit 0.7.9__py3-none-any.whl → 1.33.3__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 +36 -3
- unique_toolkit/_common/api_calling/human_verification_manager.py +357 -0
- unique_toolkit/_common/base_model_type_attribute.py +303 -0
- unique_toolkit/_common/chunk_relevancy_sorter/config.py +49 -0
- unique_toolkit/_common/chunk_relevancy_sorter/exception.py +5 -0
- unique_toolkit/_common/chunk_relevancy_sorter/schemas.py +46 -0
- unique_toolkit/_common/chunk_relevancy_sorter/service.py +374 -0
- unique_toolkit/_common/chunk_relevancy_sorter/tests/test_service.py +275 -0
- unique_toolkit/_common/default_language_model.py +12 -0
- unique_toolkit/_common/docx_generator/__init__.py +7 -0
- unique_toolkit/_common/docx_generator/config.py +12 -0
- unique_toolkit/_common/docx_generator/schemas.py +80 -0
- unique_toolkit/_common/docx_generator/service.py +225 -0
- unique_toolkit/_common/docx_generator/template/Doc Template.docx +0 -0
- unique_toolkit/_common/endpoint_builder.py +368 -0
- unique_toolkit/_common/endpoint_requestor.py +480 -0
- unique_toolkit/_common/exception.py +24 -0
- unique_toolkit/_common/experimental/endpoint_builder.py +368 -0
- unique_toolkit/_common/experimental/endpoint_requestor.py +488 -0
- unique_toolkit/_common/feature_flags/schema.py +9 -0
- unique_toolkit/_common/pydantic/rjsf_tags.py +936 -0
- unique_toolkit/_common/pydantic_helpers.py +174 -0
- unique_toolkit/_common/referencing.py +53 -0
- unique_toolkit/_common/string_utilities.py +140 -0
- unique_toolkit/_common/tests/test_referencing.py +521 -0
- unique_toolkit/_common/tests/test_string_utilities.py +506 -0
- unique_toolkit/_common/token/image_token_counting.py +67 -0
- unique_toolkit/_common/token/token_counting.py +204 -0
- unique_toolkit/_common/utils/__init__.py +1 -0
- unique_toolkit/_common/utils/files.py +43 -0
- unique_toolkit/_common/utils/image/encode.py +25 -0
- unique_toolkit/_common/utils/jinja/helpers.py +10 -0
- unique_toolkit/_common/utils/jinja/render.py +18 -0
- unique_toolkit/_common/utils/jinja/schema.py +65 -0
- unique_toolkit/_common/utils/jinja/utils.py +80 -0
- unique_toolkit/_common/utils/structured_output/__init__.py +1 -0
- unique_toolkit/_common/utils/structured_output/schema.py +5 -0
- unique_toolkit/_common/utils/write_configuration.py +51 -0
- unique_toolkit/_common/validators.py +101 -4
- unique_toolkit/agentic/__init__.py +1 -0
- unique_toolkit/agentic/debug_info_manager/debug_info_manager.py +28 -0
- unique_toolkit/agentic/debug_info_manager/test/test_debug_info_manager.py +278 -0
- unique_toolkit/agentic/evaluation/config.py +36 -0
- unique_toolkit/{evaluators → agentic/evaluation}/context_relevancy/prompts.py +25 -0
- unique_toolkit/agentic/evaluation/context_relevancy/schema.py +80 -0
- unique_toolkit/agentic/evaluation/context_relevancy/service.py +273 -0
- unique_toolkit/agentic/evaluation/evaluation_manager.py +218 -0
- unique_toolkit/agentic/evaluation/hallucination/constants.py +61 -0
- unique_toolkit/agentic/evaluation/hallucination/hallucination_evaluation.py +112 -0
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/prompts.py +1 -1
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/service.py +20 -16
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/utils.py +32 -21
- unique_toolkit/{evaluators → agentic/evaluation}/output_parser.py +20 -2
- unique_toolkit/{evaluators → agentic/evaluation}/schemas.py +27 -7
- unique_toolkit/agentic/evaluation/tests/test_context_relevancy_service.py +253 -0
- unique_toolkit/agentic/evaluation/tests/test_output_parser.py +87 -0
- unique_toolkit/agentic/history_manager/history_construction_with_contents.py +298 -0
- unique_toolkit/agentic/history_manager/history_manager.py +241 -0
- unique_toolkit/agentic/history_manager/loop_token_reducer.py +484 -0
- unique_toolkit/agentic/history_manager/utils.py +96 -0
- unique_toolkit/agentic/message_log_manager/__init__.py +5 -0
- unique_toolkit/agentic/message_log_manager/service.py +93 -0
- unique_toolkit/agentic/postprocessor/postprocessor_manager.py +212 -0
- unique_toolkit/agentic/reference_manager/reference_manager.py +103 -0
- unique_toolkit/agentic/responses_api/__init__.py +19 -0
- unique_toolkit/agentic/responses_api/postprocessors/code_display.py +71 -0
- unique_toolkit/agentic/responses_api/postprocessors/generated_files.py +297 -0
- unique_toolkit/agentic/responses_api/stream_handler.py +15 -0
- unique_toolkit/agentic/short_term_memory_manager/persistent_short_term_memory_manager.py +141 -0
- unique_toolkit/agentic/thinking_manager/thinking_manager.py +103 -0
- unique_toolkit/agentic/tools/__init__.py +1 -0
- unique_toolkit/agentic/tools/a2a/__init__.py +36 -0
- unique_toolkit/agentic/tools/a2a/config.py +17 -0
- unique_toolkit/agentic/tools/a2a/evaluation/__init__.py +15 -0
- unique_toolkit/agentic/tools/a2a/evaluation/_utils.py +66 -0
- unique_toolkit/agentic/tools/a2a/evaluation/config.py +55 -0
- unique_toolkit/agentic/tools/a2a/evaluation/evaluator.py +260 -0
- unique_toolkit/agentic/tools/a2a/evaluation/summarization_user_message.j2 +9 -0
- unique_toolkit/agentic/tools/a2a/manager.py +55 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/__init__.py +21 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/_display_utils.py +240 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/_ref_utils.py +84 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/config.py +78 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/display.py +264 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/references.py +101 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display.py +421 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display_utils.py +2103 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_ref_utils.py +603 -0
- unique_toolkit/agentic/tools/a2a/prompts.py +46 -0
- unique_toolkit/agentic/tools/a2a/response_watcher/__init__.py +6 -0
- unique_toolkit/agentic/tools/a2a/response_watcher/service.py +91 -0
- unique_toolkit/agentic/tools/a2a/tool/__init__.py +4 -0
- unique_toolkit/agentic/tools/a2a/tool/_memory.py +26 -0
- unique_toolkit/agentic/tools/a2a/tool/_schema.py +9 -0
- unique_toolkit/agentic/tools/a2a/tool/config.py +158 -0
- unique_toolkit/agentic/tools/a2a/tool/service.py +393 -0
- unique_toolkit/agentic/tools/agent_chunks_hanlder.py +65 -0
- unique_toolkit/agentic/tools/config.py +128 -0
- unique_toolkit/agentic/tools/factory.py +44 -0
- unique_toolkit/agentic/tools/mcp/__init__.py +4 -0
- unique_toolkit/agentic/tools/mcp/manager.py +71 -0
- unique_toolkit/agentic/tools/mcp/models.py +28 -0
- unique_toolkit/agentic/tools/mcp/tool_wrapper.py +234 -0
- unique_toolkit/agentic/tools/openai_builtin/__init__.py +11 -0
- unique_toolkit/agentic/tools/openai_builtin/base.py +46 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/__init__.py +8 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/config.py +88 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/service.py +250 -0
- unique_toolkit/agentic/tools/openai_builtin/manager.py +79 -0
- unique_toolkit/agentic/tools/schemas.py +145 -0
- unique_toolkit/agentic/tools/test/test_mcp_manager.py +536 -0
- unique_toolkit/agentic/tools/test/test_tool_progress_reporter.py +445 -0
- unique_toolkit/agentic/tools/tool.py +187 -0
- unique_toolkit/agentic/tools/tool_manager.py +492 -0
- unique_toolkit/agentic/tools/tool_progress_reporter.py +285 -0
- unique_toolkit/agentic/tools/utils/__init__.py +19 -0
- unique_toolkit/agentic/tools/utils/execution/__init__.py +1 -0
- unique_toolkit/agentic/tools/utils/execution/execution.py +286 -0
- unique_toolkit/agentic/tools/utils/source_handling/__init__.py +0 -0
- unique_toolkit/agentic/tools/utils/source_handling/schema.py +21 -0
- unique_toolkit/agentic/tools/utils/source_handling/source_formatting.py +207 -0
- unique_toolkit/agentic/tools/utils/source_handling/tests/test_source_formatting.py +216 -0
- unique_toolkit/app/__init__.py +9 -0
- unique_toolkit/app/dev_util.py +180 -0
- unique_toolkit/app/fast_api_factory.py +131 -0
- unique_toolkit/app/init_sdk.py +32 -1
- unique_toolkit/app/schemas.py +206 -31
- unique_toolkit/app/unique_settings.py +367 -0
- unique_toolkit/app/webhook.py +77 -0
- unique_toolkit/chat/__init__.py +8 -1
- unique_toolkit/chat/deprecated/service.py +232 -0
- unique_toolkit/chat/functions.py +648 -78
- unique_toolkit/chat/rendering.py +34 -0
- unique_toolkit/chat/responses_api.py +461 -0
- unique_toolkit/chat/schemas.py +134 -2
- unique_toolkit/chat/service.py +115 -767
- unique_toolkit/content/functions.py +353 -8
- unique_toolkit/content/schemas.py +128 -15
- unique_toolkit/content/service.py +321 -45
- unique_toolkit/content/smart_rules.py +301 -0
- unique_toolkit/content/utils.py +10 -3
- unique_toolkit/data_extraction/README.md +96 -0
- unique_toolkit/data_extraction/__init__.py +11 -0
- unique_toolkit/data_extraction/augmented/__init__.py +5 -0
- unique_toolkit/data_extraction/augmented/service.py +93 -0
- unique_toolkit/data_extraction/base.py +25 -0
- unique_toolkit/data_extraction/basic/__init__.py +11 -0
- unique_toolkit/data_extraction/basic/config.py +18 -0
- unique_toolkit/data_extraction/basic/prompt.py +13 -0
- unique_toolkit/data_extraction/basic/service.py +55 -0
- unique_toolkit/embedding/service.py +103 -12
- unique_toolkit/framework_utilities/__init__.py +1 -0
- unique_toolkit/framework_utilities/langchain/__init__.py +10 -0
- unique_toolkit/framework_utilities/langchain/client.py +71 -0
- unique_toolkit/framework_utilities/langchain/history.py +19 -0
- unique_toolkit/framework_utilities/openai/__init__.py +6 -0
- unique_toolkit/framework_utilities/openai/client.py +84 -0
- unique_toolkit/framework_utilities/openai/message_builder.py +229 -0
- unique_toolkit/framework_utilities/utils.py +23 -0
- unique_toolkit/language_model/__init__.py +3 -0
- unique_toolkit/language_model/_responses_api_utils.py +93 -0
- unique_toolkit/language_model/builder.py +27 -11
- unique_toolkit/language_model/default_language_model.py +3 -0
- unique_toolkit/language_model/functions.py +345 -43
- unique_toolkit/language_model/infos.py +1288 -46
- unique_toolkit/language_model/reference.py +242 -0
- unique_toolkit/language_model/schemas.py +481 -49
- unique_toolkit/language_model/service.py +229 -28
- unique_toolkit/protocols/support.py +145 -0
- unique_toolkit/services/__init__.py +7 -0
- unique_toolkit/services/chat_service.py +1631 -0
- unique_toolkit/services/knowledge_base.py +1094 -0
- unique_toolkit/short_term_memory/service.py +178 -41
- unique_toolkit/smart_rules/__init__.py +0 -0
- unique_toolkit/smart_rules/compile.py +56 -0
- unique_toolkit/test_utilities/events.py +197 -0
- unique_toolkit-1.33.3.dist-info/METADATA +1145 -0
- unique_toolkit-1.33.3.dist-info/RECORD +205 -0
- unique_toolkit/evaluators/__init__.py +0 -1
- unique_toolkit/evaluators/config.py +0 -35
- unique_toolkit/evaluators/constants.py +0 -1
- unique_toolkit/evaluators/context_relevancy/constants.py +0 -32
- unique_toolkit/evaluators/context_relevancy/service.py +0 -53
- unique_toolkit/evaluators/context_relevancy/utils.py +0 -142
- unique_toolkit/evaluators/hallucination/constants.py +0 -41
- unique_toolkit-0.7.9.dist-info/METADATA +0 -413
- unique_toolkit-0.7.9.dist-info/RECORD +0 -64
- /unique_toolkit/{evaluators → agentic/evaluation}/exception.py +0 -0
- {unique_toolkit-0.7.9.dist-info → unique_toolkit-1.33.3.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.7.9.dist-info → unique_toolkit-1.33.3.dist-info}/WHEEL +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
from pathlib import Path
|
|
3
|
+
from typing import Any, overload
|
|
3
4
|
|
|
5
|
+
import unique_sdk
|
|
4
6
|
from requests import Response
|
|
5
7
|
from typing_extensions import deprecated
|
|
6
8
|
|
|
9
|
+
from unique_toolkit._common.utils.files import is_file_content, is_image_content
|
|
7
10
|
from unique_toolkit._common.validate_required_values import validate_required_values
|
|
8
11
|
from unique_toolkit.app.schemas import BaseEvent, ChatEvent, Event
|
|
12
|
+
from unique_toolkit.app.unique_settings import UniqueSettings
|
|
9
13
|
from unique_toolkit.content import DOMAIN_NAME
|
|
10
14
|
from unique_toolkit.content.constants import DEFAULT_SEARCH_LANGUAGE
|
|
11
15
|
from unique_toolkit.content.functions import (
|
|
@@ -19,6 +23,7 @@ from unique_toolkit.content.functions import (
|
|
|
19
23
|
search_contents_async,
|
|
20
24
|
upload_content,
|
|
21
25
|
upload_content_from_bytes,
|
|
26
|
+
upload_content_from_bytes_async,
|
|
22
27
|
)
|
|
23
28
|
from unique_toolkit.content.schemas import (
|
|
24
29
|
Content,
|
|
@@ -30,16 +35,34 @@ from unique_toolkit.content.schemas import (
|
|
|
30
35
|
logger = logging.getLogger(f"toolkit.{DOMAIN_NAME}.{__name__}")
|
|
31
36
|
|
|
32
37
|
|
|
38
|
+
@deprecated("Use KnowledgeBaseService instead")
|
|
33
39
|
class ContentService:
|
|
34
40
|
"""
|
|
35
41
|
Provides methods for searching, downloading and uploading content in the knowledge base.
|
|
42
|
+
"""
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
@deprecated(
|
|
45
|
+
"Use __init__ with company_id, user_id and chat_id instead or use the classmethod `from_event`"
|
|
46
|
+
)
|
|
47
|
+
@overload
|
|
48
|
+
def __init__(self, event: Event | ChatEvent | BaseEvent): ...
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
Initialize the ContentService with an event (deprecated)
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@overload
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
company_id: str,
|
|
59
|
+
user_id: str,
|
|
60
|
+
chat_id: str | None = None,
|
|
61
|
+
metadata_filter: dict | None = None,
|
|
62
|
+
): ...
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
Initialize the ContentService with a company_id, user_id and chat_id and metadata_filter.
|
|
43
66
|
"""
|
|
44
67
|
|
|
45
68
|
def __init__(
|
|
@@ -48,20 +71,66 @@ class ContentService:
|
|
|
48
71
|
company_id: str | None = None,
|
|
49
72
|
user_id: str | None = None,
|
|
50
73
|
chat_id: str | None = None,
|
|
74
|
+
metadata_filter: dict | None = None,
|
|
51
75
|
):
|
|
76
|
+
"""
|
|
77
|
+
Initialize the ContentService with a company_id, user_id and chat_id.
|
|
78
|
+
"""
|
|
79
|
+
|
|
52
80
|
self._event = event # Changed to protected attribute
|
|
53
|
-
self.
|
|
81
|
+
self._metadata_filter = None
|
|
54
82
|
if event:
|
|
55
|
-
self.
|
|
56
|
-
self.
|
|
83
|
+
self._company_id: str = event.company_id
|
|
84
|
+
self._user_id: str = event.user_id
|
|
57
85
|
if isinstance(event, (ChatEvent, Event)):
|
|
58
|
-
self.
|
|
59
|
-
self.
|
|
86
|
+
self._metadata_filter = event.payload.metadata_filter
|
|
87
|
+
self._chat_id: str | None = event.payload.chat_id
|
|
60
88
|
else:
|
|
61
89
|
[company_id, user_id] = validate_required_values([company_id, user_id])
|
|
62
|
-
self.
|
|
63
|
-
self.
|
|
64
|
-
self.
|
|
90
|
+
self._company_id: str = company_id
|
|
91
|
+
self._user_id: str = user_id
|
|
92
|
+
self._chat_id: str | None = chat_id
|
|
93
|
+
self._metadata_filter = metadata_filter
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_event(cls, event: Event | ChatEvent | BaseEvent):
|
|
97
|
+
"""
|
|
98
|
+
Initialize the ContentService with an event.
|
|
99
|
+
"""
|
|
100
|
+
chat_id = None
|
|
101
|
+
metadata_filter = None
|
|
102
|
+
|
|
103
|
+
if isinstance(event, (ChatEvent | Event)):
|
|
104
|
+
chat_id = event.payload.chat_id
|
|
105
|
+
metadata_filter = event.payload.metadata_filter
|
|
106
|
+
|
|
107
|
+
return cls(
|
|
108
|
+
company_id=event.company_id,
|
|
109
|
+
user_id=event.user_id,
|
|
110
|
+
chat_id=chat_id,
|
|
111
|
+
metadata_filter=metadata_filter,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def from_settings(
|
|
116
|
+
cls,
|
|
117
|
+
settings: UniqueSettings | str | None = None,
|
|
118
|
+
metadata_filter: dict | None = None,
|
|
119
|
+
):
|
|
120
|
+
"""
|
|
121
|
+
Initialize the ContentService with a settings object and metadata filter.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
if settings is None:
|
|
125
|
+
settings = UniqueSettings.from_env_auto_with_sdk_init()
|
|
126
|
+
elif isinstance(settings, str):
|
|
127
|
+
settings = UniqueSettings.from_env_auto_with_sdk_init(filename=settings)
|
|
128
|
+
|
|
129
|
+
return cls(
|
|
130
|
+
company_id=settings.auth.company_id.get_secret_value(),
|
|
131
|
+
user_id=settings.auth.user_id.get_secret_value(),
|
|
132
|
+
metadata_filter=metadata_filter,
|
|
133
|
+
)
|
|
65
134
|
|
|
66
135
|
@property
|
|
67
136
|
@deprecated(
|
|
@@ -76,6 +145,110 @@ class ContentService:
|
|
|
76
145
|
"""
|
|
77
146
|
return self._event
|
|
78
147
|
|
|
148
|
+
@property
|
|
149
|
+
@deprecated(
|
|
150
|
+
"The company_id property is deprecated and will be removed in a future version."
|
|
151
|
+
)
|
|
152
|
+
def company_id(self) -> str | None:
|
|
153
|
+
"""
|
|
154
|
+
Get the company identifier (deprecated).
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
str | None: The company identifier.
|
|
158
|
+
"""
|
|
159
|
+
return self._company_id
|
|
160
|
+
|
|
161
|
+
@company_id.setter
|
|
162
|
+
@deprecated(
|
|
163
|
+
"The company_id setter is deprecated and will be removed in a future version."
|
|
164
|
+
)
|
|
165
|
+
def company_id(self, value: str) -> None:
|
|
166
|
+
"""
|
|
167
|
+
Set the company identifier (deprecated).
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
value (str | None): The company identifier.
|
|
171
|
+
"""
|
|
172
|
+
self._company_id = value
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
@deprecated(
|
|
176
|
+
"The user_id property is deprecated and will be removed in a future version."
|
|
177
|
+
)
|
|
178
|
+
def user_id(self) -> str | None:
|
|
179
|
+
"""
|
|
180
|
+
Get the user identifier (deprecated).
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
str | None: The user identifier.
|
|
184
|
+
"""
|
|
185
|
+
return self._user_id
|
|
186
|
+
|
|
187
|
+
@user_id.setter
|
|
188
|
+
@deprecated(
|
|
189
|
+
"The user_id setter is deprecated and will be removed in a future version."
|
|
190
|
+
)
|
|
191
|
+
def user_id(self, value: str) -> None:
|
|
192
|
+
"""
|
|
193
|
+
Set the user identifier (deprecated).
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
value (str | None): The user identifier.
|
|
197
|
+
"""
|
|
198
|
+
self._user_id = value
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
@deprecated(
|
|
202
|
+
"The chat_id property is deprecated and will be removed in a future version."
|
|
203
|
+
)
|
|
204
|
+
def chat_id(self) -> str | None:
|
|
205
|
+
"""
|
|
206
|
+
Get the chat identifier (deprecated).
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
str | None: The chat identifier.
|
|
210
|
+
"""
|
|
211
|
+
return self._chat_id
|
|
212
|
+
|
|
213
|
+
@chat_id.setter
|
|
214
|
+
@deprecated(
|
|
215
|
+
"The chat_id setter is deprecated and will be removed in a future version."
|
|
216
|
+
)
|
|
217
|
+
def chat_id(self, value: str | None) -> None:
|
|
218
|
+
"""
|
|
219
|
+
Set the chat identifier (deprecated).
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
value (str | None): The chat identifier.
|
|
223
|
+
"""
|
|
224
|
+
self._chat_id = value
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
@deprecated(
|
|
228
|
+
"The metadata_filter property is deprecated and will be removed in a future version."
|
|
229
|
+
)
|
|
230
|
+
def metadata_filter(self) -> dict | None:
|
|
231
|
+
"""
|
|
232
|
+
Get the metadata filter (deprecated).
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
dict | None: The metadata filter.
|
|
236
|
+
"""
|
|
237
|
+
return self._metadata_filter
|
|
238
|
+
|
|
239
|
+
@metadata_filter.setter
|
|
240
|
+
@deprecated(
|
|
241
|
+
"The metadata_filter setter is deprecated and will be removed in a future version."
|
|
242
|
+
)
|
|
243
|
+
def metadata_filter(self, value: dict | None) -> None:
|
|
244
|
+
"""
|
|
245
|
+
Set the metadata filter (deprecated).
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
value (dict | None): The metadata filter.
|
|
249
|
+
"""
|
|
250
|
+
self._metadata_filter = value
|
|
251
|
+
|
|
79
252
|
def search_content_chunks(
|
|
80
253
|
self,
|
|
81
254
|
search_string: str,
|
|
@@ -88,6 +261,7 @@ class ContentService:
|
|
|
88
261
|
chat_only: bool | None = None,
|
|
89
262
|
metadata_filter: dict | None = None,
|
|
90
263
|
content_ids: list[str] | None = None,
|
|
264
|
+
score_threshold: float | None = None,
|
|
91
265
|
) -> list[ContentChunk]:
|
|
92
266
|
"""
|
|
93
267
|
Performs a synchronous search for content chunks in the knowledge base.
|
|
@@ -103,6 +277,7 @@ class ContentService:
|
|
|
103
277
|
chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
|
|
104
278
|
metadata_filter (dict | None, optional): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
|
|
105
279
|
content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
|
|
280
|
+
score_threshold (float | None, optional): Sets the minimum similarity score for search results to be considered. Defaults to 0.
|
|
106
281
|
|
|
107
282
|
Returns:
|
|
108
283
|
list[ContentChunk]: The search results.
|
|
@@ -112,17 +287,17 @@ class ContentService:
|
|
|
112
287
|
"""
|
|
113
288
|
|
|
114
289
|
if metadata_filter is None:
|
|
115
|
-
metadata_filter = self.
|
|
290
|
+
metadata_filter = self._metadata_filter
|
|
116
291
|
|
|
117
|
-
chat_id = chat_id or self.
|
|
292
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
118
293
|
|
|
119
294
|
if chat_only and not chat_id:
|
|
120
295
|
raise ValueError("Please provide chat_id when limiting with chat_only")
|
|
121
296
|
|
|
122
297
|
try:
|
|
123
298
|
searches = search_content_chunks(
|
|
124
|
-
user_id=self.
|
|
125
|
-
company_id=self.
|
|
299
|
+
user_id=self._user_id,
|
|
300
|
+
company_id=self._company_id,
|
|
126
301
|
chat_id=chat_id,
|
|
127
302
|
search_string=search_string,
|
|
128
303
|
search_type=search_type,
|
|
@@ -133,12 +308,14 @@ class ContentService:
|
|
|
133
308
|
chat_only=chat_only,
|
|
134
309
|
metadata_filter=metadata_filter,
|
|
135
310
|
content_ids=content_ids,
|
|
311
|
+
score_threshold=score_threshold,
|
|
136
312
|
)
|
|
137
313
|
return searches
|
|
138
314
|
except Exception as e:
|
|
139
315
|
logger.error(f"Error while searching content chunks: {e}")
|
|
140
316
|
raise e
|
|
141
317
|
|
|
318
|
+
@deprecated("Use search_chunks_async instead")
|
|
142
319
|
async def search_content_chunks_async(
|
|
143
320
|
self,
|
|
144
321
|
search_string: str,
|
|
@@ -151,6 +328,7 @@ class ContentService:
|
|
|
151
328
|
chat_only: bool | None = None,
|
|
152
329
|
metadata_filter: dict | None = None,
|
|
153
330
|
content_ids: list[str] | None = None,
|
|
331
|
+
score_threshold: float | None = None,
|
|
154
332
|
):
|
|
155
333
|
"""
|
|
156
334
|
Performs an asynchronous search for content chunks in the knowledge base.
|
|
@@ -166,6 +344,7 @@ class ContentService:
|
|
|
166
344
|
chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
|
|
167
345
|
metadata_filter (dict | None, optional): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
|
|
168
346
|
content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
|
|
347
|
+
score_threshold (float | None, optional): Sets the minimum similarity score for search results to be considered. Defaults to 0.
|
|
169
348
|
|
|
170
349
|
Returns:
|
|
171
350
|
list[ContentChunk]: The search results.
|
|
@@ -174,17 +353,17 @@ class ContentService:
|
|
|
174
353
|
Exception: If there's an error during the search operation.
|
|
175
354
|
"""
|
|
176
355
|
if metadata_filter is None:
|
|
177
|
-
metadata_filter = self.
|
|
356
|
+
metadata_filter = self._metadata_filter
|
|
178
357
|
|
|
179
|
-
chat_id = chat_id or self.
|
|
358
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
180
359
|
|
|
181
360
|
if chat_only and not chat_id:
|
|
182
361
|
raise ValueError("Please provide chat_id when limiting with chat_only.")
|
|
183
362
|
|
|
184
363
|
try:
|
|
185
364
|
searches = await search_content_chunks_async(
|
|
186
|
-
user_id=self.
|
|
187
|
-
company_id=self.
|
|
365
|
+
user_id=self._user_id,
|
|
366
|
+
company_id=self._company_id,
|
|
188
367
|
chat_id=chat_id,
|
|
189
368
|
search_string=search_string,
|
|
190
369
|
search_type=search_type,
|
|
@@ -195,6 +374,7 @@ class ContentService:
|
|
|
195
374
|
chat_only=chat_only,
|
|
196
375
|
metadata_filter=metadata_filter,
|
|
197
376
|
content_ids=content_ids,
|
|
377
|
+
score_threshold=score_threshold,
|
|
198
378
|
)
|
|
199
379
|
return searches
|
|
200
380
|
except Exception as e:
|
|
@@ -216,11 +396,11 @@ class ContentService:
|
|
|
216
396
|
Returns:
|
|
217
397
|
list[Content]: The search results.
|
|
218
398
|
"""
|
|
219
|
-
chat_id = chat_id or self.
|
|
399
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
220
400
|
|
|
221
401
|
return search_contents(
|
|
222
|
-
user_id=self.
|
|
223
|
-
company_id=self.
|
|
402
|
+
user_id=self._user_id,
|
|
403
|
+
company_id=self._company_id,
|
|
224
404
|
chat_id=chat_id,
|
|
225
405
|
where=where,
|
|
226
406
|
)
|
|
@@ -239,11 +419,11 @@ class ContentService:
|
|
|
239
419
|
Returns:
|
|
240
420
|
list[Content]: The search results.
|
|
241
421
|
"""
|
|
242
|
-
chat_id = chat_id or self.
|
|
422
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
243
423
|
|
|
244
424
|
return await search_contents_async(
|
|
245
|
-
user_id=self.
|
|
246
|
-
company_id=self.
|
|
425
|
+
user_id=self._user_id,
|
|
426
|
+
company_id=self._company_id,
|
|
247
427
|
chat_id=chat_id,
|
|
248
428
|
where=where,
|
|
249
429
|
)
|
|
@@ -261,6 +441,9 @@ class ContentService:
|
|
|
261
441
|
scope_id: str | None = None,
|
|
262
442
|
chat_id: str | None = None,
|
|
263
443
|
skip_ingestion: bool = False,
|
|
444
|
+
skip_excel_ingestion: bool = False,
|
|
445
|
+
ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
|
|
446
|
+
metadata: dict | None = None,
|
|
264
447
|
) -> Content:
|
|
265
448
|
"""
|
|
266
449
|
Uploads content to the knowledge base.
|
|
@@ -272,20 +455,66 @@ class ContentService:
|
|
|
272
455
|
scope_id (str | None): The scope ID. Defaults to None.
|
|
273
456
|
chat_id (str | None): The chat ID. Defaults to None.
|
|
274
457
|
skip_ingestion (bool): Whether to skip ingestion. Defaults to False.
|
|
458
|
+
skip_excel_ingestion (bool): Whether to skip excel ingestion. Defaults to False.
|
|
459
|
+
ingestion_config (unique_sdk.Content.IngestionConfig | None): The ingestion configuration. Defaults to None.
|
|
460
|
+
metadata (dict | None): The metadata to associate with the content. Defaults to None.
|
|
275
461
|
|
|
276
462
|
Returns:
|
|
277
463
|
Content: The uploaded content.
|
|
278
464
|
"""
|
|
279
465
|
|
|
280
466
|
return upload_content_from_bytes(
|
|
281
|
-
user_id=self.
|
|
282
|
-
company_id=self.
|
|
467
|
+
user_id=self._user_id,
|
|
468
|
+
company_id=self._company_id,
|
|
283
469
|
content=content,
|
|
284
470
|
content_name=content_name,
|
|
285
471
|
mime_type=mime_type,
|
|
286
472
|
scope_id=scope_id,
|
|
287
473
|
chat_id=chat_id,
|
|
288
474
|
skip_ingestion=skip_ingestion,
|
|
475
|
+
ingestion_config=ingestion_config,
|
|
476
|
+
metadata=metadata,
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
async def upload_content_from_bytes_async(
|
|
480
|
+
self,
|
|
481
|
+
content: bytes,
|
|
482
|
+
content_name: str,
|
|
483
|
+
mime_type: str,
|
|
484
|
+
scope_id: str | None = None,
|
|
485
|
+
chat_id: str | None = None,
|
|
486
|
+
skip_ingestion: bool = False,
|
|
487
|
+
ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
|
|
488
|
+
metadata: dict | None = None,
|
|
489
|
+
) -> Content:
|
|
490
|
+
"""
|
|
491
|
+
Uploads content to the knowledge base.
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
content (bytes): The content to upload.
|
|
495
|
+
content_name (str): The name of the content.
|
|
496
|
+
mime_type (str): The MIME type of the content.
|
|
497
|
+
scope_id (str | None): The scope ID. Defaults to None.
|
|
498
|
+
skip_ingestion (bool): Whether to skip ingestion. Defaults to False.
|
|
499
|
+
skip_excel_ingestion (bool): Whether to skip excel ingestion. Defaults to False.
|
|
500
|
+
ingestion_config (unique_sdk.Content.IngestionConfig | None): The ingestion configuration. Defaults to None.
|
|
501
|
+
metadata (dict | None): The metadata to associate with the content. Defaults to None.
|
|
502
|
+
|
|
503
|
+
Returns:
|
|
504
|
+
Content: The uploaded content.
|
|
505
|
+
"""
|
|
506
|
+
|
|
507
|
+
return await upload_content_from_bytes_async(
|
|
508
|
+
user_id=self._user_id,
|
|
509
|
+
company_id=self._company_id,
|
|
510
|
+
content=content,
|
|
511
|
+
content_name=content_name,
|
|
512
|
+
mime_type=mime_type,
|
|
513
|
+
scope_id=scope_id,
|
|
514
|
+
chat_id=chat_id,
|
|
515
|
+
skip_ingestion=skip_ingestion,
|
|
516
|
+
ingestion_config=ingestion_config,
|
|
517
|
+
metadata=metadata,
|
|
289
518
|
)
|
|
290
519
|
|
|
291
520
|
def upload_content(
|
|
@@ -296,7 +525,10 @@ class ContentService:
|
|
|
296
525
|
scope_id: str | None = None,
|
|
297
526
|
chat_id: str | None = None,
|
|
298
527
|
skip_ingestion: bool = False,
|
|
299
|
-
|
|
528
|
+
skip_excel_ingestion: bool = False,
|
|
529
|
+
ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
|
|
530
|
+
metadata: dict[str, Any] | None = None,
|
|
531
|
+
) -> Content:
|
|
300
532
|
"""
|
|
301
533
|
Uploads content to the knowledge base.
|
|
302
534
|
|
|
@@ -307,20 +539,26 @@ class ContentService:
|
|
|
307
539
|
scope_id (str | None): The scope ID. Defaults to None.
|
|
308
540
|
chat_id (str | None): The chat ID. Defaults to None.
|
|
309
541
|
skip_ingestion (bool): Whether to skip ingestion. Defaults to False.
|
|
542
|
+
skip_excel_ingestion (bool): Whether to skip excel ingestion. Defaults to False.
|
|
543
|
+
ingestion_config (unique_sdk.Content.IngestionConfig | None): The ingestion configuration. Defaults to None.
|
|
544
|
+
metadata (dict[str, Any] | None): The metadata to associate with the content. Defaults to None.
|
|
310
545
|
|
|
311
546
|
Returns:
|
|
312
547
|
Content: The uploaded content.
|
|
313
548
|
"""
|
|
314
549
|
|
|
315
550
|
return upload_content(
|
|
316
|
-
user_id=self.
|
|
317
|
-
company_id=self.
|
|
551
|
+
user_id=self._user_id,
|
|
552
|
+
company_id=self._company_id,
|
|
318
553
|
path_to_content=path_to_content,
|
|
319
554
|
content_name=content_name,
|
|
320
555
|
mime_type=mime_type,
|
|
321
556
|
scope_id=scope_id,
|
|
322
557
|
chat_id=chat_id,
|
|
323
558
|
skip_ingestion=skip_ingestion,
|
|
559
|
+
skip_excel_ingestion=skip_excel_ingestion,
|
|
560
|
+
ingestion_config=ingestion_config,
|
|
561
|
+
metadata=metadata,
|
|
324
562
|
)
|
|
325
563
|
|
|
326
564
|
def request_content_by_id(
|
|
@@ -339,11 +577,11 @@ class ContentService:
|
|
|
339
577
|
requests.Response: The response object containing the downloaded content.
|
|
340
578
|
|
|
341
579
|
"""
|
|
342
|
-
chat_id = chat_id or self.
|
|
580
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
343
581
|
|
|
344
582
|
return request_content_by_id(
|
|
345
|
-
user_id=self.
|
|
346
|
-
company_id=self.
|
|
583
|
+
user_id=self._user_id,
|
|
584
|
+
company_id=self._company_id,
|
|
347
585
|
content_id=content_id,
|
|
348
586
|
chat_id=chat_id,
|
|
349
587
|
)
|
|
@@ -371,11 +609,11 @@ class ContentService:
|
|
|
371
609
|
Exception: If the download fails or the filename cannot be determined.
|
|
372
610
|
"""
|
|
373
611
|
|
|
374
|
-
chat_id = chat_id or self.
|
|
612
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
375
613
|
|
|
376
614
|
return download_content_to_file_by_id(
|
|
377
|
-
user_id=self.
|
|
378
|
-
company_id=self.
|
|
615
|
+
user_id=self._user_id,
|
|
616
|
+
company_id=self._company_id,
|
|
379
617
|
content_id=content_id,
|
|
380
618
|
chat_id=chat_id,
|
|
381
619
|
filename=filename,
|
|
@@ -406,11 +644,11 @@ class ContentService:
|
|
|
406
644
|
Exception: If the download fails.
|
|
407
645
|
"""
|
|
408
646
|
|
|
409
|
-
chat_id = chat_id or self.
|
|
647
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
410
648
|
|
|
411
649
|
return download_content(
|
|
412
|
-
user_id=self.
|
|
413
|
-
company_id=self.
|
|
650
|
+
user_id=self._user_id,
|
|
651
|
+
company_id=self._company_id,
|
|
414
652
|
content_id=content_id,
|
|
415
653
|
content_name=content_name,
|
|
416
654
|
chat_id=chat_id,
|
|
@@ -435,10 +673,48 @@ class ContentService:
|
|
|
435
673
|
Raises:
|
|
436
674
|
Exception: If the download fails.
|
|
437
675
|
"""
|
|
438
|
-
chat_id = chat_id or self.
|
|
676
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
439
677
|
return download_content_to_bytes(
|
|
440
|
-
user_id=self.
|
|
441
|
-
company_id=self.
|
|
678
|
+
user_id=self._user_id,
|
|
679
|
+
company_id=self._company_id,
|
|
442
680
|
content_id=content_id,
|
|
443
681
|
chat_id=chat_id,
|
|
444
682
|
)
|
|
683
|
+
|
|
684
|
+
def get_documents_uploaded_to_chat(self) -> list[Content]:
|
|
685
|
+
chat_contents = self.search_contents(
|
|
686
|
+
where={
|
|
687
|
+
"ownerId": {
|
|
688
|
+
"equals": self._chat_id,
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
content: list[Content] = []
|
|
694
|
+
for c in chat_contents:
|
|
695
|
+
if self.is_file_content(c.key):
|
|
696
|
+
content.append(c)
|
|
697
|
+
|
|
698
|
+
return content
|
|
699
|
+
|
|
700
|
+
def get_images_uploaded_to_chat(self) -> list[Content]:
|
|
701
|
+
chat_contents = self.search_contents(
|
|
702
|
+
where={
|
|
703
|
+
"ownerId": {
|
|
704
|
+
"equals": self._chat_id,
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
)
|
|
708
|
+
|
|
709
|
+
content: list[Content] = []
|
|
710
|
+
for c in chat_contents:
|
|
711
|
+
if self.is_image_content(c.key):
|
|
712
|
+
content.append(c)
|
|
713
|
+
|
|
714
|
+
return content
|
|
715
|
+
|
|
716
|
+
def is_file_content(self, filename: str) -> bool:
|
|
717
|
+
return is_file_content(filename=filename)
|
|
718
|
+
|
|
719
|
+
def is_image_content(self, filename: str) -> bool:
|
|
720
|
+
return is_image_content(filename=filename)
|