unique_toolkit 1.3.0__py3-none-any.whl → 1.3.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.
@@ -46,7 +46,8 @@ def get_event_generator(
46
46
  event_type: type[T],
47
47
  ) -> Generator[T, None, None]:
48
48
  """
49
- Generator that yields only events of the specified type from an SSE stream.
49
+ Generator that updates the unique settings according to the events and
50
+ yields only events of the specified type from an SSE stream.
50
51
 
51
52
  Args:
52
53
  sse_client: The SSE client to read events from
@@ -74,6 +75,8 @@ def get_event_generator(
74
75
  ):
75
76
  continue
76
77
 
78
+ unique_settings.update_from_event(event=parsed_event)
79
+
77
80
  yield parsed_event
78
81
 
79
82
  except Exception as e:
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  from logging import getLogger
3
3
  from pathlib import Path
4
- from typing import Self, TypeVar
4
+ from typing import TYPE_CHECKING, Self, TypeVar
5
5
  from urllib.parse import ParseResult, urlparse, urlunparse
6
6
 
7
7
  import unique_sdk
@@ -9,6 +9,10 @@ from platformdirs import user_config_dir
9
9
  from pydantic import AliasChoices, Field, SecretStr, model_validator
10
10
  from pydantic_settings import BaseSettings, SettingsConfigDict
11
11
 
12
+ if TYPE_CHECKING:
13
+ from unique_toolkit.app.schemas import BaseEvent
14
+
15
+
12
16
  logger = getLogger(__name__)
13
17
 
14
18
  T = TypeVar("T", bound=BaseSettings)
@@ -159,6 +163,13 @@ class UniqueAuth(BaseSettings):
159
163
  def _warn_about_defaults(self) -> Self:
160
164
  return warn_about_defaults(self)
161
165
 
166
+ @classmethod
167
+ def from_event(cls, event: "BaseEvent") -> Self:
168
+ return cls(
169
+ company_id=SecretStr(event.company_id),
170
+ user_id=SecretStr(event.user_id),
171
+ )
172
+
162
173
 
163
174
  class UniqueChatEventFilterOptions(BaseSettings):
164
175
  # Empty string evals to False
@@ -197,10 +208,10 @@ class UniqueSettings:
197
208
  chat_event_filter_options: UniqueChatEventFilterOptions | None = None,
198
209
  env_file: Path | None = None,
199
210
  ):
200
- self.app = app
201
- self.auth = auth
202
- self.api = api
203
- self.chat_event_filter_options = chat_event_filter_options
211
+ self._app = app
212
+ self._auth = auth
213
+ self._api = api
214
+ self._chat_event_filter_options = chat_event_filter_options
204
215
  self._env_file: Path | None = (
205
216
  env_file if (env_file and env_file.exists()) else None
206
217
  )
@@ -310,9 +321,9 @@ class UniqueSettings:
310
321
  This method configures the global unique_sdk module with the API key,
311
322
  app ID, and base URL from these settings.
312
323
  """
313
- unique_sdk.api_key = self.app.key.get_secret_value()
314
- unique_sdk.app_id = self.app.id.get_secret_value()
315
- unique_sdk.api_base = self.api.sdk_url()
324
+ unique_sdk.api_key = self._app.key.get_secret_value()
325
+ unique_sdk.app_id = self._app.id.get_secret_value()
326
+ unique_sdk.api_base = self._api.sdk_url()
316
327
 
317
328
  @classmethod
