unique_toolkit 0.7.1__py3-none-any.whl → 0.7.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.
@@ -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)
@@ -38,6 +38,7 @@ class ContentService:
38
38
  event: BaseEvent | Event, this can be None ONLY if company_id and user_id are provided.
39
39
  company_id (str): The company ID.
40
40
  user_id (str): The user ID.
41
+ chat_id (str): The chat ID. Defaults to None
41
42
  metadata_filter (dict | None): is only initialised from an Event(Deprecated) or ChatEvent.
42
43
  """
43
44
 
@@ -46,6 +47,7 @@ class ContentService:
46
47
  event: Event | BaseEvent | None = None,
47
48
  company_id: str | None = None,
48
49
  user_id: str | None = None,
50
+ chat_id: str | None = None,
49
51
  ):
50
52
  self._event = event # Changed to protected attribute
51
53
  self.metadata_filter = None
@@ -54,10 +56,12 @@ class ContentService:
54
56
  self.user_id = event.user_id
55
57
  if isinstance(event, (ChatEvent, Event)):
56
58
  self.metadata_filter = event.payload.metadata_filter
59
+ self.chat_id = event.payload.chat_id
57
60
  else:
58
61
  [company_id, user_id] = validate_required_values([company_id, user_id])
59
62
  self.company_id = company_id
60
63
  self.user_id = user_id
64
+ self.chat_id = chat_id
61
65
 
62
66
  @property
63
67
  @deprecated(
@@ -110,6 +114,8 @@ class ContentService:
110
114
  if metadata_filter is None:
111
115
  metadata_filter = self.metadata_filter
112
116
 
117
+ chat_id = chat_id or self.chat_id # type: ignore
118
+
113
119
  if chat_only and not chat_id:
114
120
  raise ValueError("Please provide chat_id when limiting with chat_only")
115
121
 
@@ -170,6 +176,8 @@ class ContentService:
170
176
  if metadata_filter is None:
171
177
  metadata_filter = self.metadata_filter
172
178
 
179
+ chat_id = chat_id or self.chat_id # type: ignore
180
+
173
181
  if chat_only and not chat_id:
174
182
  raise ValueError("Please provide chat_id when limiting with chat_only.")
175
183
 
@@ -196,6 +204,7 @@ class ContentService:
196
204
  def search_contents(
197
205
  self,
198
206
  where: dict,
207
+ chat_id: str = "",
199
208
  ) -> list[Content]:
200
209
  """
201
210
  Performs a search in the knowledge base by filter (and not a smilarity search)
@@ -207,15 +216,19 @@ class ContentService:
207
216
  Returns:
208
217
  list[Content]: The search results.
209
218
  """
219
+ chat_id = chat_id or self.chat_id # type: ignore
220
+
210
221
  return search_contents(
211
222
  user_id=self.user_id,
212
223
  company_id=self.company_id,
224
+ chat_id=chat_id,
213
225
  where=where,
214
226
  )
215
227
 
216
228
  async def search_contents_async(
217
229
  self,
218
230
  where: dict,
231
+ chat_id: str = "",
219
232
  ) -> list[Content]:
220
233
  """
221
234
  Performs an asynchronous search for content files in the knowledge base by filter.
@@ -226,16 +239,19 @@ class ContentService:
226
239
  Returns:
227
240
  list[Content]: The search results.
228
241
  """
242
+ chat_id = chat_id or self.chat_id # type: ignore
243
+
229
244
  return await search_contents_async(
230
245
  user_id=self.user_id,
231
246
  company_id=self.company_id,
247
+ chat_id=chat_id,
232
248
  where=where,
233
249
  )
234
250
 
235
251
  def search_content_on_chat(self, chat_id: str) -> list[Content]:
236
252
  where = {"ownerId": {"equals": chat_id}}
237
253
 
238
- return self.search_contents(where)
254
+ return self.search_contents(where, chat_id=chat_id)
239
255
 
240
256
  def upload_content_from_bytes(
241
257
  self,
@@ -310,7 +326,7 @@ class ContentService:
310
326
  def request_content_by_id(
311
327
  self,
312
328
  content_id: str,
313
- chat_id: str | None,
329
+ chat_id: str | None = None,
314
330
  ) -> Response:
315
331
  """
316
332
  Sends a request to download content from a chat.
@@ -323,6 +339,8 @@ class ContentService:
323
339
  requests.Response: The response object containing the downloaded content.
324
340
 
325
341
  """
342
+ chat_id = chat_id or self.chat_id # type: ignore
343
+
326
344
  return request_content_by_id(
327
345
  user_id=self.user_id,
328
346
  company_id=self.company_id,
@@ -353,6 +371,8 @@ class ContentService:
353
371
  Exception: If the download fails or the filename cannot be determined.
354
372
  """
355
373
 
