PraisonAI 0.0.42__py3-none-any.whl → 0.0.43__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.

Potentially problematic release.


This version of PraisonAI might be problematic. Click here for more details.

praisonai/cli.py CHANGED
@@ -84,6 +84,11 @@ class PraisonAI:
84
84
  deployer = CloudDeployer()
85
85
  deployer.run_commands()
86
86
  return
87
+
88
+ if getattr(args, 'chat', False):
89
+ self.create_chainlit_chat_interface()
90
+ return
91
+
87
92
  invocation_cmd = "praisonai"
88
93
  version_string = f"PraisonAI version {__version__}"
89
94
 
@@ -163,8 +168,30 @@ class PraisonAI:
163
168
  args.agent_file = 'agents.yaml'
164
169
  if args.agent_file == 'ui':
165
170
  args.ui = 'chainlit'
171
+ if args.agent_file == 'chat':
172
+ args.ui = 'chainlit'
173
+ args.chat = True
166
174
 
167
175
  return args
176
+
177
+ def create_chainlit_chat_interface(self):
178
+ """
179
+ Create a Chainlit interface for the chat application.
180
+
181
+ This function sets up a Chainlit application that listens for messages.
182
+ When a message is received, it runs PraisonAI with the provided message as the topic.
183
+ The generated agents are then used to perform tasks.
184
+
185
+ Returns:
186
+ None: This function does not return any value. It starts the Chainlit application.
187
+ """
188
+ if CHAINLIT_AVAILABLE:
189
+ import praisonai
190
+ os.environ["CHAINLIT_PORT"] = "8084"
191
+ chat_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'chat.py')
192
+ chainlit_run([chat_ui_path])
193
+ else:
194
+ print("ERROR: Chat UI is not installed. Please install it with 'pip install \"praisonai\[chat]\"' to use the chat UI.")
168
195
 
169
196
  def create_gradio_interface(self):
