cheshirecat-python-sdk 1.2.1__py3-none-any.whl → 1.7.9__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/memory.py +0 -12
- cheshirecat_python_sdk/builders/why.py +0 -6
- cheshirecat_python_sdk/client.py +30 -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 +6 -1
- cheshirecat_python_sdk/endpoints/admins.py +37 -70
- cheshirecat_python_sdk/endpoints/auth.py +54 -0
- cheshirecat_python_sdk/endpoints/auth_handler.py +8 -8
- cheshirecat_python_sdk/endpoints/base.py +48 -17
- 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 +59 -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 +70 -145
- cheshirecat_python_sdk/endpoints/message.py +29 -13
- cheshirecat_python_sdk/endpoints/plugins.py +31 -26
- cheshirecat_python_sdk/endpoints/rabbit_hole.py +51 -23
- cheshirecat_python_sdk/endpoints/users.py +22 -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 +4 -0
- 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 +2 -0
- cheshirecat_python_sdk/models/dtos.py +3 -13
- cheshirecat_python_sdk/utils.py +2 -1
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.7.9.dist-info}/METADATA +12 -10
- cheshirecat_python_sdk-1.7.9.dist-info/RECORD +49 -0
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.7.9.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.7.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,18 +1,17 @@
|
|
|
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
|
)
|
|
14
|
+
from cheshirecat_python_sdk.models.api.nested.memories import CollectionsItem
|
|
16
15
|
from cheshirecat_python_sdk.models.dtos import Why, MemoryPoint
|
|
17
16
|
|
|
18
17
|
|
|
@@ -23,180 +22,107 @@ 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.
|
|
64
|
+
def post_memory_collections(self, collection_id: str, agent_id: str) -> CollectionsItem:
|
|
82
65
|
"""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
user_id,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
def delete_conversation_history(
|
|
91
|
-
self, agent_id: str | None = None, user_id: str | None = None
|
|
92
|
-
) -> ConversationHistoryDeleteOutput:
|
|
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.
|
|
93
70
|
"""
|
|
94
|
-
This endpoint deletes the conversation history, either for the agent identified by the agent_id parameter
|
|
95
|
-
(for multi-agent installations) or for the default agent (for single-agent installations). If the user_id
|
|
96
|
-
parameter is provided, the conversation history is filtered by the user ID.
|
|
97
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
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.
|
|
100
|
-
"""
|
|
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
|
-
agent_id: str | None = None,
|
|
156
|
-
user_id: str | None = None,
|
|
157
88
|
) -> MemoryRecallOutput:
|
|
158
89
|
"""
|
|
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.
|
|
90
|
+
This endpoint retrieves memory points based on the input text. The text parameter is the input text for which
|
|
91
|
+
the memory points are retrieved. The k parameter is the number of memory points to retrieve.
|
|
164
92
|
:param text: The input text for which the memory points are retrieved.
|
|
93
|
+
:param agent_id: The agent ID.
|
|
94
|
+
:param user_id: The user ID to filter the memory points.
|
|
165
95
|
:param k: The number of memory points to retrieve.
|
|
166
96
|
:param metadata: The metadata to filter the memory points.
|
|
167
|
-
:param agent_id: The agent ID for multi-agent installations. If not provided, the default agent is used.
|
|
168
|
-
:param user_id: The user ID to filter the memory points.
|
|
169
97
|
:return: MemoryRecallOutput, a list of memory points retrieved.
|
|
170
98
|
"""
|
|
171
99
|
query = {"text": text}
|
|
172
100
|
if k:
|
|
173
|
-
query["k"] = k
|
|
101
|
+
query["k"] = k # type: ignore
|
|
174
102
|
if metadata:
|
|
175
|
-
query["metadata"] = metadata
|
|
103
|
+
query["metadata"] = json.dumps(metadata) # type: ignore
|
|
176
104
|
|
|
177
105
|
return self.get(
|
|
178
106
|
self.format_url("/recall"),
|
|
179
|
-
MemoryRecallOutput,
|
|
180
107
|
agent_id,
|
|
181
|
-
|
|
182
|
-
|
|
108
|
+
output_class=MemoryRecallOutput,
|
|
109
|
+
user_id=user_id,
|
|
110
|
+
query=query,
|
|
183
111
|
)
|
|
184
112
|
|
|
185
113
|
def post_memory_point(
|
|
186
114
|
self,
|
|
187
|
-
collection:
|
|
115
|
+
collection: str,
|
|
116
|
+
agent_id: str,
|
|
117
|
+
user_id: str,
|
|
188
118
|
memory_point: MemoryPoint,
|
|
189
|
-
agent_id: str | None = None,
|
|
190
|
-
user_id: str | None = None,
|
|
191
119
|
) -> MemoryPointOutput:
|
|
192
120
|
"""
|
|
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.
|
|
121
|
+
This method posts a memory point.
|
|
196
122
|
: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.
|
|
123
|
+
:param agent_id: The agent ID.
|
|
199
124
|
:param user_id: The user ID to associate with the memory point.
|
|
125
|
+
:param memory_point: The memory point to post.
|
|
200
126
|
:return: MemoryPointOutput, the memory point posted.
|
|
201
127
|
"""
|
|
202
128
|
if user_id and not memory_point.metadata.get("source"):
|
|
@@ -206,28 +132,26 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
206
132
|
|
|
207
133
|
return self.post_json(
|
|
208
134
|
self.format_url(f"/collections/{collection}/points"),
|
|
209
|
-
MemoryPointOutput,
|
|
210
|
-
memory_point.model_dump(),
|
|
211
135
|
agent_id,
|
|
136
|
+
output_class=MemoryPointOutput,
|
|
137
|
+
payload=memory_point.model_dump(),
|
|
212
138
|
)
|
|
213
139
|
|
|
214
140
|
def put_memory_point(
|
|
215
141
|
self,
|
|
216
|
-
collection:
|
|
142
|
+
collection: str,
|
|
143
|
+
agent_id: str,
|
|
144
|
+
user_id: str,
|
|
217
145
|
memory_point: MemoryPoint,
|
|
218
146
|
point_id: str,
|
|
219
|
-
agent_id: str | None = None,
|
|
220
|
-
user_id: str | None = None,
|
|
221
147
|
) -> MemoryPointOutput:
|
|
222
148
|
"""
|
|
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.
|
|
149
|
+
This method puts a memory point, for the agent identified by the agent_id parameter.
|
|
226
150
|
:param collection: The collection to put the memory point.
|
|
151
|
+
:param agent_id: The agent ID.
|
|
152
|
+
:param user_id: The user ID to associate with the memory point.
|
|
227
153
|
:param memory_point: The memory point to put.
|
|
228
154
|
: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
155
|
:return: MemoryPointOutput, the memory point put.
|
|
232
156
|
"""
|
|
233
157
|
if user_id and not memory_point.metadata.get("source"):
|
|
@@ -237,68 +161,67 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
237
161
|
|
|
238
162
|
return self.put(
|
|
239
163
|
self.format_url(f"/collections/{collection}/points/{point_id}"),
|
|
240
|
-
MemoryPointOutput,
|
|
241
|
-
memory_point.model_dump(),
|
|
242
164
|
agent_id,
|
|
165
|
+
output_class=MemoryPointOutput,
|
|
166
|
+
payload=memory_point.model_dump(),
|
|
243
167
|
)
|
|
244
168
|
|
|
245
169
|
def delete_memory_point(
|
|
246
170
|
self,
|
|
247
|
-
collection:
|
|
171
|
+
collection: str,
|
|
172
|
+
agent_id: str,
|
|
248
173
|
point_id: str,
|
|
249
|
-
agent_id: str | None = None,
|
|
250
174
|
) -> MemoryPointDeleteOutput:
|
|
251
175
|
"""
|
|
252
|
-
This endpoint deletes a memory point
|
|
253
|
-
installations) or for the default agent (for single-agent installations).
|
|
176
|
+
This endpoint deletes a memory point.
|
|
254
177
|
:param collection: The collection to delete the memory point.
|
|
178
|
+
:param agent_id: The agent ID.
|
|
255
179
|
: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
180
|
:return: MemoryPointDeleteOutput, a message indicating the memory point deleted.
|
|
258
181
|
"""
|
|
259
182
|
return self.delete(
|
|
260
183
|
self.format_url(f"/collections/{collection}/points/{point_id}"),
|
|
261
|
-
MemoryPointDeleteOutput,
|
|
262
184
|
agent_id,
|
|
185
|
+
output_class=MemoryPointDeleteOutput,
|
|
263
186
|
)
|
|
264
187
|
|
|
265
188
|
def delete_memory_points_by_metadata(
|
|
266
189
|
self,
|
|
267
|
-
collection:
|
|
190
|
+
collection: str,
|
|
191
|
+
agent_id: str,
|
|
268
192
|
metadata: Dict[str, Any] | None = None,
|
|
269
|
-
agent_id: str | None = None,
|
|
270
193
|
) -> MemoryPointsDeleteByMetadataOutput:
|
|
271
194
|
"""
|
|
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.
|
|
195
|
+
This endpoint deletes memory points based on the metadata. The metadata parameter is a dictionary of key-value
|
|
196
|
+
pairs that the memory points must match.
|
|
275
197
|
:param collection: The collection to delete the memory points.
|
|
198
|
+
:param agent_id: The agent ID.
|
|
276
199
|
: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
200
|
:return: MemoryPointsDeleteByMetadataOutput, a message indicating the number of memory points deleted.
|
|
279
201
|
"""
|
|
280
202
|
return self.delete(
|
|
281
203
|
self.format_url(f"/collections/{collection}/points"),
|
|
282
|
-
MemoryPointsDeleteByMetadataOutput,
|
|
283
204
|
agent_id,
|
|
205
|
+
output_class=MemoryPointsDeleteByMetadataOutput,
|
|
284
206
|
payload=metadata,
|
|
285
207
|
)
|
|
286
208
|
|
|
287
209
|
def get_memory_points(
|
|
288
210
|
self,
|
|
289
|
-
collection:
|
|
211
|
+
collection: str,
|
|
212
|
+
agent_id: str,
|
|
290
213
|
limit: int | None = None,
|
|
291
214
|
offset: int | None = None,
|
|
292
|
-
|
|
215
|
+
metadata: Dict[str, Any] | None = None,
|
|
293
216
|
) -> MemoryPointsOutput:
|
|
294
217
|
"""
|
|
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.
|
|
218
|
+
This endpoint retrieves memory points. The limit parameter is the maximum number of memory points to retrieve.
|
|
219
|
+
The offset parameter is the number of memory points to skip.
|
|
298
220
|
:param collection: The collection to retrieve the memory points.
|
|
221
|
+
:param agent_id: The agent ID.
|
|
299
222
|
:param limit: The maximum number of memory points to retrieve.
|
|
300
223
|
:param offset: The number of memory points to skip.
|
|
301
|
-
:param
|
|
224
|
+
:param metadata: The metadata to filter the memory points.
|
|
302
225
|
:return: MemoryPointsOutput, a list of memory points retrieved.
|
|
303
226
|
"""
|
|
304
227
|
query = {}
|
|
@@ -306,11 +229,13 @@ class MemoryEndpoint(AbstractEndpoint):
|
|
|
306
229
|
query["limit"] = limit
|
|
307
230
|
if offset is not None:
|
|
308
231
|
query["offset"] = offset
|
|
232
|
+
if metadata:
|
|
233
|
+
query["metadata"] = json.dumps(metadata) # type: ignore
|
|
309
234
|
|
|
310
235
|
return self.get(
|
|
311
236
|
self.format_url(f"/collections/{collection}/points"),
|
|
312
|
-
MemoryPointsOutput,
|
|
313
237
|
agent_id,
|
|
238
|
+
output_class=MemoryPointsOutput,
|
|
314
239
|
query=query,
|
|
315
240
|
)
|
|
316
241
|
|
|
@@ -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
|
)
|