unique_toolkit 1.14.2__py3-none-any.whl → 1.14.4__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.
@@ -1,16 +1,20 @@
1
- import logging
2
- from typing import Any
1
+ """
2
+ DEPRECATED: This module is maintained for backward compatibility only.
3
3
 
4
- import unique_sdk
5
- from openai.types.chat.chat_completion_message_param import ChatCompletionMessageParam
6
- from typing_extensions import deprecated
4
+ Please import from `unique_toolkit.services.chat_service` instead:
5
+ from unique_toolkit.services.chat_service import ChatService
6
+
7
+ All imports from this module will continue to work but may be removed in a future version.
8
+ """
9
+
10
+ import warnings
7
11
 
8
- from unique_toolkit._common.utils.files import is_file_content, is_image_content
9
12
  from unique_toolkit.chat.constants import (
10
13
  DEFAULT_MAX_MESSAGES,
11
14
  DEFAULT_PERCENT_OF_MAX_TOKENS,
12
15
  DOMAIN_NAME,
13
16
  )
17
+ from unique_toolkit.chat.deprecated.service import ChatServiceDeprecated
14
18
  from unique_toolkit.chat.functions import (
15
19
  create_message,
16
20
  create_message_assessment,
@@ -29,6 +33,8 @@ from unique_toolkit.chat.functions import (
29
33
  modify_message_assessment,
30
34
  modify_message_assessment_async,
31
35
  modify_message_async,
36
+ stream_complete_with_references,
37
+ stream_complete_with_references_async,
32
38
  update_message_execution,
33
39
  update_message_execution_async,
34
40
  update_message_log,
@@ -73,1429 +79,79 @@ from unique_toolkit.language_model.schemas import (
73
79
  LanguageModelTool,
74
80
  LanguageModelToolDescription,
75
81
  )
76
-
77
- from .deprecated.service import ChatServiceDeprecated
78
- from .functions import (
79
- stream_complete_with_references,
80
- stream_complete_with_references_async,
82
+ from unique_toolkit.services.chat_service import ChatService
83
+
84
+ warnings.warn(
85
+ "Importing from 'unique_toolkit.chat.service' is deprecated. "
86
+ "Please import from 'unique_toolkit.services.chat_service' instead. "
87
+ "This module will be removed in a future version.",
88
+ DeprecationWarning,
89
+ stacklevel=1,
81
90
  )
82
91
 
83
- logger = logging.getLogger(f"toolkit.{DOMAIN_NAME}.{__name__}")
84
-
85
-
86
- class ChatService(ChatServiceDeprecated):
87
- """Provides all functionalities to manage the chat session."""
88
-
89
- async def update_debug_info_async(self, debug_info: dict):
90
- """Updates the debug information for the chat session.
91
-
92
- Args:
93
- debug_info (dict): The new debug information.
94
-
95
- """
96
- return await modify_message_async(
97
- user_id=self._user_id,
98
- company_id=self._company_id,
99
- assistant_message_id=self._assistant_message_id,
100
- chat_id=self._chat_id,
101
- user_message_id=self._user_message_id,
102
- user_message_text=self._user_message_text,
103
- assistant=False,
104
- debug_info=debug_info,
105
- )
106
-
107
- def replace_debug_info(self, debug_info: dict):
108
- """Replace the debug information in the last user message
109
-
110
- Args:
111
- debug_info (dict): The new debug information.
112
-
113
- """
114
- return modify_message(
115
- user_id=self._user_id,
116
- company_id=self._company_id,
117
- assistant_message_id=self._assistant_message_id,
118
- chat_id=self._chat_id,
119
- user_message_id=self._user_message_id,
120
- user_message_text=self._user_message_text,
121
- assistant=False,
122
- debug_info=debug_info,
123
- )
124
-
125
- # Message Methods
126
- ############################################################################
127
-
128
- def modify_user_message(
129
- self,
130
- content: str,
131
- references: list[ContentReference] | None = None,
132
- debug_info: dict | None = None,
133
- message_id: str | None = None,
134
- set_completed_at: bool | None = False,
135
- ) -> ChatMessage:
136
- """Modifies a user message in the chat session synchronously.
137
-
138
- Args:
139
- content (str): The new content for the message.
140
- references (list[ContentReference]): list of ContentReference objects.
141
- debug_info (dict[str, Any]]]): Debug information.
142
- message_id (str, optional): The message ID, if not specified the last user message is edited.
143
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
144
-
145
- Returns:
146
- ChatMessage: The modified message.
147
-
148
- Raises:
149
- Exception: If the modification fails.
150
-
151
- """
152
- return modify_message(
153
- user_id=self._user_id,
154
- company_id=self._company_id,
155
- assistant_message_id=self._assistant_message_id,
156
- chat_id=self._chat_id,
157
- user_message_id=self._user_message_id,
158
- user_message_text=self._user_message_text,
159
- assistant=False,
160
- content=content,
161
- references=references,
162
- debug_info=debug_info,
163
- message_id=message_id,
164
- set_completed_at=set_completed_at or False,
165
- )
166
-
167
- async def modify_user_message_async(
168
- self,
169
- content: str,
170
- references: list[ContentReference] = [],
171
- debug_info: dict = {},
172
- message_id: str | None = None,
173
- set_completed_at: bool | None = False,
174
- ) -> ChatMessage:
175
- """Modifies a message in the chat session asynchronously.
176
-
177
- Args:
178
- content (str): The new content for the message.
179
- message_id (str, optional): The message ID. Defaults to None, then the ChatState user message id is used.
180
- references (list[ContentReference]): list of ContentReference objects. Defaults to None.
181
- debug_info (dict[str, Any]]]): Debug information. Defaults to {}.
182
- set_completed_at (bool, optional): Whether to set the completedAt field with the current date time. Defaults to False.
183
-
184
- Returns:
185
- ChatMessage: The modified message.
186
-
187
- Raises:
188
- Exception: If the modification fails.
189
-
190
- """
191
- return await modify_message_async(
192
- user_id=self._user_id,
193
- company_id=self._company_id,
194
- assistant_message_id=self._assistant_message_id,
195
- chat_id=self._chat_id,
196
- user_message_id=self._user_message_id,
197
- user_message_text=self._user_message_text,
198
- assistant=False,
199
- content=content,
200
- references=references,
201
- debug_info=debug_info,
202
- message_id=message_id,
203
- set_completed_at=set_completed_at or False,
204
- )
205
-
206
- def modify_assistant_message(
207
- self,
208
- content: str | None = None,
209
- original_content: str | None = None,
210
- references: list[ContentReference] | None = None,
211
- debug_info: dict | None = None,
212
- message_id: str | None = None,
213
- set_completed_at: bool | None = None,
214
- ) -> ChatMessage:
215
- """Modifies a message in the chat session synchronously if parameter is not specified the corresponding field will remain as is.
216
-
217
- Args:
218
- content (str, optional): The new content for the message.
219
- original_content (str, optional): The original content for the message.
220
- references (list[ContentReference]): list of ContentReference objects. Defaults to [].
221
- debug_info (dict[str, Any]]]): Debug information. Defaults to {}.
222
- message_id (Optional[str]): The message ID. Defaults to None.
223
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
224
-
225
- Returns:
226
- ChatMessage: The modified message.
227
-
228
- Raises:
229
- Exception: If the modification fails.
230
-
231
- """
232
- return modify_message(
233
- user_id=self._user_id,
234
- company_id=self._company_id,
235
- assistant_message_id=self._assistant_message_id,
236
- chat_id=self._chat_id,
237
- user_message_id=self._user_message_id,
238
- user_message_text=self._user_message_text,
239
- assistant=True,
240
- content=content,
241
- original_content=original_content,
242
- references=references,
243
- debug_info=debug_info,
244
- message_id=message_id,
245
- set_completed_at=set_completed_at or False,
246
- )
247
-
248
- async def modify_assistant_message_async(
249
- self,
250
- content: str | None = None,
251
- original_content: str | None = None,
252
- references: list[ContentReference] | None = None,
253
- debug_info: dict | None = None,
254
- message_id: str | None = None,
255
- set_completed_at: bool | None = False,
256
- ) -> ChatMessage:
257
- """Modifies a message in the chat session asynchronously.
258
-
259
- Args:
260
- content (str, optional): The new content for the message.
261
- original_content (str, optional): The original content for the message.
262
- message_id (str, optional): The message ID. Defaults to None, then the ChatState assistant message id is used.
263
- references (list[ContentReference]): list of ContentReference objects. Defaults to None.
264
- debug_info (dict[str, Any]], optional): Debug information. Defaults to None.
265
- set_completed_at (bool, optional): Whether to set the completedAt field with the current date time. Defaults to False.
266
-
267
- Returns:
268
- ChatMessage: The modified message.
269
-
270
- Raises:
271
- Exception: If the modification fails.
272
-
273
- """
274
- return await modify_message_async(
275
- user_id=self._user_id,
276
- company_id=self._company_id,
277
- assistant_message_id=self._assistant_message_id,
278
- chat_id=self._chat_id,
279
- user_message_id=self._user_message_id,
280
- user_message_text=self._user_message_text,
281
- assistant=True,
282
- content=content,
283
- original_content=original_content,
284
- references=references,
285
- debug_info=debug_info,
286
- message_id=message_id,
287
- set_completed_at=set_completed_at or False,
288
- )
289
-
290
- def create_assistant_message(
291
- self,
292
- content: str,
293
- original_content: str | None = None,
294
- references: list[ContentReference] | None = None,
295
- debug_info: dict | None = None,
296
- set_completed_at: bool | None = False,
297
- ) -> ChatMessage:
298
- """Creates a message in the chat session synchronously.
299
-
300
- Args:
301
- content (str): The content for the message.
302
- original_content (str, optional): The original content for the message.
303
- references (list[ContentReference]): list of ContentReference objects. Defaults to None.
304
- debug_info (dict[str, Any]]): Debug information. Defaults to None.
305
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
306
-
307
- Returns:
308
- ChatMessage: The created message.
309
-
310
- Raises:
311
- Exception: If the creation fails.
312
-
313
- """
314
- chat_message = create_message(
315
- user_id=self._user_id,
316
- company_id=self._company_id,
317
- chat_id=self._chat_id,
318
- assistant_id=self._assistant_id,
319
- role=ChatMessageRole.ASSISTANT,
320
- content=content,
321
- original_content=original_content,
322
- references=references,
323
- debug_info=debug_info,
324
- set_completed_at=set_completed_at,
325
- )
326
- # Update the assistant message id
327
- self._assistant_message_id = chat_message.id or "unknown"
328
- return chat_message
329
-
330
- async def create_assistant_message_async(
331
- self,
332
- content: str,
333
- original_content: str | None = None,
334
- references: list[ContentReference] | None = None,
335
- debug_info: dict | None = None,
336
- set_completed_at: bool | None = False,
337
- ) -> ChatMessage:
338
- """Creates a message in the chat session asynchronously.
339
-
340
- Args:
341
- content (str): The content for the message.
342
- original_content (str, optional): The original content for the message.
343
- references (list[ContentReference]): list of references. Defaults to None.
344
- debug_info (dict[str, Any]]): Debug information. Defaults to None.
345
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
346
-
347
- Returns:
348
- ChatMessage: The created message.
349
-
350
- Raises:
351
- Exception: If the creation fails.
352
-
353
- """
354
- chat_message = await create_message_async(
355
- user_id=self._user_id,
356
- company_id=self._company_id,
357
- chat_id=self._chat_id,
358
- assistant_id=self._assistant_id,
359
- role=ChatMessageRole.ASSISTANT,
360
- content=content,
361
- original_content=original_content,
362
- references=references,
363
- debug_info=debug_info,
364
- set_completed_at=set_completed_at,
365
- )
366
- # Update the assistant message id
367
- self._assistant_message_id = chat_message.id or "unknown"
368
- return chat_message
369
-
370
- def create_user_message(
371
- self,
372
- content: str,
373
- original_content: str | None = None,
374
- references: list[ContentReference] | None = None,
375
- debug_info: dict | None = None,
376
- set_completed_at: bool | None = False,
377
- ) -> ChatMessage:
378
- """Creates a user message in the chat session synchronously.
379
-
380
- Args:
381
- content (str): The content for the message.
382
- original_content (str, optional): The original content for the message.
383
- references (list[ContentReference]): list of ContentReference objects. Defaults to None.
384
- debug_info (dict[str, Any]]): Debug information. Defaults to None.
385
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
386
-
387
- Returns:
388
- ChatMessage: The created message.
389
-
390
- Raises:
391
- Exception: If the creation fails.
392
-
393
- """
394
- chat_message = create_message(
395
- user_id=self._user_id,
396
- company_id=self._company_id,
397
- chat_id=self._chat_id,
398
- assistant_id=self._assistant_id,
399
- role=ChatMessageRole.USER,
400
- content=content,
401
- original_content=original_content,
402
- references=references,
403
- debug_info=debug_info,
404
- set_completed_at=set_completed_at,
405
- )
406
- # Update the user message id
407
- self._user_message_id = chat_message.id or "unknown"
408
- return chat_message
409
-
410
- async def create_user_message_async(
411
- self,
412
- content: str,
413
- original_content: str | None = None,
414
- references: list[ContentReference] | None = None,
415
- debug_info: dict | None = None,
416
- set_completed_at: bool | None = False,
417
- ) -> ChatMessage:
418
- """Creates a user message in the chat session asynchronously.
419
-
420
- Args:
421
- content (str): The content for the message.
422
- original_content (str, optional): The original content for the message.
423
- references (list[ContentReference]): list of references. Defaults to None.
424
- debug_info (dict[str, Any]]): Debug information. Defaults to None.
425
- set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
426
-
427
- Returns:
428
- ChatMessage: The created message.
429
-
430
- Raises:
431
- Exception: If the creation fails.
432
-
433
- """
434
- chat_message = await create_message_async(
435
- user_id=self._user_id,
436
- company_id=self._company_id,
437
- chat_id=self._chat_id,
438
- assistant_id=self._assistant_id,
439
- role=ChatMessageRole.USER,
440
- content=content,
441
- original_content=original_content,
442
- references=references,
443
- debug_info=debug_info,
444
- set_completed_at=set_completed_at,
445
- )
446
- # Update the user message id
447
- self._user_message_id = chat_message.id or "unknown"
448
- return chat_message
449
-
450
- def free_user_input(self) -> None:
451
- """Unblocks the next user input"""
452
- self.modify_assistant_message(set_completed_at=True)
453
-
454
- # History Methods
455
- ############################################################################
456
-
457
- def get_full_history(self) -> list[ChatMessage]:
458
- """Loads the full chat history for the chat session synchronously.
459
-
460
- Returns:
461
- list[ChatMessage]: The full chat history.
462
-
463
- Raises:
464
- Exception: If the loading fails.
465
-
466
- """
467
- return get_full_history(
468
- event_user_id=self._user_id,
469
- event_company_id=self._company_id,
470
- event_payload_chat_id=self._chat_id,
471
- )
472
-
473
- async def get_full_history_async(self) -> list[ChatMessage]:
474
- """Loads the full chat history for the chat session asynchronously.
475
-
476
- Returns:
477
- list[ChatMessage]: The full chat history.
478
-
479
- Raises:
480
- Exception: If the loading fails.
481
-
482
- """
483
- return await get_full_history_async(
484
- event_user_id=self._user_id,
485
- event_company_id=self._company_id,
486
- event_payload_chat_id=self._chat_id,
487
- )
488
-
489
- def get_full_and_selected_history(
490
- self,
491
- token_limit: int,
492
- percent_of_max_tokens: float = DEFAULT_PERCENT_OF_MAX_TOKENS,
493
- max_messages: int = DEFAULT_MAX_MESSAGES,
494
- ) -> tuple[list[ChatMessage], list[ChatMessage]]:
495
- """Loads the chat history for the chat session synchronously.
496
-
497
- Args:
498
- token_limit (int): The maximum number of tokens to load.
499
- percent_of_max_tokens (float): The percentage of the maximum tokens to load. Defaults to 0.15.
500
- max_messages (int): The maximum number of messages to load. Defaults to 4.
501
-
502
- Returns:
503
- tuple[list[ChatMessage], list[ChatMessage]]: The selected and full chat history.
504
-
505
- Raises:
506
- Exception: If the loading fails.
507
-
508
- """
509
- full_history = get_full_history(
510
- event_user_id=self._user_id,
511
- event_company_id=self._company_id,
512
- event_payload_chat_id=self._chat_id,
513
- )
514
- selected_history = get_selection_from_history(
515
- full_history=full_history,
516
- max_tokens=int(round(token_limit * percent_of_max_tokens)),
517
- max_messages=max_messages,
518
- )
519
-
520
- return full_history, selected_history
521
-
522
- async def get_full_and_selected_history_async(
523
- self,
524
- token_limit: int,
525
- percent_of_max_tokens: float = DEFAULT_PERCENT_OF_MAX_TOKENS,
526
- max_messages: int = DEFAULT_MAX_MESSAGES,
527
- ) -> tuple[list[ChatMessage], list[ChatMessage]]:
528
- """Loads the chat history for the chat session asynchronously.
529
-
530
- Args:
531
- token_limit (int): The maximum number of tokens to load.
532
- percent_of_max_tokens (float): The percentage of the maximum tokens to load. Defaults to 0.15.
533
- max_messages (int): The maximum number of messages to load. Defaults to 4.
534
-
535
- Returns:
536
- tuple[list[ChatMessage], list[ChatMessage]]: The selected and full chat history.
537
-
538
- Raises:
539
- Exception: If the loading fails.
540
-
541
- """
542
- full_history = await get_full_history_async(
543
- event_user_id=self._user_id,
544
- event_company_id=self._company_id,
545
- event_payload_chat_id=self._chat_id,
546
- )
547
- selected_history = get_selection_from_history(
548
- full_history=full_history,
549
- max_tokens=int(round(token_limit * percent_of_max_tokens)),
550
- max_messages=max_messages,
551
- )
552
-
553
- return full_history, selected_history
554
-
555
- # Message Assessment Methods
556
- ############################################################################
557
-
558
- def create_message_assessment(
559
- self,
560
- assistant_message_id: str,
561
- status: ChatMessageAssessmentStatus,
562
- type: ChatMessageAssessmentType,
563
- title: str | None = None,
564
- explanation: str | None = None,
565
- label: ChatMessageAssessmentLabel | None = None,
566
- is_visible: bool = True,
567
- ) -> ChatMessageAssessment:
568
- """Creates a message assessment for an assistant message synchronously.
569
-
570
- Args:
571
- assistant_message_id (str): The ID of the assistant message to assess
572
- status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
573
- type (MessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
574
- title (str | None): The title of the assessment
575
- explanation (str | None): Explanation of the assessment
576
- label (MessageAssessmentLabel | None): The assessment label (e.g. "RED")
577
- is_visible (bool): Whether the assessment is visible to users. Defaults to True.
578
-
579
- Returns:
580
- ChatMessageAssessment: The created message assessment
581
-
582
- Raises:
583
- Exception: If the creation fails
584
-
585
- """
586
- return create_message_assessment(
587
- user_id=self._user_id,
588
- company_id=self._company_id,
589
- assistant_message_id=assistant_message_id,
590
- status=status,
591
- type=type,
592
- title=title,
593
- explanation=explanation,
594
- label=label,
595
- is_visible=is_visible,
596
- )
597
-
598
- async def create_message_assessment_async(
599
- self,
600
- assistant_message_id: str,
601
- status: ChatMessageAssessmentStatus,
602
- type: ChatMessageAssessmentType,
603
- title: str | None = None,
604
- explanation: str | None = None,
605
- label: ChatMessageAssessmentLabel | None = None,
606
- is_visible: bool = True,
607
- ) -> ChatMessageAssessment:
608
- """Creates a message assessment for an assistant message asynchronously.
609
-
610
- Args:
611
- assistant_message_id (str): The ID of the assistant message to assess
612
- status (ChatMessageAssessmentStatus): The status of the assessment (e.g. "DONE")
613
- type (ChatMessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
614
- title (str | None): The title of the assessment
615
- explanation (str | None): Explanation of the assessment
616
- label (ChatMessageAssessmentLabel | None): The assessment label (e.g. "RED")
617
- is_visible (bool): Whether the assessment is visible to users. Defaults to True.
618
-
619
- Returns:
620
- ChatMessageAssessment: The created message assessment
621
-
622
- Raises:
623
- Exception: If the creation fails
624
-
625
- """
626
- return await create_message_assessment_async(
627
- user_id=self._user_id,
628
- company_id=self._company_id,
629
- assistant_message_id=assistant_message_id,
630
- status=status,
631
- type=type,
632
- title=title,
633
- explanation=explanation,
634
- label=label,
635
- is_visible=is_visible,
636
- )
637
-
638
- def modify_message_assessment(
639
- self,
640
- assistant_message_id: str,
641
- status: ChatMessageAssessmentStatus,
642
- type: ChatMessageAssessmentType,
643
- title: str | None = None,
644
- explanation: str | None = None,
645
- label: ChatMessageAssessmentLabel | None = None,
646
- ) -> ChatMessageAssessment:
647
- """Modifies a message assessment for an assistant message synchronously.
648
-
649
- Args:
650
- assistant_message_id (str): The ID of the assistant message to assess
651
- status (MessageAssessmentStatus): The status of the assessment (e.g. "DONE")
652
- title (str | None): The title of the assessment
653
- explanation (str | None): Explanation of the assessment
654
- label (ChatMessageAssessmentLabel | None): The assessment label (e.g. "RED")
655
- type (ChatMessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
656
-
657
- Returns:
658
- dict: The modified message assessment
659
-
660
- Raises:
661
- Exception: If the modification fails
662
-
663
- """
664
- return modify_message_assessment(
665
- user_id=self._user_id,
666
- company_id=self._company_id,
667
- assistant_message_id=assistant_message_id,
668
- status=status,
669
- type=type,
670
- title=title,
671
- explanation=explanation,
672
- label=label,
673
- )
674
-
675
- async def modify_message_assessment_async(
676
- self,
677
- assistant_message_id: str,
678
- type: ChatMessageAssessmentType,
679
- title: str | None = None,
680
- status: ChatMessageAssessmentStatus | None = None,
681
- explanation: str | None = None,
682
- label: ChatMessageAssessmentLabel | None = None,
683
- ) -> ChatMessageAssessment:
684
- """Modifies a message assessment for an assistant message asynchronously.
685
-
686
- Args:
687
- assistant_message_id (str): The ID of the assistant message to assess
688
- status (ChatMessageAssessmentStatus): The status of the assessment (e.g. "DONE")
689
- title (str | None): The title of the assessment
690
- explanation (str | None): Explanation of the assessment
691
- label (ChatMessageAssessmentLabel | None): The assessment label (e.g. "RED")
692
- type (ChatMessageAssessmentType): The type of assessment (e.g. "HALLUCINATION")
693
-
694
- Returns:
695
- ChatMessageAssessment: The modified message assessment
696
-
697
- Raises:
698
- Exception: If the modification fails
699
-
700
- """
701
- return await modify_message_assessment_async(
702
- user_id=self._user_id,
703
- company_id=self._company_id,
704
- assistant_message_id=assistant_message_id,
705
- status=status,
706
- type=type,
707
- title=title,
708
- explanation=explanation,
709
- label=label,
710
- )
711
-
712
- # Message Log Methods
713
- ############################################################################
714
-
715
- def create_message_log(
716
- self,
717
- *,
718
- message_id: str,
719
- text: str,
720
- status: MessageLogStatus,
721
- order: int,
722
- details: MessageLogDetails | None = None,
723
- uncited_references: MessageLogUncitedReferences | None = None,
724
- references: list[ContentReference] | None = None,
725
- ) -> MessageLog:
726
- """Creates a message log for tracking execution steps synchronously.
727
-
728
- Args:
729
- message_id (str): The ID of the message this log belongs to
730
- text (str): The log text content
731
- status (MessageLogStatus): The status of this log entry
732
- order (int): The order/sequence number of this log entry
733
- details (MessageLogDetails | None): Additional details about this log entry
734
- uncited_references (MessageLogUncitedReferences | None): References that are not cited
735
- references (list[ContentReference] | None): List of references for this log
736
-
737
- Returns:
738
- MessageLog: The created message log
739
-
740
- Raises:
741
- Exception: If the creation fails
742
-
743
- """
744
- return create_message_log(
745
- user_id=self._user_id,
746
- company_id=self._company_id,
747
- message_id=message_id,
748
- text=text,
749
- status=status,
750
- order=order,
751
- details=details,
752
- uncited_references=uncited_references,
753
- references=references,
754
- )
755
-
756
- async def create_message_log_async(
757
- self,
758
- *,
759
- message_id: str,
760
- text: str,
761
- status: MessageLogStatus,
762
- order: int,
763
- details: MessageLogDetails | None = None,
764
- uncited_references: MessageLogUncitedReferences | None = None,
765
- references: list[ContentReference] | None = None,
766
- ) -> MessageLog:
767
- """Creates a message log for tracking execution steps asynchronously.
768
-
769
- Args:
770
- message_id (str): The ID of the message this log belongs to
771
- text (str): The log text content
772
- status (MessageLogStatus): The status of this log entry
773
- order (int): The order/sequence number of this log entry
774
- details (MessageLogDetails | None): Additional details about this log entry
775
- uncited_references (MessageLogUncitedReferences | None): References that are not cited
776
- references (list[ContentReference] | None): List of references for this log
777
-
778
- Returns:
779
- MessageLog: The created message log
780
-
781
- Raises:
782
- Exception: If the creation fails
783
-
784
- """
785
- return await create_message_log_async(
786
- user_id=self._user_id,
787
- company_id=self._company_id,
788
- message_id=message_id,
789
- text=text,
790
- status=status,
791
- order=order,
792
- details=details,
793
- uncited_references=uncited_references,
794
- references=references,
795
- )
796
-
797
- def update_message_log(
798
- self,
799
- *,
800
- message_log_id: str,
801
- order: int,
802
- text: str | None = None,
803
- status: MessageLogStatus | None = None,
804
- details: MessageLogDetails | None = None,
805
- uncited_references: MessageLogUncitedReferences | None = None,
806
- references: list[ContentReference] | None = None,
807
- ) -> MessageLog:
808
- """Updates a message log synchronously.
809
-
810
- Args:
811
- message_log_id (str): The ID of the message log to update
812
- order (int): The order/sequence number (required)
813
- text (str | None): The updated log text content
814
- status (MessageLogStatus | None): The updated status
815
- details (MessageLogDetails | None): Updated additional details
816
- uncited_references (MessageLogUncitedReferences | None): Updated uncited references
817
- references (list[ContentReference] | None): Updated list of references
818
-
819
- Returns:
820
- MessageLog: The updated message log
821
-
822
- Raises:
823
- Exception: If the update fails
824
-
825
- """
826
- return update_message_log(
827
- user_id=self._user_id,
828
- company_id=self._company_id,
829
- message_log_id=message_log_id,
830
- order=order,
831
- text=text,
832
- status=status,
833
- details=details,
834
- uncited_references=uncited_references,
835
- references=references,
836
- )
837
-
838
- async def update_message_log_async(
839
- self,
840
- *,
841
- message_log_id: str,
842
- order: int,
843
- text: str | None = None,
844
- status: MessageLogStatus | None = None,
845
- details: MessageLogDetails | None = None,
846
- uncited_references: MessageLogUncitedReferences | None = None,
847
- references: list[ContentReference] | None = None,
848
- ) -> MessageLog:
849
- """Updates a message log asynchronously.
850
-
851
- Args:
852
- message_log_id (str): The ID of the message log to update
853
- order (int): The order/sequence number (required)
854
- text (str | None): The updated log text content
855
- status (MessageLogStatus | None): The updated status
856
- details (MessageLogDetails | None): Updated additional details
857
- uncited_references (MessageLogUncitedReferences | None): Updated uncited references
858
- references (list[ContentReference] | None): Updated list of references
859
-
860
- Returns:
861
- MessageLog: The updated message log
862
-
863
- Raises:
864
- Exception: If the update fails
865
-
866
- """
867
- return await update_message_log_async(
868
- user_id=self._user_id,
869
- company_id=self._company_id,
870
- message_log_id=message_log_id,
871
- order=order,
872
- text=text,
873
- status=status,
874
- details=details,
875
- uncited_references=uncited_references,
876
- references=references,
877
- )
878
-
879
- def create_assistant_message_log(
880
- self,
881
- *,
882
- text: str,
883
- status: MessageLogStatus,
884
- order: int,
885
- details: MessageLogDetails | None = None,
886
- uncited_references: MessageLogUncitedReferences | None = None,
887
- references: list[ContentReference] | None = None,
888
- ) -> MessageLog:
889
- """Creates a message log for the current assistant message synchronously.
890
-
891
- This is a convenience method that uses the current assistant message ID.
892
-
893
- Args:
894
- text (str): The log text content
895
- status (MessageLogStatus): The status of this log entry
896
- order (int): The order/sequence number of this log entry
897
- details (MessageLogDetails | None): Additional details about this log entry
898
- uncited_references (MessageLogUncitedReferences | None): References that are not cited
899
- references (list[ContentReference] | None): List of references for this log
900
-
901
- Returns:
902
- MessageLog: The created message log
903
-
904
- Raises:
905
- Exception: If the creation fails
906
-
907
- """
908
- return self.create_message_log(
909
- message_id=self._assistant_message_id,
910
- text=text,
911
- status=status,
912
- order=order,
913
- details=details,
914
- uncited_references=uncited_references,
915
- references=references,
916
- )
917
-
918
- async def create_assistant_message_log_async(
919
- self,
920
- *,
921
- text: str,
922
- status: MessageLogStatus,
923
- order: int,
924
- details: MessageLogDetails | None = None,
925
- uncited_references: MessageLogUncitedReferences | None = None,
926
- references: list[ContentReference] | None = None,
927
- ) -> MessageLog:
928
- """Creates a message log for the current assistant message asynchronously.
929
-
930
- This is a convenience method that uses the current assistant message ID.
931
-
932
- Args:
933
- text (str): The log text content
934
- status (MessageLogStatus): The status of this log entry
935
- order (int): The order/sequence number of this log entry
936
- details (MessageLogDetails | None): Additional details about this log entry
937
- uncited_references (MessageLogUncitedReferences | None): References that are not cited
938
- references (list[ContentReference] | None): List of references for this log
939
-
940
- Returns:
941
- MessageLog: The created message log
942
-
943
- Raises:
944
- Exception: If the creation fails
945
-
946
- """
947
- return await self.create_message_log_async(
948
- message_id=self._assistant_message_id,
949
- text=text,
950
- status=status,
951
- order=order,
952
- details=details,
953
- uncited_references=uncited_references,
954
- references=references,
955
- )
956
-
957
- # Message Execution Methods
958
- ############################################################################
959
-
960
- def create_message_execution(
961
- self,
962
- *,
963
- message_id: str,
964
- type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
965
- seconds_remaining: int | None = None,
966
- percentage_completed: int | None = None,
967
- ) -> MessageExecution:
968
- """Creates a message execution for tracking long-running operations synchronously.
969
-
970
- Args:
971
- message_id (str): The ID of the message this execution belongs to
972
- type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
973
- seconds_remaining (int | None): Estimated seconds remaining for completion
974
- percentage_completed (int | None): Percentage of completion (0-100)
975
-
976
- Returns:
977
- MessageExecution: The created message execution
978
-
979
- Raises:
980
- Exception: If the creation fails
981
-
982
- """
983
- return create_message_execution(
984
- user_id=self._user_id,
985
- company_id=self._company_id,
986
- message_id=message_id,
987
- chat_id=self._chat_id,
988
- type=type,
989
- seconds_remaining=seconds_remaining,
990
- percentage_completed=percentage_completed,
991
- )
992
-
993
- async def create_message_execution_async(
994
- self,
995
- *,
996
- message_id: str,
997
- type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
998
- seconds_remaining: int | None = None,
999
- percentage_completed: int | None = None,
1000
- ) -> MessageExecution:
1001
- """Creates a message execution for tracking long-running operations asynchronously.
1002
-
1003
- Args:
1004
- message_id (str): The ID of the message this execution belongs to
1005
- type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
1006
- seconds_remaining (int | None): Estimated seconds remaining for completion
1007
- percentage_completed (int | None): Percentage of completion (0-100)
1008
-
1009
- Returns:
1010
- MessageExecution: The created message execution
1011
-
1012
- Raises:
1013
- Exception: If the creation fails
1014
-
1015
- """
1016
- return await create_message_execution_async(
1017
- user_id=self._user_id,
1018
- company_id=self._company_id,
1019
- message_id=message_id,
1020
- chat_id=self._chat_id,
1021
- type=type,
1022
- seconds_remaining=seconds_remaining,
1023
- percentage_completed=percentage_completed,
1024
- )
1025
-
1026
- def get_message_execution(
1027
- self,
1028
- *,
1029
- message_id: str,
1030
- ) -> MessageExecution:
1031
- """Gets a message execution by message ID synchronously.
1032
-
1033
- Args:
1034
- message_id (str): The ID of the message to get execution for
1035
-
1036
- Returns:
1037
- MessageExecution: The message execution
1038
-
1039
- Raises:
1040
- Exception: If the retrieval fails
1041
-
1042
- """
1043
- return get_message_execution(
1044
- user_id=self._user_id,
1045
- company_id=self._company_id,
1046
- message_id=message_id,
1047
- )
1048
-
1049
- async def get_message_execution_async(
1050
- self,
1051
- *,
1052
- message_id: str,
1053
- ) -> MessageExecution:
1054
- """Gets a message execution by message ID asynchronously.
1055
-
1056
- Args:
1057
- message_id (str): The ID of the message to get execution for
1058
-
1059
- Returns:
1060
- MessageExecution: The message execution
1061
-
1062
- Raises:
1063
- Exception: If the retrieval fails
1064
-
1065
- """
1066
- return await get_message_execution_async(
1067
- user_id=self._user_id,
1068
- company_id=self._company_id,
1069
- message_id=message_id,
1070
- )
1071
-
1072
- def update_message_execution(
1073
- self,
1074
- *,
1075
- message_id: str,
1076
- status: MessageExecutionUpdateStatus,
1077
- seconds_remaining: int | None = None,
1078
- percentage_completed: int | None = None,
1079
- ) -> MessageExecution:
1080
- """Updates a message execution synchronously.
1081
-
1082
- Args:
1083
- message_id (str): The ID of the message to update execution for
1084
- status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED)
1085
- seconds_remaining (int | None): Updated estimated seconds remaining
1086
- percentage_completed (int | None): Updated percentage of completion (0-100)
1087
-
1088
- Returns:
1089
- MessageExecution: The updated message execution
1090
-
1091
- Raises:
1092
- Exception: If the update fails
1093
-
1094
- """
1095
- return update_message_execution(
1096
- user_id=self._user_id,
1097
- company_id=self._company_id,
1098
- message_id=message_id,
1099
- status=status,
1100
- seconds_remaining=seconds_remaining,
1101
- percentage_completed=percentage_completed,
1102
- )
1103
-
1104
- async def update_message_execution_async(
1105
- self,
1106
- *,
1107
- message_id: str,
1108
- status: MessageExecutionUpdateStatus,
1109
- seconds_remaining: int | None = None,
1110
- percentage_completed: int | None = None,
1111
- ) -> MessageExecution:
1112
- """Updates a message execution asynchronously.
1113
-
1114
- Args:
1115
- message_id (str): The ID of the message to update execution for
1116
- status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED)
1117
- seconds_remaining (int | None): Updated estimated seconds remaining
1118
- percentage_completed (int | None): Updated percentage of completion (0-100)
1119
-
1120
- Returns:
1121
- MessageExecution: The updated message execution
1122
-
1123
- Raises:
1124
- Exception: If the update fails
1125
-
1126
- """
1127
- return await update_message_execution_async(
1128
- user_id=self._user_id,
1129
- company_id=self._company_id,
1130
- message_id=message_id,
1131
- status=status,
1132
- seconds_remaining=seconds_remaining,
1133
- percentage_completed=percentage_completed,
1134
- )
1135
-
1136
- def create_assistant_message_execution(
1137
- self,
1138
- *,
1139
- type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
1140
- seconds_remaining: int | None = None,
1141
- percentage_completed: int | None = None,
1142
- ) -> MessageExecution:
1143
- """Creates a message execution for the current assistant message synchronously.
1144
-
1145
- This is a convenience method that uses the current assistant message ID.
1146
-
1147
- Args:
1148
- type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
1149
- seconds_remaining (int | None): Estimated seconds remaining for completion
1150
- percentage_completed (int | None): Percentage of completion (0-100)
1151
-
1152
- Returns:
1153
- MessageExecution: The created message execution
1154
-
1155
- Raises:
1156
- Exception: If the creation fails
1157
-
1158
- """
1159
- return self.create_message_execution(
1160
- message_id=self._assistant_message_id,
1161
- type=type,
1162
- seconds_remaining=seconds_remaining,
1163
- percentage_completed=percentage_completed,
1164
- )
1165
-
1166
- async def create_assistant_message_execution_async(
1167
- self,
1168
- *,
1169
- type: MessageExecutionType = MessageExecutionType.DEEP_RESEARCH,
1170
- seconds_remaining: int | None = None,
1171
- percentage_completed: int | None = None,
1172
- ) -> MessageExecution:
1173
- """Creates a message execution for the current assistant message asynchronously.
1174
-
1175
- This is a convenience method that uses the current assistant message ID.
1176
-
1177
- Args:
1178
- type (MessageExecutionType): The type of execution. Defaults to DEEP_RESEARCH.
1179
- seconds_remaining (int | None): Estimated seconds remaining for completion
1180
- percentage_completed (int | None): Percentage of completion (0-100)
1181
-
1182
- Returns:
1183
- MessageExecution: The created message execution
1184
-
1185
- Raises:
1186
- Exception: If the creation fails
1187
-
1188
- """
1189
- return await self.create_message_execution_async(
1190
- message_id=self._assistant_message_id,
1191
- type=type,
1192
- seconds_remaining=seconds_remaining,
1193
- percentage_completed=percentage_completed,
1194
- )
1195
-
1196
- def get_assistant_message_execution(self) -> MessageExecution:
1197
- """Gets the message execution for the current assistant message synchronously.
1198
-
1199
- This is a convenience method that uses the current assistant message ID.
1200
-
1201
- Returns:
1202
- MessageExecution: The message execution
1203
-
1204
- Raises:
1205
- Exception: If the retrieval fails
1206
-
1207
- """
1208
- return self.get_message_execution(message_id=self._assistant_message_id)
1209
-
1210
- async def get_assistant_message_execution_async(self) -> MessageExecution:
1211
- """Gets the message execution for the current assistant message asynchronously.
1212
-
1213
- This is a convenience method that uses the current assistant message ID.
1214
-
1215
- Returns:
1216
- MessageExecution: The message execution
1217
-
1218
- Raises:
1219
- Exception: If the retrieval fails
1220
-
1221
- """
1222
- return await self.get_message_execution_async(
1223
- message_id=self._assistant_message_id
1224
- )
1225
-
1226
- def update_assistant_message_execution(
1227
- self,
1228
- *,
1229
- status: MessageExecutionUpdateStatus,
1230
- seconds_remaining: int | None = None,
1231
- percentage_completed: int | None = None,
1232
- ) -> MessageExecution:
1233
- """Updates the message execution for the current assistant message synchronously.
1234
-
1235
- This is a convenience method that uses the current assistant message ID.
1236
-
1237
- Args:
1238
- status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED)
1239
- seconds_remaining (int | None): Updated estimated seconds remaining
1240
- percentage_completed (int | None): Updated percentage of completion (0-100)
1241
-
1242
- Returns:
1243
- MessageExecution: The updated message execution
1244
-
1245
- Raises:
1246
- Exception: If the update fails
1247
-
1248
- """
1249
- return self.update_message_execution(
1250
- message_id=self._assistant_message_id,
1251
- status=status,
1252
- seconds_remaining=seconds_remaining,
1253
- percentage_completed=percentage_completed,
1254
- )
1255
-
1256
- async def update_assistant_message_execution_async(
1257
- self,
1258
- *,
1259
- status: MessageExecutionUpdateStatus,
1260
- seconds_remaining: int | None = None,
1261
- percentage_completed: int | None = None,
1262
- ) -> MessageExecution:
1263
- """Updates the message execution for the current assistant message asynchronously.
1264
-
1265
- This is a convenience method that uses the current assistant message ID.
1266
-
1267
- Args:
1268
- status (MessageExecutionUpdateStatus): The updated status (COMPLETED or FAILED)
1269
- seconds_remaining (int | None): Updated estimated seconds remaining
1270
- percentage_completed (int | None): Updated percentage of completion (0-100)
1271
-
1272
- Returns:
1273
- MessageExecution: The updated message execution
1274
-
1275
- Raises:
1276
- Exception: If the update fails
1277
-
1278
- """
1279
- return await self.update_message_execution_async(
1280
- message_id=self._assistant_message_id,
1281
- status=status,
1282
- seconds_remaining=seconds_remaining,
1283
- percentage_completed=percentage_completed,
1284
- )
1285
-
1286
- # Language Model Methods
1287
- ############################################################################
1288
-
1289
- @deprecated("Use complete_with_references instead")
1290
- def stream_complete(
1291
- self,
1292
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1293
- model_name: LanguageModelName | str,
1294
- content_chunks: list[ContentChunk] | None = None,
1295
- debug_info: dict = {},
1296
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1297
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1298
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1299
- start_text: str | None = None,
1300
- other_options: dict | None = None,
1301
- ) -> LanguageModelStreamResponse:
1302
- return self.complete_with_references(
1303
- messages=messages,
1304
- model_name=model_name,
1305
- content_chunks=content_chunks,
1306
- debug_info=debug_info,
1307
- temperature=temperature,
1308
- timeout=timeout,
1309
- tools=tools,
1310
- start_text=start_text,
1311
- other_options=other_options,
1312
- )
1313
-
1314
- def complete_with_references(
1315
- self,
1316
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1317
- model_name: LanguageModelName | str,
1318
- content_chunks: list[ContentChunk] | None = None,
1319
- debug_info: dict | None = None,
1320
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1321
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1322
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1323
- start_text: str | None = None,
1324
- other_options: dict | None = None,
1325
- ) -> LanguageModelStreamResponse:
1326
- """Streams a completion in the chat session synchronously."""
1327
- return stream_complete_with_references(
1328
- company_id=self._company_id,
1329
- user_id=self._user_id,
1330
- assistant_message_id=self._assistant_message_id,
1331
- user_message_id=self._user_message_id,
1332
- chat_id=self._chat_id,
1333
- assistant_id=self._assistant_id,
1334
- messages=messages,
1335
- model_name=model_name,
1336
- content_chunks=content_chunks,
1337
- debug_info=debug_info,
1338
- temperature=temperature,
1339
- timeout=timeout,
1340
- tools=tools,
1341
- start_text=start_text,
1342
- other_options=other_options,
1343
- )
1344
-
1345
- def complete(
1346
- self,
1347
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1348
- model_name: LanguageModelName | str,
1349
- content_chunks: list[ContentChunk] | None = None,
1350
- debug_info: dict | None = None,
1351
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1352
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1353
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1354
- start_text: str | None = None,
1355
- other_options: dict | None = None,
1356
- ) -> LanguageModelResponse:
1357
- response = self.complete_with_references(
1358
- messages=messages,
1359
- model_name=model_name,
1360
- content_chunks=content_chunks,
1361
- debug_info=debug_info,
1362
- temperature=temperature,
1363
- timeout=timeout,
1364
- tools=tools,
1365
- start_text=start_text,
1366
- other_options=other_options,
1367
- )
1368
-
1369
- return LanguageModelResponse.from_stream_response(response)
1370
-
1371
- @deprecated("use complete_with_references_async instead.")
1372
- async def stream_complete_async(
1373
- self,
1374
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1375
- model_name: LanguageModelName | str,
1376
- content_chunks: list[ContentChunk] | None = None,
1377
- debug_info: dict | None = None,
1378
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1379
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1380
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1381
- start_text: str | None = None,
1382
- other_options: dict | None = None,
1383
- ) -> LanguageModelStreamResponse:
1384
- """Stream a completion in the chat session asynchronously."""
1385
- return await self.complete_with_references_async(
1386
- messages=messages,
1387
- model_name=model_name,
1388
- content_chunks=content_chunks,
1389
- debug_info=debug_info,
1390
- temperature=temperature,
1391
- timeout=timeout,
1392
- tools=tools,
1393
- start_text=start_text,
1394
- other_options=other_options,
1395
- )
1396
-
1397
- async def complete_with_references_async(
1398
- self,
1399
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1400
- model_name: LanguageModelName | str,
1401
- content_chunks: list[ContentChunk] | None = None,
1402
- debug_info: dict | None = None,
1403
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1404
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1405
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1406
- start_text: str | None = None,
1407
- other_options: dict | None = None,
1408
- ) -> LanguageModelStreamResponse:
1409
- return await stream_complete_with_references_async(
1410
- company_id=self._company_id,
1411
- user_id=self._user_id,
1412
- assistant_message_id=self._assistant_message_id,
1413
- user_message_id=self._user_message_id,
1414
- chat_id=self._chat_id,
1415
- assistant_id=self._assistant_id,
1416
- messages=messages,
1417
- model_name=model_name,
1418
- content_chunks=content_chunks,
1419
- debug_info=debug_info,
1420
- temperature=temperature,
1421
- timeout=timeout,
1422
- tools=tools,
1423
- start_text=start_text,
1424
- other_options=other_options,
1425
- )
1426
-
1427
- async def complete_async(
1428
- self,
1429
- messages: LanguageModelMessages | list[ChatCompletionMessageParam],
1430
- model_name: LanguageModelName | str,
1431
- content_chunks: list[ContentChunk] | None,
1432
- debug_info: dict | None = None,
1433
- temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
1434
- timeout: int = DEFAULT_COMPLETE_TIMEOUT,
1435
- tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
1436
- start_text: str | None = None,
1437
- other_options: dict | None = None,
1438
- ) -> LanguageModelResponse:
1439
- response = self.complete_with_references_async(
1440
- messages=messages,
1441
- model_name=model_name,
1442
- content_chunks=content_chunks,
1443
- debug_info=debug_info,
1444
- temperature=temperature,
1445
- timeout=timeout,
1446
- tools=tools,
1447
- start_text=start_text,
1448
- other_options=other_options,
1449
- )
1450
-
1451
- return LanguageModelResponse.from_stream_response(await response)
1452
-
1453
- # Chat Content Methods
1454
- ############################################################################
1455
-
1456
- def upload_to_chat_from_bytes(
1457
- self,
1458
- *,
1459
- content: bytes,
1460
- content_name: str,
1461
- mime_type: str,
1462
- scope_id: str | None = None,
1463
- skip_ingestion: bool = False,
1464
- ingestion_config: unique_sdk.Content.IngestionConfig | None = None,
1465
- metadata: dict[str, Any] | None = None,
1466
- ) -> Content:
1467
- return upload_content_from_bytes(
1468
- user_id=self._user_id,
1469
- company_id=self._company_id,
1470
- content=content,
1471
- content_name=content_name,
1472
- mime_type=mime_type,
1473
- scope_id=scope_id,
1474
- chat_id=self._chat_id,
1475
- skip_ingestion=skip_ingestion,
1476
- ingestion_config=ingestion_config,
1477
- metadata=metadata,
1478
- )
1479
-
1480
- def download_chat_content_to_bytes(self, *, content_id: str) -> bytes:
1481
- return download_content_to_bytes(
1482
- user_id=self._user_id,
1483
- company_id=self._company_id,
1484
- content_id=content_id,
1485
- chat_id=self._chat_id,
1486
- )
1487
-
1488
- def download_chat_images_and_documents(self) -> tuple[list[Content], list[Content]]:
1489
- images: list[Content] = []
1490
- files: list[Content] = []
1491
- for c in search_contents(
1492
- user_id=self._user_id,
1493
- company_id=self._company_id,
1494
- chat_id=self._chat_id,
1495
- where={"ownerId": {"equals": self._chat_id}},
1496
- ):
1497
- if is_file_content(filename=c.key):
1498
- files.append(c)
1499
- if is_image_content(filename=c.key):
1500
- images.append(c)
1501
- return images, files
92
+ __all__ = [
93
+ # Main Service Class
94
+ "ChatService",
95
+ "ChatServiceDeprecated",
96
+ # Chat Functions
97
+ "create_message",
98
+ "create_message_assessment",
99
+ "create_message_assessment_async",
100
+ "create_message_async",
101
+ "create_message_execution",
102
+ "create_message_execution_async",
103
+ "create_message_log",
104
+ "create_message_log_async",
105
+ "get_full_history",
106
+ "get_full_history_async",
107
+ "get_message_execution",
108
+ "get_message_execution_async",
109
+ "get_selection_from_history",
110
+ "modify_message",
111
+ "modify_message_assessment",
112
+ "modify_message_assessment_async",
113
+ "modify_message_async",
114
+ "stream_complete_with_references",
115
+ "stream_complete_with_references_async",
116
+ "update_message_execution",
117
+ "update_message_execution_async",
118
+ "update_message_log",
119
+ "update_message_log_async",
120
+ # Chat Constants
121
+ "DEFAULT_MAX_MESSAGES",
122
+ "DEFAULT_PERCENT_OF_MAX_TOKENS",
123
+ "DOMAIN_NAME",
124
+ # Chat Schemas
125
+ "ChatMessage",
126
+ "ChatMessageAssessment",
127
+ "ChatMessageAssessmentLabel",
128
+ "ChatMessageAssessmentStatus",
129
+ "ChatMessageAssessmentType",
130
+ "ChatMessageRole",
131
+ "MessageExecution",
132
+ "MessageExecutionType",
133
+ "MessageExecutionUpdateStatus",
134
+ "MessageLog",
135
+ "MessageLogDetails",
136
+ "MessageLogStatus",
137
+ "MessageLogUncitedReferences",
138
+ # Content Functions
139
+ "download_content_to_bytes",
140
+ "search_contents",
141
+ "upload_content_from_bytes",
142
+ # Content Schemas
143
+ "Content",
144
+ "ContentChunk",
145
+ "ContentReference",
146
+ # Language Model Constants
147
+ "DEFAULT_COMPLETE_TEMPERATURE",
148
+ "DEFAULT_COMPLETE_TIMEOUT",
149
+ # Language Model Infos
150
+ "LanguageModelName",
151
+ # Language Model Schemas
152
+ "LanguageModelMessages",
153
+ "LanguageModelResponse",
154
+ "LanguageModelStreamResponse",
155
+ "LanguageModelTool",
156
+ "LanguageModelToolDescription",
157
+ ]