unique_toolkit 0.7.7__py3-none-any.whl → 1.23.0__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.
Potentially problematic release.
This version of unique_toolkit might be problematic. Click here for more details.
- unique_toolkit/__init__.py +28 -1
- unique_toolkit/_common/api_calling/human_verification_manager.py +343 -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 +252 -0
- unique_toolkit/_common/docx_generator/template/Doc Template.docx +0 -0
- unique_toolkit/_common/endpoint_builder.py +305 -0
- unique_toolkit/_common/endpoint_requestor.py +430 -0
- unique_toolkit/_common/exception.py +24 -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 +154 -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/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 +111 -0
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/prompts.py +1 -1
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/service.py +16 -15
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/utils.py +30 -20
- 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 +297 -0
- unique_toolkit/agentic/history_manager/history_manager.py +242 -0
- unique_toolkit/agentic/history_manager/loop_token_reducer.py +484 -0
- unique_toolkit/agentic/history_manager/utils.py +96 -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 +63 -0
- unique_toolkit/agentic/responses_api/postprocessors/generated_files.py +145 -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 +185 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/_ref_utils.py +73 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/config.py +45 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/display.py +180 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/references.py +101 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display_utils.py +1335 -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 +73 -0
- unique_toolkit/agentic/tools/a2a/tool/service.py +306 -0
- unique_toolkit/agentic/tools/agent_chunks_hanlder.py +65 -0
- unique_toolkit/agentic/tools/config.py +167 -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 +30 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/__init__.py +8 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/config.py +57 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/service.py +230 -0
- unique_toolkit/agentic/tools/openai_builtin/manager.py +62 -0
- unique_toolkit/agentic/tools/schemas.py +141 -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 +183 -0
- unique_toolkit/agentic/tools/tool_manager.py +523 -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 +6 -0
- unique_toolkit/app/dev_util.py +180 -0
- unique_toolkit/app/init_sdk.py +32 -1
- unique_toolkit/app/schemas.py +198 -31
- unique_toolkit/app/unique_settings.py +367 -0
- unique_toolkit/chat/__init__.py +8 -1
- unique_toolkit/chat/deprecated/service.py +232 -0
- unique_toolkit/chat/functions.py +642 -77
- unique_toolkit/chat/rendering.py +34 -0
- unique_toolkit/chat/responses_api.py +461 -0
- unique_toolkit/chat/schemas.py +133 -2
- unique_toolkit/chat/service.py +115 -767
- unique_toolkit/content/functions.py +153 -4
- unique_toolkit/content/schemas.py +122 -15
- unique_toolkit/content/service.py +278 -44
- unique_toolkit/content/smart_rules.py +301 -0
- unique_toolkit/content/utils.py +8 -3
- unique_toolkit/embedding/service.py +102 -11
- unique_toolkit/framework_utilities/__init__.py +1 -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 +83 -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/builder.py +27 -11
- unique_toolkit/language_model/default_language_model.py +3 -0
- unique_toolkit/language_model/functions.py +327 -43
- unique_toolkit/language_model/infos.py +992 -50
- unique_toolkit/language_model/reference.py +242 -0
- unique_toolkit/language_model/schemas.py +475 -48
- unique_toolkit/language_model/service.py +228 -27
- unique_toolkit/protocols/support.py +145 -0
- unique_toolkit/services/__init__.py +7 -0
- unique_toolkit/services/chat_service.py +1630 -0
- unique_toolkit/services/knowledge_base.py +861 -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-0.7.7.dist-info → unique_toolkit-1.23.0.dist-info}/METADATA +606 -7
- unique_toolkit-1.23.0.dist-info/RECORD +182 -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.7.dist-info/RECORD +0 -64
- /unique_toolkit/{evaluators → agentic/evaluation}/exception.py +0 -0
- {unique_toolkit-0.7.7.dist-info → unique_toolkit-1.23.0.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.7.7.dist-info → unique_toolkit-1.23.0.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 (
|
|
@@ -30,16 +34,34 @@ from unique_toolkit.content.schemas import (
|
|
|
30
34
|
logger = logging.getLogger(f"toolkit.{DOMAIN_NAME}.{__name__}")
|
|
31
35
|
|
|
32
36
|
|
|
37
|
+
@deprecated("Use KnowledgeBaseService instead")
|
|
33
38
|
class ContentService:
|
|
34
39
|
"""
|
|
35
40
|
Provides methods for searching, downloading and uploading content in the knowledge base.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
@deprecated(
|
|
44
|
+
"Use __init__ with company_id, user_id and chat_id instead or use the classmethod `from_event`"
|
|
45
|
+
)
|
|
46
|
+
@overload
|
|
47
|
+
def __init__(self, event: Event | ChatEvent | BaseEvent): ...
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
Initialize the ContentService with an event (deprecated)
|
|
51
|
+
"""
|
|
36
52
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
@overload
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
*,
|
|
57
|
+
company_id: str,
|
|
58
|
+
user_id: str,
|
|
59
|
+
chat_id: str | None = None,
|
|
60
|
+
metadata_filter: dict | None = None,
|
|
61
|
+
): ...
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
Initialize the ContentService with a company_id, user_id and chat_id and metadata_filter.
|
|
43
65
|
"""
|
|
44
66
|
|
|
45
67
|
def __init__(
|
|
@@ -48,20 +70,66 @@ class ContentService:
|
|
|
48
70
|
company_id: str | None = None,
|
|
49
71
|
user_id: str | None = None,
|
|
50
72
|
chat_id: str | None = None,
|
|
73
|
+
metadata_filter: dict | None = None,
|
|
51
74
|
):
|
|
75
|
+
"""
|
|
76
|
+
Initialize the ContentService with a company_id, user_id and chat_id.
|
|
77
|
+
"""
|
|
78
|
+
|
|
52
79
|
self._event = event # Changed to protected attribute
|
|
53
|
-
self.
|
|
80
|
+
self._metadata_filter = None
|
|
54
81
|
if event:
|
|
55
|
-
self.
|
|
56
|
-
self.
|
|
82
|
+
self._company_id: str = event.company_id
|
|
83
|
+
self._user_id: str = event.user_id
|
|
57
84
|
if isinstance(event, (ChatEvent, Event)):
|
|
58
|
-
self.
|
|
59
|
-
self.
|
|
85
|
+
self._metadata_filter = event.payload.metadata_filter
|
|
86
|
+
self._chat_id: str | None = event.payload.chat_id
|
|
60
87
|
else:
|
|
61
88
|
[company_id, user_id] = validate_required_values([company_id, user_id])
|
|
62
|
-
self.
|
|
63
|
-
self.
|
|
64
|
-
self.
|
|
89
|
+
self._company_id: str = company_id
|
|
90
|
+
self._user_id: str = user_id
|
|
91
|
+
self._chat_id: str | None = chat_id
|
|
92
|
+
self._metadata_filter = metadata_filter
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def from_event(cls, event: Event | ChatEvent | BaseEvent):
|
|
96
|
+
"""
|
|
97
|
+
Initialize the ContentService with an event.
|
|
98
|
+
"""
|
|
99
|
+
chat_id = None
|
|
100
|
+
metadata_filter = None
|
|
101
|
+
|
|
102
|
+
if isinstance(event, (ChatEvent | Event)):
|
|
103
|
+
chat_id = event.payload.chat_id
|
|
104
|
+
metadata_filter = event.payload.metadata_filter
|
|
105
|
+
|
|
106
|
+
return cls(
|
|
107
|
+
company_id=event.company_id,
|
|
108
|
+
user_id=event.user_id,
|
|
109
|
+
chat_id=chat_id,
|
|
110
|
+
metadata_filter=metadata_filter,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def from_settings(
|
|
115
|
+
cls,
|
|
116
|
+
settings: UniqueSettings | str | None = None,
|
|
117
|
+
metadata_filter: dict | None = None,
|
|
118
|
+
):
|
|
119
|
+
"""
|
|
120
|
+
Initialize the ContentService with a settings object and metadata filter.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
if settings is None:
|
|
124
|
+
settings = UniqueSettings.from_env_auto_with_sdk_init()
|
|
125
|
+
elif isinstance(settings, str):
|
|
126
|
+
settings = UniqueSettings.from_env_auto_with_sdk_init(filename=settings)
|
|
127
|
+
|
|
128
|
+
return cls(
|
|
129
|
+
company_id=settings.auth.company_id.get_secret_value(),
|
|
130
|
+
user_id=settings.auth.user_id.get_secret_value(),
|
|
131
|
+
metadata_filter=metadata_filter,
|
|
132
|
+
)
|
|
65
133
|
|
|
66
134
|
@property
|
|
67
135
|
@deprecated(
|
|
@@ -76,6 +144,110 @@ class ContentService:
|
|
|
76
144
|
"""
|
|
77
145
|
return self._event
|
|
78
146
|
|
|
147
|
+
@property
|
|
148
|
+
@deprecated(
|
|
149
|
+
"The company_id property is deprecated and will be removed in a future version."
|
|
150
|
+
)
|
|
151
|
+
def company_id(self) -> str | None:
|
|
152
|
+
"""
|
|
153
|
+
Get the company identifier (deprecated).
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
str | None: The company identifier.
|
|
157
|
+
"""
|
|
158
|
+
return self._company_id
|
|
159
|
+
|
|
160
|
+
@company_id.setter
|
|
161
|
+
@deprecated(
|
|
162
|
+
"The company_id setter is deprecated and will be removed in a future version."
|
|
163
|
+
)
|
|
164
|
+
def company_id(self, value: str) -> None:
|
|
165
|
+
"""
|
|
166
|
+
Set the company identifier (deprecated).
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
value (str | None): The company identifier.
|
|
170
|
+
"""
|
|
171
|
+
self._company_id = value
|
|
172
|
+
|
|
173
|
+
@property
|
|
174
|
+
@deprecated(
|
|
175
|
+
"The user_id property is deprecated and will be removed in a future version."
|
|
176
|
+
)
|
|
177
|
+
def user_id(self) -> str | None:
|
|
178
|
+
"""
|
|
179
|
+
Get the user identifier (deprecated).
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
str | None: The user identifier.
|
|
183
|
+
"""
|
|
184
|
+
return self._user_id
|
|
185
|
+
|
|
186
|
+
@user_id.setter
|
|
187
|
+
@deprecated(
|
|
188
|
+
"The user_id setter is deprecated and will be removed in a future version."
|
|
189
|
+
)
|
|
190
|
+
def user_id(self, value: str) -> None:
|
|
191
|
+
"""
|
|
192
|
+
Set the user identifier (deprecated).
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
value (str | None): The user identifier.
|
|
196
|
+
"""
|
|
197
|
+
self._user_id = value
|
|
198
|
+
|
|
199
|
+
@property
|
|
200
|
+
@deprecated(
|
|
201
|
+
"The chat_id property is deprecated and will be removed in a future version."
|
|
202
|
+
)
|
|
203
|
+
def chat_id(self) -> str | None:
|
|
204
|
+
"""
|
|
205
|
+
Get the chat identifier (deprecated).
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
str | None: The chat identifier.
|
|
209
|
+
"""
|
|
210
|
+
return self._chat_id
|
|
211
|
+
|
|
212
|
+
@chat_id.setter
|
|
213
|
+
@deprecated(
|
|
214
|
+
"The chat_id setter is deprecated and will be removed in a future version."
|
|
215
|
+
)
|
|
216
|
+
def chat_id(self, value: str | None) -> None:
|
|
217
|
+
"""
|
|
218
|
+
Set the chat identifier (deprecated).
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
value (str | None): The chat identifier.
|
|
222
|
+
"""
|
|
223
|
+
self._chat_id = value
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
@deprecated(
|
|
227
|
+
"The metadata_filter property is deprecated and will be removed in a future version."
|
|
228
|
+
)
|
|
229
|
+
def metadata_filter(self) -> dict | None:
|
|
230
|
+
"""
|
|
231
|
+
Get the metadata filter (deprecated).
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
dict | None: The metadata filter.
|
|
235
|
+
"""
|
|
236
|
+
return self._metadata_filter
|
|
237
|
+
|
|
238
|
+
@metadata_filter.setter
|
|
239
|
+
@deprecated(
|
|
240
|
+
"The metadata_filter setter is deprecated and will be removed in a future version."
|
|
241
|
+
)
|
|
242
|
+
def metadata_filter(self, value: dict | None) -> None:
|
|
243
|
+
"""
|
|
244
|
+
Set the metadata filter (deprecated).
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
value (dict | None): The metadata filter.
|
|
248
|
+
"""
|
|
249
|
+
self._metadata_filter = value
|
|
250
|
+
|
|
79
251
|
def search_content_chunks(
|
|
80
252
|
self,
|
|
81
253
|
search_string: str,
|
|
@@ -88,6 +260,7 @@ class ContentService:
|
|
|
88
260
|
chat_only: bool | None = None,
|
|
89
261
|
metadata_filter: dict | None = None,
|
|
90
262
|
content_ids: list[str] | None = None,
|
|
263
|
+
score_threshold: float | None = None,
|
|
91
264
|
) -> list[ContentChunk]:
|
|
92
265
|
"""
|
|
93
266
|
Performs a synchronous search for content chunks in the knowledge base.
|
|
@@ -103,6 +276,7 @@ class ContentService:
|
|
|
103
276
|
chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
|
|
104
277
|
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
278
|
content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
|
|
279
|
+
score_threshold (float | None, optional): Sets the minimum similarity score for search results to be considered. Defaults to 0.
|
|
106
280
|
|
|
107
281
|
Returns:
|
|
108
282
|
list[ContentChunk]: The search results.
|
|
@@ -112,17 +286,17 @@ class ContentService:
|
|
|
112
286
|
"""
|
|
113
287
|
|
|
114
288
|
if metadata_filter is None:
|
|
115
|
-
metadata_filter = self.
|
|
289
|
+
metadata_filter = self._metadata_filter
|
|
116
290
|
|
|
117
|
-
chat_id = chat_id or self.
|
|
291
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
118
292
|
|
|
119
293
|
if chat_only and not chat_id:
|
|
120
294
|
raise ValueError("Please provide chat_id when limiting with chat_only")
|
|
121
295
|
|
|
122
296
|
try:
|
|
123
297
|
searches = search_content_chunks(
|
|
124
|
-
user_id=self.
|
|
125
|
-
company_id=self.
|
|
298
|
+
user_id=self._user_id,
|
|
299
|
+
company_id=self._company_id,
|
|
126
300
|
chat_id=chat_id,
|
|
127
301
|
search_string=search_string,
|
|
128
302
|
search_type=search_type,
|
|
@@ -133,12 +307,14 @@ class ContentService:
|
|
|
133
307
|
chat_only=chat_only,
|
|
134
308
|
metadata_filter=metadata_filter,
|
|
135
309
|
content_ids=content_ids,
|
|
310
|
+
score_threshold=score_threshold,
|
|
136
311
|
)
|
|
137
312
|
return searches
|
|
138
313
|
except Exception as e:
|
|
139
314
|
logger.error(f"Error while searching content chunks: {e}")
|
|
140
315
|
raise e
|
|
141
316
|
|
|
317
|
+
@deprecated("Use search_chunks_async instead")
|
|
142
318
|
async def search_content_chunks_async(
|
|
143
319
|
self,
|
|
144
320
|
search_string: str,
|
|
@@ -151,6 +327,7 @@ class ContentService:
|
|
|
151
327
|
chat_only: bool | None = None,
|
|
152
328
|
metadata_filter: dict | None = None,
|
|
153
329
|
content_ids: list[str] | None = None,
|
|
330
|
+
score_threshold: float | None = None,
|
|
154
331
|
):
|
|
155
332
|
"""
|
|
156
333
|
Performs an asynchronous search for content chunks in the knowledge base.
|
|
@@ -166,6 +343,7 @@ class ContentService:
|
|
|
166
343
|
chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
|
|
167
344
|
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
345
|
content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
|
|
346
|
+
score_threshold (float | None, optional): Sets the minimum similarity score for search results to be considered. Defaults to 0.
|
|
169
347
|
|
|
170
348
|
Returns:
|
|
171
349
|
list[ContentChunk]: The search results.
|
|
@@ -174,17 +352,17 @@ class ContentService:
|
|
|
174
352
|
Exception: If there's an error during the search operation.
|
|
175
353
|
"""
|
|
176
354
|
if metadata_filter is None:
|
|
177
|
-
metadata_filter = self.
|
|
355
|
+
metadata_filter = self._metadata_filter
|
|
178
356
|
|
|
179
|
-
chat_id = chat_id or self.
|
|
357
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
180
358
|
|
|
181
359
|
if chat_only and not chat_id:
|
|
182
360
|
raise ValueError("Please provide chat_id when limiting with chat_only.")
|
|
183
361
|
|
|
184
362
|
try:
|
|
185
363
|
searches = await search_content_chunks_async(
|
|
186
|
-
user_id=self.
|
|
187
|
-
company_id=self.
|
|
364
|
+
user_id=self._user_id,
|
|
365
|
+
company_id=self._company_id,
|
|
188
366
|
chat_id=chat_id,
|
|
189
367
|
search_string=search_string,
|
|
190
368
|
search_type=search_type,
|
|
@@ -195,6 +373,7 @@ class ContentService:
|
|
|
195
373
|
chat_only=chat_only,
|
|
196
374
|
metadata_filter=metadata_filter,
|
|
197
375
|
content_ids=content_ids,
|
|
376
|
+
score_threshold=score_threshold,
|
|
198
377
|
)
|
|
199
378
|
return searches
|
|
200
379
|
except Exception as e:
|
|
@@ -216,11 +395,11 @@ class ContentService:
|
|
|
216
395
|
Returns:
|
|
217
396
|
list[Content]: The search results.
|
|
218
397
|
"""
|
|
219
|
-
chat_id = chat_id or self.
|
|
398
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
220
399
|
|
|
221
400
|
return search_contents(
|
|
222
|
-
user_id=self.
|
|
223
|
-
company_id=self.
|
|
401
|
+
user_id=self._user_id,
|
|
402
|
+
company_id=self._company_id,
|
|
224
403
|
chat_id=chat_id,
|
|
225
404
|
where=where,
|
|
226
405
|
)
|
|
@@ -239,11 +418,11 @@ class ContentService:
|
|
|
239
418
|
Returns:
|
|
240
419
|
list[Content]: The search results.
|
|
241
420
|
"""
|
|
242
|
-
chat_id = chat_id or self.
|
|
421
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
243
422
|
|
|
244
423
|
return await search_contents_async(
|
|
245
|
-
user_id=self.
|
|
246
|
-
company_id=self.
|
|
424
|
+
user_id=self._user_id,
|
|
425
|
+
company_id=self._company_id,
|
|
247
426
|
chat_id=chat_id,
|
|
248
427
|
where=where,
|
|
249
428
|
)
|
|
@@ -261,6 +440,9 @@ class ContentService:
|
|
|
261
440
|
scope_id: str | None = None,
|
|
262
441
|
chat_id: str | None = None,
|
|
263
442
|
skip_ingestion: bool = False,
|
|
443
|
+
skip_excel_ingestion: bool = False,
|
|
444
|
+
ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
|
|
445
|
+
metadata: dict | None = None,
|
|
264
446
|
) -> Content:
|
|
265
447
|
"""
|
|
266
448
|
Uploads content to the knowledge base.
|
|
@@ -272,20 +454,25 @@ class ContentService:
|
|
|
272
454
|
scope_id (str | None): The scope ID. Defaults to None.
|
|
273
455
|
chat_id (str | None): The chat ID. Defaults to None.
|
|
274
456
|
skip_ingestion (bool): Whether to skip ingestion. Defaults to False.
|
|
457
|
+
skip_excel_ingestion (bool): Whether to skip excel ingestion. Defaults to False.
|
|
458
|
+
ingestion_config (unique_sdk.Content.IngestionConfig | None): The ingestion configuration. Defaults to None.
|
|
459
|
+
metadata (dict | None): The metadata to associate with the content. Defaults to None.
|
|
275
460
|
|
|
276
461
|
Returns:
|
|
277
462
|
Content: The uploaded content.
|
|
278
463
|
"""
|
|
279
464
|
|
|
280
465
|
return upload_content_from_bytes(
|
|
281
|
-
user_id=self.
|
|
282
|
-
company_id=self.
|
|
466
|
+
user_id=self._user_id,
|
|
467
|
+
company_id=self._company_id,
|
|
283
468
|
content=content,
|
|
284
469
|
content_name=content_name,
|
|
285
470
|
mime_type=mime_type,
|
|
286
471
|
scope_id=scope_id,
|
|
287
472
|
chat_id=chat_id,
|
|
288
473
|
skip_ingestion=skip_ingestion,
|
|
474
|
+
ingestion_config=ingestion_config,
|
|
475
|
+
metadata=metadata,
|
|
289
476
|
)
|
|
290
477
|
|
|
291
478
|
def upload_content(
|
|
@@ -296,6 +483,9 @@ class ContentService:
|
|
|
296
483
|
scope_id: str | None = None,
|
|
297
484
|
chat_id: str | None = None,
|
|
298
485
|
skip_ingestion: bool = False,
|
|
486
|
+
skip_excel_ingestion: bool = False,
|
|
487
|
+
ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
|
|
488
|
+
metadata: dict[str, Any] | None = None,
|
|
299
489
|
):
|
|
300
490
|
"""
|
|
301
491
|
Uploads content to the knowledge base.
|
|
@@ -307,20 +497,26 @@ class ContentService:
|
|
|
307
497
|
scope_id (str | None): The scope ID. Defaults to None.
|
|
308
498
|
chat_id (str | None): The chat ID. Defaults to None.
|
|
309
499
|
skip_ingestion (bool): Whether to skip ingestion. Defaults to False.
|
|
500
|
+
skip_excel_ingestion (bool): Whether to skip excel ingestion. Defaults to False.
|
|
501
|
+
ingestion_config (unique_sdk.Content.IngestionConfig | None): The ingestion configuration. Defaults to None.
|
|
502
|
+
metadata (dict[str, Any] | None): The metadata to associate with the content. Defaults to None.
|
|
310
503
|
|
|
311
504
|
Returns:
|
|
312
505
|
Content: The uploaded content.
|
|
313
506
|
"""
|
|
314
507
|
|
|
315
508
|
return upload_content(
|
|
316
|
-
user_id=self.
|
|
317
|
-
company_id=self.
|
|
509
|
+
user_id=self._user_id,
|
|
510
|
+
company_id=self._company_id,
|
|
318
511
|
path_to_content=path_to_content,
|
|
319
512
|
content_name=content_name,
|
|
320
513
|
mime_type=mime_type,
|
|
321
514
|
scope_id=scope_id,
|
|
322
515
|
chat_id=chat_id,
|
|
323
516
|
skip_ingestion=skip_ingestion,
|
|
517
|
+
skip_excel_ingestion=skip_excel_ingestion,
|
|
518
|
+
ingestion_config=ingestion_config,
|
|
519
|
+
metadata=metadata,
|
|
324
520
|
)
|
|
325
521
|
|
|
326
522
|
def request_content_by_id(
|
|
@@ -339,11 +535,11 @@ class ContentService:
|
|
|
339
535
|
requests.Response: The response object containing the downloaded content.
|
|
340
536
|
|
|
341
537
|
"""
|
|
342
|
-
chat_id = chat_id or self.
|
|
538
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
343
539
|
|
|
344
540
|
return request_content_by_id(
|
|
345
|
-
user_id=self.
|
|
346
|
-
company_id=self.
|
|
541
|
+
user_id=self._user_id,
|
|
542
|
+
company_id=self._company_id,
|
|
347
543
|
content_id=content_id,
|
|
348
544
|
chat_id=chat_id,
|
|
349
545
|
)
|
|
@@ -371,11 +567,11 @@ class ContentService:
|
|
|
371
567
|
Exception: If the download fails or the filename cannot be determined.
|
|
372
568
|
"""
|
|
373
569
|
|
|
374
|
-
chat_id = chat_id or self.
|
|
570
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
375
571
|
|
|
376
572
|
return download_content_to_file_by_id(
|
|
377
|
-
user_id=self.
|
|
378
|
-
company_id=self.
|
|
573
|
+
user_id=self._user_id,
|
|
574
|
+
company_id=self._company_id,
|
|
379
575
|
content_id=content_id,
|
|
380
576
|
chat_id=chat_id,
|
|
381
577
|
filename=filename,
|
|
@@ -406,11 +602,11 @@ class ContentService:
|
|
|
406
602
|
Exception: If the download fails.
|
|
407
603
|
"""
|
|
408
604
|
|
|
409
|
-
chat_id = chat_id or self.
|
|
605
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
410
606
|
|
|
411
607
|
return download_content(
|
|
412
|
-
user_id=self.
|
|
413
|
-
company_id=self.
|
|
608
|
+
user_id=self._user_id,
|
|
609
|
+
company_id=self._company_id,
|
|
414
610
|
content_id=content_id,
|
|
415
611
|
content_name=content_name,
|
|
416
612
|
chat_id=chat_id,
|
|
@@ -435,10 +631,48 @@ class ContentService:
|
|
|
435
631
|
Raises:
|
|
436
632
|
Exception: If the download fails.
|
|
437
633
|
"""
|
|
438
|
-
chat_id = chat_id or self.
|
|
634
|
+
chat_id = chat_id or self._chat_id # type: ignore
|
|
439
635
|
return download_content_to_bytes(
|
|
440
|
-
user_id=self.
|
|
441
|
-
company_id=self.
|
|
636
|
+
user_id=self._user_id,
|
|
637
|
+
company_id=self._company_id,
|
|
442
638
|
content_id=content_id,
|
|
443
639
|
chat_id=chat_id,
|
|
444
640
|
)
|
|
641
|
+
|
|
642
|
+
def get_documents_uploaded_to_chat(self) -> list[Content]:
|
|
643
|
+
chat_contents = self.search_contents(
|
|
644
|
+
where={
|
|
645
|
+
"ownerId": {
|
|
646
|
+
"equals": self._chat_id,
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
content: list[Content] = []
|
|
652
|
+
for c in chat_contents:
|
|
653
|
+
if self.is_file_content(c.key):
|
|
654
|
+
content.append(c)
|
|
655
|
+
|
|
656
|
+
return content
|
|
657
|
+
|
|
658
|
+
def get_images_uploaded_to_chat(self) -> list[Content]:
|
|
659
|
+
chat_contents = self.search_contents(
|
|
660
|
+
where={
|
|
661
|
+
"ownerId": {
|
|
662
|
+
"equals": self._chat_id,
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
)
|
|
666
|
+
|
|
667
|
+
content: list[Content] = []
|
|
668
|
+
for c in chat_contents:
|
|
669
|
+
if self.is_image_content(c.key):
|
|
670
|
+
content.append(c)
|
|
671
|
+
|
|
672
|
+
return content
|
|
673
|
+
|
|
674
|
+
def is_file_content(self, filename: str) -> bool:
|
|
675
|
+
return is_file_content(filename=filename)
|
|
676
|
+
|
|
677
|
+
def is_image_content(self, filename: str) -> bool:
|
|
678
|
+
return is_image_content(filename=filename)
|