unique_toolkit 0.7.35__tar.gz → 0.7.37__tar.gz

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.
Files changed (73) hide show
  1. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/CHANGELOG.md +4 -0
  2. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/PKG-INFO +7 -1
  3. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/pyproject.toml +3 -1
  4. unique_toolkit-0.7.37/unique_toolkit/app/event_util.py +24 -0
  5. unique_toolkit-0.7.37/unique_toolkit/app/sse_client.py +20 -0
  6. unique_toolkit-0.7.37/unique_toolkit/app/unique_settings.py +61 -0
  7. unique_toolkit-0.7.37/unique_toolkit/framework_utilities/langchain/history.py +19 -0
  8. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/reference.py +4 -1
  9. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/short_term_memory/service.py +3 -3
  10. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/LICENSE +0 -0
  11. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/README.md +0 -0
  12. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/__init__.py +0 -0
  13. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/_common/_base_service.py +0 -0
  14. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/_common/_time_utils.py +0 -0
  15. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/_common/exception.py +0 -0
  16. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/_common/validate_required_values.py +0 -0
  17. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/_common/validators.py +0 -0
  18. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/__init__.py +0 -0
  19. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/init_logging.py +0 -0
  20. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/init_sdk.py +0 -0
  21. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/performance/async_tasks.py +0 -0
  22. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  23. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/schemas.py +0 -0
  24. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/app/verification.py +0 -0
  25. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/__init__.py +0 -0
  26. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/constants.py +0 -0
  27. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/functions.py +0 -0
  28. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/schemas.py +0 -0
  29. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/service.py +0 -0
  30. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/state.py +0 -0
  31. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/chat/utils.py +0 -0
  32. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/__init__.py +0 -0
  33. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/constants.py +0 -0
  34. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/functions.py +0 -0
  35. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/schemas.py +0 -0
  36. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/service.py +0 -0
  37. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/content/utils.py +0 -0
  38. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/__init__.py +0 -0
  39. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/constants.py +0 -0
  40. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/functions.py +0 -0
  41. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/schemas.py +0 -0
  42. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/service.py +0 -0
  43. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/embedding/utils.py +0 -0
  44. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/__init__.py +0 -0
  45. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/config.py +0 -0
  46. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/constants.py +0 -0
  47. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/context_relevancy/constants.py +0 -0
  48. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  49. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  50. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/context_relevancy/utils.py +0 -0
  51. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/exception.py +0 -0
  52. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/hallucination/constants.py +0 -0
  53. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  54. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  55. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/hallucination/utils.py +0 -0
  56. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/output_parser.py +0 -0
  57. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/evaluators/schemas.py +0 -0
  58. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/__init__.py +0 -0
  59. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/builder.py +0 -0
  60. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/constants.py +0 -0
  61. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/functions.py +0 -0
  62. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/infos.py +0 -0
  63. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/prompt.py +0 -0
  64. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/schemas.py +0 -0
  65. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/service.py +0 -0
  66. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/language_model/utils.py +0 -0
  67. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/protocols/support.py +0 -0
  68. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/short_term_memory/__init__.py +0 -0
  69. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/short_term_memory/constants.py +0 -0
  70. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/short_term_memory/functions.py +0 -0
  71. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/short_term_memory/schemas.py +0 -0
  72. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/smart_rules/__init__.py +0 -0
  73. {unique_toolkit-0.7.35 → unique_toolkit-0.7.37}/unique_toolkit/smart_rules/compile.py +0 -0
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.7.36] - 2025-07-25
9
+ - Fix issues with settings
10
+ - Add testing to unique settings
11
+
8
12
  ## [0.7.35] - 2025-07-23
9
13
  - Bump version of SDK to have access to the latest features and fixes
10
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.7.35
3
+ Version: 0.7.37
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -12,9 +12,11 @@ Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Requires-Dist: numpy (>=1.26.4,<2.0.0)
14
14
  Requires-Dist: pydantic (>=2.8.2,<3.0.0)
