cheshirecat-python-sdk 1.4.0__tar.gz → 1.7.8__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.
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/PKG-INFO +1 -1
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/client.py +10 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/clients/http_client.py +17 -6
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/clients/websocket_client.py +19 -10
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/__init__.py +2 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/admins.py +1 -71
- cheshirecat_python_sdk-1.7.8/cheshirecat_python_sdk/endpoints/auth.py +54 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/base.py +13 -6
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/conversation.py +22 -34
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/file_manager.py +29 -4
- cheshirecat_python_sdk-1.7.8/cheshirecat_python_sdk/endpoints/health_check.py +22 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/message.py +18 -6
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/plugins.py +13 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/rabbit_hole.py +15 -3
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/users.py +0 -28
- cheshirecat_python_sdk-1.7.8/cheshirecat_python_sdk/endpoints/utils.py +71 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/admins.py +4 -0
- cheshirecat_python_sdk-1.7.8/cheshirecat_python_sdk/models/api/conversations.py +24 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/file_managers.py +4 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/messages.py +7 -5
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/nested/memories.py +1 -1
- cheshirecat_python_sdk-1.7.8/cheshirecat_python_sdk/models/api/tokens.py +25 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/pyproject.toml +2 -2
- cheshirecat_python_sdk-1.4.0/cheshirecat_python_sdk/endpoints/health_check.py +0 -12
- cheshirecat_python_sdk-1.4.0/cheshirecat_python_sdk/models/api/conversations.py +0 -12
- cheshirecat_python_sdk-1.4.0/cheshirecat_python_sdk/models/api/tokens.py +0 -6
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/.gitignore +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/LICENSE +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/Makefile +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/README.md +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/__init__.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/__init__.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/base.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/memory.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/settings_input.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/why.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/clients/__init__.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/configuration.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/auth_handler.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/chunker.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/custom_endpoint.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/embedder.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/large_language_model.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/memory.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/endpoints/vector_database.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/enums.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/factories.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/memories.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/nested/plugins.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/plugins.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/rabbit_holes.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/api/users.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/dtos.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/utils.py +0 -0
- {cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/requirements.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cheshirecat-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.8
|
|
4
4
|
Summary: Python SDK for the Cloud-ready fork of the Cheshire Cat
|
|
5
5
|
Project-URL: Repository, https://github.com/matteocacciola/cheshirecat-python-sdk
|
|
6
6
|
Project-URL: Documentation, https://github.com/matteocacciola/cheshirecat-python-sdk#README
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/client.py
RENAMED
|
@@ -2,6 +2,7 @@ from cheshirecat_python_sdk.clients import HttpClient, WSClient
|
|
|
2
2
|
from cheshirecat_python_sdk.configuration import Configuration
|
|
3
3
|
from cheshirecat_python_sdk.endpoints import (
|
|
4
4
|
AdminsEndpoint,
|
|
5
|
+
AuthEndpoint,
|
|
5
6
|
AuthHandlerEndpoint,
|
|
6
7
|
ChunkerEndpoint,
|
|
7
8
|
ConversationEndpoint,
|
|
@@ -14,6 +15,7 @@ from cheshirecat_python_sdk.endpoints import (
|
|
|
14
15
|
PluginsEndpoint,
|
|
15
16
|
RabbitHoleEndpoint,
|
|
16
17
|
UsersEndpoint,
|
|
18
|
+
UtilsEndpoint,
|
|
17
19
|
VectorDatabaseEndpoint,
|
|
18
20
|
HealthCheckEndpoint,
|
|
19
21
|
)
|
|
@@ -54,6 +56,10 @@ class CheshireCatClient:
|
|
|
54
56
|
def admins(self):
|
|
55
57
|
return AdminsEndpoint(self)
|
|
56
58
|
|
|
59
|
+
@property
|
|
60
|
+
def auth(self):
|
|
61
|
+
return AuthEndpoint(self)
|
|
62
|
+
|
|
57
63
|
@property
|
|
58
64
|
def auth_handler(self):
|
|
59
65
|
return AuthHandlerEndpoint(self)
|
|
@@ -98,6 +104,10 @@ class CheshireCatClient:
|
|
|
98
104
|
def users(self):
|
|
99
105
|
return UsersEndpoint(self)
|
|
100
106
|
|
|
107
|
+
@property
|
|
108
|
+
def utils(self):
|
|
109
|
+
return UtilsEndpoint(self)
|
|
110
|
+
|
|
101
111
|
@property
|
|
102
112
|
def custom(self):
|
|
103
113
|
return CustomEndpoint(self)
|
|
@@ -15,8 +15,9 @@ class HttpClient:
|
|
|
15
15
|
self.port = port
|
|
16
16
|
self.apikey = apikey
|
|
17
17
|
self.token = None
|
|
18
|
-
self.user_id = None
|
|
19
18
|
self.agent_id = None
|
|
19
|
+
self.user_id = None
|
|
20
|
+
self.chat_id = None
|
|
20
21
|
self.is_https = is_https
|
|
21
22
|
self.headers = {}
|
|
22
23
|
|
|
@@ -38,23 +39,33 @@ class HttpClient:
|
|
|
38
39
|
def __before_secure_request(self):
|
|
39
40
|
if self.apikey:
|
|
40
41
|
self.headers["Authorization"] = f"Bearer {self.apikey}"
|
|
41
|
-
if self.user_id:
|
|
42
|
-
self.headers["user_id"] = self.user_id
|
|
43
42
|
if self.agent_id:
|
|
44
|
-
self.headers["
|
|
43
|
+
self.headers["X-Agent-ID"] = self.agent_id
|
|
44
|
+
if self.user_id:
|
|
45
|
+
self.headers["X-User-ID"] = self.user_id
|
|
46
|
+
if self.chat_id:
|
|
47
|
+
self.headers["X-Chat-ID"] = self.chat_id
|
|
45
48
|
|
|
46
49
|
def __before_jwt_request(self):
|
|
47
50
|
if self.token:
|
|
48
51
|
self.headers["Authorization"] = f"Bearer {self.token}"
|
|
49
52
|
if self.agent_id:
|
|
50
|
-
self.headers["
|
|
53
|
+
self.headers["X-Agent-ID"] = self.agent_id
|
|
54
|
+
if self.chat_id:
|
|
55
|
+
self.headers["X-Chat-ID"] = self.chat_id
|
|
51
56
|
|
|
52
|
-
def get_client(
|
|
57
|
+
def get_client(
|
|
58
|
+
self,
|
|
59
|
+
agent_id: str | None = None,
|
|
60
|
+
user_id: str | None = None,
|
|
61
|
+
chat_id: str | None = None,
|
|
62
|
+
) -> BaseUrlSession:
|
|
53
63
|
if not self.apikey and not self.token:
|
|
54
64
|
raise ValueError("You must provide an apikey or a token")
|
|
55
65
|
|
|
56
66
|
self.agent_id = agent_id
|
|
57
67
|
self.user_id = user_id
|
|
68
|
+
self.chat_id = chat_id
|
|
58
69
|
|
|
59
70
|
for middleware in self.middlewares:
|
|
60
71
|
middleware()
|
|
@@ -22,28 +22,37 @@ class WSClient:
|
|
|
22
22
|
self.token = token
|
|
23
23
|
return self
|
|
24
24
|
|
|
25
|
-
def get_ws_uri(
|
|
25
|
+
def get_ws_uri(
|
|
26
|
+
self,
|
|
27
|
+
agent_id: str,
|
|
28
|
+
user_id: str,
|
|
29
|
+
chat_id: str | None = None,
|
|
30
|
+
) -> str:
|
|
26
31
|
query = {"user_id": user_id}
|
|
27
|
-
if self.token:
|
|
28
|
-
query["token"] = self.token
|
|
29
|
-
elif self.apikey:
|
|
30
|
-
query["apikey"] = self.apikey
|
|
31
|
-
else:
|
|
32
|
-
raise ValueError("You must provide an apikey or a token")
|
|
33
32
|
|
|
34
33
|
scheme = "wss" if self.is_wss else "ws"
|
|
35
34
|
path = f"ws/{agent_id}"
|
|
35
|
+
if chat_id:
|
|
36
|
+
path += f"/{chat_id}"
|
|
37
|
+
|
|
36
38
|
query_string = urlencode(query)
|
|
37
39
|
port_suffix = f":{self.port}" if self.port else ""
|
|
38
40
|
|
|
39
41
|
return f"{scheme}://{self.host}{port_suffix}/{path}?{query_string}"
|
|
40
42
|
|
|
41
|
-
async def get_client(self, agent_id: str, user_id: str) -> ClientConnection:
|
|
42
|
-
uri = self.get_ws_uri(agent_id, user_id)
|
|
43
|
+
async def get_client(self, agent_id: str, user_id: str, chat_id: str | None = None) -> ClientConnection:
|
|
44
|
+
uri = self.get_ws_uri(agent_id, user_id, chat_id)
|
|
43
45
|
if self.ws_client is None:
|
|
44
46
|
try:
|
|
47
|
+
if self.token:
|
|
48
|
+
headers = {"Authorization": f"Bearer {self.token}"}
|
|
49
|
+
elif self.apikey:
|
|
50
|
+
headers = {"Authorization": f"Bearer {self.apikey}"}
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError("You must provide an apikey or a token")
|
|
53
|
+
|
|
45
54
|
# Create a WebSocket connection
|
|
46
|
-
websocket = await connect(uri, ping_interval=100000, ping_timeout=100000)
|
|
55
|
+
websocket = await connect(uri, ping_interval=100000, ping_timeout=100000, additional_headers=headers)
|
|
47
56
|
self.ws_client = websocket
|
|
48
57
|
except InvalidURI as e:
|
|
49
58
|
raise ValueError(f"Invalid WebSocket URI: {uri}") from e
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from cheshirecat_python_sdk.endpoints.admins import AdminsEndpoint
|
|
2
|
+
from cheshirecat_python_sdk.endpoints.auth import AuthEndpoint
|
|
2
3
|
from cheshirecat_python_sdk.endpoints.auth_handler import AuthHandlerEndpoint
|
|
3
4
|
from cheshirecat_python_sdk.endpoints.chunker import ChunkerEndpoint
|
|
4
5
|
from cheshirecat_python_sdk.endpoints.conversation import ConversationEndpoint
|
|
@@ -11,5 +12,6 @@ from cheshirecat_python_sdk.endpoints.message import MessageEndpoint
|
|
|
11
12
|
from cheshirecat_python_sdk.endpoints.plugins import PluginsEndpoint
|
|
12
13
|
from cheshirecat_python_sdk.endpoints.rabbit_hole import RabbitHoleEndpoint
|
|
13
14
|
from cheshirecat_python_sdk.endpoints.users import UsersEndpoint
|
|
15
|
+
from cheshirecat_python_sdk.endpoints.utils import UtilsEndpoint
|
|
14
16
|
from cheshirecat_python_sdk.endpoints.vector_database import VectorDatabaseEndpoint
|
|
15
17
|
from cheshirecat_python_sdk.endpoints.health_check import HealthCheckEndpoint
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
from typing import List
|
|
1
|
+
from typing import List
|
|
2
2
|
|
|
3
3
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint, MultipartPayload
|
|
4
4
|
from cheshirecat_python_sdk.models.api.admins import (
|
|
5
5
|
AdminOutput,
|
|
6
|
-
ResetOutput,
|
|
7
|
-
CreatedOutput,
|
|
8
6
|
PluginInstallOutput,
|
|
9
7
|
PluginInstallFromRegistryOutput,
|
|
10
8
|
PluginDetailsOutput,
|
|
@@ -12,7 +10,6 @@ from cheshirecat_python_sdk.models.api.admins import (
|
|
|
12
10
|
)
|
|
13
11
|
from cheshirecat_python_sdk.models.api.nested.plugins import PluginSettingsOutput
|
|
14
12
|
from cheshirecat_python_sdk.models.api.plugins import PluginCollectionOutput, PluginsSettingsOutput, PluginToggleOutput
|
|
15
|
-
from cheshirecat_python_sdk.models.api.tokens import TokenOutput
|
|
16
13
|
from cheshirecat_python_sdk.utils import deserialize, file_attributes
|
|
17
14
|
|
|
18
15
|
|
|
@@ -21,35 +18,6 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
21
18
|
super().__init__(client)
|
|
22
19
|
self.prefix = "/admins"
|
|
23
20
|
|
|
24
|
-
def token(self, username: str, password: str) -> TokenOutput:
|
|
25
|
-
"""
|
|
26
|
-
This endpoint is used to get a token for the user. The token is used to authenticate the user in the system.
|
|
27
|
-
When the token expires, the user must request a new token.
|
|
28
|
-
:param username: The username of the user.
|
|
29
|
-
:param password: The password of the user.
|
|
30
|
-
:return: TokenOutput, the token of the user.
|
|
31
|
-
"""
|
|
32
|
-
response = self.get_http_session().post(
|
|
33
|
-
self.format_url("/auth/token"),
|
|
34
|
-
json={"username": username, "password": password},
|
|
35
|
-
)
|
|
36
|
-
response.raise_for_status()
|
|
37
|
-
|
|
38
|
-
result = deserialize(response.json(), TokenOutput)
|
|
39
|
-
self.client.add_token(result.access_token)
|
|
40
|
-
return result
|
|
41
|
-
|
|
42
|
-
def get_available_permissions(self) -> dict[int | str, Any]:
|
|
43
|
-
"""
|
|
44
|
-
This endpoint is used to get a list of available permissions in the system. The permissions are used to define
|
|
45
|
-
the access rights of the users in the system. The permissions are defined by the system administrator.
|
|
46
|
-
:return array<int|string, Any>, the available permissions
|
|
47
|
-
"""
|
|
48
|
-
response = self.get_http_client().get(self.format_url("/auth/available-permissions"))
|
|
49
|
-
response.raise_for_status()
|
|
50
|
-
|
|
51
|
-
return response.json()
|
|
52
|
-
|
|
53
21
|
def post_admin(self, username: str, password: str, permissions: dict | None = None) -> AdminOutput:
|
|
54
22
|
"""
|
|
55
23
|
Create a new admin user.
|
|
@@ -126,44 +94,6 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
126
94
|
"""
|
|
127
95
|
return self.delete(self.format_url(f"/users/{admin_id}"), self.system_id, output_class=AdminOutput)
|
|
128
96
|
|
|
129
|
-
def post_factory_reset(self) -> ResetOutput:
|
|
130
|
-
"""
|
|
131
|
-
Reset the system to the factory settings.
|
|
132
|
-
:return: ResetOutput, the details of the reset.
|
|
133
|
-
"""
|
|
134
|
-
return self.post_json(self.format_url("/utils/factory/reset/"), self.system_id, output_class=ResetOutput)
|
|
135
|
-
|
|
136
|
-
def get_agents(self) -> List[str]:
|
|
137
|
-
"""
|
|
138
|
-
Get a list of all agents.
|
|
139
|
-
:return: List[str], the IDs of the agents.
|
|
140
|
-
"""
|
|
141
|
-
return self.get(self.format_url("/utils/agents/"), self.system_id)
|
|
142
|
-
|
|
143
|
-
def post_agent_create(self, agent_id: str) -> CreatedOutput:
|
|
144
|
-
"""
|
|
145
|
-
Create a new agent.
|
|
146
|
-
:param agent_id: The ID of the agent.
|
|
147
|
-
:return: CreatedOutput, the details of the agent.
|
|
148
|
-
"""
|
|
149
|
-
return self.post_json(self.format_url("/utils/agent/create/"), agent_id, output_class=CreatedOutput)
|
|
150
|
-
|
|
151
|
-
def post_agent_reset(self, agent_id: str) -> ResetOutput:
|
|
152
|
-
"""
|
|
153
|
-
Reset an agent to the factory settings.
|
|
154
|
-
:param agent_id: The ID of the agent.
|
|
155
|
-
:return: ResetOutput, the details of the reset.
|
|
156
|
-
"""
|
|
157
|
-
return self.post_json(self.format_url("/utils/agent/reset/"), agent_id, output_class=ResetOutput)
|
|
158
|
-
|
|
159
|
-
def post_agent_destroy(self, agent_id: str) -> ResetOutput:
|
|
160
|
-
"""
|
|
161
|
-
Destroy an agent.
|
|
162
|
-
:param agent_id: The ID of the agent.
|
|
163
|
-
:return: ResetOutput, the details of the reset.
|
|
164
|
-
"""
|
|
165
|
-
return self.post_json(self.format_url("/utils/agent/destroy/"), agent_id, output_class=ResetOutput)
|
|
166
|
-
|
|
167
97
|
def get_available_plugins(self, plugin_name: str | None = None) -> PluginCollectionOutput:
|
|
168
98
|
"""
|
|
169
99
|
Get a list of all available plugins.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
+
from cheshirecat_python_sdk.models.api.tokens import TokenOutput, MeOutput
|
|
5
|
+
from cheshirecat_python_sdk.utils import deserialize
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthEndpoint(AbstractEndpoint):
|
|
9
|
+
def __init__(self, client: "CheshireCatClient"):
|
|
10
|
+
super().__init__(client)
|
|
11
|
+
self.prefix = "/auth"
|
|
12
|
+
|
|
13
|
+
def token(self, username: str, password: str) -> TokenOutput:
|
|
14
|
+
"""
|
|
15
|
+
This endpoint is used to get a token for the user. The token is used to authenticate the user in the system. When
|
|
16
|
+
the token expires, the user must request a new token.
|
|
17
|
+
"""
|
|
18
|
+
response = self.get_http_session().post(
|
|
19
|
+
self.format_url("/token"),
|
|
20
|
+
json={
|
|
21
|
+
"username": username,
|
|
22
|
+
"password": password,
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
response.raise_for_status()
|
|
26
|
+
|
|
27
|
+
result = deserialize(response.json(), TokenOutput)
|
|
28
|
+
self.client.add_token(result.access_token)
|
|
29
|
+
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def get_available_permissions(self) -> dict[int | str, Any]:
|
|
33
|
+
"""
|
|
34
|
+
This endpoint is used to get a list of available permissions in the system. The permissions are used to define
|
|
35
|
+
the access rights of the users in the system. The permissions are defined by the system administrator.
|
|
36
|
+
:return array<int|string, Any>, the available permissions
|
|
37
|
+
"""
|
|
38
|
+
response = self.get_http_client().get(self.format_url("/available-permissions"))
|
|
39
|
+
response.raise_for_status()
|
|
40
|
+
|
|
41
|
+
return response.json()
|
|
42
|
+
|
|
43
|
+
def me(self, token: str) -> MeOutput:
|
|
44
|
+
"""
|
|
45
|
+
This endpoint is used to get the current user information. The user information includes the list of agents
|
|
46
|
+
the user has access to. This endpoint requires authentication.
|
|
47
|
+
"""
|
|
48
|
+
self.client.add_token(token)
|
|
49
|
+
|
|
50
|
+
response = self.get_http_client().get("/me")
|
|
51
|
+
response.raise_for_status()
|
|
52
|
+
|
|
53
|
+
result = deserialize(response.json(), MeOutput)
|
|
54
|
+
return result
|
|
@@ -2,6 +2,7 @@ from abc import ABC
|
|
|
2
2
|
from typing import Dict, Any, List, Tuple, Type
|
|
3
3
|
import requests
|
|
4
4
|
from pydantic import BaseModel
|
|
5
|
+
from requests_toolbelt.sessions import BaseUrlSession
|
|
5
6
|
from websockets import ClientConnection
|
|
6
7
|
|
|
7
8
|
from cheshirecat_python_sdk.utils import T, deserialize
|
|
@@ -21,14 +22,19 @@ class AbstractEndpoint(ABC):
|
|
|
21
22
|
def format_url(self, endpoint: str) -> str:
|
|
22
23
|
return f"/{self.prefix}/{endpoint}".replace("//", "/")
|
|
23
24
|
|
|
24
|
-
def get_http_client(
|
|
25
|
-
|
|
25
|
+
def get_http_client(
|
|
26
|
+
self,
|
|
27
|
+
agent_id: str | None = None,
|
|
28
|
+
user_id: str | None = None,
|
|
29
|
+
chat_id: str | None = None,
|
|
30
|
+
) -> requests.Session:
|
|
31
|
+
return self.client.http_client.get_client(agent_id, user_id, chat_id)
|
|
26
32
|
|
|
27
|
-
def get_http_session(self):
|
|
33
|
+
def get_http_session(self) -> BaseUrlSession:
|
|
28
34
|
return self.client.http_client.get_base_session()
|
|
29
35
|
|
|
30
|
-
async def get_ws_client(self, agent_id: str, user_id: str) -> ClientConnection:
|
|
31
|
-
return await self.client.ws_client.get_client(agent_id, user_id)
|
|
36
|
+
async def get_ws_client(self, agent_id: str, user_id: str, chat_id: str | None = None) -> ClientConnection:
|
|
37
|
+
return await self.client.ws_client.get_client(agent_id, user_id, chat_id)
|
|
32
38
|
|
|
33
39
|
def get(
|
|
34
40
|
self,
|
|
@@ -56,12 +62,13 @@ class AbstractEndpoint(ABC):
|
|
|
56
62
|
output_class: Type[T] | None = None,
|
|
57
63
|
payload: Dict[str, Any] | None = None,
|
|
58
64
|
user_id: str | None = None,
|
|
65
|
+
chat_id: str | None = None,
|
|
59
66
|
) -> T:
|
|
60
67
|
options = {}
|
|
61
68
|
if payload:
|
|
62
69
|
options["json"] = payload
|
|
63
70
|
|
|
64
|
-
response = self.get_http_client(agent_id, user_id).post(endpoint, **options)
|
|
71
|
+
response = self.get_http_client(agent_id, user_id, chat_id).post(endpoint, **options)
|
|
65
72
|
response.raise_for_status()
|
|
66
73
|
|
|
67
74
|
if output_class is None:
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import List
|
|
2
2
|
|
|
3
3
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
-
from cheshirecat_python_sdk.models.api.conversations import
|
|
5
|
-
|
|
4
|
+
from cheshirecat_python_sdk.models.api.conversations import (
|
|
5
|
+
ConversationHistoryOutput,
|
|
6
|
+
ConversationDeleteOutput,
|
|
7
|
+
ConversationsResponse,
|
|
8
|
+
ConversationNameChangeOutput,
|
|
9
|
+
)
|
|
6
10
|
from cheshirecat_python_sdk.utils import deserialize
|
|
7
11
|
|
|
8
12
|
|
|
@@ -26,70 +30,54 @@ class ConversationEndpoint(AbstractEndpoint):
|
|
|
26
30
|
output_class=ConversationHistoryOutput,
|
|
27
31
|
)
|
|
28
32
|
|
|
29
|
-
def
|
|
33
|
+
def get_conversations(self, agent_id: str, user_id: str) -> List[ConversationsResponse]:
|
|
30
34
|
"""
|
|
31
|
-
This endpoint returns the
|
|
35
|
+
This endpoint returns the attributes of the different conversations, given the `agent_id` and the `user_id`.
|
|
32
36
|
:param agent_id: The agent ID.
|
|
33
37
|
:param user_id: The user ID to filter the conversation history.
|
|
34
|
-
:return:
|
|
38
|
+
:return: List[ConversationsResponse], a list of conversation attributes.
|
|
35
39
|
"""
|
|
36
40
|
response = self.get_http_client(agent_id, user_id).get(self.prefix)
|
|
37
41
|
response.raise_for_status()
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
for key, item in response.json():
|
|
41
|
-
result[key] = deserialize(item, ConversationHistoryOutput)
|
|
42
|
-
return result
|
|
43
|
+
return [deserialize(item, ConversationsResponse) for item in response.json()]
|
|
43
44
|
|
|
44
|
-
def
|
|
45
|
+
def delete_conversation(self, agent_id: str, user_id: str, chat_id: str) -> ConversationDeleteOutput:
|
|
45
46
|
"""
|
|
46
|
-
This endpoint deletes the conversation
|
|
47
|
+
This endpoint deletes the conversation.
|
|
47
48
|
:param agent_id: The agent ID.
|
|
48
49
|
:param user_id: The user ID to filter the conversation history.
|
|
49
50
|
:param chat_id: The chat ID to filter the conversation history.
|
|
50
|
-
:return:
|
|
51
|
+
:return: ConversationDeleteOutput, a message indicating whether the conversation was deleted.
|
|
51
52
|
"""
|
|
52
53
|
return self.delete(
|
|
53
54
|
self.format_url(chat_id),
|
|
54
55
|
agent_id,
|
|
55
|
-
output_class=
|
|
56
|
+
output_class=ConversationDeleteOutput,
|
|
56
57
|
user_id=user_id,
|
|
57
58
|
)
|
|
58
59
|
|
|
59
|
-
def
|
|
60
|
+
def post_conversation_name(
|
|
60
61
|
self,
|
|
61
|
-
|
|
62
|
-
text: str,
|
|
62
|
+
name: str,
|
|
63
63
|
agent_id: str,
|
|
64
64
|
user_id: str,
|
|
65
65
|
chat_id: str,
|
|
66
|
-
|
|
67
|
-
why: Why | None = None,
|
|
68
|
-
) -> ConversationHistoryOutput:
|
|
66
|
+
) -> ConversationNameChangeOutput:
|
|
69
67
|
"""
|
|
70
68
|
This endpoint creates a new element in the conversation history.
|
|
71
|
-
:param
|
|
72
|
-
:param text: The text of the conversation history entry.
|
|
69
|
+
:param name: The new name to assign to the conversation
|
|
73
70
|
:param agent_id: The agent ID.
|
|
74
71
|
:param user_id: The user ID to filter the conversation history.
|
|
75
72
|
:param chat_id: The chat ID to filter the conversation history.
|
|
76
|
-
:
|
|
77
|
-
:param why: The reason for the conversation history entry.
|
|
78
|
-
:return: ConversationHistoryOutput, the conversation history entry created.
|
|
73
|
+
:return: ConversationNameChangeOutput, a message indicating whether the conversation name was changed.
|
|
79
74
|
"""
|
|
80
|
-
payload = {
|
|
81
|
-
"who": who,
|
|
82
|
-
"text": text,
|
|
83
|
-
}
|
|
84
|
-
if image:
|
|
85
|
-
payload["image"] = image
|
|
86
|
-
if why:
|
|
87
|
-
payload["why"] = why.model_dump()
|
|
75
|
+
payload = {"name": name}
|
|
88
76
|
|
|
89
77
|
return self.post_json(
|
|
90
78
|
self.format_url(chat_id),
|
|
91
79
|
agent_id,
|
|
92
|
-
output_class=
|
|
80
|
+
output_class=ConversationNameChangeOutput,
|
|
93
81
|
payload=payload,
|
|
94
82
|
user_id=user_id,
|
|
95
83
|
)
|
|
@@ -3,7 +3,7 @@ from requests import Response
|
|
|
3
3
|
|
|
4
4
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
5
5
|
from cheshirecat_python_sdk.models.api.factories import FactoryObjectSettingOutput, FactoryObjectSettingsOutput
|
|
6
|
-
from cheshirecat_python_sdk.models.api.file_managers import FileManagerAttributes
|
|
6
|
+
from cheshirecat_python_sdk.models.api.file_managers import FileManagerAttributes, FileManagerDeletedFiles
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class FileManagerEndpoint(AbstractEndpoint):
|
|
@@ -61,18 +61,43 @@ class FileManagerEndpoint(AbstractEndpoint):
|
|
|
61
61
|
"""
|
|
62
62
|
return self.get(self.prefix, agent_id, output_class=FileManagerAttributes)
|
|
63
63
|
|
|
64
|
-
def get_file(self, agent_id: str,
|
|
64
|
+
def get_file(self, agent_id: str, file_name: str) -> Response:
|
|
65
65
|
"""
|
|
66
66
|
Download a file from the file manager for the agent specified by agent_id
|
|
67
67
|
:param agent_id: The agent id
|
|
68
|
-
:param
|
|
68
|
+
:param file_name: The name of the file to download
|
|
69
69
|
:return: Response, the response containing the file content
|
|
70
70
|
"""
|
|
71
71
|
response = self.get_http_client(agent_id).get(
|
|
72
|
-
self.format_url(f"/
|
|
72
|
+
self.format_url(f"/files/{file_name}"),
|
|
73
73
|
stream=True,
|
|
74
74
|
headers={"Accept": "application/octet-stream"}
|
|
75
75
|
)
|
|
76
76
|
response.raise_for_status()
|
|
77
77
|
|
|
78
78
|
return response
|
|
79
|
+
|
|
80
|
+
def delete_file(self, agent_id: str, file_name: str) -> FileManagerDeletedFiles:
|
|
81
|
+
"""
|
|
82
|
+
Download a file from the file manager for the agent specified by agent_id
|
|
83
|
+
:param agent_id: The agent id
|
|
84
|
+
:param file_name: The name of the file to delete
|
|
85
|
+
:return: FileManagerDeletedFiles, the response containing info about the deleted file
|
|
86
|
+
"""
|
|
87
|
+
return self.delete(
|
|
88
|
+
self.format_url(f"/files/{file_name}"),
|
|
89
|
+
agent_id,
|
|
90
|
+
output_class=FileManagerDeletedFiles,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def delete_files(self, agent_id: str) -> FileManagerDeletedFiles:
|
|
94
|
+
"""
|
|
95
|
+
Download a file from the file manager for the agent specified by agent_id
|
|
96
|
+
:param agent_id: The agent id
|
|
97
|
+
:return: bool, True if all files were deleted successfully
|
|
98
|
+
"""
|
|
99
|
+
return self.delete(
|
|
100
|
+
self.format_url("/files"),
|
|
101
|
+
agent_id,
|
|
102
|
+
output_class=FileManagerDeletedFiles,
|
|
103
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
2
|
+
|
|
3
|
+
class HealthCheckEndpoint(AbstractEndpoint):
|
|
4
|
+
def liveness(self):
|
|
5
|
+
"""
|
|
6
|
+
This endpoint is used to check if the server is running.
|
|
7
|
+
:return: dict, the status of the server.
|
|
8
|
+
"""
|
|
9
|
+
response = self.get_http_session().get("/health/liveness")
|
|
10
|
+
response.raise_for_status()
|
|
11
|
+
|
|
12
|
+
return response.json()
|
|
13
|
+
|
|
14
|
+
def readiness(self):
|
|
15
|
+
"""
|
|
16
|
+
This endpoint is used to check if the server is running.
|
|
17
|
+
:return: dict, the status of the server.
|
|
18
|
+
"""
|
|
19
|
+
response = self.get_http_session().get("/health/readiness")
|
|
20
|
+
response.raise_for_status()
|
|
21
|
+
|
|
22
|
+
return response.json()
|
|
@@ -2,25 +2,34 @@ 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
|
-
def send_http_message(
|
|
11
|
+
def send_http_message(
|
|
12
|
+
self,
|
|
13
|
+
message: Message,
|
|
14
|
+
agent_id: str,
|
|
15
|
+
user_id: str,
|
|
16
|
+
chat_id: str | None = None,
|
|
17
|
+
) -> ChatOutput:
|
|
12
18
|
"""
|
|
13
19
|
This endpoint sends a message to the agent identified by the agentId parameter. The message is sent via HTTP.
|
|
14
20
|
:param message: Message object, the message to send
|
|
15
21
|
:param agent_id: the agent id
|
|
16
22
|
:param user_id: the user id
|
|
23
|
+
:param chat_id: the chat id (optional)
|
|
24
|
+
:return: ChatOutput object
|
|
17
25
|
"""
|
|
18
26
|
return self.post_json(
|
|
19
27
|
'/message',
|
|
20
28
|
agent_id,
|
|
21
|
-
output_class=
|
|
29
|
+
output_class=ChatOutput,
|
|
22
30
|
payload=message.model_dump(),
|
|
23
31
|
user_id=user_id,
|
|
32
|
+
chat_id=chat_id,
|
|
24
33
|
)
|
|
25
34
|
|
|
26
35
|
async def send_websocket_message(
|
|
@@ -28,21 +37,24 @@ class MessageEndpoint(AbstractEndpoint):
|
|
|
28
37
|
message: Message,
|
|
29
38
|
agent_id: str,
|
|
30
39
|
user_id: str,
|
|
40
|
+
chat_id: str | None = None,
|
|
31
41
|
callback: Callable[[str], None] | None = None
|
|
32
|
-
) ->
|
|
42
|
+
) -> ChatOutput:
|
|
33
43
|
"""
|
|
34
44
|
This endpoint sends a message to the agent identified by the agentId parameter. The message is sent via WebSocket.
|
|
35
45
|
:param message: Message object, the message to send
|
|
36
46
|
:param agent_id: the agent id
|
|
37
47
|
:param user_id: the user id
|
|
48
|
+
:param chat_id: the chat id
|
|
38
49
|
:param callback: callable, a callback function that will be called for each message received
|
|
50
|
+
:return: ChatOutput object
|
|
39
51
|
"""
|
|
40
52
|
try:
|
|
41
53
|
json_data = json.dumps(message.model_dump())
|
|
42
54
|
except Exception:
|
|
43
55
|
raise RuntimeError("Error encoding message")
|
|
44
56
|
|
|
45
|
-
client = await self.get_ws_client(agent_id, user_id)
|
|
57
|
+
client = await self.get_ws_client(agent_id, user_id, chat_id)
|
|
46
58
|
|
|
47
59
|
try:
|
|
48
60
|
await client.send(json_data)
|
|
@@ -62,4 +74,4 @@ class MessageEndpoint(AbstractEndpoint):
|
|
|
62
74
|
raise Exception(f"WebSocket error: {str(e)}")
|
|
63
75
|
|
|
64
76
|
await client.close()
|
|
65
|
-
return deserialize(json.loads(response),
|
|
77
|
+
return deserialize(json.loads(response), ChatOutput)
|
|
@@ -74,3 +74,16 @@ class PluginsEndpoint(AbstractEndpoint):
|
|
|
74
74
|
output_class=PluginSettingsOutput,
|
|
75
75
|
payload=values,
|
|
76
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,
|
|
89
|
+
)
|
|
@@ -20,6 +20,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
20
20
|
self,
|
|
21
21
|
file_path,
|
|
22
22
|
agent_id: str,
|
|
23
|
+
chat_id: str | None = None,
|
|
23
24
|
file_name: str | None = None,
|
|
24
25
|
metadata: Dict[str, Any] | None = None,
|
|
25
26
|
) -> UploadSingleFileResponse:
|
|
@@ -30,6 +31,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
30
31
|
The CheshireCat processes the injection in background and the client will be informed at the end of the process.
|
|
31
32
|
:param file_path: The path to the file to upload.
|
|
32
33
|
:param agent_id: The ID of the agent.
|
|
34
|
+
:param chat_id: The ID of the chat (optional).
|
|
33
35
|
:param file_name: The name of the file.
|
|
34
36
|
:param metadata: The metadata to include with the file.
|
|
35
37
|
:return: The response from the RabbitHole API.
|
|
@@ -40,9 +42,11 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
40
42
|
if metadata is not None:
|
|
41
43
|
payload.data["metadata"] = json.dumps(metadata)
|
|
42
44
|
|
|
45
|
+
endpoint = self.prefix if not chat_id else self.format_url(chat_id)
|
|
46
|
+
|
|
43
47
|
with open(file_path, "rb") as file:
|
|
44
48
|
payload.files = [("file", file_attributes(file_name, file))]
|
|
45
|
-
result = self.post_multipart(
|
|
49
|
+
result = self.post_multipart(endpoint, agent_id, output_class=UploadSingleFileResponse, payload=payload)
|
|
46
50
|
|
|
47
51
|
return result
|
|
48
52
|
|
|
@@ -50,6 +54,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
50
54
|
self,
|
|
51
55
|
file_paths: List[str],
|
|
52
56
|
agent_id: str,
|
|
57
|
+
chat_id: str | None = None,
|
|
53
58
|
metadata: Dict[str, Any] | None = None
|
|
54
59
|
) -> Dict[str, UploadSingleFileResponse]: # type: ignore
|
|
55
60
|
"""
|
|
@@ -58,6 +63,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
58
63
|
The CheshireCat processes the injection in background and the client will be informed at the end of the process.
|
|
59
64
|
:param file_paths: The paths to the files to upload.
|
|
60
65
|
:param agent_id: The ID of the agent.
|
|
66
|
+
:param chat_id: The ID of the chat (optional).
|
|
61
67
|
:param metadata: The metadata to include with the files.
|
|
62
68
|
:return: The response from the RabbitHole API.
|
|
63
69
|
"""
|
|
@@ -67,13 +73,15 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
67
73
|
|
|
68
74
|
files = []
|
|
69
75
|
file_handles = []
|
|
76
|
+
|
|
77
|
+
endpoint = self.format_url("/batch") if not chat_id else self.format_url(f"/batch/{chat_id}")
|
|
70
78
|
try:
|
|
71
79
|
for file_path in file_paths:
|
|
72
80
|
file = open(file_path, "rb")
|
|
73
81
|
file_handles.append(file)
|
|
74
82
|
files.append(("files", file_attributes(Path(file_path).name, file)))
|
|
75
83
|
|
|
76
|
-
response = self.get_http_client(agent_id).post(
|
|
84
|
+
response = self.get_http_client(agent_id).post(endpoint, data=data, files=files)
|
|
77
85
|
response.raise_for_status()
|
|
78
86
|
|
|
79
87
|
result = {}
|
|
@@ -88,6 +96,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
88
96
|
self,
|
|
89
97
|
web_url: str,
|
|
90
98
|
agent_id: str,
|
|
99
|
+
chat_id: str | None = None,
|
|
91
100
|
metadata: Dict[str, Any] | None = None
|
|
92
101
|
) -> UploadUrlResponse:
|
|
93
102
|
"""
|
|
@@ -97,6 +106,7 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
97
106
|
The CheshireCat processes the injection in background, and the client will be informed at the end of the process.
|
|
98
107
|
:param web_url: The URL of the website to ingest.
|
|
99
108
|
:param agent_id: The ID of the agent.
|
|
109
|
+
:param chat_id: The ID of the chat (optional).
|
|
100
110
|
:param metadata: The metadata to include with the files.
|
|
101
111
|
:return: The response from the RabbitHole API.
|
|
102
112
|
"""
|
|
@@ -104,7 +114,9 @@ class RabbitHoleEndpoint(AbstractEndpoint):
|
|
|
104
114
|
if metadata is not None:
|
|
105
115
|
payload["metadata"] = metadata # type: ignore
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
endpoint = self.format_url("/web") if not chat_id else self.format_url(f"/web/{chat_id}")
|
|
118
|
+
|
|
119
|
+
return self.post_json(endpoint, agent_id, output_class=UploadUrlResponse, payload=payload)
|
|
108
120
|
|
|
109
121
|
def post_memory(
|
|
110
122
|
self,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from typing import Any, List, Dict
|
|
2
2
|
|
|
3
3
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
-
from cheshirecat_python_sdk.models.api.tokens import TokenOutput
|
|
5
4
|
from cheshirecat_python_sdk.models.api.users import UserOutput
|
|
6
5
|
from cheshirecat_python_sdk.utils import deserialize
|
|
7
6
|
|
|
@@ -11,33 +10,6 @@ class UsersEndpoint(AbstractEndpoint):
|
|
|
11
10
|
super().__init__(client)
|
|
12
11
|
self.prefix = "/users"
|
|
13
12
|
|
|
14
|
-
def token(self, username: str, password: str) -> TokenOutput:
|
|
15
|
-
"""
|
|
16
|
-
This endpoint is used to get a token for the user. The token is used to authenticate the user in the system. When
|
|
17
|
-
the token expires, the user must request a new token.
|
|
18
|
-
"""
|
|
19
|
-
response = self.get_http_session().post("/auth/token", json={
|
|
20
|
-
"username": username,
|
|
21
|
-
"password": password,
|
|
22
|
-
})
|
|
23
|
-
response.raise_for_status()
|
|
24
|
-
|
|
25
|
-
result = deserialize(response.json(), TokenOutput)
|
|
26
|
-
self.client.add_token(result.access_token)
|
|
27
|
-
|
|
28
|
-
return result
|
|
29
|
-
|
|
30
|
-
def get_available_permissions(self) -> dict[int | str, Any]:
|
|
31
|
-
"""
|
|
32
|
-
This endpoint is used to get a list of available permissions in the system. The permissions are used to define
|
|
33
|
-
the access rights of the users in the system. The permissions are defined by the system administrator.
|
|
34
|
-
:return array<int|string, Any>, the available permissions
|
|
35
|
-
"""
|
|
36
|
-
response = self.get_http_client().get("/auth/available-permissions")
|
|
37
|
-
response.raise_for_status()
|
|
38
|
-
|
|
39
|
-
return response.json()
|
|
40
|
-
|
|
41
13
|
def post_user(
|
|
42
14
|
self, agent_id: str, username: str, password: str, permissions: dict[str, Any] | None = None
|
|
43
15
|
) -> UserOutput:
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
+
from cheshirecat_python_sdk.models.api.admins import ResetOutput, ClonedOutput, CreatedOutput
|
|
5
|
+
from cheshirecat_python_sdk.utils import deserialize
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UtilsEndpoint(AbstractEndpoint):
|
|
9
|
+
def __init__(self, client: "CheshireCatClient"):
|
|
10
|
+
super().__init__(client)
|
|
11
|
+
self.prefix = "/utils"
|
|
12
|
+
|
|
13
|
+
def post_factory_reset(self) -> ResetOutput:
|
|
14
|
+
"""
|
|
15
|
+
Reset the system to the factory settings.
|
|
16
|
+
:return: ResetOutput, the details of the reset.
|
|
17
|
+
"""
|
|
18
|
+
return self.post_json(self.format_url("/factory/reset/"), self.system_id, output_class=ResetOutput)
|
|
19
|
+
|
|
20
|
+
def get_agents(self) -> List[str]:
|
|
21
|
+
"""
|
|
22
|
+
Get a list of all agents.
|
|
23
|
+
:return: List[str], the IDs of the agents.
|
|
24
|
+
"""
|
|
25
|
+
return self.get(self.format_url("/agents/"), self.system_id)
|
|
26
|
+
|
|
27
|
+
def post_agent_create(self, agent_id: str) -> CreatedOutput:
|
|
28
|
+
"""
|
|
29
|
+
Create a new agent.
|
|
30
|
+
:param agent_id: The ID of the agent.
|
|
31
|
+
:return: CreatedOutput, the details of the agent.
|
|
32
|
+
"""
|
|
33
|
+
response = self.get_http_client().post(
|
|
34
|
+
self.format_url("/agents/create/"),
|
|
35
|
+
json={
|
|
36
|
+
"agent_id": agent_id,
|
|
37
|
+
},
|
|
38
|
+
)
|
|
39
|
+
response.raise_for_status()
|
|
40
|
+
|
|
41
|
+
return deserialize(response.json(), CreatedOutput)
|
|
42
|
+
|
|
43
|
+
def post_agent_reset(self, agent_id: str) -> ResetOutput:
|
|
44
|
+
"""
|
|
45
|
+
Reset an agent to the factory settings.
|
|
46
|
+
:param agent_id: The ID of the agent.
|
|
47
|
+
:return: ResetOutput, the details of the reset.
|
|
48
|
+
"""
|
|
49
|
+
return self.post_json(self.format_url("/agents/reset/"), agent_id, output_class=ResetOutput)
|
|
50
|
+
|
|
51
|
+
def post_agent_destroy(self, agent_id: str) -> ResetOutput:
|
|
52
|
+
"""
|
|
53
|
+
Destroy an agent.
|
|
54
|
+
:param agent_id: The ID of the agent.
|
|
55
|
+
:return: ResetOutput, the details of the reset.
|
|
56
|
+
"""
|
|
57
|
+
return self.post_json(self.format_url("/agents/destroy/"), agent_id, output_class=ResetOutput)
|
|
58
|
+
|
|
59
|
+
def post_agent_clone(self, agent_id: str, new_agent_id: str) -> ClonedOutput:
|
|
60
|
+
"""
|
|
61
|
+
Destroy an agent.
|
|
62
|
+
:param agent_id: The ID of the agent.
|
|
63
|
+
:param new_agent_id: The ID of the new cloned agent.
|
|
64
|
+
:return: ClonedOutput, the details of the cloning.
|
|
65
|
+
"""
|
|
66
|
+
return self.post_json(
|
|
67
|
+
self.format_url("/agents/clone/"),
|
|
68
|
+
agent_id,
|
|
69
|
+
payload={"agent_id": new_agent_id},
|
|
70
|
+
output_class=ClonedOutput
|
|
71
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
|
|
4
|
+
from cheshirecat_python_sdk.models.api.nested.memories import ConversationMessage
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConversationDeleteOutput(BaseModel):
|
|
8
|
+
deleted: bool
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ConversationHistoryOutput(BaseModel):
|
|
12
|
+
history: List[ConversationMessage]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConversationsResponse(BaseModel):
|
|
16
|
+
chat_id: str
|
|
17
|
+
name: str
|
|
18
|
+
num_messages: int
|
|
19
|
+
created_at: float | None
|
|
20
|
+
updated_at: float | None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ConversationNameChangeOutput(BaseModel):
|
|
24
|
+
changed: bool
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from pydantic import Field
|
|
1
|
+
from pydantic import Field, BaseModel
|
|
2
2
|
|
|
3
3
|
from cheshirecat_python_sdk.models.dtos import MessageBase, Why
|
|
4
4
|
|
|
@@ -7,8 +7,10 @@ class MessageOutput(MessageBase):
|
|
|
7
7
|
why: Why | None = Field(default_factory=Why) # Assuming Why has a no-args constructor
|
|
8
8
|
type: str | None = "chat" # Default argument
|
|
9
9
|
error: bool | None = False # Default argument
|
|
10
|
-
content: str = Field(init=False) # Field without a default value
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
|
|
12
|
+
class ChatOutput(BaseModel):
|
|
13
|
+
agent_id: str
|
|
14
|
+
user_id: str
|
|
15
|
+
chat_id: str
|
|
16
|
+
message: MessageOutput
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TokenOutput(BaseModel):
|
|
5
|
+
access_token: str
|
|
6
|
+
token_type: str | None = "bearer"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class User(BaseModel):
|
|
10
|
+
id: str
|
|
11
|
+
username: str
|
|
12
|
+
permissions: dict[str, list[str]]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AgentMatch(BaseModel):
|
|
16
|
+
agent_id: str
|
|
17
|
+
agent_name: str
|
|
18
|
+
agent_description: str | None = None
|
|
19
|
+
user: User
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MeOutput(BaseModel):
|
|
23
|
+
success : bool
|
|
24
|
+
agents: list[AgentMatch]
|
|
25
|
+
auto_selected: bool
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "cheshirecat-python-sdk"
|
|
3
3
|
description = "Python SDK for the Cloud-ready fork of the Cheshire Cat"
|
|
4
|
-
version = "1.
|
|
4
|
+
version = "1.7.8"
|
|
5
5
|
requires-python = ">=3.10"
|
|
6
6
|
license = { file = "LICENSE" }
|
|
7
7
|
authors = [
|
|
@@ -66,4 +66,4 @@ disable = [
|
|
|
66
66
|
]
|
|
67
67
|
|
|
68
68
|
[tool.pylint.main]
|
|
69
|
-
load-plugins = "pylint_actions, perflint"
|
|
69
|
+
load-plugins = "pylint_actions, perflint"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
2
|
-
|
|
3
|
-
class HealthCheckEndpoint(AbstractEndpoint):
|
|
4
|
-
def home(self):
|
|
5
|
-
"""
|
|
6
|
-
This endpoint is used to check if the server is running.
|
|
7
|
-
:return: dict, the status of the server.
|
|
8
|
-
"""
|
|
9
|
-
response = self.get_http_session().get("/")
|
|
10
|
-
response.raise_for_status()
|
|
11
|
-
|
|
12
|
-
return response.json()
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from typing import List
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
|
|
4
|
-
from cheshirecat_python_sdk.models.api.nested.memories import ConversationHistoryItem
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ConversationHistoryDeleteOutput(BaseModel):
|
|
8
|
-
deleted: bool
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ConversationHistoryOutput(BaseModel):
|
|
12
|
-
history: List[ConversationHistoryItem]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/builders/why.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/enums.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/models/dtos.py
RENAMED
|
File without changes
|
{cheshirecat_python_sdk-1.4.0 → cheshirecat_python_sdk-1.7.8}/cheshirecat_python_sdk/utils.py
RENAMED
|
File without changes
|
|
File without changes
|