unique_toolkit 0.7.0__py3-none-any.whl → 0.7.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.
@@ -130,6 +130,7 @@ async def search_content_chunks_async(
130
130
  def search_contents(
131
131
  user_id: str,
132
132
  company_id: str,
133
+ chat_id: str,
133
134
  where: dict,
134
135
  ):
135
136
  """
@@ -151,6 +152,7 @@ def search_contents(
151
152
  contents = unique_sdk.Content.search(
152
153
  user_id=user_id,
153
154
  company_id=company_id,
155
+ chatId=chat_id,
154
156
  # TODO add type parameter in SDK
155
157
  where=where, # type: ignore
156
158
  )
@@ -163,6 +165,7 @@ def search_contents(
163
165
  async def search_contents_async(
164
166
  user_id: str,
165
167
  company_id: str,
168
+ chat_id: str,
166
169
  where: dict,
167
170
  ):
168
171
  """Asynchronously searches for content in the knowledge base."""
@@ -173,6 +176,7 @@ async def search_contents_async(
173
176
  contents = await unique_sdk.Content.search_async(
174
177
  user_id=user_id,
175
178
  company_id=company_id,
179
+ chatId=chat_id,
176
180
  where=where, # type: ignore
177
181
  )
178
182
  return map_contents(contents)
@@ -35,9 +35,11 @@ class ContentService:
35
35
  Provides methods for searching, downloading and uploading content in the knowledge base.
36
36
 
37
37
  Attributes:
38
- company_id (str | None): The company ID.
39
- user_id (str | None): The user ID.
40
- metadata_filter (dict | None): The metadata filter.
38
+ event: BaseEvent | Event, this can be None ONLY if company_id and user_id are provided.
39
+ company_id (str): The company ID.
40
+ user_id (str): The user ID.
41
+ chat_id (str): The chat ID. Defaults to None
42
+ metadata_filter (dict | None): is only initialised from an Event(Deprecated) or ChatEvent.
41
43
  """
42
44
 
43
45
  def __init__(
@@ -45,6 +47,7 @@ class ContentService:
45
47
  event: Event | BaseEvent | None = None,
46
48
  company_id: str | None = None,
47
49
  user_id: str | None = None,
50
+ chat_id: str | None = None,
48
51
  ):
49
52
  self._event = event # Changed to protected attribute
50
53
  self.metadata_filter = None
@@ -53,10 +56,12 @@ class ContentService:
53
56
  self.user_id = event.user_id
54
57
  if isinstance(event, (ChatEvent, Event)):
55
58
  self.metadata_filter = event.payload.metadata_filter
59
+ self.chat_id = event.payload.chat_id
56
60
  else:
57
61
  [company_id, user_id] = validate_required_values([company_id, user_id])
58
62
  self.company_id = company_id
59
63
  self.user_id = user_id
64
+ self.chat_id = chat_id
60
65
 
61
66
  @property
62
67
  @deprecated(
@@ -77,6 +82,7 @@ class ContentService:
77
82
  search_type: ContentSearchType,
78
83
  limit: int,
79
84
  search_language: str = DEFAULT_SEARCH_LANGUAGE,
85
+ chat_id: str = "",
80
86
  reranker_config: ContentRerankerConfig | None = None,
81
87
  scope_ids: list[str] | None = None,
82
88
  chat_only: bool | None = None,
@@ -90,24 +96,34 @@ class ContentService:
90
96
  search_string (str): The search string.
91
97
  search_type (ContentSearchType): The type of search to perform.
92
98
  limit (int): The maximum number of results to return.
93
- search_language (str): The language for the full-text search. Defaults to "english".
94
- reranker_config (ContentRerankerConfig | None): The reranker configuration. Defaults to None.
95
- scope_ids (list[str] | None): The scope IDs. Defaults to None.
96
- chat_only (bool | None): Whether to search only in the current chat. Defaults to None.
97
- metadata_filter (dict | None): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
98
- content_ids (list[str] | None): The content IDs to search. Defaults to None.
99
+ search_language (str, optional): The language for the full-text search. Defaults to "english".
100
+ chat_id (str, optional): The chat ID for context. Defaults to empty string.
101
+ reranker_config (ContentRerankerConfig | None, optional): The reranker configuration. Defaults to None.
102
+ scope_ids (list[str] | None, optional): The scope IDs to filter by. Defaults to None.
103
+ chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
104
+ 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
+ content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
106
+
99
107
  Returns:
100
108
  list[ContentChunk]: The search results.
109
+
110
+ Raises:
111
+ Exception: If there's an error during the search operation.
101
112
  """
102
113
 
103
114
  if metadata_filter is None:
104
115
  metadata_filter = self.metadata_filter
105
116
 
117
+ chat_id = chat_id or self.chat_id # type: ignore
118
+
119
+ if chat_only and not chat_id:
120
+ raise ValueError("Please provide chat_id when limiting with chat_only")
121
+
106
122
  try:
107
123
  searches = search_content_chunks(
108
124
  user_id=self.user_id,
109
125
  company_id=self.company_id,
110
- chat_id="",
126
+ chat_id=chat_id,
111
127
  search_string=search_string,
112
128
  search_type=search_type,
113
129
  limit=limit,
@@ -129,6 +145,7 @@ class ContentService:
129
145
  search_type: ContentSearchType,
130
146
  limit: int,
131
147
  search_language: str = DEFAULT_SEARCH_LANGUAGE,
148
+ chat_id: str = "",
132
149
  reranker_config: ContentRerankerConfig | None = None,
133
150
  scope_ids: list[str] | None = None,
134
151
  chat_only: bool | None = None,
@@ -142,23 +159,33 @@ class ContentService:
142
159
  search_string (str): The search string.
143
160
  search_type (ContentSearchType): The type of search to perform.
144
161
  limit (int): The maximum number of results to return.
145
- search_language (str): The language for the full-text search. Defaults to "english".
146
- reranker_config (ContentRerankerConfig | None): The reranker configuration. Defaults to None.
147
- scope_ids (list[str] | None): The scope IDs. Defaults to None.
148
- chat_only (bool | None): Whether to search only in the current chat. Defaults to None.
149
- metadata_filter (dict | None): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
150
- content_ids (list[str] | None): The content IDs to search. Defaults to None.
162
+ search_language (str, optional): The language for the full-text search. Defaults to "english".
163
+ chat_id (str, optional): The chat ID for context. Defaults to empty string.
164
+ reranker_config (ContentRerankerConfig | None, optional): The reranker configuration. Defaults to None.
165
+ scope_ids (list[str] | None, optional): The scope IDs to filter by. Defaults to None.
166
+ chat_only (bool | None, optional): Whether to search only in the current chat. Defaults to None.
167
+ 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
+ content_ids (list[str] | None, optional): The content IDs to search within. Defaults to None.
169
+
151
170
  Returns:
152
171
  list[ContentChunk]: The search results.
172
+
173
+ Raises:
174
+ Exception: If there's an error during the search operation.
153
175
  """
154
176
  if metadata_filter is None:
155
177
  metadata_filter = self.metadata_filter
156
178
 
179
+ chat_id = chat_id or self.chat_id # type: ignore
180
+
181
+ if chat_only and not chat_id:
182
+ raise ValueError("Please provide chat_id when limiting with chat_only.")
183
+
157
184
  try:
158
185
  searches = await search_content_chunks_async(
159
186
  user_id=self.user_id,
160
187
  company_id=self.company_id,
161
- chat_id="",
188
+ chat_id=chat_id,
162
189
  search_string=search_string,
163
190
  search_type=search_type,
164
191
  limit=limit,
@@ -177,6 +204,7 @@ class ContentService:
177
204
  def search_contents(
178
205
  self,
179
206
  where: dict,
207
+ chat_id: str = "",
180
208
  ) -> list[Content]:
181
209
  """
182
210
  Performs a search in the knowledge base by filter (and not a smilarity search)
@@ -188,15 +216,19 @@ class ContentService:
188
216
  Returns:
189
217
  list[Content]: The search results.
190
218
  """
219
+ chat_id = chat_id or self.chat_id # type: ignore
220
+
191
221
  return search_contents(
192
222
  user_id=self.user_id,
193
223
  company_id=self.company_id,
224
+ chat_id=chat_id,
194
225
  where=where,
195
226
  )
196
227
 
197
228
  async def search_contents_async(
198
229
  self,
199
230
  where: dict,
231
+ chat_id: str = "",
200
232
  ) -> list[Content]:
201
233
  """
202
234
  Performs an asynchronous search for content files in the knowledge base by filter.
@@ -207,16 +239,19 @@ class ContentService:
207
239
  Returns:
208
240
  list[Content]: The search results.
209
241
  """
242
+ chat_id = chat_id or self.chat_id # type: ignore
243
+
210
244
  return await search_contents_async(
211
245
  user_id=self.user_id,
212
246
  company_id=self.company_id,
247
+ chat_id=chat_id,
213
248
  where=where,
214
249
  )
215
250
 
216
251
  def search_content_on_chat(self, chat_id: str) -> list[Content]:
217
252
  where = {"ownerId": {"equals": chat_id}}
218
253
 
219
- return self.search_contents(where)
254
+ return self.search_contents(where, chat_id=chat_id)
220
255
 
221
256
  def upload_content_from_bytes(
222
257
  self,
@@ -291,7 +326,7 @@ class ContentService:
291
326
  def request_content_by_id(
292
327
  self,
293
328
  content_id: str,
294
- chat_id: str | None,
329
+ chat_id: str | None = None,
295
330
  ) -> Response:
296
331
  """
297
332
  Sends a request to download content from a chat.
@@ -304,6 +339,8 @@ class ContentService:
304
339
  requests.Response: The response object containing the downloaded content.
305
340
 
306
341
  """
342
+ chat_id = chat_id or self.chat_id # type: ignore
343
+
307
344
  return request_content_by_id(
308
345
  user_id=self.user_id,
309
346
  company_id=self.company_id,
@@ -334,6 +371,8 @@ class ContentService:
334
371
  Exception: If the download fails or the filename cannot be determined.
335
372
  """
336
373
 
374
+ chat_id = chat_id or self.chat_id # type: ignore
375
+
337
376
  return download_content_to_file_by_id(
338
377
  user_id=self.user_id,
339
378
  company_id=self.company_id,
@@ -367,6 +406,8 @@ class ContentService:
367
406
  Exception: If the download fails.
368
407
  """
369
408
 
409
+ chat_id = chat_id or self.chat_id # type: ignore
410
+
370
411
  return download_content(
371
412
  user_id=self.user_id,
372
413
  company_id=self.company_id,
@@ -394,7 +435,7 @@ class ContentService:
394
435
  Raises:
395
436
  Exception: If the download fails.
396
437
  """
397
-
438
+ chat_id = chat_id or self.chat_id # type: ignore
398
439
  return download_content_to_bytes(
399
440
  user_id=self.user_id,
400
441
  company_id=self.company_id,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -111,9 +111,16 @@ All notable changes to this project will be documented in this file.
111
111
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
112
112
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
113
113
 
114
+
115
+ ## [0.7.2] - 2025-03-17
116
+ - HotFix `ContentService.search_content_chunks` to use `chat_id` from event if provided.
117
+
118
+ ## [0.7.1] - 2025-03-11
119
+ - Fix Breaking change: `ContentService.search_content_chunks` `ContentService.search_content_chunks` now accepts`chat_id` for the specific to handle chat_only instances
120
+
114
121
  ## [0.7.0] - 2025-03-11
115
122
  - Fix the issue with `ShortTermMemoryService.create_memory_async` adding `self.chat_id` and `self.message_id` as part of the parameter.
116
- - Breaking chang: `ContentService.search_content_on_chat` now requires you pass in a `chat_id` for the specific chat instance
123
+ - Breaking change: `ContentService.search_content_on_chat` now requires you pass in a `chat_id` for the specific chat instance
117
124
 
118
125
  ## [0.6.9] - 2025-03-11
119
126
  - Add o1-preview as part of the language model info, make the name consistent across board.
@@ -20,9 +20,9 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
20
20
  unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
21
21
  unique_toolkit/content/__init__.py,sha256=EdJg_A_7loEtCQf4cah3QARQreJx6pdz89Rm96YbMVg,940
22
22
  unique_toolkit/content/constants.py,sha256=1iy4Y67xobl5VTnJB6SxSyuoBWbdLl9244xfVMUZi5o,60
23
- unique_toolkit/content/functions.py,sha256=iuclQjuiupIJPk0-6ldl35EVkQ2h34_dxKxWisMrxWM,17001
23
+ unique_toolkit/content/functions.py,sha256=yB87wrbtmHzr3jGJUHetmuhy-7RVtnqG2IQ6gqFAun8,17093
24
24
  unique_toolkit/content/schemas.py,sha256=zks_Pkki2VhxICJJgHZyc-LPmRuj5dLbw3pgcUT7SW8,2362
25
- unique_toolkit/content/service.py,sha256=xcFN-vUakuovuzMXMN8qOmdlUzt2f1ZwHE4RzOWYjnQ,14040
25
+ unique_toolkit/content/service.py,sha256=cb5q8oFbKQbuyikQyTdrSvJMfVdpC9K3S5GT0NkD5uo,15771
26
26
  unique_toolkit/content/utils.py,sha256=GUVPrkZfMoAj4MRoBs5BD_7vSuLZTZx69hyWzYFrI50,7747
27
27
  unique_toolkit/embedding/__init__.py,sha256=uUyzjonPvuDCYsvXCIt7ErQXopLggpzX-MEQd3_e2kE,250
28
28
  unique_toolkit/embedding/constants.py,sha256=Lj8-Lcy1FvuC31PM9Exq7vaFuxQV4pEI1huUMFX-J2M,52
@@ -58,7 +58,7 @@ unique_toolkit/short_term_memory/constants.py,sha256=698CL6-wjup2MvU19RxSmQk3gX7
58
58
  unique_toolkit/short_term_memory/functions.py,sha256=3WiK-xatY5nh4Dr5zlDUye1k3E6kr41RiscwtTplw5k,4484
59
59
  unique_toolkit/short_term_memory/schemas.py,sha256=OhfcXyF6ACdwIXW45sKzjtZX_gkcJs8FEZXcgQTNenw,1406
60
60
  unique_toolkit/short_term_memory/service.py,sha256=0wrwuo6K17Edcuiwp5LMCvxFuBSDP82HF0_5qwi0nYc,5307
61
- unique_toolkit-0.7.0.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
62
- unique_toolkit-0.7.0.dist-info/METADATA,sha256=jDT49L28AksCEFj_0CXSyHJKg5Q2IWGXqNYLr0ninHY,20561
63
- unique_toolkit-0.7.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
64
- unique_toolkit-0.7.0.dist-info/RECORD,,
61
+ unique_toolkit-0.7.2.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
62
+ unique_toolkit-0.7.2.dist-info/METADATA,sha256=grlxS6ihrKZ5fk-IeNN7iGqMK0iKVkAPMOzN8Kx-u28,20871
63
+ unique_toolkit-0.7.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
64
+ unique_toolkit-0.7.2.dist-info/RECORD,,