15
+ Requires-Dist: pydantic-settings (>=2.10.1,<3.0.0)
15
16
  Requires-Dist: pyhumps (>=3.8.0,<4.0.0)
16
17
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
17
18
  Requires-Dist: regex (>=2024.5.15,<2025.0.0)
19
+ Requires-Dist: sseclient (>=0.0.27,<0.0.28)
18
20
  Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
19
21
  Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
20
22
  Requires-Dist: unique-sdk (>=0.9.40,<0.10.0)
@@ -111,6 +113,10 @@ All notable changes to this project will be documented in this file.
111
113
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
112
114
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
113
115
 
116
+ ## [0.7.36] - 2025-07-25
117
+ - Fix issues with settings
118
+ - Add testing to unique settings
119
+
114
120
  ## [0.7.35] - 2025-07-23
115
121
  - Bump version of SDK to have access to the latest features and fixes
116
122
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.7.35"
3
+ version = "0.7.37"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -21,6 +21,8 @@ python-dotenv = "^1.0.1"
21
21
  regex = "^2024.5.15"
22
22
  tiktoken = "^0.7.0"
23
23
  unique-sdk = "^0.9.40"
24
+ pydantic-settings = "^2.10.1"
25
+ sseclient = "^0.0.27"
24
26
 
25
27
  [tool.poetry.group.dev.dependencies]
26
28
  ruff = "0.11.7"
@@ -0,0 +1,24 @@
1
+ import json
2
+ from logging import getLogger
3
+ from typing import Literal, overload
4
+
5
+ from unique_toolkit.app import ChatEvent, EventName
6
+
7
+ LOGGER = getLogger(__name__)
8
+
9
+
10
+ @overload
11
+ def load_and_filter_event(
12
+ event: dict,
13
+ event_type: Literal[EventName.EXTERNAL_MODULE_CHOSEN],
14
+ ) -> type[ChatEvent] | None: ...
15
+
16
+
17
+ def load_and_filter_event(event: dict, event_type: EventName):
18
+ event = json.loads(event.data)
19
+
20
+ match event_type:
21
+ case EventName.EXTERNAL_MODULE_CHOSEN:
22
+ return ChatEvent(**event)
23
+
24
+ return None
@@ -0,0 +1,20 @@
1
+ from logging import getLogger
2
+
3
+ from sseclient import SSEClient
4
+
5
+ from unique_toolkit.app.unique_settings import UniqueSettings
6
+
7
+ LOGGER = getLogger(__name__)
8
+
9
+
10
+ def get_sse_client(
11
+ unique_settings: UniqueSettings,
12
+ subscriptions: list[str],
13
+ ) -> SSEClient:
14
+ url = f"{unique_settings.app.base_url}/public/event-socket/events/stream?subscriptions={','.join(subscriptions)}"
15
+ headers = {
16
+ "Authorization": f"Bearer {unique_settings.app.key}",
17
+ "x-app-id": unique_settings.app.id,
18
+ "x-company-id": unique_settings.auth.company_id,
19
+ }
20
+ return SSEClient(url=url, headers=headers)
@@ -0,0 +1,61 @@
1
+ from pathlib import Path
2
+
3
+ from pydantic import SecretStr
4
+ from pydantic_settings import BaseSettings, SettingsConfigDict
5
+
6
+
7
+ class UniqueApp(BaseSettings):
8
+ id: SecretStr
9
+ key: SecretStr
10
+ base_url: str
11
+ endpoint: str
12
+ endpoint_secret: SecretStr
13
+
14
+ model_config = SettingsConfigDict(
15
+ env_prefix="unique_app_",
16
+ env_file_encoding="utf-8",
17
+ case_sensitive=False,
18
+ extra="ignore",
19
+ )
20
+
21
+
22
+ class UniqueAuth(BaseSettings):
23
+ company_id: SecretStr
24
+ user_id: SecretStr
25
+
26
+ model_config = SettingsConfigDict(
27
+ env_prefix="unique_auth_",
28
+ env_file_encoding="utf-8",
29
+ case_sensitive=False,
30
+ extra="ignore",
31
+ )
32
+
33
+
34
+ class UniqueSettings:
35
+ def __init__(self, auth: UniqueAuth, app: UniqueApp):
36
+ self.app = app
37
+ self.auth = auth
38
+
39
+ @classmethod
40
+ def from_env(cls, env_file: Path | None = None) -> "UniqueSettings":
41
+ """Initialize settings from environment variables and/or env file.
42
+
43
+ Args:
44
+ env_file: Optional path to environment file. If provided, will load variables from this file.
45
+
46
+ Returns:
47
+ UniqueSettings instance with values loaded from environment/env file.
48
+
49
+ Raises:
50
+ FileNotFoundError: If env_file is provided but does not exist.
51
+ ValidationError: If required environment variables are missing.
52
+ """
53
+ if env_file and not env_file.exists():
54
+ raise FileNotFoundError(f"Environment file not found: {env_file}")
55
+
56
+ # Initialize settings with environment file if provided
57
+ env_file_str = str(env_file) if env_file else None
58
+ auth = UniqueAuth(_env_file=env_file_str, _env_file_encoding="utf-8")
59
+ app = UniqueApp(_env_file=env_file_str, _env_file_encoding="utf-8")
60
+
61
+ return cls(auth=auth, app=app)
@@ -0,0 +1,19 @@
1
+ from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
2
+
3
+ from unique_toolkit.chat import ChatMessage as UniqueMessage
4
+ from unique_toolkit.chat import ChatMessageRole as UniqueRole
5
+
6
+
7
+ def unique_history_to_langchain_history(
8
+ unique_history: list[UniqueMessage],
9
+ ) -> list[BaseMessage]:
10
+ history = []
11
+ for m in unique_history:
12
+ if m.role == UniqueRole.ASSISTANT:
13
+ history.append(AIMessage(content=m.content))
14
+ elif m.role == UniqueRole.USER:
15
+ history.append(HumanMessage(content=m.content))
16
+ else:
17
+ raise Exception("Unknown message role.")
18
+
19
+ return history
@@ -114,6 +114,7 @@ def _preprocess_message(text: str) -> str:
114
114
  def replace_source_colon(match):
