unique_toolkit 1.14.0__py3-none-any.whl → 1.14.2__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.

@@ -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
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 1.14.0
3
+ Version: 1.14.2
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Cedric Klinkert
@@ -118,6 +118,12 @@ All notable changes to this project will be documented in this file.
118
118
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
119
119
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
120
120
 
121
+ ## [1.14.2] - 2025-10-08
122
+ - Add utilities for testing and fix external import issue
123
+
124
+ ## [1.14.1] - 2025-10-08
125
+ - Add utilities for testing
126
+
121
127
  ## [1.14.0] - 2025-10-07
122
128
  - Manipulate Metadata with knowledge base service
123
129
 
@@ -149,7 +149,8 @@ unique_toolkit/short_term_memory/schemas.py,sha256=OhfcXyF6ACdwIXW45sKzjtZX_gkcJ
149
149
  unique_toolkit/short_term_memory/service.py,sha256=5PeVBu1ZCAfyDb2HLVvlmqSbyzBBuE9sI2o9Aajqjxg,8884
150
150
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
151
151
  unique_toolkit/smart_rules/compile.py,sha256=Ozhh70qCn2yOzRWr9d8WmJeTo7AQurwd3tStgBMPFLA,1246
152
- unique_toolkit-1.14.0.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
153
- unique_toolkit-1.14.0.dist-info/METADATA,sha256=OWdWXkAGiHMEPujnxslwCXHkheERRJy_wC9Ad4uX7v0,36240
154
- unique_toolkit-1.14.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
155
- unique_toolkit-1.14.0.dist-info/RECORD,,
152
+ unique_toolkit/test_utilities/events.py,sha256=_mwV2bs5iLjxS1ynDCjaIq-gjjKhXYCK-iy3dRfvO3g,6410
153
+ unique_toolkit-1.14.2.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
154
+ unique_toolkit-1.14.2.dist-info/METADATA,sha256=eQ2eUEf5ZJGmkVM0ktzovm6CoLh_uTTnhGVQlHlsmII,36378
155
+ unique_toolkit-1.14.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
156
+ unique_toolkit-1.14.2.dist-info/RECORD,,