unique_toolkit 0.7.7__py3-none-any.whl → 1.23.0__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.
Potentially problematic release.
This version of unique_toolkit might be problematic. Click here for more details.
- unique_toolkit/__init__.py +28 -1
- unique_toolkit/_common/api_calling/human_verification_manager.py +343 -0
- unique_toolkit/_common/base_model_type_attribute.py +303 -0
- unique_toolkit/_common/chunk_relevancy_sorter/config.py +49 -0
- unique_toolkit/_common/chunk_relevancy_sorter/exception.py +5 -0
- unique_toolkit/_common/chunk_relevancy_sorter/schemas.py +46 -0
- unique_toolkit/_common/chunk_relevancy_sorter/service.py +374 -0
- unique_toolkit/_common/chunk_relevancy_sorter/tests/test_service.py +275 -0
- unique_toolkit/_common/default_language_model.py +12 -0
- unique_toolkit/_common/docx_generator/__init__.py +7 -0
- unique_toolkit/_common/docx_generator/config.py +12 -0
- unique_toolkit/_common/docx_generator/schemas.py +80 -0
- unique_toolkit/_common/docx_generator/service.py +252 -0
- unique_toolkit/_common/docx_generator/template/Doc Template.docx +0 -0
- unique_toolkit/_common/endpoint_builder.py +305 -0
- unique_toolkit/_common/endpoint_requestor.py +430 -0
- unique_toolkit/_common/exception.py +24 -0
- unique_toolkit/_common/feature_flags/schema.py +9 -0
- unique_toolkit/_common/pydantic/rjsf_tags.py +936 -0
- unique_toolkit/_common/pydantic_helpers.py +154 -0
- unique_toolkit/_common/referencing.py +53 -0
- unique_toolkit/_common/string_utilities.py +140 -0
- unique_toolkit/_common/tests/test_referencing.py +521 -0
- unique_toolkit/_common/tests/test_string_utilities.py +506 -0
- unique_toolkit/_common/token/image_token_counting.py +67 -0
- unique_toolkit/_common/token/token_counting.py +204 -0
- unique_toolkit/_common/utils/__init__.py +1 -0
- unique_toolkit/_common/utils/files.py +43 -0
- unique_toolkit/_common/utils/structured_output/__init__.py +1 -0
- unique_toolkit/_common/utils/structured_output/schema.py +5 -0
- unique_toolkit/_common/utils/write_configuration.py +51 -0
- unique_toolkit/_common/validators.py +101 -4
- unique_toolkit/agentic/__init__.py +1 -0
- unique_toolkit/agentic/debug_info_manager/debug_info_manager.py +28 -0
- unique_toolkit/agentic/debug_info_manager/test/test_debug_info_manager.py +278 -0
- unique_toolkit/agentic/evaluation/config.py +36 -0
- unique_toolkit/{evaluators → agentic/evaluation}/context_relevancy/prompts.py +25 -0
- unique_toolkit/agentic/evaluation/context_relevancy/schema.py +80 -0
- unique_toolkit/agentic/evaluation/context_relevancy/service.py +273 -0
- unique_toolkit/agentic/evaluation/evaluation_manager.py +218 -0
- unique_toolkit/agentic/evaluation/hallucination/constants.py +61 -0
- unique_toolkit/agentic/evaluation/hallucination/hallucination_evaluation.py +111 -0
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/prompts.py +1 -1
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/service.py +16 -15
- unique_toolkit/{evaluators → agentic/evaluation}/hallucination/utils.py +30 -20
- unique_toolkit/{evaluators → agentic/evaluation}/output_parser.py +20 -2
- unique_toolkit/{evaluators → agentic/evaluation}/schemas.py +27 -7
- unique_toolkit/agentic/evaluation/tests/test_context_relevancy_service.py +253 -0
- unique_toolkit/agentic/evaluation/tests/test_output_parser.py +87 -0
- unique_toolkit/agentic/history_manager/history_construction_with_contents.py +297 -0
- unique_toolkit/agentic/history_manager/history_manager.py +242 -0
- unique_toolkit/agentic/history_manager/loop_token_reducer.py +484 -0
- unique_toolkit/agentic/history_manager/utils.py +96 -0
- unique_toolkit/agentic/postprocessor/postprocessor_manager.py +212 -0
- unique_toolkit/agentic/reference_manager/reference_manager.py +103 -0
- unique_toolkit/agentic/responses_api/__init__.py +19 -0
- unique_toolkit/agentic/responses_api/postprocessors/code_display.py +63 -0
- unique_toolkit/agentic/responses_api/postprocessors/generated_files.py +145 -0
- unique_toolkit/agentic/responses_api/stream_handler.py +15 -0
- unique_toolkit/agentic/short_term_memory_manager/persistent_short_term_memory_manager.py +141 -0
- unique_toolkit/agentic/thinking_manager/thinking_manager.py +103 -0
- unique_toolkit/agentic/tools/__init__.py +1 -0
- unique_toolkit/agentic/tools/a2a/__init__.py +36 -0
- unique_toolkit/agentic/tools/a2a/config.py +17 -0
- unique_toolkit/agentic/tools/a2a/evaluation/__init__.py +15 -0
- unique_toolkit/agentic/tools/a2a/evaluation/_utils.py +66 -0
- unique_toolkit/agentic/tools/a2a/evaluation/config.py +55 -0
- unique_toolkit/agentic/tools/a2a/evaluation/evaluator.py +260 -0
- unique_toolkit/agentic/tools/a2a/evaluation/summarization_user_message.j2 +9 -0
- unique_toolkit/agentic/tools/a2a/manager.py +55 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/__init__.py +21 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/_display_utils.py +185 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/_ref_utils.py +73 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/config.py +45 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/display.py +180 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/references.py +101 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display_utils.py +1335 -0
- unique_toolkit/agentic/tools/a2a/postprocessing/test/test_ref_utils.py +603 -0
- unique_toolkit/agentic/tools/a2a/prompts.py +46 -0
- unique_toolkit/agentic/tools/a2a/response_watcher/__init__.py +6 -0
- unique_toolkit/agentic/tools/a2a/response_watcher/service.py +91 -0
- unique_toolkit/agentic/tools/a2a/tool/__init__.py +4 -0
- unique_toolkit/agentic/tools/a2a/tool/_memory.py +26 -0
- unique_toolkit/agentic/tools/a2a/tool/_schema.py +9 -0
- unique_toolkit/agentic/tools/a2a/tool/config.py +73 -0
- unique_toolkit/agentic/tools/a2a/tool/service.py +306 -0
- unique_toolkit/agentic/tools/agent_chunks_hanlder.py +65 -0
- unique_toolkit/agentic/tools/config.py +167 -0
- unique_toolkit/agentic/tools/factory.py +44 -0
- unique_toolkit/agentic/tools/mcp/__init__.py +4 -0
- unique_toolkit/agentic/tools/mcp/manager.py +71 -0
- unique_toolkit/agentic/tools/mcp/models.py +28 -0
- unique_toolkit/agentic/tools/mcp/tool_wrapper.py +234 -0
- unique_toolkit/agentic/tools/openai_builtin/__init__.py +11 -0
- unique_toolkit/agentic/tools/openai_builtin/base.py +30 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/__init__.py +8 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/config.py +57 -0
- unique_toolkit/agentic/tools/openai_builtin/code_interpreter/service.py +230 -0
- unique_toolkit/agentic/tools/openai_builtin/manager.py +62 -0
- unique_toolkit/agentic/tools/schemas.py +141 -0
- unique_toolkit/agentic/tools/test/test_mcp_manager.py +536 -0
- unique_toolkit/agentic/tools/test/test_tool_progress_reporter.py +445 -0
- unique_toolkit/agentic/tools/tool.py +183 -0
- unique_toolkit/agentic/tools/tool_manager.py +523 -0
- unique_toolkit/agentic/tools/tool_progress_reporter.py +285 -0
- unique_toolkit/agentic/tools/utils/__init__.py +19 -0
- unique_toolkit/agentic/tools/utils/execution/__init__.py +1 -0
- unique_toolkit/agentic/tools/utils/execution/execution.py +286 -0
- unique_toolkit/agentic/tools/utils/source_handling/__init__.py +0 -0
- unique_toolkit/agentic/tools/utils/source_handling/schema.py +21 -0
- unique_toolkit/agentic/tools/utils/source_handling/source_formatting.py +207 -0
- unique_toolkit/agentic/tools/utils/source_handling/tests/test_source_formatting.py +216 -0
- unique_toolkit/app/__init__.py +6 -0
- unique_toolkit/app/dev_util.py +180 -0
- unique_toolkit/app/init_sdk.py +32 -1
- unique_toolkit/app/schemas.py +198 -31
- unique_toolkit/app/unique_settings.py +367 -0
- unique_toolkit/chat/__init__.py +8 -1
- unique_toolkit/chat/deprecated/service.py +232 -0
- unique_toolkit/chat/functions.py +642 -77
- unique_toolkit/chat/rendering.py +34 -0
- unique_toolkit/chat/responses_api.py +461 -0
- unique_toolkit/chat/schemas.py +133 -2
- unique_toolkit/chat/service.py +115 -767
- unique_toolkit/content/functions.py +153 -4
- unique_toolkit/content/schemas.py +122 -15
- unique_toolkit/content/service.py +278 -44
- unique_toolkit/content/smart_rules.py +301 -0
- unique_toolkit/content/utils.py +8 -3
- unique_toolkit/embedding/service.py +102 -11
- unique_toolkit/framework_utilities/__init__.py +1 -0
- unique_toolkit/framework_utilities/langchain/client.py +71 -0
- unique_toolkit/framework_utilities/langchain/history.py +19 -0
- unique_toolkit/framework_utilities/openai/__init__.py +6 -0
- unique_toolkit/framework_utilities/openai/client.py +83 -0
- unique_toolkit/framework_utilities/openai/message_builder.py +229 -0
- unique_toolkit/framework_utilities/utils.py +23 -0
- unique_toolkit/language_model/__init__.py +3 -0
- unique_toolkit/language_model/builder.py +27 -11
- unique_toolkit/language_model/default_language_model.py +3 -0
- unique_toolkit/language_model/functions.py +327 -43
- unique_toolkit/language_model/infos.py +992 -50
- unique_toolkit/language_model/reference.py +242 -0
- unique_toolkit/language_model/schemas.py +475 -48
- unique_toolkit/language_model/service.py +228 -27
- unique_toolkit/protocols/support.py +145 -0
- unique_toolkit/services/__init__.py +7 -0
- unique_toolkit/services/chat_service.py +1630 -0
- unique_toolkit/services/knowledge_base.py +861 -0
- unique_toolkit/short_term_memory/service.py +178 -41
- unique_toolkit/smart_rules/__init__.py +0 -0
- unique_toolkit/smart_rules/compile.py +56 -0
- unique_toolkit/test_utilities/events.py +197 -0
- {unique_toolkit-0.7.7.dist-info → unique_toolkit-1.23.0.dist-info}/METADATA +606 -7
- unique_toolkit-1.23.0.dist-info/RECORD +182 -0
- unique_toolkit/evaluators/__init__.py +0 -1
- unique_toolkit/evaluators/config.py +0 -35
- unique_toolkit/evaluators/constants.py +0 -1
- unique_toolkit/evaluators/context_relevancy/constants.py +0 -32
- unique_toolkit/evaluators/context_relevancy/service.py +0 -53
- unique_toolkit/evaluators/context_relevancy/utils.py +0 -142
- unique_toolkit/evaluators/hallucination/constants.py +0 -41
- unique_toolkit-0.7.7.dist-info/RECORD +0 -64
- /unique_toolkit/{evaluators → agentic/evaluation}/exception.py +0 -0
- {unique_toolkit-0.7.7.dist-info → unique_toolkit-1.23.0.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.7.7.dist-info → unique_toolkit-1.23.0.dist-info}/WHEEL +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from typing import overload
|
|
2
|
+
|
|
1
3
|
from typing_extensions import deprecated
|
|
2
4
|
|
|
3
5
|
from unique_toolkit._common.validate_required_values import validate_required_values
|
|
@@ -16,17 +18,35 @@ from .schemas import ShortTermMemory
|
|
|
16
18
|
class ShortTermMemoryService:
|
|
17
19
|
"""
|
|
18
20
|
Provides methods to manage short term memory.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@deprecated(
|
|
24
|
+
"Use __init__ with company_id and user_id instead or use the classmethod `from_event`"
|
|
25
|
+
)
|
|
26
|
+
@overload
|
|
27
|
+
def __init__(self, event: Event | ChatEvent | BaseEvent): ...
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
Initialize the ShortTermMemoryService with an event (deprecated)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
@overload
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
*,
|
|
37
|
+
company_id: str,
|
|
38
|
+
user_id: str,
|
|
39
|
+
chat_id: str | None,
|
|
40
|
+
message_id: str | None,
|
|
41
|
+
): ...
|
|
19
42
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
company_id (str | None): The company ID.
|
|
23
|
-
chat_id (str | None): The chat ID.
|
|
24
|
-
message_id (str | None): The message ID.
|
|
43
|
+
"""
|
|
44
|
+
Initialize the ShortTermMemoryService with a company_id, user_id, chat_id and message_id.
|
|
25
45
|
"""
|
|
26
46
|
|
|
27
47
|
def __init__(
|
|
28
48
|
self,
|
|
29
|
-
event: Event | BaseEvent | None = None,
|
|
49
|
+
event: Event | ChatEvent | BaseEvent | None = None,
|
|
30
50
|
user_id: str | None = None,
|
|
31
51
|
company_id: str | None = None,
|
|
32
52
|
chat_id: str | None = None,
|
|
@@ -34,20 +54,33 @@ class ShortTermMemoryService:
|
|
|
34
54
|
):
|
|
35
55
|
self._event = event
|
|
36
56
|
if event:
|
|
37
|
-
self.
|
|
38
|
-
self.
|
|
57
|
+
self._company_id: str = event.company_id
|
|
58
|
+
self._user_id: str = event.user_id
|
|
39
59
|
if isinstance(event, (ChatEvent, Event)):
|
|
40
|
-
self.
|
|
41
|
-
self.
|
|
60
|
+
self._chat_id = event.payload.chat_id
|
|
61
|
+
self._message_id = event.payload.user_message.id
|
|
42
62
|
else:
|
|
43
63
|
[company_id, user_id] = validate_required_values([company_id, user_id])
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
self.
|
|
49
|
-
self.
|
|
50
|
-
self.
|
|
64
|
+
|
|
65
|
+
if not (chat_id or message_id):
|
|
66
|
+
raise ValueError("Chat_id or message_id must be provided")
|
|
67
|
+
|
|
68
|
+
self._company_id: str = company_id
|
|
69
|
+
self._user_id: str = user_id
|
|
70
|
+
self._chat_id: str | None = chat_id
|
|
71
|
+
self._message_id: str | None = message_id
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def from_event(cls, event: ChatEvent):
|
|
75
|
+
"""
|
|
76
|
+
Initialize the ShortTermMemoryService with a chat event.
|
|
77
|
+
"""
|
|
78
|
+
return cls(
|
|
79
|
+
company_id=event.company_id,
|
|
80
|
+
user_id=event.user_id,
|
|
81
|
+
chat_id=event.payload.chat_id,
|
|
82
|
+
message_id=event.payload.user_message.id,
|
|
83
|
+
)
|
|
51
84
|
|
|
52
85
|
@property
|
|
53
86
|
@deprecated(
|
|
@@ -62,6 +95,110 @@ class ShortTermMemoryService:
|
|
|
62
95
|
"""
|
|
63
96
|
return self._event
|
|
64
97
|
|
|
98
|
+
@property
|
|
99
|
+
@deprecated(
|
|
100
|
+
"The company_id property is deprecated and will be removed in a future version."
|
|
101
|
+
)
|
|
102
|
+
def company_id(self) -> str | None:
|
|
103
|
+
"""
|
|
104
|
+
Get the company identifier (deprecated).
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
str | None: The company identifier.
|
|
108
|
+
"""
|
|
109
|
+
return self._company_id
|
|
110
|
+
|
|
111
|
+
@company_id.setter
|
|
112
|
+
@deprecated(
|
|
113
|
+
"The company_id setter is deprecated and will be removed in a future version."
|
|
114
|
+
)
|
|
115
|
+
def company_id(self, value: str) -> None:
|
|
116
|
+
"""
|
|
117
|
+
Set the company identifier (deprecated).
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
value (str | None): The company identifier.
|
|
121
|
+
"""
|
|
122
|
+
self._company_id = value
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
@deprecated(
|
|
126
|
+
"The user_id property is deprecated and will be removed in a future version."
|
|
127
|
+
)
|
|
128
|
+
def user_id(self) -> str | None:
|
|
129
|
+
"""
|
|
130
|
+
Get the user identifier (deprecated).
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
str | None: The user identifier.
|
|
134
|
+
"""
|
|
135
|
+
return self._user_id
|
|
136
|
+
|
|
137
|
+
@user_id.setter
|
|
138
|
+
@deprecated(
|
|
139
|
+
"The user_id setter is deprecated and will be removed in a future version."
|
|
140
|
+
)
|
|
141
|
+
def user_id(self, value: str) -> None:
|
|
142
|
+
"""
|
|
143
|
+
Set the user identifier (deprecated).
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
value (str | None): The user identifier.
|
|
147
|
+
"""
|
|
148
|
+
self._user_id = value
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
@deprecated(
|
|
152
|
+
"The chat_id property is deprecated and will be removed in a future version."
|
|
153
|
+
)
|
|
154
|
+
def chat_id(self) -> str | None:
|
|
155
|
+
"""
|
|
156
|
+
Get the chat identifier (deprecated).
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
str | None: The chat identifier.
|
|
160
|
+
"""
|
|
161
|
+
return self._chat_id
|
|
162
|
+
|
|
163
|
+
@chat_id.setter
|
|
164
|
+
@deprecated(
|
|
165
|
+
"The chat_id setter is deprecated and will be removed in a future version."
|
|
166
|
+
)
|
|
167
|
+
def chat_id(self, value: str | None) -> None:
|
|
168
|
+
"""
|
|
169
|
+
Set the chat identifier (deprecated).
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
value (str | None): The chat identifier.
|
|
173
|
+
"""
|
|
174
|
+
self._chat_id = value
|
|
175
|
+
|
|
176
|
+
@property
|
|
177
|
+
@deprecated(
|
|
178
|
+
"The message_id property is deprecated and will be removed in a future version."
|
|
179
|
+
)
|
|
180
|
+
def message_id(self) -> str | None:
|
|
181
|
+
"""
|
|
182
|
+
Get the message identifier (deprecated).
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
str | None: The message identifier.
|
|
186
|
+
"""
|
|
187
|
+
return self._message_id
|
|
188
|
+
|
|
189
|
+
@message_id.setter
|
|
190
|
+
@deprecated(
|
|
191
|
+
"The message_id setter is deprecated and will be removed in a future version."
|
|
192
|
+
)
|
|
193
|
+
def message_id(self, value: str | None) -> None:
|
|
194
|
+
"""
|
|
195
|
+
Set the message identifier (deprecated).
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
value (str | None): The message identifier.
|
|
199
|
+
"""
|
|
200
|
+
self._message_id = value
|
|
201
|
+
|
|
65
202
|
@classmethod
|
|
66
203
|
@deprecated("Instantiate class directly from event")
|
|
67
204
|
def from_chat_event(cls, chat_event: Event) -> "ShortTermMemoryService":
|
|
@@ -87,11 +224,11 @@ class ShortTermMemoryService:
|
|
|
87
224
|
"""
|
|
88
225
|
|
|
89
226
|
return await find_latest_memory_async(
|
|
90
|
-
user_id=self.
|
|
91
|
-
company_id=self.
|
|
227
|
+
user_id=self._user_id,
|
|
228
|
+
company_id=self._company_id,
|
|
92
229
|
key=key,
|
|
93
|
-
chat_id=self.
|
|
94
|
-
message_id=self.
|
|
230
|
+
chat_id=self._chat_id,
|
|
231
|
+
message_id=self._message_id,
|
|
95
232
|
)
|
|
96
233
|
|
|
97
234
|
def find_latest_memory(self, key: str) -> ShortTermMemory:
|
|
@@ -109,11 +246,11 @@ class ShortTermMemoryService:
|
|
|
109
246
|
"""
|
|
110
247
|
|
|
111
248
|
return find_latest_memory(
|
|
112
|
-
user_id=self.
|
|
113
|
-
company_id=self.
|
|
249
|
+
user_id=self._user_id,
|
|
250
|
+
company_id=self._company_id,
|
|
114
251
|
key=key,
|
|
115
|
-
chat_id=self.
|
|
116
|
-
message_id=self.
|
|
252
|
+
chat_id=self._chat_id,
|
|
253
|
+
message_id=self._message_id,
|
|
117
254
|
)
|
|
118
255
|
|
|
119
256
|
async def create_memory_async(self, key: str, value: str | dict):
|
|
@@ -132,12 +269,12 @@ class ShortTermMemoryService:
|
|
|
132
269
|
"""
|
|
133
270
|
|
|
134
271
|
return await create_memory_async(
|
|
135
|
-
user_id=self.
|
|
136
|
-
company_id=self.
|
|
272
|
+
user_id=self._user_id,
|
|
273
|
+
company_id=self._company_id,
|
|
137
274
|
key=key,
|
|
138
275
|
value=value,
|
|
139
|
-
chat_id=self.
|
|
140
|
-
message_id=self.
|
|
276
|
+
chat_id=self._chat_id,
|
|
277
|
+
message_id=self._message_id,
|
|
141
278
|
)
|
|
142
279
|
|
|
143
280
|
def create_memory(self, key: str, value: str | dict):
|
|
@@ -155,31 +292,31 @@ class ShortTermMemoryService:
|
|
|
155
292
|
"""
|
|
156
293
|
|
|
157
294
|
return create_memory(
|
|
158
|
-
user_id=self.
|
|
159
|
-
company_id=self.
|
|
295
|
+
user_id=self._user_id,
|
|
296
|
+
company_id=self._company_id,
|
|
160
297
|
key=key,
|
|
161
298
|
value=value,
|
|
162
|
-
chat_id=self.
|
|
163
|
-
message_id=self.
|
|
299
|
+
chat_id=self._chat_id,
|
|
300
|
+
message_id=self._message_id,
|
|
164
301
|
)
|
|
165
302
|
|
|
166
303
|
@deprecated("Use create_memory_async instead")
|
|
167
304
|
async def set(self, key: str, value: str | dict):
|
|
168
305
|
return await create_memory_async(
|
|
169
|
-
user_id=self.
|
|
170
|
-
company_id=self.
|
|
306
|
+
user_id=self._user_id,
|
|
307
|
+
company_id=self._company_id,
|
|
171
308
|
key=key,
|
|
172
309
|
value=value,
|
|
173
|
-
chat_id=self.
|
|
174
|
-
message_id=self.
|
|
310
|
+
chat_id=self._chat_id,
|
|
311
|
+
message_id=self._message_id,
|
|
175
312
|
)
|
|
176
313
|
|
|
177
314
|
@deprecated("Use find_latest_memory_async instead")
|
|
178
315
|
async def get(self, key: str) -> ShortTermMemory:
|
|
179
316
|
return await find_latest_memory_async(
|
|
180
|
-
user_id=self.
|
|
181
|
-
company_id=self.
|
|
317
|
+
user_id=self._user_id,
|
|
318
|
+
company_id=self._company_id,
|
|
182
319
|
key=key,
|
|
183
|
-
chat_id=self.
|
|
184
|
-
message_id=self.
|
|
320
|
+
chat_id=self._chat_id,
|
|
321
|
+
message_id=self._message_id,
|
|
185
322
|
)
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from unique_toolkit.content.smart_rules import (
|
|
4
|
+
AndStatement,
|
|
5
|
+
BaseStatement,
|
|
6
|
+
Operator,
|
|
7
|
+
OrStatement,
|
|
8
|
+
Statement,
|
|
9
|
+
UniqueQL,
|
|
10
|
+
array_operator,
|
|
11
|
+
binary_operator,
|
|
12
|
+
calculate_current_date,
|
|
13
|
+
calculate_earlier_date,
|
|
14
|
+
calculate_later_date,
|
|
15
|
+
empty_operator,
|
|
16
|
+
eval_nested_operator,
|
|
17
|
+
eval_operator,
|
|
18
|
+
get_fallback_values,
|
|
19
|
+
is_array_of_strings,
|
|
20
|
+
null_operator,
|
|
21
|
+
parse_uniqueql,
|
|
22
|
+
replace_tool_parameters_patterns,
|
|
23
|
+
replace_user_metadata_patterns,
|
|
24
|
+
replace_variables,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
warnings.warn(
|
|
28
|
+
"unique_toolkit.smart_rules.compile is deprecated. "
|
|
29
|
+
"Please use unique_toolkit.content.smart_rules instead.",
|
|
30
|
+
DeprecationWarning,
|
|
31
|
+
stacklevel=2,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
"AndStatement",
|
|
36
|
+
"BaseStatement",
|
|
37
|
+
"Operator",
|
|
38
|
+
"OrStatement",
|
|
39
|
+
"Statement",
|
|
40
|
+
"UniqueQL",
|
|
41
|
+
"array_operator",
|
|
42
|
+
"binary_operator",
|
|
43
|
+
"calculate_current_date",
|
|
44
|
+
"calculate_earlier_date",
|
|
45
|
+
"calculate_later_date",
|
|
46
|
+
"empty_operator",
|
|
47
|
+
"eval_nested_operator",
|
|
48
|
+
"eval_operator",
|
|
49
|
+
"get_fallback_values",
|
|
50
|
+
"is_array_of_strings",
|
|
51
|
+
"null_operator",
|
|
52
|
+
"parse_uniqueql",
|
|
53
|
+
"replace_tool_parameters_patterns",
|
|
54
|
+
"replace_user_metadata_patterns",
|
|
55
|
+
"replace_variables",
|
|
56
|
+
]
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import string
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from unique_toolkit.app.schemas import (
|
|
7
|
+
BaseEvent,
|
|
8
|
+
ChatEvent,
|
|
9
|
+
ChatEventAdditionalParameters,
|
|
10
|
+
ChatEventAssistantMessage,
|
|
11
|
+
ChatEventPayload,
|
|
12
|
+
ChatEventUserMessage,
|
|
13
|
+
EventName,
|
|
14
|
+
)
|
|
15
|
+
from unique_toolkit.app.unique_settings import UniqueSettings
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def generated_numeric_string(length: int) -> str:
|
|
19
|
+
return "".join(random.choices(string.digits, k=length))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def generated_alphanumeric_string(length: int) -> str:
|
|
23
|
+
return "".join(random.choices(string.ascii_letters + string.digits, k=length))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def generated_chat_id() -> str:
|
|
27
|
+
return f"chat_{generated_alphanumeric_string(16)}"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def generated_assistant_id() -> str:
|
|
31
|
+
return f"assistant_{generated_alphanumeric_string(16)}"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def generated_user_message_id() -> str:
|
|
35
|
+
return f"msg_{generated_alphanumeric_string(16)}"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestEventFactory:
|
|
39
|
+
"""Factory for creating test event objects with sensible defaults.
|
|
40
|
+
|
|
41
|
+
Simplifies test setup by providing convenient methods to generate
|
|
42
|
+
chat events, messages, and related objects for testing.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, settings: UniqueSettings | None = None) -> None:
|
|
46
|
+
self._settings = settings
|
|
47
|
+
|
|
48
|
+
def _get_user_id(self) -> str:
|
|
49
|
+
if self._settings is None:
|
|
50
|
+
return generated_numeric_string(16)
|
|
51
|
+
else:
|
|
52
|
+
return self._settings.auth.user_id.get_secret_value()
|
|
53
|
+
|
|
54
|
+
def _get_company_id(self) -> str:
|
|
55
|
+
if self._settings is None:
|
|
56
|
+
return generated_numeric_string(16)
|
|
57
|
+
else:
|
|
58
|
+
return self._settings.auth.company_id.get_secret_value()
|
|
59
|
+
|
|
60
|
+
def get_chat_event_user_message(
|
|
61
|
+
self,
|
|
62
|
+
text: str,
|
|
63
|
+
*,
|
|
64
|
+
created_at: datetime | None = None,
|
|
65
|
+
language: str = "DE",
|
|
66
|
+
original_text: str | None = None,
|
|
67
|
+
) -> ChatEventUserMessage:
|
|
68
|
+
if created_at is None:
|
|
69
|
+
created_at = datetime.now()
|
|
70
|
+
|
|
71
|
+
return ChatEventUserMessage(
|
|
72
|
+
id=generated_user_message_id(),
|
|
73
|
+
text=text,
|
|
74
|
+
original_text=original_text or text,
|
|
75
|
+
created_at=created_at.isoformat(),
|
|
76
|
+
language=language,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def get_chat_event_assistant_message(
|
|
80
|
+
self, *, created_at: datetime | None = None
|
|
81
|
+
) -> ChatEventAssistantMessage:
|
|
82
|
+
if created_at is None:
|
|
83
|
+
created_at = datetime.now()
|
|
84
|
+
|
|
85
|
+
return ChatEventAssistantMessage(
|
|
86
|
+
id=generated_assistant_id(), created_at=created_at.isoformat()
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
def get_chat_event_additional_parameters(
|
|
90
|
+
self,
|
|
91
|
+
*,
|
|
92
|
+
translate_to_language: str | None = None,
|
|
93
|
+
content_id_to_translate: str | None = None,
|
|
94
|
+
) -> ChatEventAdditionalParameters:
|
|
95
|
+
return ChatEventAdditionalParameters(
|
|
96
|
+
translate_to_language=translate_to_language,
|
|
97
|
+
content_id_to_translate=content_id_to_translate,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def get_base_event(
|
|
101
|
+
self,
|
|
102
|
+
*,
|
|
103
|
+
event: EventName = EventName.EXTERNAL_MODULE_CHOSEN,
|
|
104
|
+
user_id: str | None = None,
|
|
105
|
+
company_id: str | None = None,
|
|
106
|
+
) -> BaseEvent:
|
|
107
|
+
return BaseEvent(
|
|
108
|
+
id=generated_alphanumeric_string(16),
|
|
109
|
+
event=event,
|
|
110
|
+
user_id=user_id or self._get_user_id(),
|
|
111
|
+
company_id=company_id or self._get_company_id(),
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def get_chat_event_payload(
|
|
115
|
+
self,
|
|
116
|
+
*,
|
|
117
|
+
name: str,
|
|
118
|
+
description: str,
|
|
119
|
+
user_message_text: str,
|
|
120
|
+
user_message_created_at: datetime | None = None,
|
|
121
|
+
user_message_language: str = "DE",
|
|
122
|
+
user_message_original_text: str | None = None,
|
|
123
|
+
assistant_message_created_at: datetime | None = None,
|
|
124
|
+
configuration: dict[str, Any] | None = None,
|
|
125
|
+
chat_id: str | None = None,
|
|
126
|
+
assistant_id: str | None = None,
|
|
127
|
+
) -> ChatEventPayload:
|
|
128
|
+
if chat_id is None:
|
|
129
|
+
chat_id = generated_chat_id()
|
|
130
|
+
|
|
131
|
+
if assistant_id is None:
|
|
132
|
+
assistant_id = generated_assistant_id()
|
|
133
|
+
|
|
134
|
+
assistant_message = self.get_chat_event_assistant_message(
|
|
135
|
+
created_at=assistant_message_created_at or datetime.now()
|
|
136
|
+
)
|
|
137
|
+
user_message = self.get_chat_event_user_message(
|
|
138
|
+
text=user_message_text,
|
|
139
|
+
created_at=user_message_created_at or datetime.now(),
|
|
140
|
+
language=user_message_language,
|
|
141
|
+
original_text=user_message_original_text,
|
|
142
|
+
)
|
|
143
|
+
return ChatEventPayload(
|
|
144
|
+
name=name,
|
|
145
|
+
description=description,
|
|
146
|
+
configuration=configuration or {},
|
|
147
|
+
chat_id=chat_id,
|
|
148
|
+
assistant_id=assistant_id,
|
|
149
|
+
user_message=user_message,
|
|
150
|
+
assistant_message=assistant_message,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
def get_chat_event(
|
|
154
|
+
self,
|
|
155
|
+
*,
|
|
156
|
+
name: str,
|
|
157
|
+
event_name: EventName = EventName.EXTERNAL_MODULE_CHOSEN,
|
|
158
|
+
description: str,
|
|
159
|
+
user_message_text: str,
|
|
160
|
+
user_message_created_at: datetime = datetime.now(),
|
|
161
|
+
user_message_language: str = "DE",
|
|
162
|
+
user_message_original_text: str | None = None,
|
|
163
|
+
assistant_message_created_at: datetime | None = None,
|
|
164
|
+
configuration: dict[str, Any] | None = None,
|
|
165
|
+
chat_id: str | None = None,
|
|
166
|
+
assistant_id: str | None = None,
|
|
167
|
+
user_id: str | None = None,
|
|
168
|
+
company_id: str | None = None,
|
|
169
|
+
version: str = "1.0",
|
|
170
|
+
) -> ChatEvent:
|
|
171
|
+
if chat_id is None:
|
|
172
|
+
chat_id = generated_chat_id()
|
|
173
|
+
|
|
174
|
+
if assistant_id is None:
|
|
175
|
+
assistant_id = generated_assistant_id()
|
|
176
|
+
|
|
177
|
+
payload = self.get_chat_event_payload(
|
|
178
|
+
name=name,
|
|
179
|
+
description=description,
|
|
180
|
+
user_message_text=user_message_text,
|
|
181
|
+
user_message_created_at=user_message_created_at,
|
|
182
|
+
user_message_language=user_message_language,
|
|
183
|
+
user_message_original_text=user_message_original_text,
|
|
184
|
+
assistant_message_created_at=assistant_message_created_at,
|
|
185
|
+
configuration=configuration or {},
|
|
186
|
+
chat_id=chat_id,
|
|
187
|
+
assistant_id=assistant_id,
|
|
188
|
+
)
|
|
189
|
+
return ChatEvent(
|
|
190
|
+
id=generated_alphanumeric_string(16),
|
|
191
|
+
event=event_name,
|
|
192
|
+
user_id=user_id or self._get_user_id(),
|
|
193
|
+
company_id=company_id or self._get_company_id(),
|
|
194
|
+
payload=payload,
|
|
195
|
+
created_at=int(datetime.now().timestamp()),
|
|
196
|
+
version=version,
|
|
197
|
+
)
|