unique_toolkit 0.5.22__py3-none-any.whl → 0.5.23__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/chat/service.py +81 -26
- unique_toolkit-0.5.23.dist-info/LICENSE +1 -0
- {unique_toolkit-0.5.22.dist-info → unique_toolkit-0.5.23.dist-info}/METADATA +7 -4
- {unique_toolkit-0.5.22.dist-info → unique_toolkit-0.5.23.dist-info}/RECORD +5 -5
- unique_toolkit-0.5.22.dist-info/LICENSE +0 -21
- {unique_toolkit-0.5.22.dist-info → unique_toolkit-0.5.23.dist-info}/WHEEL +0 -0
unique_toolkit/chat/service.py
CHANGED
@@ -35,7 +35,9 @@ class ChatService(BaseService):
|
|
35
35
|
Args:
|
36
36
|
debug_info (dict): The new debug information.
|
37
37
|
"""
|
38
|
-
params = self.
|
38
|
+
params = self._construct_message_modify_params(
|
39
|
+
assistant=False, debug_info=debug_info
|
40
|
+
)
|
39
41
|
try:
|
40
42
|
await unique_sdk.Message.modify_async(**params)
|
41
43
|
except Exception as e:
|
@@ -49,7 +51,9 @@ class ChatService(BaseService):
|
|
49
51
|
Args:
|
50
52
|
debug_info (dict): The new debug information.
|
51
53
|
"""
|
52
|
-
params = self.
|
54
|
+
params = self._construct_message_modify_params(
|
55
|
+
assistant=False, debug_info=debug_info
|
56
|
+
)
|
53
57
|
try:
|
54
58
|
unique_sdk.Message.modify(**params)
|
55
59
|
except Exception as e:
|
@@ -62,6 +66,7 @@ class ChatService(BaseService):
|
|
62
66
|
references: Optional[list[ContentReference]] = None,
|
63
67
|
debug_info: Optional[dict] = None,
|
64
68
|
message_id: Optional[str] = None,
|
69
|
+
set_completed_at: Optional[bool] = False,
|
65
70
|
) -> ChatMessage:
|
66
71
|
"""
|
67
72
|
Modifies a message in the chat session synchronously.
|
@@ -71,6 +76,7 @@ class ChatService(BaseService):
|
|
71
76
|
references (list[ContentReference]): list of ContentReference objects. Defaults to [].
|
72
77
|
debug_info (dict[str, Any]]]): Debug information. Defaults to {}.
|
73
78
|
message_id (str, optional): The message ID. Defaults to None, then the ChatState user message id is used.
|
79
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
74
80
|
|
75
81
|
Returns:
|
76
82
|
ChatMessage: The modified message.
|
@@ -79,12 +85,13 @@ class ChatService(BaseService):
|
|
79
85
|
Exception: If the modification fails.
|
80
86
|
"""
|
81
87
|
try:
|
82
|
-
params = self.
|
88
|
+
params = self._construct_message_modify_params(
|
83
89
|
assistant=False,
|
84
90
|
content=content,
|
85
91
|
references=references,
|
86
92
|
debug_info=debug_info,
|
87
93
|
message_id=message_id,
|
94
|
+
set_completed_at=set_completed_at,
|
88
95
|
)
|
89
96
|
message = unique_sdk.Message.modify(**params)
|
90
97
|
except Exception as e:
|
@@ -98,6 +105,7 @@ class ChatService(BaseService):
|
|
98
105
|
references: list[ContentReference] = [],
|
99
106
|
debug_info: dict = {},
|
100
107
|
message_id: Optional[str] = None,
|
108
|
+
set_completed_at: Optional[bool] = False,
|
101
109
|
) -> ChatMessage:
|
102
110
|
"""
|
103
111
|
Modifies a message in the chat session asynchronously.
|
@@ -107,6 +115,7 @@ class ChatService(BaseService):
|
|
107
115
|
message_id (str, optional): The message ID. Defaults to None, then the ChatState user message id is used.
|
108
116
|
references (list[ContentReference]): list of ContentReference objects. Defaults to None.
|
109
117
|
debug_info (Optional[dict[str, Any]]], optional): Debug information. Defaults to None.
|
118
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
110
119
|
|
111
120
|
Returns:
|
112
121
|
ChatMessage: The modified message.
|
@@ -115,12 +124,13 @@ class ChatService(BaseService):
|
|
115
124
|
Exception: If the modification fails.
|
116
125
|
"""
|
117
126
|
try:
|
118
|
-
params = self.
|
127
|
+
params = self._construct_message_modify_params(
|
119
128
|
assistant=False,
|
120
129
|
content=content,
|
121
130
|
references=references,
|
122
131
|
debug_info=debug_info,
|
123
132
|
message_id=message_id,
|
133
|
+
set_completed_at=set_completed_at,
|
124
134
|
)
|
125
135
|
message = await unique_sdk.Message.modify_async(**params)
|
126
136
|
except Exception as e:
|
@@ -134,6 +144,7 @@ class ChatService(BaseService):
|
|
134
144
|
references: list[ContentReference] = [],
|
135
145
|
debug_info: dict = {},
|
136
146
|
message_id: Optional[str] = None,
|
147
|
+
set_completed_at: Optional[bool] = False,
|
137
148
|
) -> ChatMessage:
|
138
149
|
"""
|
139
150
|
Modifies a message in the chat session synchronously.
|
@@ -143,6 +154,7 @@ class ChatService(BaseService):
|
|
143
154
|
references (list[ContentReference]): list of ContentReference objects. Defaults to [].
|
144
155
|
debug_info (dict[str, Any]]]): Debug information. Defaults to {}.
|
145
156
|
message_id (Optional[str]): The message ID. Defaults to None.
|
157
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
146
158
|
|
147
159
|
Returns:
|
148
160
|
ChatMessage: The modified message.
|
@@ -151,12 +163,13 @@ class ChatService(BaseService):
|
|
151
163
|
Exception: If the modification fails.
|
152
164
|
"""
|
153
165
|
try:
|
154
|
-
params = self.
|
166
|
+
params = self._construct_message_modify_params(
|
155
167
|
assistant=True,
|
156
168
|
content=content,
|
157
169
|
references=references,
|
158
170
|
debug_info=debug_info,
|
159
171
|
message_id=message_id,
|
172
|
+
set_completed_at=set_completed_at,
|
160
173
|
)
|
161
174
|
message = unique_sdk.Message.modify(**params)
|
162
175
|
except Exception as e:
|
@@ -170,6 +183,7 @@ class ChatService(BaseService):
|
|
170
183
|
references: list[ContentReference] = [],
|
171
184
|
debug_info: dict = {},
|
172
185
|
message_id: Optional[str] = None,
|
186
|
+
set_completed_at: Optional[bool] = False,
|
173
187
|
) -> ChatMessage:
|
174
188
|
"""
|
175
189
|
Modifies a message in the chat session asynchronously.
|
@@ -179,6 +193,7 @@ class ChatService(BaseService):
|
|
179
193
|
message_id (str, optional): The message ID. Defaults to None, then the ChatState assistant message id is used.
|
180
194
|
references (list[ContentReference]): list of ContentReference objects. Defaults to None.
|
181
195
|
debug_info (Optional[dict[str, Any]]], optional): Debug information. Defaults to None.
|
196
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
182
197
|
|
183
198
|
Returns:
|
184
199
|
ChatMessage: The modified message.
|
@@ -187,12 +202,13 @@ class ChatService(BaseService):
|
|
187
202
|
Exception: If the modification fails.
|
188
203
|
"""
|
189
204
|
try:
|
190
|
-
params = self.
|
205
|
+
params = self._construct_message_modify_params(
|
191
206
|
assistant=True,
|
192
207
|
content=content,
|
193
208
|
references=references,
|
194
209
|
debug_info=debug_info,
|
195
210
|
message_id=message_id,
|
211
|
+
set_completed_at=set_completed_at,
|
196
212
|
)
|
197
213
|
message = await unique_sdk.Message.modify_async(**params)
|
198
214
|
except Exception as e:
|
@@ -287,6 +303,7 @@ class ChatService(BaseService):
|
|
287
303
|
content: str,
|
288
304
|
references: list[ContentReference] = [],
|
289
305
|
debug_info: dict = {},
|
306
|
+
set_completed_at: Optional[bool] = False,
|
290
307
|
):
|
291
308
|
"""
|
292
309
|
Creates a message in the chat session synchronously.
|
@@ -295,6 +312,7 @@ class ChatService(BaseService):
|
|
295
312
|
content (str): The content for the message.
|
296
313
|
references (list[ContentReference]): list of ContentReference objects. Defaults to None.
|
297
314
|
debug_info (dict[str, Any]]): Debug information. Defaults to None.
|
315
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
298
316
|
|
299
317
|
Returns:
|
300
318
|
ChatMessage: The created message.
|
@@ -304,16 +322,14 @@ class ChatService(BaseService):
|
|
304
322
|
"""
|
305
323
|
|
306
324
|
try:
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
text=content,
|
313
|
-
role=ChatMessageRole.ASSISTANT.name,
|
314
|
-
references=self._map_references(references), # type: ignore
|
315
|
-
debugInfo=debug_info,
|
325
|
+
params = self._construct_message_create_params(
|
326
|
+
content=content,
|
327
|
+
references=references,
|
328
|
+
debug_info=debug_info,
|
329
|
+
set_completed_at=set_completed_at,
|
316
330
|
)
|
331
|
+
|
332
|
+
message = unique_sdk.Message.create(**params)
|
317
333
|
except Exception as e:
|
318
334
|
self.logger.error(f"Failed to create assistant message: {e}")
|
319
335
|
raise e
|
@@ -324,6 +340,7 @@ class ChatService(BaseService):
|
|
324
340
|
content: str,
|
325
341
|
references: list[ContentReference] = [],
|
326
342
|
debug_info: dict = {},
|
343
|
+
set_completed_at: Optional[bool] = False,
|
327
344
|
):
|
328
345
|
"""
|
329
346
|
Creates a message in the chat session asynchronously.
|
@@ -332,6 +349,7 @@ class ChatService(BaseService):
|
|
332
349
|
content (str): The content for the message.
|
333
350
|
references (list[ContentReference]): list of references. Defaults to None.
|
334
351
|
debug_info (dict[str, Any]]): Debug information. Defaults to None.
|
352
|
+
set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
|
335
353
|
|
336
354
|
Returns:
|
337
355
|
ChatMessage: The created message.
|
@@ -340,16 +358,14 @@ class ChatService(BaseService):
|
|
340
358
|
Exception: If the creation fails.
|
341
359
|
"""
|
342
360
|
try:
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
text=content,
|
349
|
-
role=ChatMessageRole.ASSISTANT.name,
|
350
|
-
references=self._map_references(references), # type: ignore
|
351
|
-
debugInfo=debug_info,
|
361
|
+
params = self._construct_message_create_params(
|
362
|
+
content=content,
|
363
|
+
references=references,
|
364
|
+
debug_info=debug_info,
|
365
|
+
set_completed_at=set_completed_at,
|
352
366
|
)
|
367
|
+
|
368
|
+
message = await unique_sdk.Message.create_async(**params)
|
353
369
|
except Exception as e:
|
354
370
|
self.logger.error(f"Failed to create assistant message: {e}")
|
355
371
|
raise e
|
@@ -477,13 +493,14 @@ class ChatService(BaseService):
|
|
477
493
|
last_index = max(0, last_index)
|
478
494
|
return messages[last_index:]
|
479
495
|
|
480
|
-
def
|
496
|
+
def _construct_message_modify_params(
|
481
497
|
self,
|
482
498
|
assistant: bool = True,
|
483
499
|
content: Optional[str] = None,
|
484
500
|
references: Optional[list[ContentReference]] = None,
|
485
501
|
debug_info: Optional[dict] = None,
|
486
502
|
message_id: Optional[str] = None,
|
503
|
+
set_completed_at: Optional[bool] = False,
|
487
504
|
):
|
488
505
|
if message_id:
|
489
506
|
# Message ID specified. No need to guess
|
@@ -497,6 +514,11 @@ class ChatService(BaseService):
|
|
497
514
|
if content is None:
|
498
515
|
content = self.event.payload.user_message.text
|
499
516
|
|
517
|
+
if set_completed_at:
|
518
|
+
completed_at_datetime = _time_utils.get_datetime_now()
|
519
|
+
else:
|
520
|
+
completed_at_datetime = None
|
521
|
+
|
500
522
|
params = {
|
501
523
|
"user_id": self.event.user_id,
|
502
524
|
"company_id": self.event.company_id,
|
@@ -505,6 +527,39 @@ class ChatService(BaseService):
|
|
505
527
|
"text": content,
|
506
528
|
"references": self._map_references(references) if references else [],
|
507
529
|
"debugInfo": debug_info,
|
508
|
-
"completedAt":
|
530
|
+
"completedAt": completed_at_datetime,
|
531
|
+
}
|
532
|
+
return params
|
533
|
+
|
534
|
+
def _construct_message_create_params(
|
535
|
+
self,
|
536
|
+
role: ChatMessageRole = ChatMessageRole.ASSISTANT,
|
537
|
+
content: Optional[str] = None,
|
538
|
+
references: Optional[list[ContentReference]] = None,
|
539
|
+
debug_info: Optional[dict] = None,
|
540
|
+
assistantId: Optional[str] = None,
|
541
|
+
set_completed_at: Optional[bool] = False,
|
542
|
+
):
|
543
|
+
if assistantId:
|
544
|
+
# Assistant ID specified. No need to guess
|
545
|
+
assistantId = assistantId
|
546
|
+
else:
|
547
|
+
assistantId = self.event.payload.assistant_id
|
548
|
+
|
549
|
+
if set_completed_at:
|
550
|
+
completed_at_datetime = _time_utils.get_datetime_now()
|
551
|
+
else:
|
552
|
+
completed_at_datetime = None
|
553
|
+
|
554
|
+
params = {
|
555
|
+
"user_id": self.event.user_id,
|
556
|
+
"company_id": self.event.company_id,
|
557
|
+
"assistantId": assistantId,
|
558
|
+
"role": role.value.upper(),
|
559
|
+
"chatId": self.event.payload.chat_id,
|
560
|
+
"text": content,
|
561
|
+
"references": self._map_references(references) if references else [],
|
562
|
+
"debugInfo": debug_info,
|
563
|
+
"completedAt": completed_at_datetime,
|
509
564
|
}
|
510
565
|
return params
|
@@ -0,0 +1 @@
|
|
1
|
+
`unique_toolkit` is covered by the [`Unique License v1`](https://github.com/Unique-AG/license/releases/tag/unique-license.v1), unless the/a header or a nested LICENSE specifies another license.
|
@@ -1,12 +1,12 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.23
|
4
4
|
Summary:
|
5
|
-
License:
|
5
|
+
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
7
7
|
Author-email: martin.fadler@unique.ch
|
8
8
|
Requires-Python: >=3.11,<4.0
|
9
|
-
Classifier: License ::
|
9
|
+
Classifier: License :: Other/Proprietary License
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -17,7 +17,7 @@ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
|
17
17
|
Requires-Dist: regex (>=2024.5.15,<2025.0.0)
|
18
18
|
Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
|
19
19
|
Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
|
20
|
-
Requires-Dist: unique-sdk (>=0.9.
|
20
|
+
Requires-Dist: unique-sdk (>=0.9.7,<0.10.0)
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
|
23
23
|
# Unique Toolkit
|
@@ -100,6 +100,9 @@ All notable changes to this project will be documented in this file.
|
|
100
100
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
101
101
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
102
102
|
|
103
|
+
## [0.5.23] - 2024-09-23
|
104
|
+
- Add `set_completed_at` as a boolen parameter to the following functions: `modify_user_message`, `modify_user_message_async`, `modify_assistant_message`, `modify_assistant_message_async`, `create_assistant_message` and `create_assistant_message`. This parameter allows the `completedAt` timestamp on the database to be updated when set to True.
|
105
|
+
|
103
106
|
## [0.5.22] - 2024-09-17
|
104
107
|
- Add `LanguageModelToolMessage` as additional `LanguageModelMessage`
|
105
108
|
|
@@ -10,7 +10,7 @@ unique_toolkit/app/schemas.py,sha256=tzrmUFKZUdC1P3LxZ7DrElpkMtekUDoClb7jCRzGqNQ
|
|
10
10
|
unique_toolkit/app/verification.py,sha256=UZqTHg3PX_QxMjeLH_BVBYoMVqMnMpeMoqvyTBKDqj8,1996
|
11
11
|
unique_toolkit/chat/__init__.py,sha256=1prdTVfLOf6NgU-Aa1VIO-XiR6OYuRm51LaVRfKDCqc,267
|
12
12
|
unique_toolkit/chat/schemas.py,sha256=IHOnb3pWlRlSPoEUWBTl6LK8YeMdlg2iXi9ghyBeiLw,1495
|
13
|
-
unique_toolkit/chat/service.py,sha256=
|
13
|
+
unique_toolkit/chat/service.py,sha256=5BurWe0skZ7O3DVztAcU_fRJeO8bbD_Xv7sOlMQYTmI,20252
|
14
14
|
unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,1445
|
15
15
|
unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
|
16
16
|
unique_toolkit/content/__init__.py,sha256=MSH2sxjQyKD2Sef92fzE5Dt9SihdzivB6yliSwJfTmQ,890
|
@@ -26,7 +26,7 @@ unique_toolkit/language_model/infos.py,sha256=ETAUV0YTs6BjwuiTdhKz247CtL0W8Jwo3-
|
|
26
26
|
unique_toolkit/language_model/schemas.py,sha256=sLpE29Ks0zEfhZUQrYOt1Cak2xzQcr9fpTXFDHkfURA,4868
|
27
27
|
unique_toolkit/language_model/service.py,sha256=CvVo5CBa5Ia_fQD3DtJRsVChybuUfGFV5ml2_78_p1I,13395
|
28
28
|
unique_toolkit/language_model/utils.py,sha256=WBPj1XKkDgxy_-T8HCZvsfkkSzj_1w4UZzNmyvdbBLY,1081
|
29
|
-
unique_toolkit-0.5.
|
30
|
-
unique_toolkit-0.5.
|
31
|
-
unique_toolkit-0.5.
|
32
|
-
unique_toolkit-0.5.
|
29
|
+
unique_toolkit-0.5.23.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
30
|
+
unique_toolkit-0.5.23.dist-info/METADATA,sha256=hSBE8S9sPqcS7ZvvaKEZh-PUL1tvYauGjq4_XbXWYGE,11719
|
31
|
+
unique_toolkit-0.5.23.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
32
|
+
unique_toolkit-0.5.23.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 Unique-AG
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
File without changes
|