aicosmos-client 0.0.3__py3-none-any.whl → 0.0.5__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.
- aicosmos_client/cli.py +29 -27
- aicosmos_client/client.py +22 -27
- aicosmos_client-0.0.5.dist-info/METADATA +66 -0
- aicosmos_client-0.0.5.dist-info/RECORD +7 -0
- aicosmos_client-0.0.3.dist-info/METADATA +0 -21
- aicosmos_client-0.0.3.dist-info/RECORD +0 -7
- {aicosmos_client-0.0.3.dist-info → aicosmos_client-0.0.5.dist-info}/WHEEL +0 -0
- {aicosmos_client-0.0.3.dist-info → aicosmos_client-0.0.5.dist-info}/licenses/LICENSE +0 -0
aicosmos_client/cli.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import asyncio
|
2
2
|
from typing import Dict
|
3
3
|
|
4
|
+
from client import AICosmosClient
|
4
5
|
from textual import on, work
|
5
6
|
from textual.app import App, ComposeResult
|
6
7
|
from textual.containers import Container
|
@@ -18,7 +19,6 @@ from textual.widgets import (
|
|
18
19
|
RichLog,
|
19
20
|
Static,
|
20
21
|
)
|
21
|
-
from .client import AICosmosClient
|
22
22
|
|
23
23
|
|
24
24
|
class LoginScreen(Screen):
|
@@ -176,11 +176,11 @@ class SessionScreen(Screen):
|
|
176
176
|
@work(exclusive=True)
|
177
177
|
async def load_sessions(self) -> None:
|
178
178
|
self.query_one("#session-list").clear()
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
try:
|
180
|
+
self.sessions = self.app.client.get_my_sessions()
|
181
|
+
except Exception as e:
|
182
182
|
self.query_one("#session-list").append(
|
183
|
-
ListItem(Label(f"{
|
183
|
+
ListItem(Label(f"Failed: {e}"), id="no-sessions")
|
184
184
|
)
|
185
185
|
return
|
186
186
|
|
@@ -193,9 +193,9 @@ class SessionScreen(Screen):
|
|
193
193
|
for session in self.sessions:
|
194
194
|
session_id = session["session_id"]
|
195
195
|
clean_id = self.sanitize_id(session_id)
|
196
|
-
title = session["
|
197
|
-
|
198
|
-
|
196
|
+
title = session["title"]
|
197
|
+
if not title:
|
198
|
+
title = f"Session {session_id[:6]}"
|
199
199
|
self.query_one("#session-list").append(
|
200
200
|
ListItem(Label(title), id=f"session-{clean_id}")
|
201
201
|
)
|
@@ -203,15 +203,16 @@ class SessionScreen(Screen):
|
|
203
203
|
@on(Button.Pressed, "#create-session")
|
204
204
|
@work(exclusive=True)
|
205
205
|
async def create_session(self) -> None:
|
206
|
-
|
206
|
+
try:
|
207
|
+
session_id = self.app.client.create_session()
|
208
|
+
except Exception as e:
|
209
|
+
self.query_one("#session-error").update(f"Failed to create session: {e}")
|
210
|
+
return
|
207
211
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
self.app.push_screen("chat")
|
213
|
-
else:
|
214
|
-
self.query_one("#session-error").update("Failed to create session")
|
212
|
+
self.app.current_session = session_id
|
213
|
+
self.app.uninstall_screen("chat")
|
214
|
+
self.app.install_screen(ChatScreen(), "chat")
|
215
|
+
self.app.push_screen("chat")
|
215
216
|
|
216
217
|
@on(ListView.Selected)
|
217
218
|
def session_selected(self, event: ListView.Selected) -> None:
|
@@ -399,11 +400,12 @@ class ChatScreen(Screen):
|
|
399
400
|
@work(exclusive=True)
|
400
401
|
async def load_conversation(self) -> None:
|
401
402
|
"""Fetch conversation history"""
|
402
|
-
|
403
|
-
self.app.
|
404
|
-
|
405
|
-
|
406
|
-
|
403
|
+
try:
|
404
|
+
self.conversation = self.app.client.get_session_history(
|
405
|
+
self.app.current_session
|
406
|
+
)
|
407
|
+
except Exception as e:
|
408
|
+
self.query_one("#chat-log").write(f"[red]Error: {e}[/red]")
|
407
409
|
return
|
408
410
|
self.update_message_display()
|
409
411
|
|
@@ -433,12 +435,12 @@ class ChatScreen(Screen):
|
|
433
435
|
send_button.disabled = True
|
434
436
|
|
435
437
|
try:
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
self.query_one("#chat-log").write(f"[red]Error: {
|
438
|
+
try:
|
439
|
+
conversation_history = await asyncio.to_thread(
|
440
|
+
self.app.client.chat, self.app.current_session, message
|
441
|
+
)
|
442
|
+
except Exception as e:
|
443
|
+
self.query_one("#chat-log").write(f"[red]Error: {e}[/red]")
|
442
444
|
return
|
443
445
|
new_messages = conversation_history[len(self.conversation) :]
|
444
446
|
for msg in new_messages:
|
aicosmos_client/client.py
CHANGED
@@ -9,9 +9,7 @@ class AICosmosClient:
|
|
9
9
|
self.password: str = password
|
10
10
|
self.access_token: str = None
|
11
11
|
|
12
|
-
|
13
|
-
if not login:
|
14
|
-
raise ValueError(f"Failed to login. {message}")
|
12
|
+
self._login()
|
15
13
|
|
16
14
|
def _login(self):
|
17
15
|
login_data = {
|
@@ -27,11 +25,11 @@ class AICosmosClient:
|
|
27
25
|
if response.status_code == 200:
|
28
26
|
token_data = response.json()
|
29
27
|
self.access_token = token_data["access_token"]
|
30
|
-
return
|
28
|
+
return
|
31
29
|
else:
|
32
|
-
|
30
|
+
raise ValueError(f"Status code: {response.status_code}")
|
33
31
|
except Exception as e:
|
34
|
-
|
32
|
+
raise ValueError(f"Error: {e}")
|
35
33
|
|
36
34
|
def _get_auth_headers(self):
|
37
35
|
if not self.access_token:
|
@@ -49,11 +47,11 @@ class AICosmosClient:
|
|
49
47
|
)
|
50
48
|
success = response.status_code == 200
|
51
49
|
if success:
|
52
|
-
return response.json()
|
50
|
+
return response.json()
|
53
51
|
else:
|
54
|
-
|
52
|
+
raise ValueError(f"Status code: {response.status_code}")
|
55
53
|
except Exception as e:
|
56
|
-
|
54
|
+
raise ValueError(f"Error: {e}")
|
57
55
|
|
58
56
|
def create_session(self):
|
59
57
|
if not self.access_token:
|
@@ -64,11 +62,11 @@ class AICosmosClient:
|
|
64
62
|
)
|
65
63
|
if response.status_code == 200:
|
66
64
|
response_json = response.json()
|
67
|
-
return response_json["session_id"]
|
65
|
+
return response_json["session_id"]
|
68
66
|
else:
|
69
|
-
|
67
|
+
raise ValueError(f"Status code: {response.status_code}")
|
70
68
|
except Exception as e:
|
71
|
-
|
69
|
+
raise ValueError(f"Error: {e}")
|
72
70
|
|
73
71
|
def delete_session(self, session_id: str):
|
74
72
|
if not self.access_token:
|
@@ -79,11 +77,11 @@ class AICosmosClient:
|
|
79
77
|
headers=self._get_auth_headers(),
|
80
78
|
)
|
81
79
|
if response.status_code == 200:
|
82
|
-
return
|
80
|
+
return
|
83
81
|
else:
|
84
|
-
|
82
|
+
raise ValueError(f"Status code: {response.status_code}")
|
85
83
|
except Exception as e:
|
86
|
-
|
84
|
+
raise ValueError(f"Error: {e}")
|
87
85
|
|
88
86
|
def get_my_sessions(self):
|
89
87
|
if not self.access_token:
|
@@ -99,21 +97,18 @@ class AICosmosClient:
|
|
99
97
|
return [
|
100
98
|
{
|
101
99
|
"session_id": session["session_id"],
|
102
|
-
"title": session["environment_info"].get("title",
|
100
|
+
"title": session["environment_info"].get("title", None),
|
103
101
|
}
|
104
102
|
for session in sessions
|
105
|
-
]
|
103
|
+
]
|
106
104
|
else:
|
107
|
-
|
105
|
+
raise ValueError(f"Status code: {response.status_code}")
|
108
106
|
except Exception as e:
|
109
|
-
|
107
|
+
raise ValueError(f"Error: {e}")
|
110
108
|
|
111
109
|
def get_session_history(self, session_id: str):
|
112
|
-
session
|
113
|
-
|
114
|
-
return [], message
|
115
|
-
else:
|
116
|
-
return session.get("conversation", []), message
|
110
|
+
session = self._get_session_status(session_id)
|
111
|
+
return session.get("conversation", [])
|
117
112
|
|
118
113
|
def chat(self, session_id: str, prompt: str):
|
119
114
|
if not self.access_token:
|
@@ -130,8 +125,8 @@ class AICosmosClient:
|
|
130
125
|
)
|
131
126
|
success = response.status_code == 200
|
132
127
|
if success:
|
133
|
-
return response.json()["conversation_history"]
|
128
|
+
return response.json()["conversation_history"]
|
134
129
|
else:
|
135
|
-
|
130
|
+
raise ValueError(f"Status code: {response.status_code}")
|
136
131
|
except Exception as e:
|
137
|
-
|
132
|
+
raise ValueError(f"Error: {e}")
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: aicosmos_client
|
3
|
+
Version: 0.0.5
|
4
|
+
Summary: client for AICosmos platform
|
5
|
+
Project-URL: Homepage, https://github.com/pypa/sampleproject
|
6
|
+
Project-URL: Issues, https://github.com/pypa/sampleproject/issues
|
7
|
+
Author-email: Example Author <author@example.com>
|
8
|
+
License-Expression: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.9
|
13
|
+
Requires-Dist: requests>=2.25.0
|
14
|
+
Requires-Dist: textual>=5.0.0
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
|
17
|
+
# Client for AICosmos
|
18
|
+
|
19
|
+
This package implements the client for AICosmos. Before using this package, please make sure that you have a valid account for AICosmos.
|
20
|
+
|
21
|
+
### AICosmosClient
|
22
|
+
By using this client, you can chat with our backend in "base" mode. To login, you will need the server's address, your username and your password. You can either start a new session, or use an existing one.
|
23
|
+
|
24
|
+
Our framework is a little bit different from "chat completions", where you give an llm the conversation history. Instead, your conversation history, along with other tool execution results, are stored in our database. This gives your a clean and simple interface to use, without worrying about constructing complicated contexts.
|
25
|
+
|
26
|
+
```Python
|
27
|
+
from aicosmos_client.client import AICosmosClient
|
28
|
+
|
29
|
+
# login
|
30
|
+
client = AICosmosClient(
|
31
|
+
base_url="http://xxx.xxx", username="xxx", password="xxxxxx"
|
32
|
+
)
|
33
|
+
|
34
|
+
# create a new session
|
35
|
+
try:
|
36
|
+
new_session_id = client.create_session()
|
37
|
+
except Exception as e:
|
38
|
+
print(f"Error creating new session: {e}")
|
39
|
+
exit(0)
|
40
|
+
|
41
|
+
# lookup all the sessions
|
42
|
+
try:
|
43
|
+
my_sessions = client.get_my_sessions()
|
44
|
+
except Exception as e:
|
45
|
+
print(f"Error getting my sessions: {e}")
|
46
|
+
exit(0)
|
47
|
+
# [{"session_id", "title"}, ...]
|
48
|
+
print(my_sessions)
|
49
|
+
|
50
|
+
# enjoy the conversation
|
51
|
+
try:
|
52
|
+
conversation_history = client.chat(new_session_id, "Hello")
|
53
|
+
except Exception as e:
|
54
|
+
print(f"Error chatting: {e}")
|
55
|
+
exit(0)
|
56
|
+
print(conversation_history)
|
57
|
+
```
|
58
|
+
|
59
|
+
## AICosmosCLI
|
60
|
+
To show that the client is enough to build an application, we offer you an command-line interface!
|
61
|
+
|
62
|
+
```Python
|
63
|
+
from aicosmos_client.cli import AICosmosCLI
|
64
|
+
|
65
|
+
AICosmosCLI().run()
|
66
|
+
```
|
@@ -0,0 +1,7 @@
|
|
1
|
+
aicosmos_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
aicosmos_client/cli.py,sha256=V6fewmdU2Im3NNbVw0OrVbxd1mkTGYKTdfgNKJl0CwY,13979
|
3
|
+
aicosmos_client/client.py,sha256=akVMmyDrAqOg0JI4mv_MBIA6I3VhLwDkstJlTEwiF5w,4664
|
4
|
+
aicosmos_client-0.0.5.dist-info/METADATA,sha256=7mdmOAHYtWfyEuYOiVsJPiDT4PzPBBF3LyZ83L-rC6c,2175
|
5
|
+
aicosmos_client-0.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
+
aicosmos_client-0.0.5.dist-info/licenses/LICENSE,sha256=XBdpsYae127l7YQyMSVQwUUo22FPis7sMts7oBjkN_g,1056
|
7
|
+
aicosmos_client-0.0.5.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: aicosmos_client
|
3
|
-
Version: 0.0.3
|
4
|
-
Summary: client for AICosmos platform
|
5
|
-
Project-URL: Homepage, https://github.com/pypa/sampleproject
|
6
|
-
Project-URL: Issues, https://github.com/pypa/sampleproject/issues
|
7
|
-
Author-email: Example Author <author@example.com>
|
8
|
-
License-Expression: MIT
|
9
|
-
License-File: LICENSE
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
12
|
-
Requires-Python: >=3.9
|
13
|
-
Requires-Dist: requests>=2.25.0
|
14
|
-
Requires-Dist: textual>=5.0.0
|
15
|
-
Description-Content-Type: text/markdown
|
16
|
-
|
17
|
-
# Example Package
|
18
|
-
|
19
|
-
This is a simple example package. You can use
|
20
|
-
[GitHub-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
|
21
|
-
to write your content.
|
@@ -1,7 +0,0 @@
|
|
1
|
-
aicosmos_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
aicosmos_client/cli.py,sha256=8VzGfvUGPmEbnbK_yqC3-UEcTMCMg8xs_Zy-xQzeDj0,13939
|
3
|
-
aicosmos_client/client.py,sha256=t3qlfanWG_NngNp9VPwHcJh_JC-2sQR-RRMvXWVQVcM,4875
|
4
|
-
aicosmos_client-0.0.3.dist-info/METADATA,sha256=mhPwxEWtskK0Umu592yqdgTMf-gstv7zjzL-KuSs17w,712
|
5
|
-
aicosmos_client-0.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
-
aicosmos_client-0.0.3.dist-info/licenses/LICENSE,sha256=XBdpsYae127l7YQyMSVQwUUo22FPis7sMts7oBjkN_g,1056
|
7
|
-
aicosmos_client-0.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|