318
329
  def from_env_auto_with_sdk_init(
@@ -331,3 +342,26 @@ class UniqueSettings:
331
342
  settings = cls.from_env_auto(filename)
332
343
  settings.init_sdk()
333
344
  return settings
345
+
346
+ def update_from_event(self, event: "BaseEvent") -> None:
347
+ self._auth = UniqueAuth.from_event(event)
348
+
349
+ @property
350
+ def api(self) -> UniqueApi:
351
+ return self._api
352
+
353
+ @property
354
+ def app(self) -> UniqueApp:
355
+ return self._app
356
+
357
+ @property
358
+ def auth(self) -> UniqueAuth:
359
+ return self._auth
360
+
361
+ @auth.setter
362
+ def auth(self, value: UniqueAuth) -> None:
363
+ self._auth = value
364
+
365
+ @property
366
+ def chat_event_filter_options(self) -> UniqueChatEventFilterOptions | None:
367
+ return self._chat_event_filter_options
@@ -26,15 +26,41 @@ class ContentMetadata(BaseModel):
26
26
 
27
27
  class ContentChunk(BaseModel):
28
28
  model_config = model_config
29
- id: str
30
- text: str
31
- order: int
32
- key: str | None = None
33
- chunk_id: str | None = None
34
- url: str | None = None
35
- title: str | None = None
36
- start_page: int | None = None
37
- end_page: int | None = None
29
+ id: str = Field(
30
+ default="",
31
+ description="The id of the content this chunk belongs to. The id starts with 'cont_' followed by an alphanumeric string of length 24.",
32
+ examples=["cont_abcdefgehijklmnopqrstuvwx"],
33
+ )
34
+ text: str = Field(default="", description="The text content of the chunk.")
35
+ order: int = Field(
36
+ default=0,
37
+ description="The order of the chunk in the original content. Concatenating the chunks in order will give the original content.",
38
+ )
39
+ key: str | None = Field(
40
+ default=None,
41
+ description="The key of the chunk. For document chunks this is the the filename",
42
+ )
43
+ chunk_id: str | None = Field(
44
+ default=None,
45
+ description="The id of the chunk. The id starts with 'chunk_' followed by an alphanumeric string of length 24.",
46
+ examples=["chunk_abcdefgehijklmnopqrstuv"],
47
+ )
48
+ url: str | None = Field(
49
+ default=None,
50
+ description="For chunk retrieved from the web this is the url of the chunk.",
51
+ )
52
+ title: str | None = Field(
53
+ default=None,
54
+ description="The title of the chunk. For document chunks this is the title of the document.",
55
+ )
56
+ start_page: int | None = Field(
57
+ default=None,
58
+ description="The start page of the chunk. For document chunks this is the start page of the document.",
59
+ )
60
+ end_page: int | None = Field(
61
+ default=None,
62
+ description="The end page of the chunk. For document chunks this is the end page of the document.",
63
+ )
38
64
 
39
65
  object: str | None = None
40
66
  metadata: ContentMetadata | None = None
@@ -45,9 +71,19 @@ class ContentChunk(BaseModel):
45
71
 
46
72
  class Content(BaseModel):
47
73
  model_config = model_config
48
- id: str
49
- key: str
50
- title: str | None = None
74
+ id: str = Field(
75
+ default="",
76
+ description="The id of the content. The id starts with 'cont_' followed by an alphanumeric string of length 24.",
77
+ examples=["cont_abcdefgehijklmnopqrstuvwx"],
78
+ )
79
+ key: str = Field(
80
+ default="",
81
+ description="The key of the content. For documents this is the the filename",
82
+ )
83
+ title: str | None = Field(
84
+ default=None,
85
+ description="The title of the content. For documents this is the title of the document.",
86
+ )
51
87
  url: str | None = None
52
88
  chunks: list[ContentChunk] = []
53
89
  write_url: str | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 1.3.0
3
+ Version: 1.3.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.3.2] - 2025-09-29
122
+ - Auto-update unique settings on event arrival in SSE client
123
+
124
+ ## [1.3.1] - 2025-09-29
125
+ - More documentation on referencing
126
+
121
127
  ## [1.3.0] - 2025-09-28
122
128
  - Add utilitiy to enhance pydantic model with metadata
123
129
  - Add capability to collect this metadata with same hierarchy as nested pydantic models
@@ -81,13 +81,13 @@ unique_toolkit/agentic/tools/utils/source_handling/schema.py,sha256=l4B6kA6grbL-
81
81
  unique_toolkit/agentic/tools/utils/source_handling/source_formatting.py,sha256=uZ0QXqrPWgId3ZA67dvjHQ6xrW491LK1xxx_sVJmFHg,9160
82
82
  unique_toolkit/agentic/tools/utils/source_handling/tests/test_source_formatting.py,sha256=EA8iVvb3L91OFk2XMbGcFuhe2etqm3Sx9QCYDGiOSOM,6995
83
83
  unique_toolkit/app/__init__.py,sha256=ETxYDpEizg_PKmi4JPX_P76ySq-us-xypfAIdKQ1QZU,1284
84
- unique_toolkit/app/dev_util.py,sha256=BmrVpZ86_X3NCd9irNPvT5VFL9-7tF7muZeaCL53j4M,5185
84
+ unique_toolkit/app/dev_util.py,sha256=5tkGEcjHZ1u4kY0yUOhTWLjhXLvAcEMutY3h8j1bBJE,5312
85
85
  unique_toolkit/app/init_logging.py,sha256=Sh26SRxOj8i8dzobKhYha2lLrkrMTHfB1V4jR3h23gQ,678
