unique_toolkit 0.8.6__py3-none-any.whl → 0.8.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unique_toolkit/app/__init__.py +3 -3
- unique_toolkit/chat/functions.py +82 -74
- unique_toolkit/chat/schemas.py +48 -2
- unique_toolkit/chat/service.py +148 -147
- unique_toolkit/framework_utilities/openai/message_builder.py +21 -12
- unique_toolkit/language_model/builder.py +23 -11
- unique_toolkit/language_model/functions.py +109 -10
- unique_toolkit/language_model/schemas.py +49 -11
- {unique_toolkit-0.8.6.dist-info → unique_toolkit-0.8.8.dist-info}/METADATA +11 -1
- {unique_toolkit-0.8.6.dist-info → unique_toolkit-0.8.8.dist-info}/RECORD +12 -12
- {unique_toolkit-0.8.6.dist-info → unique_toolkit-0.8.8.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.8.6.dist-info → unique_toolkit-0.8.8.dist-info}/WHEEL +0 -0
unique_toolkit/chat/service.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import Optional
|
|
3
2
|
|
|
3
|
+
from openai.types.chat.chat_completion_message_param import ChatCompletionMessageParam
|
|
4
4
|
from typing_extensions import deprecated
|
|
5
5
|
|
|
6
6
|
from unique_toolkit.app.schemas import ChatEvent, Event
|
|
@@ -55,9 +55,7 @@ logger = logging.getLogger(f"toolkit.{DOMAIN_NAME}.{__name__}")
|
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
class ChatService:
|
|
58
|
-
"""
|
|
59
|
-
Provides all functionalities to manage the chat session.
|
|
60
|
-
"""
|
|
58
|
+
"""Provides all functionalities to manage the chat session."""
|
|
61
59
|
|
|
62
60
|
def __init__(self, event: ChatEvent | Event):
|
|
63
61
|
self._event = event
|
|
@@ -71,11 +69,10 @@ class ChatService:
|
|
|
71
69
|
|
|
72
70
|
@property
|
|
73
71
|
@deprecated(
|
|
74
|
-
"The event property is deprecated and will be removed in a future version."
|
|
72
|
+
"The event property is deprecated and will be removed in a future version.",
|
|
75
73
|
)
|
|
76
74
|
def event(self) -> Event | ChatEvent:
|
|
77
|
-
"""
|
|
78
|
-
Get the event object (deprecated).
|
|
75
|
+
"""Get the event object (deprecated).
|
|
79
76
|
|
|
80
77
|
Returns:
|
|
81
78
|
Event | BaseEvent | None: The event object.
|
|
@@ -85,11 +82,10 @@ class ChatService:
|
|
|
85
82
|
|
|
86
83
|
@property
|
|
87
84
|
@deprecated(
|
|
88
|
-
"The company_id property is deprecated and will be removed in a future version."
|
|
85
|
+
"The company_id property is deprecated and will be removed in a future version.",
|
|
89
86
|
)
|
|
90
87
|
def company_id(self) -> str:
|
|
91
|
-
"""
|
|
92
|
-
Get the company identifier (deprecated).
|
|
88
|
+
"""Get the company identifier (deprecated).
|
|
93
89
|
|
|
94
90
|
Returns:
|
|
95
91
|
str | None: The company identifier.
|
|
@@ -99,179 +95,179 @@ class ChatService:
|
|
|
99
95
|
|
|
100
96
|
@company_id.setter
|
|
101
97
|
@deprecated(
|
|
102
|
-
"The company_id setter is deprecated and will be removed in a future version."
|
|
98
|
+
"The company_id setter is deprecated and will be removed in a future version.",
|
|
103
99
|
)
|
|
104
100
|
def company_id(self, value: str) -> None:
|
|
105
|
-
"""
|
|
106
|
-
Set the company identifier (deprecated).
|
|
101
|
+
"""Set the company identifier (deprecated).
|
|
107
102
|
|
|
108
103
|
Args:
|
|
109
104
|
value (str | None): The company identifier.
|
|
105
|
+
|
|
110
106
|
"""
|
|
111
107
|
self._company_id = value
|
|
112
108
|
|
|
113
109
|
@property
|
|
114
110
|
@deprecated(
|
|
115
|
-
"The user_id property is deprecated and will be removed in a future version."
|
|
111
|
+
"The user_id property is deprecated and will be removed in a future version.",
|
|
116
112
|
)
|
|
117
113
|
def user_id(self) -> str:
|
|
118
|
-
"""
|
|
119
|
-
Get the user identifier (deprecated).
|
|
114
|
+
"""Get the user identifier (deprecated).
|
|
120
115
|
|
|
121
116
|
Returns:
|
|
122
117
|
str | None: The user identifier.
|
|
118
|
+
|
|
123
119
|
"""
|
|
124
120
|
return self._user_id
|
|
125
121
|
|
|
126
122
|
@user_id.setter
|
|
127
123
|
@deprecated(
|
|
128
|
-
"The user_id setter is deprecated and will be removed in a future version."
|
|
124
|
+
"The user_id setter is deprecated and will be removed in a future version.",
|
|
129
125
|
)
|
|
130
126
|
def user_id(self, value: str) -> None:
|
|
131
|
-
"""
|
|
132
|
-
Set the user identifier (deprecated).
|
|
127
|
+
"""Set the user identifier (deprecated).
|
|
133
128
|
|
|
134
129
|
Args:
|
|
135
130
|
value (str | None): The user identifier.
|
|
131
|
+
|
|
136
132
|
"""
|
|
137
133
|
self._user_id = value
|
|
138
134
|
|
|
139
135
|
@property
|
|
140
136
|
@deprecated(
|
|
141
|
-
"The assistant_message_id property is deprecated and will be removed in a future version."
|
|
137
|
+
"The assistant_message_id property is deprecated and will be removed in a future version.",
|
|
142
138
|
)
|
|
143
139
|
def assistant_message_id(self) -> str:
|
|
144
|
-
"""
|
|
145
|
-
Get the assistant message identifier (deprecated).
|
|
140
|
+
"""Get the assistant message identifier (deprecated).
|
|
146
141
|
|
|
147
142
|
Returns:
|
|
148
143
|
str | None: The assistant message identifier.
|
|
144
|
+
|
|
149
145
|
"""
|
|
150
146
|
return self._assistant_message_id
|
|
151
147
|
|
|
152
148
|
@assistant_message_id.setter
|
|
153
149
|
@deprecated(
|
|
154
|
-
"The assistant_message_id setter is deprecated and will be removed in a future version."
|
|
150
|
+
"The assistant_message_id setter is deprecated and will be removed in a future version.",
|
|
155
151
|
)
|
|
156
152
|
def assistant_message_id(self, value: str) -> None:
|
|
157
|
-
"""
|
|
158
|
-
Set the assistant message identifier (deprecated).
|
|
153
|
+
"""Set the assistant message identifier (deprecated).
|
|
159
154
|
|
|
160
155
|
Args:
|
|
161
156
|
value (str | None): The assistant message identifier.
|
|
157
|
+
|
|
162
158
|
"""
|
|
163
159
|
self._assistant_message_id = value
|
|
164
160
|
|
|
165
161
|
@property
|
|
166
162
|
@deprecated(
|
|
167
|
-
"The user_message_id property is deprecated and will be removed in a future version."
|
|
163
|
+
"The user_message_id property is deprecated and will be removed in a future version.",
|
|
168
164
|
)
|
|
169
165
|
def user_message_id(self) -> str:
|
|
170
|
-
"""
|
|
171
|
-
Get the user message identifier (deprecated).
|
|
166
|
+
"""Get the user message identifier (deprecated).
|
|
172
167
|
|
|
173
168
|
Returns:
|
|
174
169
|
str | None: The user message identifier.
|
|
170
|
+
|
|
175
171
|
"""
|
|
176
172
|
return self._user_message_id
|
|
177
173
|
|
|
178
174
|
@user_message_id.setter
|
|
179
175
|
@deprecated(
|
|
180
|
-
"The user_message_id setter is deprecated and will be removed in a future version."
|
|
176
|
+
"The user_message_id setter is deprecated and will be removed in a future version.",
|
|
181
177
|
)
|
|
182
178
|
def user_message_id(self, value: str) -> None:
|
|
183
|
-
"""
|
|
184
|
-
Set the user message identifier (deprecated).
|
|
179
|
+
"""Set the user message identifier (deprecated).
|
|
185
180
|
|
|
186
181
|
Args:
|
|
187
182
|
value (str | None): The user message identifier.
|
|
183
|
+
|
|
188
184
|
"""
|
|
189
185
|
self._user_message_id = value
|
|
190
186
|
|
|
191
187
|
@property
|
|
192
188
|
@deprecated(
|
|
193
|
-
"The chat_id property is deprecated and will be removed in a future version."
|
|
189
|
+
"The chat_id property is deprecated and will be removed in a future version.",
|
|
194
190
|
)
|
|
195
191
|
def chat_id(self) -> str:
|
|
196
|
-
"""
|
|
197
|
-
Get the chat identifier (deprecated).
|
|
192
|
+
"""Get the chat identifier (deprecated).
|
|
198
193
|
|
|
199
194
|
Returns:
|
|
200
195
|
str | None: The chat identifier.
|
|
196
|
+
|
|
201
197
|
"""
|
|
202
198
|
return self._chat_id
|
|
203
199
|
|
|
204
200
|
@chat_id.setter
|
|
205
201
|
@deprecated(
|
|
206
|
-
"The chat_id setter is deprecated and will be removed in a future version."
|
|
202
|
+
"The chat_id setter is deprecated and will be removed in a future version.",
|
|
207
203
|
)
|
|
208
204
|
def chat_id(self, value: str) -> None:
|
|
209
|
-
"""
|
|
210
|
-
Set the chat identifier (deprecated).
|
|
205
|
+
"""Set the chat identifier (deprecated).
|
|
211
206
|
|
|
212
207
|
Args:
|
|
213
208
|
value (str | None): The chat identifier.
|
|
209
|
+
|
|
214
210
|
"""
|
|
215
211
|
self._chat_id = value
|
|
216
212
|
|
|
217
213
|
@property
|
|
218
214
|
@deprecated(
|
|
219
|
-
"The assistant_id property is deprecated and will be removed in a future version."
|
|
215
|
+
"The assistant_id property is deprecated and will be removed in a future version.",
|
|
220
216
|
)
|
|
221
217
|
def assistant_id(self) -> str:
|
|
222
|
-
"""
|
|
223
|
-
Get the assistant identifier (deprecated).
|
|
218
|
+
"""Get the assistant identifier (deprecated).
|
|
224
219
|
|
|
225
220
|
Returns:
|
|
226
221
|
str | None: The assistant identifier.
|
|
222
|
+
|
|
227
223
|
"""
|
|
228
224
|
return self._assistant_id
|
|
229
225
|
|
|
230
226
|
@assistant_id.setter
|
|
231
227
|
@deprecated(
|
|
232
|
-
"The assistant_id setter is deprecated and will be removed in a future version."
|
|
228
|
+
"The assistant_id setter is deprecated and will be removed in a future version.",
|
|
233
229
|
)
|
|
234
230
|
def assistant_id(self, value: str) -> None:
|
|
235
|
-
"""
|
|
236
|
-
Set the assistant identifier (deprecated).
|
|
231
|
+
"""Set the assistant identifier (deprecated).
|
|
237
232
|
|
|
238
233
|
Args:
|
|
239
234
|
value (str | None): The assistant identifier.
|
|
235
|
+
|
|
240
236
|
"""
|
|
241
237
|
self._assistant_id = value
|
|
242
238
|
|
|
243
239
|
@property
|
|
244
240
|
@deprecated(
|
|
245
|
-
"The user_message_text property is deprecated and will be removed in a future version."
|
|
241
|
+
"The user_message_text property is deprecated and will be removed in a future version.",
|
|
246
242
|
)
|
|
247
243
|
def user_message_text(self) -> str:
|
|
248
|
-
"""
|
|
249
|
-
Get the user message text (deprecated).
|
|
244
|
+
"""Get the user message text (deprecated).
|
|
250
245
|
|
|
251
246
|
Returns:
|
|
252
247
|
str | None: The user message text.
|
|
248
|
+
|
|
253
249
|
"""
|
|
254
250
|
return self._user_message_text
|
|
255
251
|
|
|
256
252
|
@user_message_text.setter
|
|
257
253
|
@deprecated(
|
|
258
|
-
"The user_message_text setter is deprecated and will be removed in a future version."
|
|
254
|
+
"The user_message_text setter is deprecated and will be removed in a future version.",
|
|
259
255
|
)
|
|
260
256
|
def user_message_text(self, value: str) -> None:
|
|
261
|
-
"""
|
|
262
|
-
Set the user message text (deprecated).
|
|
257
|
+
"""Set the user message text (deprecated).
|
|
263
258
|
|
|
264
259
|
Args:
|
|
265
260
|
value (str | None): The user message text.
|
|
261
|
+
|
|
266
262
|
"""
|
|
267
263
|
self._user_message_text = value
|
|
268
264
|
|
|
269
265
|
async def update_debug_info_async(self, debug_info: dict):
|
|
270
|
-
"""
|
|
271
|
-
Updates the debug information for the chat session.
|
|
266
|
+
"""Updates the debug information for the chat session.
|
|
272
267
|
|
|
273
268
|
Args:
|
|
274
269
|
debug_info (dict): The new debug information.
|
|
270
|
+
|
|
275
271
|
"""
|
|
276
272
|
return await modify_message_async(
|
|
277
273
|
user_id=self._user_id,
|
|
@@ -284,14 +280,32 @@ class ChatService:
|
|
|
284
280
|
debug_info=debug_info,
|
|
285
281
|
)
|
|
286
282
|
|
|
283
|
+
@deprecated("Use `replace_debug_info`")
|
|
287
284
|
def update_debug_info(self, debug_info: dict):
|
|
288
|
-
"""
|
|
289
|
-
Updates the debug information for the chat session.
|
|
285
|
+
"""Updates the debug information for the chat session.
|
|
290
286
|
|
|
291
287
|
Args:
|
|
292
288
|
debug_info (dict): The new debug information.
|
|
289
|
+
|
|
293
290
|
"""
|
|
291
|
+
return modify_message(
|
|
292
|
+
user_id=self._user_id,
|
|
293
|
+
company_id=self._company_id,
|
|
294
|
+
assistant_message_id=self._assistant_message_id,
|
|
295
|
+
chat_id=self._chat_id,
|
|
296
|
+
user_message_id=self._user_message_id,
|
|
297
|
+
user_message_text=self._user_message_text,
|
|
298
|
+
assistant=False,
|
|
299
|
+
debug_info=debug_info,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
def replace_debug_info(self, debug_info: dict):
|
|
303
|
+
"""Replace the debug information in the last user message
|
|
294
304
|
|
|
305
|
+
Args:
|
|
306
|
+
debug_info (dict): The new debug information.
|
|
307
|
+
|
|
308
|
+
"""
|
|
295
309
|
return modify_message(
|
|
296
310
|
user_id=self._user_id,
|
|
297
311
|
company_id=self._company_id,
|
|
@@ -306,19 +320,18 @@ class ChatService:
|
|
|
306
320
|
def modify_user_message(
|
|
307
321
|
self,
|
|
308
322
|
content: str,
|
|
309
|
-
references: list[ContentReference] =
|
|
310
|
-
debug_info: dict =
|
|
323
|
+
references: list[ContentReference] | None = None,
|
|
324
|
+
debug_info: dict | None = None,
|
|
311
325
|
message_id: str | None = None,
|
|
312
326
|
set_completed_at: bool | None = False,
|
|
313
327
|
) -> ChatMessage:
|
|
314
|
-
"""
|
|
315
|
-
Modifies a user message in the chat session synchronously.
|
|
328
|
+
"""Modifies a user message in the chat session synchronously.
|
|
316
329
|
|
|
317
330
|
Args:
|
|
318
331
|
content (str): The new content for the message.
|
|
319
|
-
references (list[ContentReference]): list of ContentReference objects.
|
|
320
|
-
debug_info (dict[str, Any]]]): Debug information.
|
|
321
|
-
message_id (str, optional): The message ID
|
|
332
|
+
references (list[ContentReference]): list of ContentReference objects.
|
|
333
|
+
debug_info (dict[str, Any]]]): Debug information.
|
|
334
|
+
message_id (str, optional): The message ID, if not specified the last user message is edited.
|
|
322
335
|
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
|
323
336
|
|
|
324
337
|
Returns:
|
|
@@ -326,8 +339,8 @@ class ChatService:
|
|
|
326
339
|
|
|
327
340
|
Raises:
|
|
328
341
|
Exception: If the modification fails.
|
|
329
|
-
"""
|
|
330
342
|
|
|
343
|
+
"""
|
|
331
344
|
return modify_message(
|
|
332
345
|
user_id=self._user_id,
|
|
333
346
|
company_id=self._company_id,
|
|
@@ -351,8 +364,7 @@ class ChatService:
|
|
|
351
364
|
message_id: str | None = None,
|
|
352
365
|
set_completed_at: bool | None = False,
|
|
353
366
|
) -> ChatMessage:
|
|
354
|
-
"""
|
|
355
|
-
Modifies a message in the chat session asynchronously.
|
|
367
|
+
"""Modifies a message in the chat session asynchronously.
|
|
356
368
|
|
|
357
369
|
Args:
|
|
358
370
|
content (str): The new content for the message.
|
|
@@ -366,8 +378,8 @@ class ChatService:
|
|
|
366
378
|
|
|
367
379
|
Raises:
|
|
368
380
|
Exception: If the modification fails.
|
|
369
|
-
"""
|
|
370
381
|
|
|
382
|
+
"""
|
|
371
383
|
return await modify_message_async(
|
|
372
384
|
user_id=self._user_id,
|
|
373
385
|
company_id=self._company_id,
|
|
@@ -387,13 +399,12 @@ class ChatService:
|
|
|
387
399
|
self,
|
|
388
400
|
content: str | None = None,
|
|
389
401
|
original_content: str | None = None,
|
|
390
|
-
references: list[ContentReference] =
|
|
391
|
-
debug_info: dict =
|
|
402
|
+
references: list[ContentReference] | None = None,
|
|
403
|
+
debug_info: dict | None = None,
|
|
392
404
|
message_id: str | None = None,
|
|
393
|
-
set_completed_at: bool
|
|
405
|
+
set_completed_at: bool = False,
|
|
394
406
|
) -> ChatMessage:
|
|
395
|
-
"""
|
|
396
|
-
Modifies a message in the chat session synchronously.
|
|
407
|
+
"""Modifies a message in the chat session synchronously.
|
|
397
408
|
|
|
398
409
|
Args:
|
|
399
410
|
content (str, optional): The new content for the message.
|
|
@@ -408,8 +419,8 @@ class ChatService:
|
|
|
408
419
|
|
|
409
420
|
Raises:
|
|
410
421
|
Exception: If the modification fails.
|
|
411
|
-
"""
|
|
412
422
|
|
|
423
|
+
"""
|
|
413
424
|
return modify_message(
|
|
414
425
|
user_id=self._user_id,
|
|
415
426
|
company_id=self._company_id,
|
|
@@ -430,13 +441,12 @@ class ChatService:
|
|
|
430
441
|
self,
|
|
431
442
|
content: str | None = None,
|
|
432
443
|
original_content: str | None = None,
|
|
433
|
-
references: list[ContentReference] =
|
|
434
|
-
debug_info: dict =
|
|
444
|
+
references: list[ContentReference] | None = None,
|
|
445
|
+
debug_info: dict | None = None,
|
|
435
446
|
message_id: str | None = None,
|
|
436
447
|
set_completed_at: bool | None = False,
|
|
437
448
|
) -> ChatMessage:
|
|
438
|
-
"""
|
|
439
|
-
Modifies a message in the chat session asynchronously.
|
|
449
|
+
"""Modifies a message in the chat session asynchronously.
|
|
440
450
|
|
|
441
451
|
Args:
|
|
442
452
|
content (str, optional): The new content for the message.
|
|
@@ -451,8 +461,8 @@ class ChatService:
|
|
|
451
461
|
|
|
452
462
|
Raises:
|
|
453
463
|
Exception: If the modification fails.
|
|
454
|
-
"""
|
|
455
464
|
|
|
465
|
+
"""
|
|
456
466
|
return await modify_message_async(
|
|
457
467
|
user_id=self._user_id,
|
|
458
468
|
company_id=self._company_id,
|
|
@@ -470,14 +480,14 @@ class ChatService:
|
|
|
470
480
|
)
|
|
471
481
|
|
|
472
482
|
def get_full_history(self) -> list[ChatMessage]:
|
|
473
|
-
"""
|
|
474
|
-
Loads the full chat history for the chat session synchronously.
|
|
483
|
+
"""Loads the full chat history for the chat session synchronously.
|
|
475
484
|
|
|
476
485
|
Returns:
|
|
477
486
|
list[ChatMessage]: The full chat history.
|
|
478
487
|
|
|
479
488
|
Raises:
|
|
480
489
|
Exception: If the loading fails.
|
|
490
|
+
|
|
481
491
|
"""
|
|
482
492
|
return get_full_history(
|
|
483
493
|
event_user_id=self._user_id,
|
|
@@ -486,14 +496,14 @@ class ChatService:
|
|
|
486
496
|
)
|
|
487
497
|
|
|
488
498
|
async def get_full_history_async(self) -> list[ChatMessage]:
|
|
489
|
-
"""
|
|
490
|
-
Loads the full chat history for the chat session asynchronously.
|
|
499
|
+
"""Loads the full chat history for the chat session asynchronously.
|
|
491
500
|
|
|
492
501
|
Returns:
|
|
493
502
|
list[ChatMessage]: The full chat history.
|
|
494
503
|
|
|
495
504
|
Raises:
|
|
496
505
|
Exception: If the loading fails.
|
|
506
|
+
|
|
497
507
|
"""
|
|
498
508
|
return await get_full_history_async(
|
|
499
509
|
event_user_id=self._user_id,
|
|
@@ -507,8 +517,7 @@ class ChatService:
|
|
|
507
517
|
percent_of_max_tokens: float = DEFAULT_PERCENT_OF_MAX_TOKENS,
|
|
508
518
|
max_messages: int = DEFAULT_MAX_MESSAGES,
|
|
509
519
|
) -> tuple[list[ChatMessage], list[ChatMessage]]:
|
|
510
|
-
"""
|
|
511
|
-
Loads the chat history for the chat session synchronously.
|
|
520
|
+
"""Loads the chat history for the chat session synchronously.
|
|
512
521
|
|
|
513
522
|
Args:
|
|
514
523
|
token_limit (int): The maximum number of tokens to load.
|
|
@@ -520,6 +529,7 @@ class ChatService:
|
|
|
520
529
|
|
|
521
530
|
Raises:
|
|
522
531
|
Exception: If the loading fails.
|
|
532
|
+
|
|
523
533
|
"""
|
|
524
534
|
full_history = get_full_history(
|
|
525
535
|
event_user_id=self._user_id,
|
|
@@ -540,8 +550,7 @@ class ChatService:
|
|
|
540
550
|
percent_of_max_tokens: float = DEFAULT_PERCENT_OF_MAX_TOKENS,
|
|
541
551
|
max_messages: int = DEFAULT_MAX_MESSAGES,
|
|
542
552
|
) -> tuple[list[ChatMessage], list[ChatMessage]]:
|
|
543
|
-
"""
|
|
544
|
-
Loads the chat history for the chat session asynchronously.
|
|
553
|
+
"""Loads the chat history for the chat session asynchronously.
|
|
545
554
|
|
|
546
555
|
Args:
|
|
547
556
|
token_limit (int): The maximum number of tokens to load.
|
|
@@ -553,6 +562,7 @@ class ChatService:
|
|
|
553
562
|
|
|
554
563
|
Raises:
|
|
555
564
|
Exception: If the loading fails.
|
|
565
|
+
|
|
556
566
|
"""
|
|
557
567
|
full_history = await get_full_history_async(
|
|
558
568
|
event_user_id=self._user_id,
|
|
@@ -571,12 +581,11 @@ class ChatService:
|
|
|
571
581
|
self,
|
|
572
582
|
content: str,
|
|
573
583
|
original_content: str | None = None,
|
|
574
|
-
references: list[ContentReference] =
|
|
575
|
-
debug_info: dict =
|
|
584
|
+
references: list[ContentReference] | None = None,
|
|
585
|
+
debug_info: dict | None = None,
|
|
576
586
|
set_completed_at: bool | None = False,
|
|
577
587
|
) -> ChatMessage:
|
|
578
|
-
"""
|
|
579
|
-
Creates a message in the chat session synchronously.
|
|
588
|
+
"""Creates a message in the chat session synchronously.
|
|
580
589
|
|
|
581
590
|
Args:
|
|
582
591
|
content (str): The content for the message.
|
|
@@ -590,8 +599,8 @@ class ChatService:
|
|
|
590
599
|
|
|
591
600
|
Raises:
|
|
592
601
|
Exception: If the creation fails.
|
|
593
|
-
"""
|
|
594
602
|
|
|
603
|
+
"""
|
|
595
604
|
chat_message = create_message(
|
|
596
605
|
user_id=self._user_id,
|
|
597
606
|
company_id=self._company_id,
|
|
@@ -612,12 +621,11 @@ class ChatService:
|
|
|
612
621
|
self,
|
|
613
622
|
content: str,
|
|
614
623
|
original_content: str | None = None,
|
|
615
|
-
references: list[ContentReference] =
|
|
616
|
-
debug_info: dict =
|
|
624
|
+
references: list[ContentReference] | None = None,
|
|
625
|
+
debug_info: dict | None = None,
|
|
617
626
|
set_completed_at: bool | None = False,
|
|
618
627
|
) -> ChatMessage:
|
|
619
|
-
"""
|
|
620
|
-
Creates a message in the chat session asynchronously.
|
|
628
|
+
"""Creates a message in the chat session asynchronously.
|
|
621
629
|
|
|
622
630
|
Args:
|
|
623
631
|
content (str): The content for the message.
|
|
@@ -631,8 +639,8 @@ class ChatService:
|
|
|
631
639
|
|
|
632
640
|
Raises:
|
|
633
641
|
Exception: If the creation fails.
|
|
634
|
-
"""
|
|
635
642
|
|
|
643
|
+
"""
|
|
636
644
|
chat_message = await create_message_async(
|
|
637
645
|
user_id=self._user_id,
|
|
638
646
|
company_id=self._company_id,
|
|
@@ -649,16 +657,16 @@ class ChatService:
|
|
|
649
657
|
self._assistant_message_id = chat_message.id or "unknown"
|
|
650
658
|
return chat_message
|
|
651
659
|
|
|
660
|
+
@deprecated("Not working at the moment.")
|
|
652
661
|
def create_user_message(
|
|
653
662
|
self,
|
|
654
663
|
content: str,
|
|
655
664
|
original_content: str | None = None,
|
|
656
|
-
references: list[ContentReference] =
|
|
657
|
-
debug_info: dict =
|
|
665
|
+
references: list[ContentReference] | None = None,
|
|
666
|
+
debug_info: dict | None = None,
|
|
658
667
|
set_completed_at: bool | None = False,
|
|
659
668
|
) -> ChatMessage:
|
|
660
|
-
"""
|
|
661
|
-
Creates a user message in the chat session synchronously.
|
|
669
|
+
"""Creates a user message in the chat session synchronously.
|
|
662
670
|
|
|
663
671
|
Args:
|
|
664
672
|
content (str): The content for the message.
|
|
@@ -672,8 +680,8 @@ class ChatService:
|
|
|
672
680
|
|
|
673
681
|
Raises:
|
|
674
682
|
Exception: If the creation fails.
|
|
675
|
-
"""
|
|
676
683
|
|
|
684
|
+
"""
|
|
677
685
|
chat_message = create_message(
|
|
678
686
|
user_id=self._user_id,
|
|
679
687
|
company_id=self._company_id,
|
|
@@ -694,12 +702,11 @@ class ChatService:
|
|
|
694
702
|
self,
|
|
695
703
|
content: str,
|
|
696
704
|
original_content: str | None = None,
|
|
697
|
-
references: list[ContentReference] =
|
|
698
|
-
debug_info: dict =
|
|
705
|
+
references: list[ContentReference] | None = None,
|
|
706
|
+
debug_info: dict | None = None,
|
|
699
707
|
set_completed_at: bool | None = False,
|
|
700
708
|
) -> ChatMessage:
|
|
701
|
-
"""
|
|
702
|
-
Creates a user message in the chat session asynchronously.
|
|
709
|
+
"""Creates a user message in the chat session asynchronously.
|
|
703
710
|
|
|
704
711
|
Args:
|
|
705
712
|
content (str): The content for the message.
|
|
@@ -713,8 +720,8 @@ class ChatService:
|
|
|
713
720
|
|
|
714
721
|
Raises:
|
|
715
722
|
Exception: If the creation fails.
|
|
716
|
-
"""
|
|
717
723
|
|
|
724
|
+
"""
|
|
718
725
|
chat_message = await create_message_async(
|
|
719
726
|
user_id=self._user_id,
|
|
720
727
|
company_id=self._company_id,
|
|
@@ -741,8 +748,7 @@ class ChatService:
|
|
|
741
748
|
label: ChatMessageAssessmentLabel | None = None,
|
|
742
749
|
is_visible: bool = True,
|
|
743
750
|
) -> ChatMessageAssessment:
|
|
744
|
-
"""
|
|
745
|
-
Creates a message assessment for an assistant message synchronously.
|
|
751
|
+
"""Creates a message assessment for an assistant message synchronously.
|
|
746
752
|
|
|
747
753
|
Args:
|
|
748
754
|
assistant_message_id (str): The ID of the assistant message to assess
|
|
@@ -758,8 +764,8 @@ class ChatService:
|
|
|
758
764
|
|
|
759
765
|
Raises:
|
|
760
766
|
Exception: If the creation fails
|
|
761
|
-
"""
|
|
762
767
|
|
|
768
|
+
"""
|
|
763
769
|
return create_message_assessment(
|
|
764
770
|
user_id=self._user_id,
|
|
765
771
|
company_id=self._company_id,
|
|
@@ -782,8 +788,7 @@ class ChatService:
|
|
|
782
788
|
label: ChatMessageAssessmentLabel | None = None,
|
|
783
789
|
is_visible: bool = True,
|
|
784
790
|
) -> ChatMessageAssessment:
|
|
785
|
-
"""
|
|
786
|
-
Creates a message assessment for an assistant message asynchronously.
|
|
791
|
+
"""Creates a message assessment for an assistant message asynchronously.
|
|
787
792
|
|
|
788
793
|
Args:
|
|
789
794
|
assistant_message_id (str): The ID of the assistant message to assess
|
|
@@ -799,8 +804,8 @@ class ChatService:
|
|
|
799
804
|
|
|
800
805
|
Raises:
|
|
801
806
|
Exception: If the creation fails
|
|
802
|
-
"""
|
|
803
807
|
|
|
808
|
+
"""
|
|
804
809
|
return await create_message_assessment_async(
|
|
805
810
|
user_id=self._user_id,
|
|
806
811
|
company_id=self._company_id,
|
|
@@ -822,8 +827,7 @@ class ChatService:
|
|
|
822
827
|
explanation: str | None = None,
|
|
823
828
|
label: ChatMessageAssessmentLabel | None = None,
|
|
824
829
|
) -> ChatMessageAssessment:
|
|
825
|
-
"""
|
|
826
|
-
Modifies a message assessment for an assistant message synchronously.
|
|
830
|
+
"""Modifies a message assessment for an assistant message synchronously.
|
|
827
831
|
|
|
828
832
|
Args:
|
|
829
833
|
assistant_message_id (str): The ID of the assistant message to assess
|
|
@@ -838,8 +842,8 @@ class ChatService:
|
|
|
838
842
|
|
|
839
843
|
Raises:
|
|
840
844
|
Exception: If the modification fails
|
|
841
|
-
"""
|
|
842
845
|
|
|
846
|
+
"""
|
|
843
847
|
return modify_message_assessment(
|
|
844
848
|
user_id=self._user_id,
|
|
845
849
|
company_id=self._company_id,
|
|
@@ -860,8 +864,7 @@ class ChatService:
|
|
|
860
864
|
explanation: str | None = None,
|
|
861
865
|
label: ChatMessageAssessmentLabel | None = None,
|
|
862
866
|
) -> ChatMessageAssessment:
|
|
863
|
-
"""
|
|
864
|
-
Modifies a message assessment for an assistant message asynchronously.
|
|
867
|
+
"""Modifies a message assessment for an assistant message asynchronously.
|
|
865
868
|
|
|
866
869
|
Args:
|
|
867
870
|
assistant_message_id (str): The ID of the assistant message to assess
|
|
@@ -876,6 +879,7 @@ class ChatService:
|
|
|
876
879
|
|
|
877
880
|
Raises:
|
|
878
881
|
Exception: If the modification fails
|
|
882
|
+
|
|
879
883
|
"""
|
|
880
884
|
return await modify_message_assessment_async(
|
|
881
885
|
user_id=self._user_id,
|
|
@@ -891,15 +895,15 @@ class ChatService:
|
|
|
891
895
|
@deprecated("Use complete_with_references instead")
|
|
892
896
|
def stream_complete(
|
|
893
897
|
self,
|
|
894
|
-
messages: LanguageModelMessages,
|
|
898
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
895
899
|
model_name: LanguageModelName | str,
|
|
896
900
|
content_chunks: list[ContentChunk] | None = None,
|
|
897
901
|
debug_info: dict = {},
|
|
898
902
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
899
903
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
900
|
-
tools:
|
|
901
|
-
start_text:
|
|
902
|
-
other_options:
|
|
904
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
905
|
+
start_text: str | None = None,
|
|
906
|
+
other_options: dict | None = None,
|
|
903
907
|
) -> LanguageModelStreamResponse:
|
|
904
908
|
return self.complete_with_references(
|
|
905
909
|
messages=messages,
|
|
@@ -915,20 +919,17 @@ class ChatService:
|
|
|
915
919
|
|
|
916
920
|
def complete_with_references(
|
|
917
921
|
self,
|
|
918
|
-
messages: LanguageModelMessages,
|
|
922
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
919
923
|
model_name: LanguageModelName | str,
|
|
920
924
|
content_chunks: list[ContentChunk] | None = None,
|
|
921
|
-
debug_info: dict =
|
|
925
|
+
debug_info: dict | None = None,
|
|
922
926
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
923
927
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
924
|
-
tools:
|
|
925
|
-
start_text:
|
|
926
|
-
other_options:
|
|
928
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
929
|
+
start_text: str | None = None,
|
|
930
|
+
other_options: dict | None = None,
|
|
927
931
|
) -> LanguageModelStreamResponse:
|
|
928
|
-
"""
|
|
929
|
-
Streams a completion in the chat session synchronously.
|
|
930
|
-
"""
|
|
931
|
-
|
|
932
|
+
"""Streams a completion in the chat session synchronously."""
|
|
932
933
|
return stream_complete_with_references(
|
|
933
934
|
company_id=self._company_id,
|
|
934
935
|
user_id=self._user_id,
|
|
@@ -949,15 +950,15 @@ class ChatService:
|
|
|
949
950
|
|
|
950
951
|
def complete(
|
|
951
952
|
self,
|
|
952
|
-
messages: LanguageModelMessages,
|
|
953
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
953
954
|
model_name: LanguageModelName | str,
|
|
954
955
|
content_chunks: list[ContentChunk] | None = None,
|
|
955
|
-
debug_info: dict =
|
|
956
|
+
debug_info: dict | None = None,
|
|
956
957
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
957
958
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
958
|
-
tools:
|
|
959
|
-
start_text:
|
|
960
|
-
other_options:
|
|
959
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
960
|
+
start_text: str | None = None,
|
|
961
|
+
other_options: dict | None = None,
|
|
961
962
|
) -> LanguageModelResponse:
|
|
962
963
|
response = self.complete_with_references(
|
|
963
964
|
messages=messages,
|
|
@@ -976,15 +977,15 @@ class ChatService:
|
|
|
976
977
|
@deprecated("use complete_with_references_async instead.")
|
|
977
978
|
async def stream_complete_async(
|
|
978
979
|
self,
|
|
979
|
-
messages: LanguageModelMessages,
|
|
980
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
980
981
|
model_name: LanguageModelName | str,
|
|
981
982
|
content_chunks: list[ContentChunk] | None = None,
|
|
982
|
-
debug_info: dict =
|
|
983
|
+
debug_info: dict | None = None,
|
|
983
984
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
984
985
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
985
|
-
tools:
|
|
986
|
-
start_text:
|
|
987
|
-
other_options:
|
|
986
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
987
|
+
start_text: str | None = None,
|
|
988
|
+
other_options: dict | None = None,
|
|
988
989
|
) -> LanguageModelStreamResponse:
|
|
989
990
|
"""Stream a completion in the chat session asynchronously."""
|
|
990
991
|
return await self.complete_with_references_async(
|
|
@@ -1001,15 +1002,15 @@ class ChatService:
|
|
|
1001
1002
|
|
|
1002
1003
|
async def complete_with_references_async(
|
|
1003
1004
|
self,
|
|
1004
|
-
messages: LanguageModelMessages,
|
|
1005
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
1005
1006
|
model_name: LanguageModelName | str,
|
|
1006
1007
|
content_chunks: list[ContentChunk] | None = None,
|
|
1007
|
-
debug_info: dict =
|
|
1008
|
+
debug_info: dict | None = None,
|
|
1008
1009
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
1009
1010
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
1010
|
-
tools:
|
|
1011
|
-
start_text:
|
|
1012
|
-
other_options:
|
|
1011
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
1012
|
+
start_text: str | None = None,
|
|
1013
|
+
other_options: dict | None = None,
|
|
1013
1014
|
) -> LanguageModelStreamResponse:
|
|
1014
1015
|
return await stream_complete_with_references_async(
|
|
1015
1016
|
company_id=self._company_id,
|
|
@@ -1031,15 +1032,15 @@ class ChatService:
|
|
|
1031
1032
|
|
|
1032
1033
|
async def complete_async(
|
|
1033
1034
|
self,
|
|
1034
|
-
messages: LanguageModelMessages,
|
|
1035
|
+
messages: LanguageModelMessages | list[ChatCompletionMessageParam],
|
|
1035
1036
|
model_name: LanguageModelName | str,
|
|
1036
1037
|
content_chunks: list[ContentChunk] | None,
|
|
1037
|
-
debug_info: dict =
|
|
1038
|
+
debug_info: dict | None = None,
|
|
1038
1039
|
temperature: float = DEFAULT_COMPLETE_TEMPERATURE,
|
|
1039
1040
|
timeout: int = DEFAULT_COMPLETE_TIMEOUT,
|
|
1040
|
-
tools:
|
|
1041
|
-
start_text:
|
|
1042
|
-
other_options:
|
|
1041
|
+
tools: list[LanguageModelTool | LanguageModelToolDescription] | None = None,
|
|
1042
|
+
start_text: str | None = None,
|
|
1043
|
+
other_options: dict | None = None,
|
|
1043
1044
|
) -> LanguageModelResponse:
|
|
1044
1045
|
response = self.complete_with_references_async(
|
|
1045
1046
|
messages=messages,
|