cheshirecat-python-sdk 1.3.9__tar.gz → 1.7.11__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.3.9 → cheshirecat_python_sdk-1.7.11}/Makefile +3 -3
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/PKG-INFO +4 -4
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/README.md +2 -2
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/__init__.py +0 -1
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/builders/memory.py +0 -12
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/builders/why.py +0 -6
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/client.py +20 -5
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/clients/http_client.py +20 -6
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/clients/websocket_client.py +19 -10
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/configuration.py +1 -1
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/__init__.py +4 -1
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/endpoints/admins.py +100 -0
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/endpoints/auth.py +54 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/base.py +15 -5
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/endpoints/conversation.py +83 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/file_manager.py +29 -4
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/endpoints/health_check.py +22 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/memory.py +14 -71
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/message.py +18 -6
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/plugins.py +13 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/rabbit_hole.py +15 -3
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/users.py +14 -29
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/endpoints/utils.py +71 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/enums.py +0 -11
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/admins.py +5 -7
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/models/api/conversations.py +24 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/factories.py +6 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/file_managers.py +4 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/memories.py +0 -9
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/messages.py +7 -5
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/nested/memories.py +1 -1
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/nested/plugins.py +6 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/plugins.py +14 -6
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/models/api/tokens.py +25 -0
- cheshirecat_python_sdk-1.7.11/cheshirecat_python_sdk/models/api/users.py +11 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/dtos.py +0 -10
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/utils.py +2 -1
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/pyproject.toml +3 -3
- cheshirecat_python_sdk-1.3.9/cheshirecat_python_sdk/endpoints/admins.py +0 -237
- cheshirecat_python_sdk-1.3.9/cheshirecat_python_sdk/endpoints/settings.py +0 -55
- cheshirecat_python_sdk-1.3.9/cheshirecat_python_sdk/models/api/settings.py +0 -22
- cheshirecat_python_sdk-1.3.9/cheshirecat_python_sdk/models/api/tokens.py +0 -6
- cheshirecat_python_sdk-1.3.9/cheshirecat_python_sdk/models/api/users.py +0 -8
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/.gitignore +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/LICENSE +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/builders/__init__.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/builders/base.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/builders/settings_input.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/clients/__init__.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/auth_handler.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/chunker.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/custom_endpoint.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/embedder.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/large_language_model.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/endpoints/vector_database.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/models/api/rabbit_holes.py +0 -0
- {cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/requirements.txt +0 -0
|
@@ -13,16 +13,16 @@ args=
|
|
|
13
13
|
help: ## Show help
|
|
14
14
|
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
install: ## Update the local virtual environment with the latest requirements.
|
|
17
17
|
$(PYTHON) -m pip install --upgrade pip-tools pip wheel
|
|
18
18
|
$(PIP_SYNC) requirements.txt
|
|
19
19
|
$(PYTHON) -m pip install -r requirements.txt
|
|
20
20
|
|
|
21
|
-
compile
|
|
21
|
+
compile: ## Compile requirements for the local virtual environment.
|
|
22
22
|
$(PYTHON) -m pip install --upgrade pip-tools pip wheel
|
|
23
23
|
$(PIP_COMPILE) --no-upgrade --output-file requirements.txt pyproject.toml
|
|
24
24
|
|
|
25
|
-
update
|
|
25
|
+
update: ## Update requirements for the local virtual environment.
|
|
26
26
|
$(PIP_COMPILE) --upgrade --output-file requirements.txt pyproject.toml
|
|
27
27
|
|
|
28
28
|
publish: ## Publish the package to PyPI.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cheshirecat-python-sdk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.11
|
|
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
|
|
@@ -683,7 +683,7 @@ License: GNU GENERAL PUBLIC LICENSE
|
|
|
683
683
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
684
684
|
License-File: LICENSE
|
|
685
685
|
Keywords: Cheshire-Cat,LLM,OpenAPI,OpenSource,RAG
|
|
686
|
-
Classifier: Development Status ::
|
|
686
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
687
687
|
Classifier: Framework :: FastAPI
|
|
688
688
|
Classifier: Programming Language :: Python :: 3
|
|
689
689
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -767,7 +767,7 @@ result = asyncio.run(cheshire_cat_client.rabbit_hole.post_web(url, "agent"))
|
|
|
767
767
|
Memory management utilities:
|
|
768
768
|
|
|
769
769
|
```python
|
|
770
|
-
from cheshirecat_python_sdk import
|
|
770
|
+
from cheshirecat_python_sdk import CheshireCatClient, Configuration, Message
|
|
771
771
|
|
|
772
772
|
configuration = Configuration(host="localhost", port=1865, auth_key="test", secure_connection=False)
|
|
773
773
|
cheshire_cat_client = CheshireCatClient(configuration)
|
|
@@ -778,5 +778,5 @@ cheshire_cat_client.memory.get_memory_recall("HELLO", "agent", "user") # recall
|
|
|
778
778
|
url = "https://www.google.com"
|
|
779
779
|
|
|
780
780
|
# delete memory points by metadata, like this example delete by source
|
|
781
|
-
cheshire_cat_client.memory.delete_memory_points_by_metadata(
|
|
781
|
+
cheshire_cat_client.memory.delete_memory_points_by_metadata("declarative", "agent", {"source": url})
|
|
782
782
|
```
|
|
@@ -66,7 +66,7 @@ result = asyncio.run(cheshire_cat_client.rabbit_hole.post_web(url, "agent"))
|
|
|
66
66
|
Memory management utilities:
|
|
67
67
|
|
|
68
68
|
```python
|
|
69
|
-
from cheshirecat_python_sdk import
|
|
69
|
+
from cheshirecat_python_sdk import CheshireCatClient, Configuration, Message
|
|
70
70
|
|
|
71
71
|
configuration = Configuration(host="localhost", port=1865, auth_key="test", secure_connection=False)
|
|
72
72
|
cheshire_cat_client = CheshireCatClient(configuration)
|
|
@@ -77,5 +77,5 @@ cheshire_cat_client.memory.get_memory_recall("HELLO", "agent", "user") # recall
|
|
|
77
77
|
url = "https://www.google.com"
|
|
78
78
|
|
|
79
79
|
# delete memory points by metadata, like this example delete by source
|
|
80
|
-
cheshire_cat_client.memory.delete_memory_points_by_metadata(
|
|
80
|
+
cheshire_cat_client.memory.delete_memory_points_by_metadata("declarative", "agent", {"source": url})
|
|
81
81
|
```
|
{cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/__init__.py
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from cheshirecat_python_sdk.client import CheshireCatClient
|
|
2
2
|
from cheshirecat_python_sdk.clients import HttpClient, WSClient
|
|
3
3
|
from cheshirecat_python_sdk.configuration import Configuration
|
|
4
|
-
from cheshirecat_python_sdk.enums import Collection, Role
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
from cheshirecat_python_sdk.builders import *
|
|
@@ -6,31 +6,19 @@ from cheshirecat_python_sdk.models.dtos import Memory, MemoryPoint
|
|
|
6
6
|
|
|
7
7
|
class MemoryBuilder(BaseBuilder):
|
|
8
8
|
def __init__(self):
|
|
9
|
-
self.episodic: Dict[str, Any] | None = None
|
|
10
9
|
self.declarative: Dict[str, Any] | None = None
|
|
11
|
-
self.procedural: Dict[str, Any] | None = None
|
|
12
10
|
|
|
13
11
|
@staticmethod
|
|
14
12
|
def create():
|
|
15
13
|
return MemoryBuilder()
|
|
16
14
|
|
|
17
|
-
def set_episodic(self, episodic: Dict[str, Any] | None = None):
|
|
18
|
-
self.episodic = episodic or {}
|
|
19
|
-
return self
|
|
20
|
-
|
|
21
15
|
def set_declarative(self, declarative: Dict[str, Any] | None = None):
|
|
22
16
|
self.declarative = declarative or {}
|
|
23
17
|
return self
|
|
24
18
|
|
|
25
|
-
def set_procedural(self, procedural: Dict[str, Any] | None = None):
|
|
26
|
-
self.procedural = procedural or {}
|
|
27
|
-
return self
|
|
28
|
-
|
|
29
19
|
def build(self):
|
|
30
20
|
memory = Memory()
|
|
31
|
-
memory.episodic = self.episodic
|
|
32
21
|
memory.declarative = self.declarative
|
|
33
|
-
memory.procedural = self.procedural
|
|
34
22
|
|
|
35
23
|
return memory
|
|
36
24
|
|
|
@@ -9,7 +9,6 @@ class WhyBuilder(BaseBuilder):
|
|
|
9
9
|
self.input: str | None = None
|
|
10
10
|
self.intermediate_steps: Dict[str, Any] | None = None
|
|
11
11
|
self.memory: Memory | None = None
|
|
12
|
-
self.model_interactions: Dict[str, Any] | None = None
|
|
13
12
|
|
|
14
13
|
@staticmethod
|
|
15
14
|
def create() -> "WhyBuilder":
|
|
@@ -27,14 +26,9 @@ class WhyBuilder(BaseBuilder):
|
|
|
27
26
|
self.memory = memory
|
|
28
27
|
return self
|
|
29
28
|
|
|
30
|
-
def set_model_interactions(self, model_interactions: Dict[str, Any] | None = None) -> "WhyBuilder":
|
|
31
|
-
self.model_interactions = model_interactions
|
|
32
|
-
return self
|
|
33
|
-
|
|
34
29
|
def build(self) -> Why:
|
|
35
30
|
return Why(
|
|
36
31
|
input=self.input,
|
|
37
32
|
intermediate_steps=self.intermediate_steps,
|
|
38
33
|
memory=self.memory,
|
|
39
|
-
model_interactions=self.model_interactions,
|
|
40
34
|
)
|
{cheshirecat_python_sdk-1.3.9 → cheshirecat_python_sdk-1.7.11}/cheshirecat_python_sdk/client.py
RENAMED
|
@@ -2,8 +2,10 @@ 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,
|
|
8
|
+
ConversationEndpoint,
|
|
7
9
|
CustomEndpoint,
|
|
8
10
|
EmbedderEndpoint,
|
|
9
11
|
FileManagerEndpoint,
|
|
@@ -12,9 +14,10 @@ from cheshirecat_python_sdk.endpoints import (
|
|
|
12
14
|
MessageEndpoint,
|
|
13
15
|
PluginsEndpoint,
|
|
14
16
|
RabbitHoleEndpoint,
|
|
15
|
-
SettingsEndpoint,
|
|
16
17
|
UsersEndpoint,
|
|
18
|
+
UtilsEndpoint,
|
|
17
19
|
VectorDatabaseEndpoint,
|
|
20
|
+
HealthCheckEndpoint,
|
|
18
21
|
)
|
|
19
22
|
|
|
20
23
|
|
|
@@ -53,6 +56,10 @@ class CheshireCatClient:
|
|
|
53
56
|
def admins(self):
|
|
54
57
|
return AdminsEndpoint(self)
|
|
55
58
|
|
|
59
|
+
@property
|
|
60
|
+
def auth(self):
|
|
61
|
+
return AuthEndpoint(self)
|
|
62
|
+
|
|
56
63
|
@property
|
|
57
64
|
def auth_handler(self):
|
|
58
65
|
return AuthHandlerEndpoint(self)
|
|
@@ -61,6 +68,10 @@ class CheshireCatClient:
|
|
|
61
68
|
def chunker(self):
|
|
62
69
|
return ChunkerEndpoint(self)
|
|
63
70
|
|
|
71
|
+
@property
|
|
72
|
+
def conversation(self):
|
|
73
|
+
return ConversationEndpoint(self)
|
|
74
|
+
|
|
64
75
|
@property
|
|
65
76
|
def embedder(self):
|
|
66
77
|
return EmbedderEndpoint(self)
|
|
@@ -89,14 +100,14 @@ class CheshireCatClient:
|
|
|
89
100
|
def rabbit_hole(self):
|
|
90
101
|
return RabbitHoleEndpoint(self)
|
|
91
102
|
|
|
92
|
-
@property
|
|
93
|
-
def settings(self):
|
|
94
|
-
return SettingsEndpoint(self)
|
|
95
|
-
|
|
96
103
|
@property
|
|
97
104
|
def users(self):
|
|
98
105
|
return UsersEndpoint(self)
|
|
99
106
|
|
|
107
|
+
@property
|
|
108
|
+
def utils(self):
|
|
109
|
+
return UtilsEndpoint(self)
|
|
110
|
+
|
|
100
111
|
@property
|
|
101
112
|
def custom(self):
|
|
102
113
|
return CustomEndpoint(self)
|
|
@@ -104,3 +115,7 @@ class CheshireCatClient:
|
|
|
104
115
|
@property
|
|
105
116
|
def vector_database(self):
|
|
106
117
|
return VectorDatabaseEndpoint(self)
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def health_check(self):
|
|
121
|
+
return HealthCheckEndpoint(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,27 +39,40 @@ 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()
|
|
61
72
|
|
|
73
|
+
return self.get_base_session()
|
|
74
|
+
|
|
75
|
+
def get_base_session(self) -> BaseUrlSession:
|
|
62
76
|
session = BaseUrlSession(base_url=self.get_http_uri())
|
|
63
77
|
session.headers = self.headers
|
|
64
78
|
|
|
@@ -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,6 +1,8 @@
|
|
|
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
|
|
5
|
+
from cheshirecat_python_sdk.endpoints.conversation import ConversationEndpoint
|
|
4
6
|
from cheshirecat_python_sdk.endpoints.custom_endpoint import CustomEndpoint
|
|
5
7
|
from cheshirecat_python_sdk.endpoints.embedder import EmbedderEndpoint
|
|
6
8
|
from cheshirecat_python_sdk.endpoints.file_manager import FileManagerEndpoint
|
|
@@ -9,6 +11,7 @@ from cheshirecat_python_sdk.endpoints.memory import MemoryEndpoint
|
|
|
9
11
|
from cheshirecat_python_sdk.endpoints.message import MessageEndpoint
|
|
10
12
|
from cheshirecat_python_sdk.endpoints.plugins import PluginsEndpoint
|
|
11
13
|
from cheshirecat_python_sdk.endpoints.rabbit_hole import RabbitHoleEndpoint
|
|
12
|
-
from cheshirecat_python_sdk.endpoints.settings import SettingsEndpoint
|
|
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
|
|
17
|
+
from cheshirecat_python_sdk.endpoints.health_check import HealthCheckEndpoint
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint, MultipartPayload
|
|
2
|
+
from cheshirecat_python_sdk.models.api.admins import (
|
|
3
|
+
PluginInstallOutput,
|
|
4
|
+
PluginInstallFromRegistryOutput,
|
|
5
|
+
PluginDetailsOutput,
|
|
6
|
+
PluginDeleteOutput,
|
|
7
|
+
)
|
|
8
|
+
from cheshirecat_python_sdk.models.api.nested.plugins import PluginSettingsOutput
|
|
9
|
+
from cheshirecat_python_sdk.models.api.plugins import PluginCollectionOutput, PluginsSettingsOutput, PluginToggleOutput
|
|
10
|
+
from cheshirecat_python_sdk.utils import file_attributes
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AdminsEndpoint(AbstractEndpoint):
|
|
14
|
+
def __init__(self, client: "CheshireCatClient"):
|
|
15
|
+
super().__init__(client)
|
|
16
|
+
self.prefix = "/plugins"
|
|
17
|
+
|
|
18
|
+
def get_available_plugins(self, plugin_name: str | None = None) -> PluginCollectionOutput:
|
|
19
|
+
"""
|
|
20
|
+
Get a list of all available plugins.
|
|
21
|
+
:param plugin_name: The name of the plugin.
|
|
22
|
+
:return: PluginCollectionOutput, the details of the plugins.
|
|
23
|
+
"""
|
|
24
|
+
return self.get(
|
|
25
|
+
self.format_url("/installed"),
|
|
26
|
+
self.system_id,
|
|
27
|
+
output_class=PluginCollectionOutput,
|
|
28
|
+
query={"query": plugin_name} if plugin_name else None,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def post_install_plugin_from_zip(self, path_zip: str) -> PluginInstallOutput:
|
|
32
|
+
payload = MultipartPayload()
|
|
33
|
+
|
|
34
|
+
with open(path_zip, "rb") as file:
|
|
35
|
+
payload.files = [("file", file_attributes(path_zip, file))]
|
|
36
|
+
result = self.post_multipart(
|
|
37
|
+
self.format_url("/install/upload"),
|
|
38
|
+
self.system_id,
|
|
39
|
+
output_class=PluginInstallOutput,
|
|
40
|
+
payload=payload,
|
|
41
|
+
)
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
def post_install_plugin_from_registry(self, url: str) -> PluginInstallFromRegistryOutput:
|
|
45
|
+
"""
|
|
46
|
+
Install a new plugin from a registry. The plugin is installed asynchronously.
|
|
47
|
+
:param url: The URL of the plugin.
|
|
48
|
+
:return: PluginInstallFromRegistryOutput, the details of the installation.
|
|
49
|
+
"""
|
|
50
|
+
return self.post_json(
|
|
51
|
+
self.format_url("/install/registry"),
|
|
52
|
+
self.system_id,
|
|
53
|
+
output_class=PluginInstallFromRegistryOutput,
|
|
54
|
+
payload={"url": url},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def get_plugins_settings(self) -> PluginsSettingsOutput:
|
|
58
|
+
"""
|
|
59
|
+
Get the default settings of all the plugins.
|
|
60
|
+
:return: PluginsSettingsOutput, the details of the settings.
|
|
61
|
+
"""
|
|
62
|
+
return self.get(self.format_url("/system/settings"), self.system_id, output_class=PluginsSettingsOutput)
|
|
63
|
+
|
|
64
|
+
def get_plugin_settings(self, plugin_id: str) -> PluginSettingsOutput:
|
|
65
|
+
"""
|
|
66
|
+
Get the default settings of a specific plugin.
|
|
67
|
+
:param plugin_id: The ID of the plugin.
|
|
68
|
+
:return: PluginSettingsOutput, the details of the settings.
|
|
69
|
+
"""
|
|
70
|
+
return self.get(
|
|
71
|
+
self.format_url(f"/system/settings/{plugin_id}"), self.system_id, output_class=PluginSettingsOutput
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def get_plugin_details(self, plugin_id: str) -> PluginDetailsOutput:
|
|
75
|
+
"""
|
|
76
|
+
Get the details of a specific plugin.
|
|
77
|
+
:param plugin_id: The ID of the plugin.
|
|
78
|
+
:return: PluginDetailsOutput, the details of the plugin.
|
|
79
|
+
"""
|
|
80
|
+
return self.get(self.format_url(f"/system/details/{plugin_id}"), self.system_id, output_class=PluginDetailsOutput)
|
|
81
|
+
|
|
82
|
+
def delete_plugin(self, plugin_id: str) -> PluginDeleteOutput:
|
|
83
|
+
"""
|
|
84
|
+
Delete a specific plugin.
|
|
85
|
+
:param plugin_id: The ID of the plugin.
|
|
86
|
+
:return: PluginDeleteOutput, the details of the plugin.
|
|
87
|
+
"""
|
|
88
|
+
return self.delete(self.format_url(f"/uninstall/{plugin_id}"), self.system_id, output_class=PluginDeleteOutput)
|
|
89
|
+
|
|
90
|
+
def put_toggle_plugin(self, plugin_id: str) -> PluginToggleOutput:
|
|
91
|
+
"""
|
|
92
|
+
This endpoint toggles a plugin, on a system level
|
|
93
|
+
:param plugin_id: The id of the plugin to toggle
|
|
94
|
+
:return: PluginToggleOutput, the toggled plugin
|
|
95
|
+
"""
|
|
96
|
+
return self.put(
|
|
97
|
+
self.format_url(f"/system/toggle/{plugin_id}"),
|
|
98
|
+
self.system_id,
|
|
99
|
+
output_class=PluginToggleOutput,
|
|
100
|
+
)
|
|
@@ -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,11 +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
|
-
|
|
28
|
-
return
|
|
33
|
+
def get_http_session(self) -> BaseUrlSession:
|
|
34
|
+
return self.client.http_client.get_base_session()
|
|
35
|
+
|
|
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)
|
|
29
38
|
|
|
30
39
|
def get(
|
|
31
40
|
self,
|
|
@@ -53,12 +62,13 @@ class AbstractEndpoint(ABC):
|
|
|
53
62
|
output_class: Type[T] | None = None,
|
|
54
63
|
payload: Dict[str, Any] | None = None,
|
|
55
64
|
user_id: str | None = None,
|
|
65
|
+
chat_id: str | None = None,
|
|
56
66
|
) -> T:
|
|
57
67
|
options = {}
|
|
58
68
|
if payload:
|
|
59
69
|
options["json"] = payload
|
|
60
70
|
|
|
61
|
-
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)
|
|
62
72
|
response.raise_for_status()
|
|
63
73
|
|
|
64
74
|
if output_class is None:
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
+
from cheshirecat_python_sdk.models.api.conversations import (
|
|
5
|
+
ConversationHistoryOutput,
|
|
6
|
+
ConversationDeleteOutput,
|
|
7
|
+
ConversationsResponse,
|
|
8
|
+
ConversationNameChangeOutput,
|
|
9
|
+
)
|
|
10
|
+
from cheshirecat_python_sdk.utils import deserialize
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ConversationEndpoint(AbstractEndpoint):
|
|
14
|
+
def __init__(self, client: "CheshireCatClient"):
|
|
15
|
+
super().__init__(client)
|
|
16
|
+
self.prefix = "/conversation"
|
|
17
|
+
|
|
18
|
+
def get_conversation_history(self, agent_id: str, user_id: str, chat_id: str) -> ConversationHistoryOutput:
|
|
19
|
+
"""
|
|
20
|
+
This endpoint returns the conversation history.
|
|
21
|
+
:param agent_id: The agent ID.
|
|
22
|
+
:param user_id: The user ID to filter the conversation history.
|
|
23
|
+
:param chat_id: The chat ID to filter the conversation history.
|
|
24
|
+
:return: ConversationHistoryOutput, a list of conversation history entries.
|
|
25
|
+
"""
|
|
26
|
+
return self.get(
|
|
27
|
+
self.format_url(chat_id),
|
|
28
|
+
agent_id,
|
|
29
|
+
user_id=user_id,
|
|
30
|
+
output_class=ConversationHistoryOutput,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def get_conversations(self, agent_id: str, user_id: str) -> List[ConversationsResponse]:
|
|
34
|
+
"""
|
|
35
|
+
This endpoint returns the attributes of the different conversations, given the `agent_id` and the `user_id`.
|
|
36
|
+
:param agent_id: The agent ID.
|
|
37
|
+
:param user_id: The user ID to filter the conversation history.
|
|
38
|
+
:return: List[ConversationsResponse], a list of conversation attributes.
|
|
39
|
+
"""
|
|
40
|
+
response = self.get_http_client(agent_id, user_id).get(self.prefix)
|
|
41
|
+
response.raise_for_status()
|
|
42
|
+
|
|
43
|
+
return [deserialize(item, ConversationsResponse) for item in response.json()]
|
|
44
|
+
|
|
45
|
+
def delete_conversation(self, agent_id: str, user_id: str, chat_id: str) -> ConversationDeleteOutput:
|
|
46
|
+
"""
|
|
47
|
+
This endpoint deletes the conversation.
|
|
48
|
+
:param agent_id: The agent ID.
|
|
49
|
+
:param user_id: The user ID to filter the conversation history.
|
|
50
|
+
:param chat_id: The chat ID to filter the conversation history.
|
|
51
|
+
:return: ConversationDeleteOutput, a message indicating whether the conversation was deleted.
|
|
52
|
+
"""
|
|
53
|
+
return self.delete(
|
|
54
|
+
self.format_url(chat_id),
|
|
55
|
+
agent_id,
|
|
56
|
+
output_class=ConversationDeleteOutput,
|
|
57
|
+
user_id=user_id,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def post_conversation_name(
|
|
61
|
+
self,
|
|
62
|
+
name: str,
|
|
63
|
+
agent_id: str,
|
|
64
|
+
user_id: str,
|
|
65
|
+
chat_id: str,
|
|
66
|
+
) -> ConversationNameChangeOutput:
|
|
67
|
+
"""
|
|
68
|
+
This endpoint creates a new element in the conversation history.
|
|
69
|
+
:param name: The new name to assign to the conversation
|
|
70
|
+
:param agent_id: The agent ID.
|
|
71
|
+
:param user_id: The user ID to filter the conversation history.
|
|
72
|
+
:param chat_id: The chat ID to filter the conversation history.
|
|
73
|
+
:return: ConversationNameChangeOutput, a message indicating whether the conversation name was changed.
|
|
74
|
+
"""
|
|
75
|
+
payload = {"name": name}
|
|
76
|
+
|
|
77
|
+
return self.post_json(
|
|
78
|
+
self.format_url(chat_id),
|
|
79
|
+
agent_id,
|
|
80
|
+
output_class=ConversationNameChangeOutput,
|
|
81
|
+
payload=payload,
|
|
82
|
+
user_id=user_id,
|
|
83
|
+
)
|