115
115
  numbers = re.findall(r"\d+", match.group(0))
116
116
  return "".join(f"[{n}]" for n in numbers)
117
+
117
118
  text = re.sub(r"\[source:\s*([\d,\s]+)\]", replace_source_colon, text)
118
119
 
119
120
  # Replace '[[A], [B], ...]', '[[A], B, C, ...]', and '[X, Y, Z]' with [A][B][C]... where A,B,C are numbers
@@ -122,7 +123,9 @@ def _preprocess_message(text: str) -> str:
122
123
  return "".join(f"[{n}]" for n in numbers)
123
124
 
124
125
  text = re.sub(
125
- r"(?:\[\[(\d+)\](?:,\s*(?:\[)?\d+(?:\])?)*\]|\[([\d,\s]+)\])", replace_combined_brackets, text
126
+ r"(?:\[\[(\d+)\](?:,\s*(?:\[)?\d+(?:\])?)*\]|\[([\d,\s]+)\])",
127
+ replace_combined_brackets,
128
+ text,
126
129
  )
127
130
 
128
131
  return text
@@ -41,9 +41,9 @@ class ShortTermMemoryService:
41
41
  self._message_id = event.payload.user_message.id
42
42
  else:
43
43
  [company_id, user_id] = validate_required_values([company_id, user_id])
44
- assert (
45
- chat_id or message_id
46
- ), "Either chat_id or message_id must be provided"
44
+
45
+ if not (chat_id or message_id):
46
+ raise ValueError("Chat_id or message_id must be provided")
47
47
 
48
48
  self._company_id: str = company_id
49
49
  self._user_id: str = user_id
File without changes