170
197
  """
@@ -247,7 +274,7 @@ class PraisonAI:
247
274
  chainlit_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'chainlit_ui.py')
248
275
  chainlit_run([chainlit_ui_path])
249
276
  else:
250
- print("ERROR: Chainlit is not installed. Please install it with 'pip install chainlit' to use the UI.")
277
+ print("ERROR: Chainlit is not installed. Please install it with 'pip install \"praisonai\[ui]\"' to use the UI.")
251
278
 
252
279
  if __name__ == "__main__":
253
280
  praison_ai = PraisonAI()
praisonai/deploy.py CHANGED
@@ -56,7 +56,7 @@ class CloudDeployer:
56
56
  file.write("FROM python:3.11-slim\n")
57
57
  file.write("WORKDIR /app\n")
58
58
  file.write("COPY . .\n")
59
- file.write("RUN pip install flask praisonai==0.0.42 gunicorn markdown\n")
59
+ file.write("RUN pip install flask praisonai==0.0.43 gunicorn markdown\n")
60
60
  file.write("EXPOSE 8080\n")
61
61
  file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
62
62
 
praisonai/ui/chat.py ADDED
@@ -0,0 +1,308 @@
1
+ import chainlit as cl
2
+ from chainlit.input_widget import TextInput
3
+ from chainlit.types import ThreadDict
4
+ from litellm import acompletion
5
+ import os
6
+ import sqlite3
7
+ from datetime import datetime
8
+ from typing import Dict, List, Optional
9
+ from dotenv import load_dotenv
10
+ load_dotenv()
11
+ import chainlit.data as cl_data
12
+ from chainlit.step import StepDict
13
+ from literalai.helper import utc_now
14
+
15
+ now = utc_now()
16
+
17
+ create_step_counter = 0
18
+
19
+ import json
20
+
21
+ DB_PATH = "threads.db"
22
+
23
+ def initialize_db():
24
+ conn = sqlite3.connect(DB_PATH)
25
+ cursor = conn.cursor()
26
+ cursor.execute('''
27
+ CREATE TABLE IF NOT EXISTS threads (
28
+ id TEXT PRIMARY KEY,
29
+ name TEXT,
30
+ createdAt TEXT,
31
+ userId TEXT,
32
+ userIdentifier TEXT
33
+ )
34
+ ''')
35
+ cursor.execute('''
36
+ CREATE TABLE IF NOT EXISTS steps (
37
+ id TEXT PRIMARY KEY,
38
+ threadId TEXT,
39
+ name TEXT,
40
+ createdAt TEXT,
41
+ type TEXT,
42
+ output TEXT,
43
+ FOREIGN KEY (threadId) REFERENCES threads (id)
44
+ )
45
+ ''')
46
+ conn.commit()
47
+ conn.close()
48
+
49
+ def save_thread_to_db(thread):
50
+ conn = sqlite3.connect(DB_PATH)
51
+ cursor = conn.cursor()
52
+ cursor.execute('''
53
+ INSERT OR REPLACE INTO threads (id, name, createdAt, userId, userIdentifier)
54
+ VALUES (?, ?, ?, ?, ?)
55
+ ''', (thread['id'], thread['name'], thread['createdAt'], thread['userId'], thread['userIdentifier']))
56
+
57
+ # No steps to save as steps are empty in the provided thread data
58
+ conn.commit()
59
+ conn.close()
60
+ print("saved")
61
+
62
+ def update_thread_in_db(thread):
63
+ conn = sqlite3.connect(DB_PATH)
64
+ cursor = conn.cursor()
65
+
66
+ # Insert or update the thread
67
+ cursor.execute('''
68
+ INSERT OR REPLACE INTO threads (id, name, createdAt, userId, userIdentifier)
69
+ VALUES (?, ?, ?, ?, ?)
70
+ ''', (thread['id'], thread['name'], thread['createdAt'], thread['userId'], thread['userIdentifier']))
71
+
72
+ # Fetch message_history from metadata
73
+ message_history = thread['metadata']['message_history']
74
+
75
+ # Ensure user messages come first followed by assistant messages
76
+ user_messages = [msg for msg in message_history if msg['role'] == 'user']
77
+ assistant_messages = [msg for msg in message_history if msg['role'] == 'assistant']
78
+ ordered_steps = [val for pair in zip(user_messages, assistant_messages) for val in pair]
79
+
80
+ # Generate steps from ordered message_history
81
+ steps = []
82
+ for idx, message in enumerate(ordered_steps):
83
+ step_id = f"{thread['id']}-step-{idx}"
84
+ step_type = 'user_message' if message['role'] == 'user' else 'assistant_message'
85
+ step_name = 'user' if message['role'] == 'user' else 'assistant'
86
+ created_at = message.get('createdAt', thread['createdAt']) # Use thread's createdAt if no timestamp in message
87
+ steps.append({
88
+ 'id': step_id,
89
+ 'threadId': thread['id'],
90
+ 'name': step_name,
91
+ 'createdAt': created_at,
92
+ 'type': step_type,
93
+ 'output': message['content']
94
+ })
95
+
96
+ # Insert all steps into the database
97
+ for step in steps:
98
+ cursor.execute('''
99
+ INSERT OR REPLACE INTO steps (id, threadId, name, createdAt, type, output)
100
+ VALUES (?, ?, ?, ?, ?, ?)
101
+ ''', (step['id'], step['threadId'], step['name'], step['createdAt'], step['type'], step['output']))
102
+
103
+ conn.commit()
104
+ conn.close()
105
+
106
+ def load_threads_from_db():
107
+ conn = sqlite3.connect(DB_PATH)
108
+ cursor = conn.cursor()
109
+ cursor.execute('SELECT * FROM threads')
110
+ thread_rows = cursor.fetchall()
111
+ threads = []
112
+ for thread_row in thread_rows:
113
+ cursor.execute('SELECT * FROM steps WHERE threadId = ?', (thread_row[0],))
114
+ step_rows = cursor.fetchall()
115
+ steps = []
116
+ for step_row in step_rows:
117
+ steps.append({
118
+ "id": step_row[0],
119
+ "threadId": step_row[1],
120
+ "name": step_row[2],
121
+ "createdAt": step_row[3],
122
+ "type": step_row[4],
123
+ "output": step_row[5]
124
+ })
125
+ threads.append({
126
+ "id": thread_row[0],
127
+ "name": thread_row[1],
128
+ "createdAt": thread_row[2],
129
+ "userId": thread_row[3],
130
+ "userIdentifier": thread_row[4],
131
+ "steps": steps
132
+ })
133
+ conn.close()
134
+ return threads
135
+
136
+ # Initialize the database
137
+ initialize_db()
138
+ thread_history = load_threads_from_db()
139
+
140
+ deleted_thread_ids = [] # type: List[str]
141
+
142
+ class TestDataLayer(cl_data.BaseDataLayer):
143
+ async def get_user(self, identifier: str):
144
+ return cl.PersistedUser(id="test", createdAt=now, identifier=identifier)
145
+
146
+ async def create_user(self, user: cl.User):
147
+ return cl.PersistedUser(id="test", createdAt=now, identifier=user.identifier)
148
+
149
+ async def update_thread(
150
+ self,
151
+ thread_id: str,
152
+ name: Optional[str] = None,
153
+ user_id: Optional[str] = None,
154
+ metadata: Optional[Dict] = None,
155
+ tags: Optional[List[str]] = None,
156
+ ):
157
+ thread = next((t for t in thread_history if t["id"] == thread_id), None)
158
+ if thread:
159
+ if name:
160
+ thread["name"] = name
161
+ if metadata:
162
+ thread["metadata"] = metadata
163
+ if tags:
164
+ thread["tags"] = tags
165
+ update_thread_in_db(thread)
166
+ cl.user_session.set("message_history", thread['metadata']['message_history'])
167
+ cl.user_session.set("thread_id", thread["id"])
168
+ print("Updated")
169
+
170
+ else:
171
+ thread_history.append(
172
+ {
173
+ "id": thread_id,
174
+ "name": name,
175
+ "metadata": metadata,
176
+ "tags": tags,
177
+ "createdAt": utc_now(),
178
+ "userId": user_id,
179
+ "userIdentifier": "admin",
180
+ "steps": [],
181
+ }
182
+ )
183
+ thread = {
184
+ "id": thread_id,
185
+ "name": name,
186
+ "metadata": metadata,
187
+ "tags": tags,
188
+ "createdAt": utc_now(),
189
+ "userId": user_id,
190
+ "userIdentifier": "admin",
191
+ "steps": [],
192
+ }
193
+ save_thread_to_db(thread)
194
+
195
+ @cl_data.queue_until_user_message()
196
+ async def create_step(self, step_dict: StepDict):
197
+ global create_step_counter
198
+ create_step_counter += 1
199
+
200
+ thread = next(
201
+ (t for t in thread_history if t["id"] == step_dict.get("threadId")), None
202
+ )
203
+ if thread:
204
+ thread["steps"].append(step_dict)
205
+
206
+ async def get_thread_author(self, thread_id: str):
207
+ return "admin"
208
+
209
+ async def list_threads(
210
+ self, pagination: cl_data.Pagination, filters: cl_data.ThreadFilter
211
+ ) -> cl_data.PaginatedResponse[cl_data.ThreadDict]:
212
+ return cl_data.PaginatedResponse(
213
+ data=[t for t in thread_history if t["id"] not in deleted_thread_ids],
214
+ pageInfo=cl_data.PageInfo(
215
+ hasNextPage=False, startCursor=None, endCursor=None
216
+ ),
217
+ )
218
+
219
+ async def get_thread(self, thread_id: str):
220
+ thread_history = load_threads_from_db()
221
+ return next((t for t in thread_history if t["id"] == thread_id), None)
222
+
223
+ async def delete_thread(self, thread_id: str):
224
+ deleted_thread_ids.append(thread_id)
225
+
226
+ cl_data._data_layer = TestDataLayer()
227
+
228
+ @cl.on_chat_start
229
+ async def start():
230
+ initialize_db()
231
+ await cl.ChatSettings(
232
+ [
233
+ TextInput(
234
+ id="model_name",
235
+ label="Enter the Model Name",
236
+ placeholder="e.g., gpt-3.5-turbo"
237
+ )
238
+ ]
239
+ ).send()
240
+
241
+ @cl.on_settings_update
242
+ async def setup_agent(settings):
243
+ model_name = settings["model_name"]
244
+ cl.user_session.set("model_name", model_name)
245
+
246
+ @cl.on_message
247
+ async def main(message: cl.Message):
248
+ model_name = cl.user_session.get("model_name", "gpt-3.5-turbo")
249
+ message_history = cl.user_session.get("message_history", [])
250
+ message_history.append({"role": "user", "content": message.content})
251
+
252
+ msg = cl.Message(content="")
253
+ await msg.send()
254
+
255
+ response = await acompletion(
256
+ model=model_name,
257
+ messages=message_history,
258
+ stream=True,
259
+ temperature=0.7,
260
+ max_tokens=500,
261
+ top_p=1
262
+ )
263
+
264
+ full_response = ""
265
+ async for part in response:
266
+ if token := part['choices'][0]['delta']['content']:
267
+ await msg.stream_token(token)
268
+ full_response += token
269
+ print(full_response)
270
+ message_history.append({"role": "assistant", "content": full_response})
271
+ print(message_history)
272
+ cl.user_session.set("message_history", message_history)
273
+ await msg.update()
274
+
275
+ username = os.getenv("CHAINLIT_USERNAME", "admin") # Default to "admin" if not found
276
+ password = os.getenv("CHAINLIT_PASSWORD", "admin") # Default to "admin" if not found
277
+
278
+ @cl.password_auth_callback
279
+ def auth_callback(username: str, password: str):
280
+ if (username, password) == (username, password):
281
+ return cl.User(
282
+ identifier=username, metadata={"role": "ADMIN", "provider": "credentials"}
283
+ )
284
+ else:
285
+ return None
286
+
287
+ async def send_count():
288
+ await cl.Message(
289
+ f"Create step counter: {create_step_counter}", disable_feedback=True
290
+ ).send()
291
+
292
+ @cl.on_chat_resume
293
+ async def on_chat_resume(thread: cl_data.ThreadDict):
294
+ thread_id = thread["id"]
295
+ cl.user_session.set("thread_id", thread["id"])
296
+ message_history = cl.user_session.get("message_history", [])
297
+ steps = thread["steps"]
298
+
299
+ for message in steps:
300
+ msg_type = message.get("type")
301
+ if msg_type == "user_message":
302
+ message_history.append({"role": "user", "content": message.get("output", "")})
303
+ elif msg_type == "assistant_message":
304
+ message_history.append({"role": "assistant", "content": message.get("output", "")})
305
+ else:
306
+ print(f"Message without type: {message}")
307
+
308
+ cl.user_session.set("message_history", message_history)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PraisonAI
3
- Version: 0.0.42
3
+ Version: 0.0.43
4
4
  Summary: PraisonAI application combines AutoGen and CrewAI or similar frameworks into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customization, and efficient human-agent collaboration.
5
5
  Author: Mervin Praison
6
6
  Requires-Python: >=3.10,<3.13
@@ -11,13 +11,14 @@ Classifier: Programming Language :: Python :: 3.12
11
11
  Provides-Extra: agentops
12
12
  Provides-Extra: anthropic
13
13
  Provides-Extra: api
14
+ Provides-Extra: chat
14
15
  Provides-Extra: cohere
15
16
  Provides-Extra: google
16
17
  Provides-Extra: gradio
17
18
  Provides-Extra: openai
18
19
  Provides-Extra: ui
19
20
  Requires-Dist: agentops (>=0.2.6) ; extra == "agentops"
20
- Requires-Dist: chainlit (>=1.1.301,<2.0.0) ; extra == "ui"
21
+ Requires-Dist: chainlit (>=1.1.301,<2.0.0) ; extra == "ui" or extra == "chat"
21
22
  Requires-Dist: crewai (>=0.32.0)
22
23
  Requires-Dist: flask (>=3.0.0) ; extra == "api"
23
24
  Requires-Dist: gradio (>=4.26.0) ; extra == "gradio"
@@ -25,6 +26,7 @@ Requires-Dist: langchain-anthropic (>=0.1.13) ; extra == "anthropic"
25
26
  Requires-Dist: langchain-cohere (>=0.1.4) ; extra == "cohere"
26
27
  Requires-Dist: langchain-google-genai (>=1.0.4) ; extra == "google"
27
28
  Requires-Dist: langchain-openai (>=0.1.7) ; extra == "openai"
29
+ Requires-Dist: litellm (>=1.41.8) ; extra == "chat"
28
30
  Requires-Dist: markdown (>=3.5)
29
31
  Requires-Dist: praisonai-tools (>=0.0.7)
30
32
  Requires-Dist: pyautogen (>=0.2.19)
@@ -41,9 +43,12 @@ Description-Content-Type: text/markdown
41
43
  <img alt="PraisonAI Logo" src="docs/images/praisonai-logo-black-large.png">
42
44
  </picture>
43
45
  </p>
46
+ <div align="center">
44
47
 
45
48
  # Praison AI
46
49
 
50
+ </div>
51
+
47
52
  Praison AI, leveraging both AutoGen and CrewAI or any other agent framework, represents a low-code, centralised framework designed to simplify the creation and orchestration of multi-agent systems for various LLM applications, emphasizing ease of use, customization, and human-agent interaction.
48
53
 
49
54
  ## TL;DR
@@ -3,8 +3,8 @@ praisonai/__main__.py,sha256=MVgsjMThjBexHt4nhd760JCqvP4x0IQcwo8kULOK4FQ,144
3
3
  praisonai/agents_generator.py,sha256=8d1WRbubvEkBrW1HZ7_xnGyqgJi0yxmXa3MgTIqef1c,19127
4
4
  praisonai/auto.py,sha256=9spTXqj47Hmmqv5QHRYE_RzSVHH_KoPbaZjskUj2UcE,7895
5
5
  praisonai/chainlit_ui.py,sha256=bNR7s509lp0I9JlJNvwCZRUZosC64qdvlFCt8NmFamQ,12216
6
- praisonai/cli.py,sha256=cwuXGubuac7yTeiqx5o5S7ZN7erZAfe-6p35b3HM5SU,11066
7
- praisonai/deploy.py,sha256=zDllG5qOzprqN6gxLQp4GZVDxsAhUH8gpUFZlvc3ZK8,6031
6
+ praisonai/cli.py,sha256=RAPXxz6FxEG8Ek7XVRrzZ0FE1fwNHRd-prOjVjJjd0k,12180
7
+ praisonai/deploy.py,sha256=E-K35liJeVRHhJtEpE9_41IFg0lT4dr1f2amobYxpws,6031
8
8
  praisonai/inbuilt_tools/__init__.py,sha256=mUKnbL6Gram9c9f2m8wJwEzURBLmPEOcHzwySBH89YA,74
9
9
  praisonai/inbuilt_tools/autogen_tools.py,sha256=svYkM2N7DVFvbiwgoAS7U_MqTOD8rHf8VD3BaFUV5_Y,14907
10
10
  praisonai/inc/__init__.py,sha256=sPDlYBBwdk0VlWzaaM_lG0_LD07lS2HRGvPdxXJFiYg,62
@@ -14,9 +14,10 @@ praisonai/public/game.svg,sha256=y2QMaA01m8XzuDjTOBWzupOC3-TpnUl9ah89mIhviUw,240
14
14
  praisonai/public/movie.svg,sha256=aJ2EQ8vXZusVsF2SeuAVxP4RFJzQ14T26ejrGYdBgzk,1289
15
15
  praisonai/public/thriller.svg,sha256=2dYY72EcgbEyTxS4QzjAm37Y4srtPWEW4vCMFki98ZI,3163
16
16
  praisonai/test.py,sha256=RZKq3UEFb6AnFFiHER3zBXfNmlteSLBlrTmOvnpnZLo,4092
17
+ praisonai/ui/chat.py,sha256=kyfWIIpVdb6D54SnoMPw3MQp0xk6sppgTzT-Xflz9Tw,10149
17
18
  praisonai/version.py,sha256=ugyuFliEqtAwQmH4sTlc16YXKYbFWDmfyk87fErB8-8,21
18
- praisonai-0.0.42.dist-info/LICENSE,sha256=kqvFysVlnFxYOu0HxCe2HlmZmJtdmNGOxWRRkT9TsWc,1035
19
- praisonai-0.0.42.dist-info/METADATA,sha256=UUZhr0iagP5BMqQD9fHtX9B-5nrzli787_LoKOXPhqk,7967
20
- praisonai-0.0.42.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
21
- praisonai-0.0.42.dist-info/entry_points.txt,sha256=Qg41eW3A1-dvdV5tF7LqChfYof8Rihk2rN1fiEE3vnk,53
22
- praisonai-0.0.42.dist-info/RECORD,,
19
+ praisonai-0.0.43.dist-info/LICENSE,sha256=kqvFysVlnFxYOu0HxCe2HlmZmJtdmNGOxWRRkT9TsWc,1035
20
+ praisonai-0.0.43.dist-info/METADATA,sha256=UW42K2ecDGhjfNlqV5rd_Xh6xYkQqLSwxMZzRgh6zVY,8088
21
+ praisonai-0.0.43.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
22
+ praisonai-0.0.43.dist-info/entry_points.txt,sha256=Qg41eW3A1-dvdV5tF7LqChfYof8Rihk2rN1fiEE3vnk,53
23
+ praisonai-0.0.43.dist-info/RECORD,,