unique_toolkit 0.5.37__py3-none-any.whl → 0.5.39__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.
- unique_toolkit/content/service.py +15 -4
- unique_toolkit/language_model/schemas.py +15 -0
- unique_toolkit/language_model/utils.py +24 -0
- {unique_toolkit-0.5.37.dist-info → unique_toolkit-0.5.39.dist-info}/METADATA +11 -2
- {unique_toolkit-0.5.37.dist-info → unique_toolkit-0.5.39.dist-info}/RECORD +7 -7
- {unique_toolkit-0.5.37.dist-info → unique_toolkit-0.5.39.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.5.37.dist-info → unique_toolkit-0.5.39.dist-info}/WHEEL +0 -0
@@ -29,6 +29,7 @@ class ContentService(BaseService):
|
|
29
29
|
|
30
30
|
def __init__(self, event: Event, logger: Optional[logging.Logger] = None):
|
31
31
|
super().__init__(event, logger)
|
32
|
+
self.metadata_filter = event.payload.metadata_filter
|
32
33
|
|
33
34
|
DEFAULT_SEARCH_LANGUAGE = "english"
|
34
35
|
|
@@ -42,6 +43,7 @@ class ContentService(BaseService):
|
|
42
43
|
scope_ids: Optional[list[str]] = None,
|
43
44
|
chat_only: Optional[bool] = None,
|
44
45
|
metadata_filter: Optional[dict] = None,
|
46
|
+
content_ids: Optional[list[str]] = None,
|
45
47
|
) -> list[ContentChunk]:
|
46
48
|
"""
|
47
49
|
Performs a synchronous search for content chunks in the knowledge base.
|
@@ -54,14 +56,17 @@ class ContentService(BaseService):
|
|
54
56
|
reranker_config (Optional[ContentRerankerConfig]): The reranker configuration. Defaults to None.
|
55
57
|
scope_ids (Optional[list[str]]): The scope IDs. Defaults to None.
|
56
58
|
chat_only (Optional[bool]): Whether to search only in the current chat. Defaults to None.
|
57
|
-
metadata_filter (Optional[dict]): UniqueQL metadata filter. Defaults to None.
|
58
|
-
|
59
|
+
metadata_filter (Optional[dict]): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
|
60
|
+
content_ids (Optional[list[str]]): The content IDs to search. Defaults to None.
|
59
61
|
Returns:
|
60
62
|
list[ContentChunk]: The search results.
|
61
63
|
"""
|
62
64
|
if not scope_ids:
|
63
65
|
self.logger.warning("No scope IDs provided for search.")
|
64
66
|
|
67
|
+
if metadata_filter is None:
|
68
|
+
metadata_filter = self.metadata_filter
|
69
|
+
|
65
70
|
try:
|
66
71
|
searches = unique_sdk.Search.create(
|
67
72
|
user_id=self.event.user_id,
|
@@ -79,6 +84,7 @@ class ContentService(BaseService):
|
|
79
84
|
language=search_language,
|
80
85
|
chatOnly=chat_only,
|
81
86
|
metaDataFilter=metadata_filter,
|
87
|
+
contentIds=content_ids,
|
82
88
|
)
|
83
89
|
except Exception as e:
|
84
90
|
self.logger.error(f"Error while searching content chunks: {e}")
|
@@ -101,6 +107,7 @@ class ContentService(BaseService):
|
|
101
107
|
scope_ids: Optional[list[str]] = None,
|
102
108
|
chat_only: Optional[bool] = None,
|
103
109
|
metadata_filter: Optional[dict] = None,
|
110
|
+
content_ids: Optional[list[str]] = None,
|
104
111
|
):
|
105
112
|
"""
|
106
113
|
Performs an asynchronous search for content chunks in the knowledge base.
|
@@ -113,14 +120,17 @@ class ContentService(BaseService):
|
|
113
120
|
reranker_config (Optional[ContentRerankerConfig]): The reranker configuration. Defaults to None.
|
114
121
|
scope_ids (Optional[list[str]]): The scope IDs. Defaults to None.
|
115
122
|
chat_only (Optional[bool]): Whether to search only in the current chat. Defaults to None.
|
116
|
-
metadata_filter (Optional[dict]): UniqueQL metadata filter. Defaults to None.
|
117
|
-
|
123
|
+
metadata_filter (Optional[dict]): UniqueQL metadata filter. If unspecified/None, it tries to use the metadata filter from the event. Defaults to None.
|
124
|
+
content_ids (Optional[list[str]]): The content IDs to search. Defaults to None.
|
118
125
|
Returns:
|
119
126
|
list[ContentChunk]: The search results.
|
120
127
|
"""
|
121
128
|
if not scope_ids:
|
122
129
|
self.logger.warning("No scope IDs provided for search.")
|
123
130
|
|
131
|
+
if metadata_filter is None:
|
132
|
+
metadata_filter = self.metadata_filter
|
133
|
+
|
124
134
|
try:
|
125
135
|
searches = await unique_sdk.Search.create_async(
|
126
136
|
user_id=self.event.user_id,
|
@@ -138,6 +148,7 @@ class ContentService(BaseService):
|
|
138
148
|
language=search_language,
|
139
149
|
chatOnly=chat_only,
|
140
150
|
metaDataFilter=metadata_filter,
|
151
|
+
contentIds=content_ids,
|
141
152
|
)
|
142
153
|
except Exception as e:
|
143
154
|
self.logger.error(f"Error while searching content chunks: {e}")
|
@@ -14,6 +14,8 @@ from pydantic import (
|
|
14
14
|
model_validator,
|
15
15
|
)
|
16
16
|
|
17
|
+
from unique_toolkit.language_model.utils import format_message
|
18
|
+
|
17
19
|
# set config to convert camelCase to snake_case
|
18
20
|
model_config = ConfigDict(
|
19
21
|
alias_generator=camelize,
|
@@ -88,6 +90,9 @@ class LanguageModelMessage(BaseModel):
|
|
88
90
|
content: Optional[str | list[dict]] = None
|
89
91
|
tool_calls: Optional[list[LanguageModelFunctionCall]] = None
|
90
92
|
|
93
|
+
def __str__(self):
|
94
|
+
return format_message(self.role.capitalize(), message=self.content, num_tabs=1)
|
95
|
+
|
91
96
|
|
92
97
|
class LanguageModelSystemMessage(LanguageModelMessage):
|
93
98
|
role: LanguageModelMessageRole = LanguageModelMessageRole.SYSTEM
|
@@ -118,6 +123,13 @@ class LanguageModelToolMessage(LanguageModelMessage):
|
|
118
123
|
name: str
|
119
124
|
tool_call_id: str
|
120
125
|
|
126
|
+
def __str__(self):
|
127
|
+
return format_message(
|
128
|
+
user=self.role.capitalize(),
|
129
|
+
message=f"{self.name}, {self.tool_call_id}, {self.content}",
|
130
|
+
num_tabs=1,
|
131
|
+
)
|
132
|
+
|
121
133
|
@field_validator("role", mode="before")
|
122
134
|
def set_role(cls, value):
|
123
135
|
return LanguageModelMessageRole.TOOL
|
@@ -132,6 +144,9 @@ class LanguageModelMessages(RootModel):
|
|
132
144
|
| LanguageModelUserMessage
|
133
145
|
]
|
134
146
|
|
147
|
+
def __str__(self):
|
148
|
+
return "\n\n".join([str(message) for message in self.root])
|
149
|
+
|
135
150
|
def __iter__(self):
|
136
151
|
return iter(self.root)
|
137
152
|
|
@@ -42,3 +42,27 @@ def find_last_json_object(text: str) -> str | None:
|
|
42
42
|
return matches[-1]
|
43
43
|
else:
|
44
44
|
return None
|
45
|
+
|
46
|
+
|
47
|
+
def format_message(user: str, message: str, num_tabs: int = 1) -> str:
|
48
|
+
"""
|
49
|
+
Formats a message from a user by indenting each line with a specified number of tabs.
|
50
|
+
|
51
|
+
Args:
|
52
|
+
user (str): The name of the user sending the message.
|
53
|
+
message (str): The message content that may include multiple lines.
|
54
|
+
num_tabs (int): The number of tabs to use for indenting each line. Default is 1 tab.
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
str: A formatted string with user and indented message lines.
|
58
|
+
|
59
|
+
Example:
|
60
|
+
>>> format_message("Alice", "Hello\nWorld", 2)
|
61
|
+
Alice:
|
62
|
+
\t\tHello
|
63
|
+
\t\tWorld
|
64
|
+
"""
|
65
|
+
indentation = "\t" * num_tabs
|
66
|
+
indented_message = message.replace("\n", "\n" + indentation)
|
67
|
+
formatted_message = f"{user}:\n{indentation}{indented_message}"
|
68
|
+
return formatted_message
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.39
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
@@ -17,7 +17,7 @@ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
|
17
17
|
Requires-Dist: regex (>=2024.5.15,<2025.0.0)
|
18
18
|
Requires-Dist: tiktoken (>=0.7.0,<0.8.0)
|
19
19
|
Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
|
20
|
-
Requires-Dist: unique-sdk (>=0.9.
|
20
|
+
Requires-Dist: unique-sdk (>=0.9.14,<0.10.0)
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
|
23
23
|
# Unique Toolkit
|
@@ -100,6 +100,15 @@ All notable changes to this project will be documented in this file.
|
|
100
100
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
101
101
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
102
102
|
|
103
|
+
|
104
|
+
|
105
|
+
## [0.5.39] - 2024-12-09
|
106
|
+
- Add `contentIds` to `Search.create` and `Search.create_async`
|
107
|
+
- Use `metadata_filter` from event in `ContentService.search_content_chunks` and `ContentService.async_search_content_chunks` as default.
|
108
|
+
|
109
|
+
## [0.5.38] - 2024-11-26
|
110
|
+
- Added string representation to `LanguageModelMessage` and `LanguageModelMessages` class
|
111
|
+
|
103
112
|
## [0.5.37] - 2024-11-26
|
104
113
|
- `content` parameter in `ChatService.modify_assistant_message` and `ChatService.modify_assistant_message_async` is now optional
|
105
114
|
- Added optional parameter `original_content` to `ChatService.modify_assistant_message` and `ChatService.modify_assistant_message_async`
|
@@ -17,7 +17,7 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
|
|
17
17
|
unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
|
18
18
|
unique_toolkit/content/__init__.py,sha256=MSH2sxjQyKD2Sef92fzE5Dt9SihdzivB6yliSwJfTmQ,890
|
19
19
|
unique_toolkit/content/schemas.py,sha256=zks_Pkki2VhxICJJgHZyc-LPmRuj5dLbw3pgcUT7SW8,2362
|
20
|
-
unique_toolkit/content/service.py,sha256=
|
20
|
+
unique_toolkit/content/service.py,sha256=rznSUyOuB4nbo6bFworzFv86kzo6TVT4Nc8GMAeAJB4,17711
|
21
21
|
unique_toolkit/content/utils.py,sha256=Lake671plRsqNvO3pN_rmyVcpwbdED_KQpLcCnc4lv4,6902
|
22
22
|
unique_toolkit/embedding/__init__.py,sha256=dr8M9jvslQTxPpxgaGwzxY0FildiWf-DidN_cahPAWw,191
|
23
23
|
unique_toolkit/embedding/schemas.py,sha256=1GvKCaSk4jixzVQ2PKq8yDqwGEVY_hWclYtoAr6CC2g,96
|
@@ -37,10 +37,10 @@ unique_toolkit/evaluators/output_parser.py,sha256=eI72qkzK1dZyUvnfP2SOAQCGBj_-Pw
|
|
37
37
|
unique_toolkit/evaluators/schemas.py,sha256=Jaue6Uhx75X1CyHKWj8sT3RE1JZXTqoLtfLt2xQNCX8,2507
|
38
38
|
unique_toolkit/language_model/__init__.py,sha256=YuhyczGPj6w9xX-sOVUhmozvzIFxcckHFEkeMBecr5s,1784
|
39
39
|
unique_toolkit/language_model/infos.py,sha256=kQK6F3r8xTN7oT6b39J7rxW-Y4iPXjx_Fr9bCOVQdm0,12509
|
40
|
-
unique_toolkit/language_model/schemas.py,sha256=
|
40
|
+
unique_toolkit/language_model/schemas.py,sha256=wg_ly66UvLOVNdrq8xr-0uN0HPY41UIk5mVPxdG-VGs,6687
|
41
41
|
unique_toolkit/language_model/service.py,sha256=s5X6EStyYumiYqlD9gkW4GANif18d9QZOMysmUSfv8M,13433
|
42
|
-
unique_toolkit/language_model/utils.py,sha256=
|
43
|
-
unique_toolkit-0.5.
|
44
|
-
unique_toolkit-0.5.
|
45
|
-
unique_toolkit-0.5.
|
46
|
-
unique_toolkit-0.5.
|
42
|
+
unique_toolkit/language_model/utils.py,sha256=bPQ4l6_YO71w-zaIPanUUmtbXC1_hCvLK0tAFc3VCRc,1902
|
43
|
+
unique_toolkit-0.5.39.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
44
|
+
unique_toolkit-0.5.39.dist-info/METADATA,sha256=30jmpa5iHACeXTpmNB0XyY6GSanJvFAi10S8K0qg4Ew,14411
|
45
|
+
unique_toolkit-0.5.39.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
46
|
+
unique_toolkit-0.5.39.dist-info/RECORD,,
|
File without changes
|
File without changes
|