PraisonAI 2.0.61__cp313-cp313-manylinux_2_39_x86_64.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/__init__.py +6 -0
- praisonai/__main__.py +10 -0
- praisonai/agents_generator.py +648 -0
- praisonai/api/call.py +292 -0
- praisonai/auto.py +238 -0
- praisonai/chainlit_ui.py +304 -0
- praisonai/cli.py +518 -0
- praisonai/deploy.py +138 -0
- praisonai/inbuilt_tools/__init__.py +24 -0
- praisonai/inbuilt_tools/autogen_tools.py +117 -0
- praisonai/inc/__init__.py +2 -0
- praisonai/inc/config.py +96 -0
- praisonai/inc/models.py +128 -0
- praisonai/public/android-chrome-192x192.png +0 -0
- praisonai/public/android-chrome-512x512.png +0 -0
- praisonai/public/apple-touch-icon.png +0 -0
- praisonai/public/fantasy.svg +3 -0
- praisonai/public/favicon-16x16.png +0 -0
- praisonai/public/favicon-32x32.png +0 -0
- praisonai/public/favicon.ico +0 -0
- praisonai/public/game.svg +3 -0
- praisonai/public/logo_dark.png +0 -0
- praisonai/public/logo_light.png +0 -0
- praisonai/public/movie.svg +3 -0
- praisonai/public/praison-ai-agents-architecture-dark.png +0 -0
- praisonai/public/praison-ai-agents-architecture.png +0 -0
- praisonai/public/thriller.svg +3 -0
- praisonai/setup/__init__.py +1 -0
- praisonai/setup/build.py +21 -0
- praisonai/setup/config.yaml +60 -0
- praisonai/setup/post_install.py +23 -0
- praisonai/setup/setup_conda_env.py +25 -0
- praisonai/setup/setup_conda_env.sh +72 -0
- praisonai/setup.py +16 -0
- praisonai/test.py +105 -0
- praisonai/train.py +276 -0
- praisonai/ui/README.md +21 -0
- praisonai/ui/agents.py +822 -0
- praisonai/ui/callbacks.py +57 -0
- praisonai/ui/chat.py +387 -0
- praisonai/ui/code.py +440 -0
- praisonai/ui/colab.py +474 -0
- praisonai/ui/colab_chainlit.py +81 -0
- praisonai/ui/components/aicoder.py +269 -0
- praisonai/ui/config/.chainlit/config.toml +120 -0
- praisonai/ui/config/.chainlit/translations/bn.json +231 -0
- praisonai/ui/config/.chainlit/translations/en-US.json +229 -0
- praisonai/ui/config/.chainlit/translations/gu.json +231 -0
- praisonai/ui/config/.chainlit/translations/he-IL.json +231 -0
- praisonai/ui/config/.chainlit/translations/hi.json +231 -0
- praisonai/ui/config/.chainlit/translations/kn.json +231 -0
- praisonai/ui/config/.chainlit/translations/ml.json +231 -0
- praisonai/ui/config/.chainlit/translations/mr.json +231 -0
- praisonai/ui/config/.chainlit/translations/ta.json +231 -0
- praisonai/ui/config/.chainlit/translations/te.json +231 -0
- praisonai/ui/config/.chainlit/translations/zh-CN.json +229 -0
- praisonai/ui/config/chainlit.md +1 -0
- praisonai/ui/config/translations/bn.json +231 -0
- praisonai/ui/config/translations/en-US.json +229 -0
- praisonai/ui/config/translations/gu.json +231 -0
- praisonai/ui/config/translations/he-IL.json +231 -0
- praisonai/ui/config/translations/hi.json +231 -0
- praisonai/ui/config/translations/kn.json +231 -0
- praisonai/ui/config/translations/ml.json +231 -0
- praisonai/ui/config/translations/mr.json +231 -0
- praisonai/ui/config/translations/ta.json +231 -0
- praisonai/ui/config/translations/te.json +231 -0
- praisonai/ui/config/translations/zh-CN.json +229 -0
- praisonai/ui/context.py +283 -0
- praisonai/ui/db.py +291 -0
- praisonai/ui/public/fantasy.svg +3 -0
- praisonai/ui/public/game.svg +3 -0
- praisonai/ui/public/logo_dark.png +0 -0
- praisonai/ui/public/logo_light.png +0 -0
- praisonai/ui/public/movie.svg +3 -0
- praisonai/ui/public/praison.css +3 -0
- praisonai/ui/public/thriller.svg +3 -0
- praisonai/ui/realtime.py +476 -0
- praisonai/ui/realtimeclient/__init__.py +653 -0
- praisonai/ui/realtimeclient/realtimedocs.txt +1484 -0
- praisonai/ui/realtimeclient/tools.py +236 -0
- praisonai/ui/sql_alchemy.py +707 -0
- praisonai/ui/tools.md +133 -0
- praisonai/version.py +1 -0
- praisonai-2.0.61.dist-info/LICENSE +20 -0
- praisonai-2.0.61.dist-info/METADATA +679 -0
- praisonai-2.0.61.dist-info/RECORD +89 -0
- praisonai-2.0.61.dist-info/WHEEL +4 -0
- praisonai-2.0.61.dist-info/entry_points.txt +5 -0
praisonai/chainlit_ui.py
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# praisonai/chainlit_ui.py
|
|
2
|
+
from praisonai.agents_generator import AgentsGenerator
|
|
3
|
+
from praisonai.auto import AutoGenerator
|
|
4
|
+
import chainlit as cl
|
|
5
|
+
import os
|
|
6
|
+
from chainlit.types import ThreadDict
|
|
7
|
+
from chainlit.input_widget import Select, TextInput
|
|
8
|
+
from typing import Optional
|
|
9
|
+
from dotenv import load_dotenv
|
|
10
|
+
load_dotenv()
|
|
11
|
+
from contextlib import redirect_stdout
|
|
12
|
+
from io import StringIO
|
|
13
|
+
import logging
|
|
14
|
+
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper(), format='%(asctime)s - %(levelname)s - %(message)s')
|
|
15
|
+
|
|
16
|
+
framework = "crewai"
|
|
17
|
+
config_list = [
|
|
18
|
+
{
|
|
19
|
+
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
|
20
|
+
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
|
21
|
+
'api_key': os.environ.get("OPENAI_API_KEY", "")
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
agent_file = "test.yaml"
|
|
25
|
+
|
|
26
|
+
actions=[
|
|
27
|
+
cl.Action(name="run", value="run", label="✅ Run"),
|
|
28
|
+
cl.Action(name="modify", value="modify", label="🔧 Modify"),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
@cl.action_callback("run")
|
|
32
|
+
async def on_run(action):
|
|
33
|
+
await main(cl.Message(content=""))
|
|
34
|
+
|
|
35
|
+
@cl.action_callback("modify")
|
|
36
|
+
async def on_modify(action):
|
|
37
|
+
await cl.Message(content="Modify the agents and tools from below settings").send()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@cl.set_chat_profiles
|
|
41
|
+
async def set_profiles(current_user: cl.User):
|
|
42
|
+
return [
|
|
43
|
+
cl.ChatProfile(
|
|
44
|
+
name="Auto",
|
|
45
|
+
markdown_description="Automatically generate agents and tasks based on your input.",
|
|
46
|
+
starters=[
|
|
47
|
+
cl.Starter(
|
|
48
|
+
label="Create a movie script",
|
|
49
|
+
message="Create a movie script about a futuristic society where AI and humans coexist, focusing on the conflict and resolution between them. Start with an intriguing opening scene.",
|
|
50
|
+
icon="/public/movie.svg",
|
|
51
|
+
),
|
|
52
|
+
cl.Starter(
|
|
53
|
+
label="Design a fantasy world",
|
|
54
|
+
message="Design a detailed fantasy world with unique geography, cultures, and magical systems. Start by describing the main continent and its inhabitants.",
|
|
55
|
+
icon="/public/fantasy.svg",
|
|
56
|
+
),
|
|
57
|
+
cl.Starter(
|
|
58
|
+
label="Write a futuristic political thriller",
|
|
59
|
+
message="Write a futuristic political thriller involving a conspiracy within a global government. Start with a high-stakes meeting that sets the plot in motion.",
|
|
60
|
+
icon="/public/thriller.svg",
|
|
61
|
+
),
|
|
62
|
+
cl.Starter(
|
|
63
|
+
label="Develop a new board game",
|
|
64
|
+
message="Develop a new, innovative board game. Describe the game's objective, rules, and unique mechanics. Create a scenario to illustrate gameplay.",
|
|
65
|
+
icon="/public/game.svg",
|
|
66
|
+
),
|
|
67
|
+
]
|
|
68
|
+
),
|
|
69
|
+
cl.ChatProfile(
|
|
70
|
+
name="Manual",
|
|
71
|
+
markdown_description="Manually define your agents and tasks using a YAML file.",
|
|
72
|
+
),
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@cl.on_chat_start
|
|
77
|
+
async def start_chat():
|
|
78
|
+
cl.user_session.set(
|
|
79
|
+
"message_history",
|
|
80
|
+
[{"role": "system", "content": "You are a helpful assistant."}],
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# Create tools.py if it doesn't exist
|
|
84
|
+
if not os.path.exists("tools.py"):
|
|
85
|
+
with open("tools.py", "w") as f:
|
|
86
|
+
f.write("# Add your custom tools here\n")
|
|
87
|
+
|
|
88
|
+
settings = await cl.ChatSettings(
|
|
89
|
+
[
|
|
90
|
+
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
|
|
91
|
+
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
|
|
92
|
+
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
|
|
93
|
+
Select(
|
|
94
|
+
id="Framework",
|
|
95
|
+
label="Framework",
|
|
96
|
+
values=["crewai", "autogen"],
|
|
97
|
+
initial_index=0,
|
|
98
|
+
),
|
|
99
|
+
]
|
|
100
|
+
).send()
|
|
101
|
+
cl.user_session.set("settings", settings)
|
|
102
|
+
chat_profile = cl.user_session.get("chat_profile")
|
|
103
|
+
if chat_profile=="Manual":
|
|
104
|
+
|
|
105
|
+
agent_file = "agents.yaml"
|
|
106
|
+
full_agent_file_path = os.path.abspath(agent_file) # Get full path
|
|
107
|
+
if os.path.exists(full_agent_file_path):
|
|
108
|
+
with open(full_agent_file_path, 'r') as f:
|
|
109
|
+
yaml_content = f.read()
|
|
110
|
+
msg = cl.Message(content=yaml_content, language="yaml")
|
|
111
|
+
await msg.send()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
full_tools_file_path = os.path.abspath("tools.py") # Get full path
|
|
115
|
+
if os.path.exists(full_tools_file_path):
|
|
116
|
+
with open(full_tools_file_path, 'r') as f:
|
|
117
|
+
tools_content = f.read()
|
|
118
|
+
msg = cl.Message(content=tools_content, language="python")
|
|
119
|
+
await msg.send()
|
|
120
|
+
|
|
121
|
+
settings = await cl.ChatSettings(
|
|
122
|
+
[
|
|
123
|
+
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
|
|
124
|
+
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
|
|
125
|
+
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
|
|
126
|
+
Select(
|
|
127
|
+
id="Framework",
|
|
128
|
+
label="Framework",
|
|
129
|
+
values=["crewai", "autogen"],
|
|
130
|
+
initial_index=0,
|
|
131
|
+
),
|
|
132
|
+
TextInput(id="agents", label="agents.yaml", initial=yaml_content, multiline=True),
|
|
133
|
+
TextInput(id="tools", label="tools.py", initial=tools_content, multiline=True),
|
|
134
|
+
]
|
|
135
|
+
).send()
|
|
136
|
+
cl.user_session.set("settings", settings)
|
|
137
|
+
|
|
138
|
+
res = await cl.AskActionMessage(
|
|
139
|
+
content="Pick an action!",
|
|
140
|
+
actions=actions,
|
|
141
|
+
).send()
|
|
142
|
+
if res and res.get("value") == "modify":
|
|
143
|
+
await cl.Message(content="Modify the agents and tools from below settings", actions=actions).send()
|
|
144
|
+
elif res and res.get("value") == "run":
|
|
145
|
+
await main(cl.Message(content="", actions=actions))
|
|
146
|
+
|
|
147
|
+
await on_settings_update(settings)
|
|
148
|
+
|
|
149
|
+
@cl.on_settings_update
|
|
150
|
+
async def on_settings_update(settings):
|
|
151
|
+
"""Handle updates to the ChatSettings form."""
|
|
152
|
+
global config_list, framework
|
|
153
|
+
config_list[0]['model'] = settings["Model"]
|
|
154
|
+
config_list[0]['base_url'] = settings["BaseUrl"]
|
|
155
|
+
config_list[0]['api_key'] = settings["ApiKey"]
|
|
156
|
+
os.environ["OPENAI_API_KEY"] = config_list[0]['api_key']
|
|
157
|
+
os.environ["OPENAI_MODEL_NAME"] = config_list[0]['model']
|
|
158
|
+
os.environ["OPENAI_API_BASE"] = config_list[0]['base_url']
|
|
159
|
+
framework = settings["Framework"]
|
|
160
|
+
|
|
161
|
+
if "agents" in settings:
|
|
162
|
+
with open("agents.yaml", "w") as f:
|
|
163
|
+
f.write(settings["agents"])
|
|
164
|
+
if "tools" in settings:
|
|
165
|
+
with open("tools.py", "w") as f:
|
|
166
|
+
f.write(settings["tools"])
|
|
167
|
+
|
|
168
|
+
print("Settings updated")
|
|
169
|
+
|
|
170
|
+
@cl.on_chat_resume
|
|
171
|
+
async def on_chat_resume(thread: ThreadDict):
|
|
172
|
+
message_history = cl.user_session.get("message_history", [])
|
|
173
|
+
root_messages = [m for m in thread["steps"] if m["parentId"] is None]
|
|
174
|
+
for message in root_messages:
|
|
175
|
+
if message["type"] == "user_message":
|
|
176
|
+
message_history.append({"role": "user", "content": message["output"]})
|
|
177
|
+
elif message["type"] == "ai_message":
|
|
178
|
+
message_history.append({"role": "assistant", "content": message["content"]})
|
|
179
|
+
cl.user_session.set("message_history", message_history)
|
|
180
|
+
|
|
181
|
+
# @cl.step(type="tool")
|
|
182
|
+
# async def tool(data: Optional[str] = None, language: Optional[str] = None):
|
|
183
|
+
# return cl.Message(content=data, language=language)
|
|
184
|
+
|
|
185
|
+
@cl.step(type="tool", show_input=False)
|
|
186
|
+
async def run_agents(agent_file: str, framework: str):
|
|
187
|
+
"""Runs the agents and returns the result."""
|
|
188
|
+
agents_generator = AgentsGenerator(agent_file, framework, config_list)
|
|
189
|
+
current_step = cl.context.current_step
|
|
190
|
+
print("Current Step:", current_step)
|
|
191
|
+
|
|
192
|
+
stdout_buffer = StringIO()
|
|
193
|
+
with redirect_stdout(stdout_buffer):
|
|
194
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
195
|
+
|
|
196
|
+
complete_output = stdout_buffer.getvalue()
|
|
197
|
+
|
|
198
|
+
async with cl.Step(name="gpt4", type="llm", show_input=True) as step:
|
|
199
|
+
step.input = ""
|
|
200
|
+
|
|
201
|
+
for line in stdout_buffer.getvalue().splitlines():
|
|
202
|
+
print(line)
|
|
203
|
+
await step.stream_token(line)
|
|
204
|
+
|
|
205
|
+
tool_res = await output(complete_output)
|
|
206
|
+
|
|
207
|
+
yield result
|
|
208
|
+
|
|
209
|
+
@cl.step(type="tool", show_input=False, language="yaml")
|
|
210
|
+
async def output(output):
|
|
211
|
+
return output
|
|
212
|
+
|
|
213
|
+
@cl.step(type="tool", show_input=False, language="yaml")
|
|
214
|
+
def agent(output):
|
|
215
|
+
return(f"""
|
|
216
|
+
Agent Step Completed!
|
|
217
|
+
Output: {output}
|
|
218
|
+
""")
|
|
219
|
+
|
|
220
|
+
@cl.step(type="tool", show_input=False, language="yaml")
|
|
221
|
+
def task(output):
|
|
222
|
+
return(f"""
|
|
223
|
+
Task Completed!
|
|
224
|
+
Task: {output.description}
|
|
225
|
+
Output: {output.raw_output}
|
|
226
|
+
{output}
|
|
227
|
+
""")
|
|
228
|
+
|
|
229
|
+
@cl.on_message
|
|
230
|
+
async def main(message: cl.Message):
|
|
231
|
+
"""Run PraisonAI with the provided message as the topic."""
|
|
232
|
+
message_history = cl.user_session.get("message_history")
|
|
233
|
+
if message_history is None:
|
|
234
|
+
message_history = []
|
|
235
|
+
cl.user_session.set("message_history", message_history)
|
|
236
|
+
message_history.append({"role": "user", "content": message.content})
|
|
237
|
+
topic = message.content
|
|
238
|
+
chat_profile = cl.user_session.get("chat_profile")
|
|
239
|
+
|
|
240
|
+
if chat_profile == "Auto":
|
|
241
|
+
agent_file = "agents.yaml"
|
|
242
|
+
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
|
|
243
|
+
await cl.sleep(2)
|
|
244
|
+
agent_file = generator.generate()
|
|
245
|
+
agents_generator = AgentsGenerator(
|
|
246
|
+
agent_file,
|
|
247
|
+
framework,
|
|
248
|
+
config_list,
|
|
249
|
+
# agent_callback=agent,
|
|
250
|
+
# task_callback=task
|
|
251
|
+
)
|
|
252
|
+
# Capture stdout
|
|
253
|
+
stdout_buffer = StringIO()
|
|
254
|
+
with redirect_stdout(stdout_buffer):
|
|
255
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
256
|
+
|
|
257
|
+
complete_output = stdout_buffer.getvalue()
|
|
258
|
+
tool_res = await output(complete_output)
|
|
259
|
+
msg = cl.Message(content=result)
|
|
260
|
+
await msg.send()
|
|
261
|
+
message_history.append({"role": "assistant", "content": message.content})
|
|
262
|
+
else: # chat_profile == "Manual"
|
|
263
|
+
agent_file = "agents.yaml"
|
|
264
|
+
full_agent_file_path = os.path.abspath(agent_file) # Get full path
|
|
265
|
+
full_tools_file_path = os.path.abspath("tools.py")
|
|
266
|
+
if os.path.exists(full_agent_file_path):
|
|
267
|
+
with open(full_agent_file_path, 'r') as f:
|
|
268
|
+
yaml_content = f.read()
|
|
269
|
+
# tool_res = await tool()
|
|
270
|
+
msg_agents = cl.Message(content=yaml_content, language="yaml")
|
|
271
|
+
await msg_agents.send()
|
|
272
|
+
if os.path.exists(full_tools_file_path):
|
|
273
|
+
with open(full_tools_file_path, 'r') as f:
|
|
274
|
+
tools_content = f.read()
|
|
275
|
+
msg_tools = cl.Message(content=tools_content, language="python")
|
|
276
|
+
await msg_tools.send()
|
|
277
|
+
else:
|
|
278
|
+
# If the file doesn't exist, follow the same process as "Auto"
|
|
279
|
+
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
|
|
280
|
+
agent_file = generator.generate()
|
|
281
|
+
|
|
282
|
+
agents_generator = AgentsGenerator(agent_file, framework, config_list)
|
|
283
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
284
|
+
msg = cl.Message(content=result, actions=actions)
|
|
285
|
+
await msg.send()
|
|
286
|
+
message_history.append({"role": "assistant", "content": message.content})
|
|
287
|
+
|
|
288
|
+
# Load environment variables from .env file
|
|
289
|
+
load_dotenv()
|
|
290
|
+
|
|
291
|
+
# Get username and password from environment variables
|
|
292
|
+
username = os.getenv("CHAINLIT_USERNAME", "admin") # Default to "admin" if not found
|
|
293
|
+
password = os.getenv("CHAINLIT_PASSWORD", "admin") # Default to "admin" if not found
|
|
294
|
+
|
|
295
|
+
@cl.password_auth_callback
|
|
296
|
+
def auth_callback(username: str, password: str):
|
|
297
|
+
# Fetch the user matching username from your database
|
|
298
|
+
# and compare the hashed password with the value stored in the database
|
|
299
|
+
if (username, password) == (username, password):
|
|
300
|
+
return cl.User(
|
|
301
|
+
identifier=username, metadata={"role": "ADMIN", "provider": "credentials"}
|
|
302
|
+
)
|
|
303
|
+
else:
|
|
304
|
+
return None
|