86
86
  unique_toolkit/app/init_sdk.py,sha256=5_oDoETr6akwYyBCb0ivTdMNu3SVgPSkrXcDS6ELyY8,2269
87
87
  unique_toolkit/app/performance/async_tasks.py,sha256=H0l3OAcosLwNHZ8d2pd-Di4wHIXfclEvagi5kfqLFPA,1941
88
88
  unique_toolkit/app/performance/async_wrapper.py,sha256=yVVcRDkcdyfjsxro-N29SBvi-7773wnfDplef6-y8xw,1077
89
89
  unique_toolkit/app/schemas.py,sha256=UE1UaL_N2o48O-mLb_rF3Sp9MrVkfdDE6f_dm7WTOO4,9137
90
- unique_toolkit/app/unique_settings.py,sha256=JNU0LrlldVx1GUeSS0Mr1tqT67934KWU2OeVWkNUu28,11510
90
+ unique_toolkit/app/unique_settings.py,sha256=849pbASOu8QbHu9QfCJhYTisjKRet34J-fRs0gNKZ0Q,12369
91
91
  unique_toolkit/app/verification.py,sha256=GxFFwcJMy25fCA_Xe89wKW7bgqOu8PAs5y8QpHF0GSc,3861
92
92
  unique_toolkit/chat/__init__.py,sha256=LRs2G-JTVuci4lbtHTkVUiNcZcSR6uqqfnAyo7af6nY,619
93
93
  unique_toolkit/chat/constants.py,sha256=05kq6zjqUVB2d6_P7s-90nbljpB3ryxwCI-CAz0r2O4,83
@@ -99,7 +99,7 @@ unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,
99
99
  unique_toolkit/content/__init__.py,sha256=EdJg_A_7loEtCQf4cah3QARQreJx6pdz89Rm96YbMVg,940
100
100
  unique_toolkit/content/constants.py,sha256=1iy4Y67xobl5VTnJB6SxSyuoBWbdLl9244xfVMUZi5o,60
101
101
  unique_toolkit/content/functions.py,sha256=1zhxaJEYTvvd4qzkrbEFcrjdJxhHkfUY3dEpNfNC_hk,19052
102
- unique_toolkit/content/schemas.py,sha256=KJ604BOx0vBh2AwlTCZkOo55aHsI6yj8vxDAARKKqEo,2995
102
+ unique_toolkit/content/schemas.py,sha256=WB3InkKIvfWbyg9CsKFLn8Zf4zrE-YqGpCc3a0zOk7k,4774
103
103
  unique_toolkit/content/service.py,sha256=ZUXJwfNdHsAw_F7cfRMDVgHpSKxiwG6Cn8p7c4hV8TM,24053
104
104
  unique_toolkit/content/utils.py,sha256=qNVmHTuETaPNGqheg7TbgPr1_1jbNHDc09N5RrmUIyo,7901
105
105
  unique_toolkit/embedding/__init__.py,sha256=uUyzjonPvuDCYsvXCIt7ErQXopLggpzX-MEQd3_e2kE,250
@@ -133,7 +133,7 @@ unique_toolkit/short_term_memory/schemas.py,sha256=OhfcXyF6ACdwIXW45sKzjtZX_gkcJ
133
133
  unique_toolkit/short_term_memory/service.py,sha256=5PeVBu1ZCAfyDb2HLVvlmqSbyzBBuE9sI2o9Aajqjxg,8884
134
134
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
135
135
  unique_toolkit/smart_rules/compile.py,sha256=cxWjb2dxEI2HGsakKdVCkSNi7VK9mr08w5sDcFCQyWI,9553
136
- unique_toolkit-1.3.0.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
137
- unique_toolkit-1.3.0.dist-info/METADATA,sha256=63zIDL6zXri4f4WWuUFB4jb0m5XGi6oL4jdSUlCfTf4,33548
138
- unique_toolkit-1.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
139
- unique_toolkit-1.3.0.dist-info/RECORD,,
136
+ unique_toolkit-1.3.2.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
137
+ unique_toolkit-1.3.2.dist-info/METADATA,sha256=64vZcZcbk6v47satQNAuj1iuDrkR15OyO2GjqoOOX6s,33695
138
+ unique_toolkit-1.3.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
139
+ unique_toolkit-1.3.2.dist-info/RECORD,,