cheshirecat-python-sdk 1.2.1__py3-none-any.whl → 1.8.4__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.
- cheshirecat_python_sdk/__init__.py +0 -1
- cheshirecat_python_sdk/builders/__init__.py +1 -1
- cheshirecat_python_sdk/builders/memory.py +1 -32
- cheshirecat_python_sdk/builders/why.py +8 -14
- cheshirecat_python_sdk/client.py +35 -5
- cheshirecat_python_sdk/clients/http_client.py +21 -7
- cheshirecat_python_sdk/clients/websocket_client.py +21 -15
- cheshirecat_python_sdk/configuration.py +1 -1
- cheshirecat_python_sdk/endpoints/__init__.py +7 -1
- cheshirecat_python_sdk/endpoints/admins.py +33 -145
- cheshirecat_python_sdk/endpoints/agentic_workflow.py +52 -0
- cheshirecat_python_sdk/endpoints/auth.py +54 -0
- cheshirecat_python_sdk/endpoints/auth_handler.py +8 -8
- cheshirecat_python_sdk/endpoints/base.py +53 -19
- cheshirecat_python_sdk/endpoints/chunker.py +8 -8
- cheshirecat_python_sdk/endpoints/conversation.py +83 -0
- cheshirecat_python_sdk/endpoints/custom_endpoint.py +57 -0
- cheshirecat_python_sdk/endpoints/embedder.py +4 -4
- cheshirecat_python_sdk/endpoints/file_manager.py +65 -8
- cheshirecat_python_sdk/endpoints/health_check.py +22 -0
- cheshirecat_python_sdk/endpoints/large_language_model.py +8 -8
- cheshirecat_python_sdk/endpoints/memory.py +101 -146
- cheshirecat_python_sdk/endpoints/message.py +29 -13
- cheshirecat_python_sdk/endpoints/plugins.py +31 -26
- cheshirecat_python_sdk/endpoints/rabbit_hole.py +53 -23
- cheshirecat_python_sdk/endpoints/users.py +35 -56
- cheshirecat_python_sdk/endpoints/utils.py +71 -0
- cheshirecat_python_sdk/endpoints/vector_database.py +52 -0
- cheshirecat_python_sdk/enums.py +0 -11
- cheshirecat_python_sdk/models/api/admins.py +5 -7
- cheshirecat_python_sdk/models/api/conversations.py +24 -0
- cheshirecat_python_sdk/models/api/factories.py +6 -0
- cheshirecat_python_sdk/models/api/file_managers.py +18 -0
- cheshirecat_python_sdk/models/api/memories.py +2 -10
- cheshirecat_python_sdk/models/api/messages.py +8 -6
- cheshirecat_python_sdk/models/api/nested/memories.py +5 -5
- cheshirecat_python_sdk/models/api/nested/plugins.py +8 -2
- cheshirecat_python_sdk/models/api/plugins.py +30 -22
- cheshirecat_python_sdk/models/api/tokens.py +19 -0
- cheshirecat_python_sdk/models/api/users.py +4 -1
- cheshirecat_python_sdk/models/dtos.py +14 -18
- cheshirecat_python_sdk/utils.py +2 -1
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.8.4.dist-info}/METADATA +12 -10
- cheshirecat_python_sdk-1.8.4.dist-info/RECORD +50 -0
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.8.4.dist-info}/WHEEL +1 -1
- cheshirecat_python_sdk/endpoints/settings.py +0 -63
- cheshirecat_python_sdk/models/api/settings.py +0 -22
- cheshirecat_python_sdk-1.2.1.dist-info/RECORD +0 -43
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.8.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
|
+
import json
|
|
2
3
|
|
|
3
|
-
from cheshirecat_python_sdk.enums import Collection, Role
|
|
4
4
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
5
5
|
from cheshirecat_python_sdk.models.api.memories import (
|
|
6
6
|
CollectionsOutput,
|
|
7
7
|
CollectionPointsDestroyOutput,
|
|
8
|
-
ConversationHistoryOutput,
|
|
9
|
-
ConversationHistoryDeleteOutput,
|
|
10
8
|
MemoryRecallOutput,
|
|
11
9
|
MemoryPointOutput,
|
|
12
10
|
MemoryPointDeleteOutput,
|
|
13
11
|
MemoryPointsDeleteByMetadataOutput,
|
|
14
12
|
MemoryPointsOutput,
|
|
15
13
|
)
|
|
16
|
-
from cheshirecat_python_sdk.models.
|
|
14
|
+
from cheshirecat_python_sdk.models.api.nested.memories import CollectionsItem
|
|
15
|
+
from cheshirecat_python_sdk.models.dtos import Why, MemoryPoint, FilterSource
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
class MemoryEndpoint(AbstractEndpoint):
|
|
@@ -23,180 +22,110 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
23
22
|
|
|
24
23
|
# Memory Collections API
|
|
25
24
|
|
|
26
|
-
def get_memory_collections(self, agent_id: str
|
|
25
|
+
def get_memory_collections(self, agent_id: str) -> CollectionsOutput:
|
|
27
26
|
"""
|
|
28
|
-
This endpoint returns the collections of memory points
|
|
29
|
-
|
|
30
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
27
|
+
This endpoint returns the collections of memory points.
|
|
28
|
+
:param agent_id: The agent ID.
|
|
31
29
|
:return: CollectionsOutput, a list of collections of memory points.
|
|
32
30
|
"""
|
|
33
31
|
return self.get(
|
|
34
32
|
self.format_url("/collections"),
|
|
35
|
-
CollectionsOutput,
|
|
36
33
|
agent_id,
|
|
34
|
+
output_class=CollectionsOutput,
|
|
37
35
|
)
|
|
38
36
|
|
|
39
|
-
def delete_all_memory_collection_points(self, agent_id: str
|
|
37
|
+
def delete_all_memory_collection_points(self, agent_id: str) -> CollectionPointsDestroyOutput:
|
|
40
38
|
"""
|
|
41
|
-
This endpoint deletes all memory points in all collections for the agent identified by the agentId parameter
|
|
42
|
-
|
|
43
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
39
|
+
This endpoint deletes all memory points in all collections for the agent identified by the agentId parameter.
|
|
40
|
+
:param agent_id: The agent ID.
|
|
44
41
|
:return: CollectionPointsDestroyOutput, a message indicating the number of memory points deleted.
|
|
45
42
|
"""
|
|
46
43
|
return self.delete(
|
|
47
44
|
self.format_url("/collections"),
|
|
48
|
-
CollectionPointsDestroyOutput,
|
|
49
45
|
agent_id,
|
|
46
|
+
output_class=CollectionPointsDestroyOutput,
|
|
50
47
|
)
|
|
51
48
|
|
|
52
49
|
def delete_all_single_memory_collection_points(
|
|
53
|
-
self, collection:
|
|
50
|
+
self, collection: str, agent_id: str
|
|
54
51
|
) -> CollectionPointsDestroyOutput:
|
|
55
52
|
"""
|
|
56
|
-
This method deletes all the points in a single collection of memory
|
|
57
|
-
agentId parameter (for multi-agent installations) or for the default agent (for single-agent installations).
|
|
53
|
+
This method deletes all the points in a single collection of memory.
|
|
58
54
|
:param collection: The collection to delete.
|
|
59
|
-
:param agent_id: The agent ID
|
|
55
|
+
:param agent_id: The agent ID.
|
|
60
56
|
:return: CollectionPointsDestroyOutput, a message indicating the number of memory points deleted.
|
|
61
57
|
"""
|
|
62
58
|
return self.delete(
|
|
63
59
|
self.format_url(f"/collections/{collection}"),
|
|
64
|
-
CollectionPointsDestroyOutput,
|
|
65
60
|
agent_id,
|
|
61
|
+
output_class=CollectionPointsDestroyOutput,
|
|
66
62
|
)
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# Memory Conversation History API
|
|
71
|
-
|
|
72
|
-
def get_conversation_history(
|
|
73
|
-
self, agent_id: str | None = None, user_id: str | None = None
|
|
74
|
-
) -> ConversationHistoryOutput:
|
|
75
|
-
"""
|
|
76
|
-
This endpoint returns the conversation history, either for the agent identified by the agent_id parameter
|
|
77
|
-
(for multi-agent installations) or for the default agent (for single-agent installations). If the user_id
|
|
78
|
-
parameter is provided, the conversation history is filtered by the user ID.
|
|
79
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
80
|
-
:param user_id: The user ID to filter the conversation history.
|
|
81
|
-
:return: ConversationHistoryOutput, a list of conversation history entries.
|
|
82
|
-
"""
|
|
83
|
-
return self.get(
|
|
84
|
-
self.format_url("/conversation_history"),
|
|
85
|
-
ConversationHistoryOutput,
|
|
86
|
-
agent_id,
|
|
87
|
-
user_id,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
def delete_conversation_history(
|
|
91
|
-
self, agent_id: str | None = None, user_id: str | None = None
|
|
92
|
-
) -> ConversationHistoryDeleteOutput:
|
|
64
|
+
def post_memory_collections(self, collection_id: str, agent_id: str) -> CollectionsItem:
|
|
93
65
|
"""
|
|
94
|
-
This endpoint
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
:
|
|
98
|
-
:param user_id: The user ID to filter the conversation history.
|
|
99
|
-
:return: ConversationHistoryDeleteOutput, a message indicating the number of conversation history entries deleted.
|
|
66
|
+
This endpoint returns the collections of memory points.
|
|
67
|
+
:param collection_id: The ID of the collection to create.
|
|
68
|
+
:param agent_id: The agent ID.
|
|
69
|
+
:return: CollectionsItem, the collection created.
|
|
100
70
|
"""
|
|
101
|
-
return self.delete(
|
|
102
|
-
self.format_url("/conversation_history"),
|
|
103
|
-
ConversationHistoryDeleteOutput,
|
|
104
|
-
agent_id,
|
|
105
|
-
user_id,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
def post_conversation_history(
|
|
109
|
-
self,
|
|
110
|
-
who: Role,
|
|
111
|
-
text: str,
|
|
112
|
-
image: str | bytes | None = None,
|
|
113
|
-
why: Why | None = None,
|
|
114
|
-
agent_id: str | None = None,
|
|
115
|
-
user_id: str | None = None
|
|
116
|
-
) -> ConversationHistoryOutput:
|
|
117
|
-
"""
|
|
118
|
-
This endpoint creates a new element in the conversation history, either for the agent identified by the agent_id
|
|
119
|
-
parameter (for multi-agent installations) or for the default agent (for single-agent installations). If the
|
|
120
|
-
user_id parameter is provided, the conversation history is added to the user ID.
|
|
121
|
-
:param who: The role of the user in the conversation.
|
|
122
|
-
:param text: The text of the conversation history entry.
|
|
123
|
-
:param image: The image of the conversation history entry.
|
|
124
|
-
:param why: The reason for the conversation history entry.
|
|
125
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
126
|
-
:param user_id: The user ID to filter the conversation history.
|
|
127
|
-
:return: ConversationHistoryOutput, the conversation history entry created.
|
|
128
|
-
"""
|
|
129
|
-
payload = {
|
|
130
|
-
"who": who.value,
|
|
131
|
-
"text": text,
|
|
132
|
-
}
|
|
133
|
-
if image:
|
|
134
|
-
payload["image"] = image
|
|
135
|
-
if why:
|
|
136
|
-
payload["why"] = why.model_dump()
|
|
137
|
-
|
|
138
71
|
return self.post_json(
|
|
139
|
-
self.format_url("/
|
|
140
|
-
ConversationHistoryOutput,
|
|
141
|
-
payload,
|
|
72
|
+
self.format_url(f"/collections/{collection_id}"),
|
|
142
73
|
agent_id,
|
|
143
|
-
|
|
74
|
+
output_class=CollectionsItem,
|
|
144
75
|
)
|
|
145
76
|
|
|
146
|
-
# END Memory
|
|
77
|
+
# END Memory Collections API
|
|
147
78
|
|
|
148
79
|
# Memory Points API
|
|
149
80
|
|
|
150
81
|
def get_memory_recall(
|
|
151
82
|
self,
|
|
152
83
|
text: str,
|
|
84
|
+
agent_id: str,
|
|
85
|
+
user_id: str,
|
|
153
86
|
k: int | None = None,
|
|
154
87
|
metadata: Dict[str, Any] | None = None,
|
|
155
|
-
|
|
156
|
-
user_id: str | None = None,
|
|
88
|
+
chat_id: str | None = None,
|
|
157
89
|
) -> MemoryRecallOutput:
|
|
158
90
|
"""
|
|
159
|
-
This endpoint retrieves memory points based on the input text
|
|
160
|
-
|
|
161
|
-
parameter is the input text for which the memory points are retrieved. The k parameter is the number of memory
|
|
162
|
-
points to retrieve.
|
|
163
|
-
If the user_id parameter is provided, the memory points are filtered by the user ID.
|
|
91
|
+
This endpoint retrieves memory points based on the input text. The text parameter is the input text for which
|
|
92
|
+
the memory points are retrieved. The k parameter is the number of memory points to retrieve.
|
|
164
93
|
:param text: The input text for which the memory points are retrieved.
|
|
94
|
+
:param agent_id: The agent ID.
|
|
95
|
+
:param user_id: The user ID to filter the memory points.
|
|
165
96
|
:param k: The number of memory points to retrieve.
|
|
166
97
|
:param metadata: The metadata to filter the memory points.
|
|
167
|
-
:param
|
|
168
|
-
:param user_id: The user ID to filter the memory points.
|
|
98
|
+
:param chat_id: The chat id, optional
|
|
169
99
|
:return: MemoryRecallOutput, a list of memory points retrieved.
|
|
170
100
|
"""
|
|
171
101
|
query = {"text": text}
|
|
172
102
|
if k:
|
|
173
|
-
query["k"] = k
|
|
103
|
+
query["k"] = k # type: ignore
|
|
174
104
|
if metadata:
|
|
175
|
-
query["metadata"] = metadata
|
|
105
|
+
query["metadata"] = json.dumps(metadata) # type: ignore
|
|
176
106
|
|
|
177
107
|
return self.get(
|
|
178
108
|
self.format_url("/recall"),
|
|
179
|
-
MemoryRecallOutput,
|
|
180
109
|
agent_id,
|
|
181
|
-
|
|
182
|
-
|
|
110
|
+
output_class=MemoryRecallOutput,
|
|
111
|
+
user_id=user_id,
|
|
112
|
+
query=query,
|
|
113
|
+
chat_id=chat_id,
|
|
183
114
|
)
|
|
184
115
|
|
|
185
116
|
def post_memory_point(
|
|
186
117
|
self,
|
|
187
|
-
collection:
|
|
118
|
+
collection: str,
|
|
119
|
+
agent_id: str,
|
|
120
|
+
user_id: str,
|
|
188
121
|
memory_point: MemoryPoint,
|
|
189
|
-
agent_id: str | None = None,
|
|
190
|
-
user_id: str | None = None,
|
|
191
122
|
) -> MemoryPointOutput:
|
|
192
123
|
"""
|
|
193
|
-
This method posts a memory point
|
|
194
|
-
installations) or for the default agent (for single-agent installations).
|
|
195
|
-
If the user_id parameter is provided, the memory point is associated with the user ID.
|
|
124
|
+
This method posts a memory point.
|
|
196
125
|
:param collection: The collection to post the memory point.
|
|
197
|
-
:param
|
|
198
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
126
|
+
:param agent_id: The agent ID.
|
|
199
127
|
:param user_id: The user ID to associate with the memory point.
|
|
128
|
+
:param memory_point: The memory point to post.
|
|
200
129
|
:return: MemoryPointOutput, the memory point posted.
|
|
201
130
|
"""
|
|
202
131
|
if user_id and not memory_point.metadata.get("source"):
|
|
@@ -206,28 +135,26 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
206
135
|
|
|
207
136
|
return self.post_json(
|
|
208
137
|
self.format_url(f"/collections/{collection}/points"),
|
|
209
|
-
MemoryPointOutput,
|
|
210
|
-
memory_point.model_dump(),
|
|
211
138
|
agent_id,
|
|
139
|
+
output_class=MemoryPointOutput,
|
|
140
|
+
payload=memory_point.model_dump(),
|
|
212
141
|
)
|
|
213
142
|
|
|
214
143
|
def put_memory_point(
|
|
215
144
|
self,
|
|
216
|
-
collection:
|
|
145
|
+
collection: str,
|
|
146
|
+
agent_id: str,
|
|
147
|
+
user_id: str,
|
|
217
148
|
memory_point: MemoryPoint,
|
|
218
149
|
point_id: str,
|
|
219
|
-
agent_id: str | None = None,
|
|
220
|
-
user_id: str | None = None,
|
|
221
150
|
) -> MemoryPointOutput:
|
|
222
151
|
"""
|
|
223
|
-
This method puts a memory point,
|
|
224
|
-
installations) or for the default agent (for single-agent installations).
|
|
225
|
-
If the user_id parameter is provided, the memory point is associated with the user ID.
|
|
152
|
+
This method puts a memory point, for the agent identified by the agent_id parameter.
|
|
226
153
|
:param collection: The collection to put the memory point.
|
|
154
|
+
:param agent_id: The agent ID.
|
|
155
|
+
:param user_id: The user ID to associate with the memory point.
|
|
227
156
|
:param memory_point: The memory point to put.
|
|
228
157
|
:param point_id: The ID of the memory point to put.
|
|
229
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
230
|
-
:param user_id: The user ID to associate with the memory point.
|
|
231
158
|
:return: MemoryPointOutput, the memory point put.
|
|
232
159
|
"""
|
|
233
160
|
if user_id and not memory_point.metadata.get("source"):
|
|
@@ -237,68 +164,67 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
237
164
|
|
|
238
165
|
return self.put(
|
|
239
166
|
self.format_url(f"/collections/{collection}/points/{point_id}"),
|
|
240
|
-
MemoryPointOutput,
|
|
241
|
-
memory_point.model_dump(),
|
|
242
167
|
agent_id,
|
|
168
|
+
output_class=MemoryPointOutput,
|
|
169
|
+
payload=memory_point.model_dump(),
|
|
243
170
|
)
|
|
244
171
|
|
|
245
172
|
def delete_memory_point(
|
|
246
173
|
self,
|
|
247
|
-
collection:
|
|
174
|
+
collection: str,
|
|
175
|
+
agent_id: str,
|
|
248
176
|
point_id: str,
|
|
249
|
-
agent_id: str | None = None,
|
|
250
177
|
) -> MemoryPointDeleteOutput:
|
|
251
178
|
"""
|
|
252
|
-
This endpoint deletes a memory point
|
|
253
|
-
installations) or for the default agent (for single-agent installations).
|
|
179
|
+
This endpoint deletes a memory point.
|
|
254
180
|
:param collection: The collection to delete the memory point.
|
|
181
|
+
:param agent_id: The agent ID.
|
|
255
182
|
:param point_id: The ID of the memory point to delete.
|
|
256
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
257
183
|
:return: MemoryPointDeleteOutput, a message indicating the memory point deleted.
|
|
258
184
|
"""
|
|
259
185
|
return self.delete(
|
|
260
186
|
self.format_url(f"/collections/{collection}/points/{point_id}"),
|
|
261
|
-
MemoryPointDeleteOutput,
|
|
262
187
|
agent_id,
|
|
188
|
+
output_class=MemoryPointDeleteOutput,
|
|
263
189
|
)
|
|
264
190
|
|
|
265
191
|
def delete_memory_points_by_metadata(
|
|
266
192
|
self,
|
|
267
|
-
collection:
|
|
193
|
+
collection: str,
|
|
194
|
+
agent_id: str,
|
|
268
195
|
metadata: Dict[str, Any] | None = None,
|
|
269
|
-
agent_id: str | None = None,
|
|
270
196
|
) -> MemoryPointsDeleteByMetadataOutput:
|
|
271
197
|
"""
|
|
272
|
-
This endpoint deletes memory points based on the metadata
|
|
273
|
-
|
|
274
|
-
metadata parameter is a dictionary of key-value pairs that the memory points must match.
|
|
198
|
+
This endpoint deletes memory points based on the metadata. The metadata parameter is a dictionary of key-value
|
|
199
|
+
pairs that the memory points must match.
|
|
275
200
|
:param collection: The collection to delete the memory points.
|
|
201
|
+
:param agent_id: The agent ID.
|
|
276
202
|
:param metadata: The metadata to filter the memory points.
|
|
277
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
278
203
|
:return: MemoryPointsDeleteByMetadataOutput, a message indicating the number of memory points deleted.
|
|
279
204
|
"""
|
|
280
205
|
return self.delete(
|
|
281
206
|
self.format_url(f"/collections/{collection}/points"),
|
|
282
|
-
MemoryPointsDeleteByMetadataOutput,
|
|
283
207
|
agent_id,
|
|
208
|
+
output_class=MemoryPointsDeleteByMetadataOutput,
|
|
284
209
|
payload=metadata,
|
|
285
210
|
)
|
|
286
211
|
|
|
287
212
|
def get_memory_points(
|
|
288
213
|
self,
|
|
289
|
-
collection:
|
|
214
|
+
collection: str,
|
|
215
|
+
agent_id: str,
|
|
290
216
|
limit: int | None = None,
|
|
291
217
|
offset: int | None = None,
|
|
292
|
-
|
|
218
|
+
metadata: Dict[str, Any] | None = None,
|
|
293
219
|
) -> MemoryPointsOutput:
|
|
294
220
|
"""
|
|
295
|
-
This endpoint retrieves memory points
|
|
296
|
-
|
|
297
|
-
maximum number of memory points to retrieve. The offset parameter is the number of memory points to skip.
|
|
221
|
+
This endpoint retrieves memory points. The limit parameter is the maximum number of memory points to retrieve.
|
|
222
|
+
The offset parameter is the number of memory points to skip.
|
|
298
223
|
:param collection: The collection to retrieve the memory points.
|
|
224
|
+
:param agent_id: The agent ID.
|
|
299
225
|
:param limit: The maximum number of memory points to retrieve.
|
|
300
226
|
:param offset: The number of memory points to skip.
|
|
301
|
-
:param
|
|
227
|
+
:param metadata: The metadata to filter the memory points.
|
|
302
228
|
:return: MemoryPointsOutput, a list of memory points retrieved.
|
|
303
229
|
"""
|
|
304
230
|
query = {}
|
|
@@ -306,12 +232,41 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
306
232
|
query["limit"] = limit
|
|
307
233
|
if offset is not None:
|
|
308
234
|
query["offset"] = offset
|
|
235
|
+
if metadata:
|
|
236
|
+
query["metadata"] = json.dumps(metadata) # type: ignore
|
|
309
237
|
|
|
310
238
|
return self.get(
|
|
311
239
|
self.format_url(f"/collections/{collection}/points"),
|
|
312
|
-
MemoryPointsOutput,
|
|
313
240
|
agent_id,
|
|
241
|
+
output_class=MemoryPointsOutput,
|
|
314
242
|
query=query,
|
|
315
243
|
)
|
|
316
244
|
|
|
245
|
+
def has_source(self, agent_id: str, filter_source: FilterSource, chat_id: str | None = None) -> bool:
|
|
246
|
+
"""
|
|
247
|
+
Checks if the given filter source exists for a specified agent.
|
|
248
|
+
|
|
249
|
+
This method determines whether a specific source, defined by the given filter_source, is associated with the
|
|
250
|
+
provided agent in the memory database.
|
|
251
|
+
It optionally considers a specific chat ID when filtering the data. The result indicates the existence of such a
|
|
252
|
+
source.
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
agent_id: Unique identifier of the agent for which the check is performed.
|
|
256
|
+
filter_source: FilterSource object that defines the source or hash to check.
|
|
257
|
+
chat_id: An optional chat identifier to narrow the scope of the check. If not provided, the check will
|
|
258
|
+
operate in a broader context.
|
|
259
|
+
|
|
260
|
+
Returns:
|
|
261
|
+
A boolean value indicating whether the specified filter source exists in the agent's memory database.
|
|
262
|
+
"""
|
|
263
|
+
metadata = {"source": filter_source.source} if filter_source.source else {"hash": filter_source.hash}
|
|
264
|
+
if chat_id:
|
|
265
|
+
metadata["chat_id"] = chat_id
|
|
266
|
+
|
|
267
|
+
collection_name = "declarative" if chat_id is None else "episodic"
|
|
268
|
+
points = self.get_memory_points(collection_name, agent_id, metadata=metadata)
|
|
269
|
+
|
|
270
|
+
return len(points.points) > 0
|
|
271
|
+
|
|
317
272
|
# END Memory Points API
|
|
@@ -2,43 +2,59 @@ from typing import Callable
|
|
|
2
2
|
import json
|
|
3
3
|
|
|
4
4
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
5
|
-
from cheshirecat_python_sdk.models.api.messages import
|
|
5
|
+
from cheshirecat_python_sdk.models.api.messages import ChatOutput
|
|
6
6
|
from cheshirecat_python_sdk.models.dtos import Message
|
|
7
7
|
from cheshirecat_python_sdk.utils import deserialize
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class MessageEndpoint(AbstractEndpoint):
|
|
11
11
|
def send_http_message(
|
|
12
|
-
self,
|
|
13
|
-
|
|
12
|
+
self,
|
|
13
|
+
message: Message,
|
|
14
|
+
agent_id: str,
|
|
15
|
+
user_id: str,
|
|
16
|
+
chat_id: str | None = None,
|
|
17
|
+
) -> ChatOutput:
|
|
14
18
|
"""
|
|
15
19
|
This endpoint sends a message to the agent identified by the agentId parameter. The message is sent via HTTP.
|
|
16
20
|
:param message: Message object, the message to send
|
|
17
|
-
:param agent_id: the agent id
|
|
18
|
-
:param user_id: the user id
|
|
21
|
+
:param agent_id: the agent id
|
|
22
|
+
:param user_id: the user id
|
|
23
|
+
:param chat_id: the chat id (optional)
|
|
24
|
+
:return: ChatOutput object
|
|
19
25
|
"""
|
|
20
|
-
return self.post_json(
|
|
26
|
+
return self.post_json(
|
|
27
|
+
'/message',
|
|
28
|
+
agent_id,
|
|
29
|
+
output_class=ChatOutput,
|
|
30
|
+
payload=message.model_dump(),
|
|
31
|
+
user_id=user_id,
|
|
32
|
+
chat_id=chat_id,
|
|
33
|
+
)
|
|
21
34
|
|
|
22
35
|
async def send_websocket_message(
|
|
23
36
|
self,
|
|
24
37
|
message: Message,
|
|
25
|
-
agent_id: str
|
|
26
|
-
user_id: str
|
|
38
|
+
agent_id: str,
|
|
39
|
+
user_id: str,
|
|
40
|
+
chat_id: str | None = None,
|
|
27
41
|
callback: Callable[[str], None] | None = None
|
|
28
|
-
) ->
|
|
42
|
+
) -> ChatOutput:
|
|
29
43
|
"""
|
|
30
44
|
This endpoint sends a message to the agent identified by the agentId parameter. The message is sent via WebSocket.
|
|
31
45
|
:param message: Message object, the message to send
|
|
32
|
-
:param agent_id: the agent id
|
|
33
|
-
:param user_id: the user id
|
|
46
|
+
:param agent_id: the agent id
|
|
47
|
+
:param user_id: the user id
|
|
48
|
+
:param chat_id: the chat id
|
|
34
49
|
:param callback: callable, a callback function that will be called for each message received
|
|
50
|
+
:return: ChatOutput object
|
|
35
51
|
"""
|
|
36
52
|
try:
|
|
37
53
|
json_data = json.dumps(message.model_dump())
|
|
38
54
|
except Exception:
|
|
39
55
|
raise RuntimeError("Error encoding message")
|
|
40
56
|
|
|
41
|
-
client = await self.get_ws_client(agent_id, user_id)
|
|
57
|
+
client = await self.get_ws_client(agent_id, user_id, chat_id)
|
|
42
58
|
|
|
43
59
|
try:
|
|
44
60
|
await client.send(json_data)
|
|
@@ -58,4 +74,4 @@ class MessageEndpoint(AbstractEndpoint):
|
|
|
58
74
|
raise Exception(f"WebSocket error: {str(e)}")
|
|
59
75
|
|
|
60
76
|
await client.close()
|
|
61
|
-
return deserialize(json.loads(response),
|
|
77
|
+
return deserialize(json.loads(response), ChatOutput)
|
|
@@ -8,77 +8,82 @@ class PluginsEndpoint(AbstractEndpoint):
|
|
|
8
8
|
super().__init__(client)
|
|
9
9
|
self.prefix = "/plugins"
|
|
10
10
|
|
|
11
|
-
def get_available_plugins(
|
|
12
|
-
self, plugin_name: str | None = None, agent_id: str | None = None
|
|
13
|
-
) -> PluginCollectionOutput:
|
|
11
|
+
def get_available_plugins(self, agent_id: str, plugin_name: str | None = None) -> PluginCollectionOutput:
|
|
14
12
|
"""
|
|
15
|
-
This endpoint returns the available plugins
|
|
16
|
-
(for multi-agent installations) or for the default agent (for single-agent installations).
|
|
17
|
-
:param plugin_name: The name of the plugin to get
|
|
13
|
+
This endpoint returns the available plugins.
|
|
18
14
|
:param agent_id: The id of the agent
|
|
15
|
+
:param plugin_name: The name of the plugin to get
|
|
19
16
|
:return: PluginCollectionOutput, the available plugins
|
|
20
17
|
"""
|
|
21
18
|
return self.get(
|
|
22
19
|
self.prefix,
|
|
23
|
-
PluginCollectionOutput,
|
|
24
20
|
agent_id,
|
|
21
|
+
output_class=PluginCollectionOutput,
|
|
25
22
|
query={"query": plugin_name} if plugin_name else {},
|
|
26
23
|
)
|
|
27
24
|
|
|
28
|
-
def put_toggle_plugin(self, plugin_id: str, agent_id: str
|
|
25
|
+
def put_toggle_plugin(self, plugin_id: str, agent_id: str) -> PluginToggleOutput:
|
|
29
26
|
"""
|
|
30
|
-
This endpoint toggles a plugin,
|
|
31
|
-
installations) or for the default agent (for single-agent installations).
|
|
27
|
+
This endpoint toggles a plugin, for the agent identified by the agent_id parameter.
|
|
32
28
|
:param plugin_id: The id of the plugin to toggle
|
|
33
29
|
:param agent_id: The id of the agent
|
|
34
30
|
:return: PluginToggleOutput, the toggled plugin
|
|
35
31
|
"""
|
|
36
32
|
return self.put(
|
|
37
33
|
self.format_url(f"/toggle/{plugin_id}"),
|
|
38
|
-
PluginToggleOutput,
|
|
39
|
-
{},
|
|
40
34
|
agent_id,
|
|
35
|
+
output_class=PluginToggleOutput,
|
|
41
36
|
)
|
|
42
37
|
|
|
43
|
-
def get_plugins_settings(self, agent_id: str
|
|
38
|
+
def get_plugins_settings(self, agent_id: str) -> PluginsSettingsOutput:
|
|
44
39
|
"""
|
|
45
|
-
This endpoint retrieves the plugins settings
|
|
46
|
-
(for multi-agent installations) or for the default agent (for single-agent installations).
|
|
40
|
+
This endpoint retrieves the plugins settings.
|
|
47
41
|
:param agent_id: The id of the agent
|
|
48
42
|
:return: PluginsSettingsOutput, the plugins settings
|
|
49
43
|
"""
|
|
50
44
|
return self.get(
|
|
51
45
|
self.format_url("/settings"),
|
|
52
|
-
PluginsSettingsOutput,
|
|
53
46
|
agent_id,
|
|
47
|
+
output_class=PluginsSettingsOutput,
|
|
54
48
|
)
|
|
55
49
|
|
|
56
|
-
def get_plugin_settings(self, plugin_id: str, agent_id: str
|
|
50
|
+
def get_plugin_settings(self, plugin_id: str, agent_id: str) -> PluginSettingsOutput:
|
|
57
51
|
"""
|
|
58
|
-
This endpoint retrieves the plugin settings
|
|
59
|
-
(for multi-agent installations) or for the default agent (for single-agent installations).
|
|
52
|
+
This endpoint retrieves the plugin settings.
|
|
60
53
|
:param plugin_id: The id of the plugin
|
|
61
54
|
:param agent_id: The id of the agent
|
|
62
55
|
:return: PluginSettingsOutput, the plugin settings
|
|
63
56
|
"""
|
|
64
57
|
return self.get(
|
|
65
58
|
self.format_url(f"/settings/{plugin_id}"),
|
|
66
|
-
PluginSettingsOutput,
|
|
67
59
|
agent_id,
|
|
60
|
+
output_class=PluginSettingsOutput,
|
|
68
61
|
)
|
|
69
62
|
|
|
70
|
-
def put_plugin_settings(self, plugin_id: str,
|
|
63
|
+
def put_plugin_settings(self, plugin_id: str, agent_id: str, values: dict) -> PluginSettingsOutput:
|
|
71
64
|
"""
|
|
72
|
-
This endpoint updates the plugin settings
|
|
73
|
-
(for multi-agent installations) or for the default agent (for single-agent installations).
|
|
65
|
+
This endpoint updates the plugin settings.
|
|
74
66
|
:param plugin_id: The id of the plugin
|
|
75
|
-
:param values: The values to update
|
|
76
67
|
:param agent_id: The id of the agent
|
|
68
|
+
:param values: The values to update
|
|
77
69
|
:return: PluginSettingsOutput, the updated plugin settings
|
|
78
70
|
"""
|
|
79
71
|
return self.put(
|
|
80
72
|
self.format_url(f"/settings/{plugin_id}"),
|
|
81
|
-
PluginSettingsOutput,
|
|
82
|
-
values,
|
|
83
73
|
agent_id,
|
|
74
|
+
output_class=PluginSettingsOutput,
|
|
75
|
+
payload=values,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def post_plugin_reset_settings(self, plugin_id: str, agent_id: str) -> PluginSettingsOutput:
|
|
79
|
+
"""
|
|
80
|
+
This endpoint resets the plugin settings to the factory values
|
|
81
|
+
:param plugin_id: The id of the plugin
|
|
82
|
+
:param agent_id: The id of the agent
|
|
83
|
+
:return: PluginSettingsOutput, the plugin settings after reset
|
|
84
|
+
"""
|
|
85
|
+
return self.post_json(
|
|
86
|
+
self.format_url(f"/settings/{plugin_id}"),
|
|
87
|
+
agent_id,
|
|
88
|
+
output_class=PluginSettingsOutput,
|
|
84
89
|
)
|