unique_toolkit 0.7.34__tar.gz → 0.7.36__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.34 → unique_toolkit-0.7.36}/CHANGELOG.md +7 -0
  2. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/PKG-INFO +10 -2
  3. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/pyproject.toml +3 -2
  4. unique_toolkit-0.7.36/unique_toolkit/app/event_util.py +24 -0
  5. unique_toolkit-0.7.36/unique_toolkit/app/sse_client.py +22 -0
  6. unique_toolkit-0.7.36/unique_toolkit/app/unique_settings.py +28 -0
  7. unique_toolkit-0.7.36/unique_toolkit/framework_utilities/langchain/history.py +19 -0
  8. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/reference.py +4 -1
  9. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/short_term_memory/service.py +3 -3
  10. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/LICENSE +0 -0
  11. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/README.md +0 -0
  12. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/__init__.py +0 -0
  13. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/_common/_base_service.py +0 -0
  14. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/_common/_time_utils.py +0 -0
  15. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/_common/exception.py +0 -0
  16. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/_common/validate_required_values.py +0 -0
  17. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/_common/validators.py +0 -0
  18. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/__init__.py +0 -0
  19. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/init_logging.py +0 -0
  20. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/init_sdk.py +0 -0
  21. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/performance/async_tasks.py +0 -0
  22. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/performance/async_wrapper.py +0 -0
  23. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/schemas.py +0 -0
  24. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/app/verification.py +0 -0
  25. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/__init__.py +0 -0
  26. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/constants.py +0 -0
  27. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/functions.py +0 -0
  28. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/schemas.py +0 -0
  29. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/service.py +0 -0
  30. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/state.py +0 -0
  31. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/chat/utils.py +0 -0
  32. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/__init__.py +0 -0
  33. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/constants.py +0 -0
  34. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/functions.py +0 -0
  35. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/schemas.py +0 -0
  36. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/service.py +0 -0
  37. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/content/utils.py +0 -0
  38. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/__init__.py +0 -0
  39. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/constants.py +0 -0
  40. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/functions.py +0 -0
  41. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/schemas.py +0 -0
  42. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/service.py +0 -0
  43. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/embedding/utils.py +0 -0
  44. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/__init__.py +0 -0
  45. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/config.py +0 -0
  46. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/constants.py +0 -0
  47. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/context_relevancy/constants.py +0 -0
  48. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/context_relevancy/prompts.py +0 -0
  49. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/context_relevancy/service.py +0 -0
  50. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/context_relevancy/utils.py +0 -0
  51. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/exception.py +0 -0
  52. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/hallucination/constants.py +0 -0
  53. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/hallucination/prompts.py +0 -0
  54. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/hallucination/service.py +0 -0
  55. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/hallucination/utils.py +0 -0
  56. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/output_parser.py +0 -0
  57. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/evaluators/schemas.py +0 -0
  58. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/__init__.py +0 -0
  59. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/builder.py +0 -0
  60. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/constants.py +0 -0
  61. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/functions.py +0 -0
  62. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/infos.py +0 -0
  63. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/prompt.py +0 -0
  64. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/schemas.py +0 -0
  65. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/service.py +0 -0
  66. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/language_model/utils.py +0 -0
  67. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/protocols/support.py +0 -0
  68. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/short_term_memory/__init__.py +0 -0
  69. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/short_term_memory/constants.py +0 -0
  70. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/short_term_memory/functions.py +0 -0
  71. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/short_term_memory/schemas.py +0 -0
  72. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/smart_rules/__init__.py +0 -0
  73. {unique_toolkit-0.7.34 → unique_toolkit-0.7.36}/unique_toolkit/smart_rules/compile.py +0 -0
@@ -5,6 +5,13 @@ 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-24
9
+ - Add utilities for SSE client and secrets
10
+ - Helper function to convert unique history to langchain history
11
+
12
+ ## [0.7.35] - 2025-07-23
13
+ - Bump version of SDK to have access to the latest features and fixes
14
+
8
15
  ## [0.7.34] - 2025-05-30
9
16
  - Fix incorrect mapping in `ContentService` for the `search_content` function when mapping into `ContentChunk` object
10
17
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.7.34
3
+ Version: 0.7.36
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -12,12 +12,13 @@ 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)
18
19
  Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
19
20
  Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
20
- Requires-Dist: unique-sdk (>=0.9.36,<0.10.0)
21
+ Requires-Dist: unique-sdk (>=0.9.40,<0.10.0)
21
22
  Description-Content-Type: text/markdown
22
23
 
23
24
  # Unique Toolkit
@@ -111,6 +112,13 @@ All notable changes to this project will be documented in this file.
111
112
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
112
113
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
113
114
 
115
+ ## [0.7.36] - 2025-07-24
116
+ - Add utilities for SSE client and secrets
117
+ - Helper function to convert unique history to langchain history
118
+
119
+ ## [0.7.35] - 2025-07-23
120
+ - Bump version of SDK to have access to the latest features and fixes
121
+
114
122
  ## [0.7.34] - 2025-05-30
115
123
  - Fix incorrect mapping in `ContentService` for the `search_content` function when mapping into `ContentChunk` object
116
124
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "unique_toolkit"
3
- version = "0.7.34"
3
+ version = "0.7.36"
4
4
  description = ""
5
5
  authors = [
6
6
  "Martin Fadler <martin.fadler@unique.ch>",
@@ -20,7 +20,8 @@ numpy = "^1.26.4"
20
20
  python-dotenv = "^1.0.1"
21
21
  regex = "^2024.5.15"
22
22
  tiktoken = "^0.7.0"
23
- unique-sdk = "^0.9.36"
23
+ unique-sdk = "^0.9.40"
24
+ pydantic-settings = "^2.10.1"
24
25
 
25
26
  [tool.poetry.group.dev.dependencies]
26
27
  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,22 @@
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
+ LOGGER.info(f"SSEheaders: {headers}")
21
+ LOGGER.info(f"SSE Url: {url}")
22
+ return SSEClient(url=url, headers=headers)
@@ -0,0 +1,28 @@
1
+ from pydantic_settings import BaseSettings, SettingsConfigDict
2
+
3
+ config_dict = SettingsConfigDict(
4
+ env_file_encoding="utf-8",
5
+ extra="ignore",
6
+ )
7
+
8
+
9
+ class UniqueApp(BaseSettings):
10
+ id: str
11
+ key: str
12
+ base_url: str
13
+ endpoint: str
14
+ endpoint_secret: str
15
+
16
+ model_config = SettingsConfigDict(env_prefix="unique_app_", **config_dict)
17
+
18
+
19
+ class UniqueAuth(BaseSettings):
20
+ company_id: str
21
+ user_id: str
22
+
23
+ model_config = SettingsConfigDict(env_prefix="unique_auth_", **config_dict)
24
+
25
+
26
+ class UniqueSettings:
27
+ app: UniqueApp = UniqueApp()
28
+ auth: UniqueAuth = UniqueAuth()
@@ -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