374
+ chat_id = chat_id or self.chat_id # type: ignore
375
+
356
376
  return download_content_to_file_by_id(
357
377
  user_id=self.user_id,
358
378
  company_id=self.company_id,
@@ -386,6 +406,8 @@ class ContentService:
386
406
  Exception: If the download fails.
387
407
  """
388
408
 
409
+ chat_id = chat_id or self.chat_id # type: ignore
410
+
389
411
  return download_content(
390
412
  user_id=self.user_id,
391
413
  company_id=self.company_id,
@@ -413,7 +435,7 @@ class ContentService:
413
435
  Raises:
414
436
  Exception: If the download fails.
415
437
  """
416
-
438
+ chat_id = chat_id or self.chat_id # type: ignore
417
439
  return download_content_to_bytes(
418
440
  user_id=self.user_id,
419
441
  company_id=self.company_id,
@@ -2,6 +2,8 @@ from typing_extensions import Self
2
2
 
3
3
  from unique_toolkit.language_model import (
4
4
  LanguageModelAssistantMessage,
5
+ LanguageModelFunction,
6
+ LanguageModelFunctionCall,
5
7
  LanguageModelMessage,
6
8
  LanguageModelMessageRole,
7
9
  LanguageModelMessages,
@@ -48,11 +50,22 @@ class MessagesBuilder:
48
50
  self.messages.append(message)
49
51
  return self
50
52
 
51
- def assistant_message_append(self, content: str) -> Self:
53
+ def assistant_message_append(
54
+ self, content: str, tool_calls: list[LanguageModelFunction] | None = None
55
+ ) -> Self:
52
56
  """Appends an assistant message to the messages list."""
53
57
  message = LanguageModelAssistantMessage(content=content)
58
+ if tool_calls:
59
+ message.tool_calls = [
60
+ LanguageModelFunctionCall(
61
+ id=tool_call.id,
62
+ type="function",
63
+ function=tool_call,
64
+ )
65
+ for tool_call in tool_calls
66
+ ]
54
67
  self.messages.append(message)
55
- return self # Return self to allow method chaining
68
+ return self
56
69
 
57
70
  def tool_message_append(self, name: str, tool_call_id: str, content: str) -> Self:
58
71
  """Appends a tool message to the messages list."""
@@ -60,7 +73,7 @@ class MessagesBuilder:
60
73
  name=name, tool_call_id=tool_call_id, content=content
61
74
  )
62
75
  self.messages.append(message)
63
- return self # Return self to allow method chaining
76
+ return self
64
77
 
65
78
  def build(self, reset: bool = True) -> LanguageModelMessages:
66
79
  """Returns the list of messages and resets the builder"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -111,6 +111,13 @@ 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.3] - 2025-03-20
116
+ - Enable handling tool calls in message builder
117
+
118
+ ## [0.7.2] - 2025-03-17
119
+ - HotFix `ContentService.search_content_chunks` to use `chat_id` from event if provided.
120
+
114
121
  ## [0.7.1] - 2025-03-11
115
122
  - Fix Breaking change: `ContentService.search_content_chunks` `ContentService.search_content_chunks` now accepts`chat_id` for the specific to handle chat_only instances
116
123
 
@@ -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=jnXUtQ9ax8tS52lrUIOzMypYCJiRZ56XeIz87hIMur4,14988
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
@@ -45,7 +45,7 @@ unique_toolkit/evaluators/hallucination/utils.py,sha256=4KTJH8low_fBzOcuVlcHB2FR
45
45
  unique_toolkit/evaluators/output_parser.py,sha256=eI72qkzK1dZyUvnfP2SOAQCGBj_-PwX5wy_aLPMsJMY,883
46
46
  unique_toolkit/evaluators/schemas.py,sha256=Jaue6Uhx75X1CyHKWj8sT3RE1JZXTqoLtfLt2xQNCX8,2507
47
47
  unique_toolkit/language_model/__init__.py,sha256=jWko_vQj48wjnpTtlkg8iNdef0SMI3FN2kGywXRTMzg,1880
48
- unique_toolkit/language_model/builder.py,sha256=_lUL2shMN1Je2LLYu2PiehOvfWtn5pg1yUuYyiw3f_c,2710
48
+ unique_toolkit/language_model/builder.py,sha256=aIAXWWUoB5G-HONJiAt3MdRGd4jdP8nA-HYX2D2WlSI,3048
49
49
  unique_toolkit/language_model/constants.py,sha256=B-topqW0r83dkC_25DeQfnPk3n53qzIHUCBS7YJ0-1U,119
50
50
  unique_toolkit/language_model/functions.py,sha256=I5jHhHsKoq7GwEQyTrM8LXB2n_6dvMAk7UklenjuHSY,7945
51
51
  unique_toolkit/language_model/infos.py,sha256=HRdQLG3oetwc-bPHtsXvDRRLsK7fSsC1q8FubvxLMsw,16459
@@ -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.1.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
62
- unique_toolkit-0.7.1.dist-info/METADATA,sha256=vEkFTjpS9QGRvfgIHvRt80Fxyi49Fh127CFKlmXjIqs,20756
63
- unique_toolkit-0.7.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
64
- unique_toolkit-0.7.1.dist-info/RECORD,,
61
+ unique_toolkit-0.7.3.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
62
+ unique_toolkit-0.7.3.dist-info/METADATA,sha256=ynA_2RASnYvrs5DSqAcq7-taxnu1iZQe2gSRBiJupd4,20944
63
+ unique_toolkit-0.7.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
64
+ unique_toolkit-0.7.3.dist-info/RECORD,,