PraisonAI 0.0.59rc2__cp312-cp312-manylinux_2_35_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 +381 -0
- praisonai/auto.py +190 -0
- praisonai/chainlit_ui.py +304 -0
- praisonai/cli.py +337 -0
- praisonai/deploy.py +138 -0
- praisonai/inbuilt_tools/__init__.py +2 -0
- praisonai/inbuilt_tools/autogen_tools.py +209 -0
- praisonai/inc/__init__.py +2 -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/thriller.svg +3 -0
- praisonai/test.py +105 -0
- praisonai/train.py +232 -0
- praisonai/ui/chat.py +304 -0
- praisonai/ui/code.py +318 -0
- praisonai/ui/context.py +283 -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/thriller.svg +3 -0
- praisonai/ui/sql_alchemy.py +638 -0
- praisonai/version.py +1 -0
- praisonai-0.0.59rc2.dist-info/LICENSE +20 -0
- praisonai-0.0.59rc2.dist-info/METADATA +344 -0
- praisonai-0.0.59rc2.dist-info/RECORD +41 -0
- praisonai-0.0.59rc2.dist-info/WHEEL +4 -0
- praisonai-0.0.59rc2.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
|
praisonai/cli.py
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# praisonai/cli.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from .version import __version__
|
|
5
|
+
import yaml, os
|
|
6
|
+
from rich import print
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
from crewai import Agent, Task, Crew
|
|
9
|
+
load_dotenv()
|
|
10
|
+
import autogen
|
|
11
|
+
import argparse
|
|
12
|
+
from .auto import AutoGenerator
|
|
13
|
+
from .agents_generator import AgentsGenerator
|
|
14
|
+
from .inbuilt_tools import *
|
|
15
|
+
import shutil
|
|
16
|
+
import logging
|
|
17
|
+
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO'), format='%(asctime)s - %(levelname)s - %(message)s')
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from chainlit.cli import chainlit_run
|
|
21
|
+
CHAINLIT_AVAILABLE = True
|
|
22
|
+
except ImportError:
|
|
23
|
+
CHAINLIT_AVAILABLE = False
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
import gradio as gr
|
|
27
|
+
GRADIO_AVAILABLE = True
|
|
28
|
+
except ImportError:
|
|
29
|
+
GRADIO_AVAILABLE = False
|
|
30
|
+
|
|
31
|
+
class PraisonAI:
|
|
32
|
+
def __init__(self, agent_file="agents.yaml", framework="", auto=False, init=False, agent_yaml=None):
|
|
33
|
+
"""
|
|
34
|
+
Initialize the PraisonAI object with default parameters.
|
|
35
|
+
|
|
36
|
+
Parameters:
|
|
37
|
+
agent_file (str): The default agent file to use. Defaults to "agents.yaml".
|
|
38
|
+
framework (str): The default framework to use. Defaults to "crewai".
|
|
39
|
+
auto (bool): A flag indicating whether to enable auto mode. Defaults to False.
|
|
40
|
+
init (bool): A flag indicating whether to enable initialization mode. Defaults to False.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
config_list (list): A list of configuration dictionaries for the OpenAI API.
|
|
44
|
+
agent_file (str): The agent file to use.
|
|
45
|
+
framework (str): The framework to use.
|
|
46
|
+
auto (bool): A flag indicating whether to enable auto mode.
|
|
47
|
+
init (bool): A flag indicating whether to enable initialization mode.
|
|
48
|
+
agent_yaml (str, optional): The content of the YAML file. Defaults to None.
|
|
49
|
+
"""
|
|
50
|
+
self.agent_yaml = agent_yaml
|
|
51
|
+
self.config_list = [
|
|
52
|
+
{
|
|
53
|
+
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
|
54
|
+
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
|
55
|
+
'api_key': os.environ.get("OPENAI_API_KEY")
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
self.agent_file = agent_file
|
|
59
|
+
self.framework = framework
|
|
60
|
+
self.auto = auto
|
|
61
|
+
self.init = init
|
|
62
|
+
|
|
63
|
+
def run(self):
|
|
64
|
+
"""
|
|
65
|
+
Run the PraisonAI application.
|
|
66
|
+
"""
|
|
67
|
+
self.main()
|
|
68
|
+
|
|
69
|
+
def main(self):
|
|
70
|
+
"""
|
|
71
|
+
The main function of the PraisonAI object. It parses the command-line arguments,
|
|
72
|
+
initializes the necessary attributes, and then calls the appropriate methods based on the
|
|
73
|
+
provided arguments.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
self (PraisonAI): An instance of the PraisonAI class.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
Any: Depending on the arguments provided, the function may return a result from the
|
|
80
|
+
AgentsGenerator, a deployment result from the CloudDeployer, or a message indicating
|
|
81
|
+
the successful creation of a file.
|
|
82
|
+
"""
|
|
83
|
+
args = self.parse_args()
|
|
84
|
+
if args is None:
|
|
85
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
86
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
87
|
+
return result
|
|
88
|
+
if args.deploy:
|
|
89
|
+
from .deploy import CloudDeployer
|
|
90
|
+
deployer = CloudDeployer()
|
|
91
|
+
deployer.run_commands()
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
if getattr(args, 'chat', False):
|
|
95
|
+
self.create_chainlit_chat_interface()
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
if getattr(args, 'code', False):
|
|
99
|
+
self.create_code_interface()
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
if args.agent_file == 'train':
|
|
103
|
+
from .train import main as train_main
|
|
104
|
+
train_args = sys.argv[2:] # Get all arguments after 'train'
|
|
105
|
+
train_main(train_args) # Pass the arguments to train.py's main function
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
invocation_cmd = "praisonai"
|
|
109
|
+
version_string = f"PraisonAI version {__version__}"
|
|
110
|
+
|
|
111
|
+
self.framework = args.framework or self.framework
|
|
112
|
+
|
|
113
|
+
if args.agent_file:
|
|
114
|
+
if args.agent_file.startswith("tests.test"): # Argument used for testing purposes. eg: python -m unittest tests.test
|
|
115
|
+
print("test")
|
|
116
|
+
else:
|
|
117
|
+
self.agent_file = args.agent_file
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if args.auto or args.init:
|
|
121
|
+
temp_topic = ' '.join(args.auto) if args.auto else ' '.join(args.init)
|
|
122
|
+
self.topic = temp_topic
|
|
123
|
+
elif self.auto or self.init: # Use the auto attribute if args.auto is not provided
|
|
124
|
+
self.topic = self.auto
|
|
125
|
+
|
|
126
|
+
if args.auto or self.auto:
|
|
127
|
+
self.agent_file = "test.yaml"
|
|
128
|
+
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
|
|
129
|
+
self.agent_file = generator.generate()
|
|
130
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
131
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
132
|
+
return result
|
|
133
|
+
elif args.init or self.init:
|
|
134
|
+
self.agent_file = "agents.yaml"
|
|
135
|
+
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
|
|
136
|
+
self.agent_file = generator.generate()
|
|
137
|
+
print("File {} created successfully".format(self.agent_file))
|
|
138
|
+
return "File {} created successfully".format(self.agent_file)
|
|
139
|
+
|
|
140
|
+
if args.ui:
|
|
141
|
+
if args.ui == "gradio":
|
|
142
|
+
self.create_gradio_interface()
|
|
143
|
+
elif args.ui == "chainlit":
|
|
144
|
+
self.create_chainlit_interface()
|
|
145
|
+
else:
|
|
146
|
+
# Modify below code to allow default ui
|
|
147
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list, agent_yaml=self.agent_yaml)
|
|
148
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
149
|
+
return result
|
|
150
|
+
else:
|
|
151
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list, agent_yaml=self.agent_yaml)
|
|
152
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
153
|
+
return result
|
|
154
|
+
|
|
155
|
+
def parse_args(self):
|
|
156
|
+
"""
|
|
157
|
+
Parse the command-line arguments for the PraisonAI CLI.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
self (PraisonAI): An instance of the PraisonAI class.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
argparse.Namespace: An object containing the parsed command-line arguments.
|
|
164
|
+
|
|
165
|
+
Raises:
|
|
166
|
+
argparse.ArgumentError: If the arguments provided are invalid.
|
|
167
|
+
|
|
168
|
+
Example:
|
|
169
|
+
>>> args = praison_ai.parse_args()
|
|
170
|
+
>>> print(args.agent_file) # Output: 'agents.yaml'
|
|
171
|
+
"""
|
|
172
|
+
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
|
|
173
|
+
parser.add_argument("--framework", choices=["crewai", "autogen"], help="Specify the framework")
|
|
174
|
+
parser.add_argument("--ui", choices=["chainlit", "gradio"], help="Specify the UI framework (gradio or chainlit).")
|
|
175
|
+
parser.add_argument("--auto", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
|
|
176
|
+
parser.add_argument("--init", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
|
|
177
|
+
parser.add_argument("agent_file", nargs="?", help="Specify the agent file")
|
|
178
|
+
parser.add_argument("--deploy", action="store_true", help="Deploy the application") # New argument
|
|
179
|
+
args, unknown_args = parser.parse_known_args()
|
|
180
|
+
|
|
181
|
+
if unknown_args and unknown_args[0] == '-b' and unknown_args[1] == 'api:app':
|
|
182
|
+
args.agent_file = 'agents.yaml'
|
|
183
|
+
if args.agent_file == 'api:app' or args.agent_file == '/app/api:app':
|
|
184
|
+
args.agent_file = 'agents.yaml'
|
|
185
|
+
if args.agent_file == 'ui':
|
|
186
|
+
args.ui = 'chainlit'
|
|
187
|
+
if args.agent_file == 'chat':
|
|
188
|
+
args.ui = 'chainlit'
|
|
189
|
+
args.chat = True
|
|
190
|
+
if args.agent_file == 'code':
|
|
191
|
+
args.ui = 'chainlit'
|
|
192
|
+
args.code = True
|
|
193
|
+
|
|
194
|
+
return args
|
|
195
|
+
|
|
196
|
+
def create_chainlit_chat_interface(self):
|
|
197
|
+
"""
|
|
198
|
+
Create a Chainlit interface for the chat application.
|
|
199
|
+
|
|
200
|
+
This function sets up a Chainlit application that listens for messages.
|
|
201
|
+
When a message is received, it runs PraisonAI with the provided message as the topic.
|
|
202
|
+
The generated agents are then used to perform tasks.
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
None: This function does not return any value. It starts the Chainlit application.
|
|
206
|
+
"""
|
|
207
|
+
if CHAINLIT_AVAILABLE:
|
|
208
|
+
import praisonai
|
|
209
|
+
os.environ["CHAINLIT_PORT"] = "8084"
|
|
210
|
+
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
|
|
211
|
+
if not os.path.exists("public"): # Check if the folder exists in the current directory
|
|
212
|
+
if os.path.exists(public_folder):
|
|
213
|
+
shutil.copytree(public_folder, 'public', dirs_exist_ok=True)
|
|
214
|
+
logging.info("Public folder copied successfully!")
|
|
215
|
+
else:
|
|
216
|
+
logging.info("Public folder not found in the package.")
|
|
217
|
+
else:
|
|
218
|
+
logging.info("Public folder already exists.")
|
|
219
|
+
chat_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'chat.py')
|
|
220
|
+
chainlit_run([chat_ui_path])
|
|
221
|
+
else:
|
|
222
|
+
print("ERROR: Chat UI is not installed. Please install it with 'pip install \"praisonai\[chat]\"' to use the chat UI.")
|
|
223
|
+
|
|
224
|
+
def create_code_interface(self):
|
|
225
|
+
"""
|
|
226
|
+
Create a Chainlit interface for the code application.
|
|
227
|
+
|
|
228
|
+
This function sets up a Chainlit application that listens for messages.
|
|
229
|
+
When a message is received, it runs PraisonAI with the provided message as the topic.
|
|
230
|
+
The generated agents are then used to perform tasks.
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
None: This function does not return any value. It starts the Chainlit application.
|
|
234
|
+
"""
|
|
235
|
+
if CHAINLIT_AVAILABLE:
|
|
236
|
+
import praisonai
|
|
237
|
+
os.environ["CHAINLIT_PORT"] = "8086"
|
|
238
|
+
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
|
|
239
|
+
if not os.path.exists("public"): # Check if the folder exists in the current directory
|
|
240
|
+
if os.path.exists(public_folder):
|
|
241
|
+
shutil.copytree(public_folder, 'public', dirs_exist_ok=True)
|
|
242
|
+
logging.info("Public folder copied successfully!")
|
|
243
|
+
else:
|
|
244
|
+
logging.info("Public folder not found in the package.")
|
|
245
|
+
else:
|
|
246
|
+
logging.info("Public folder already exists.")
|
|
247
|
+
code_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'code.py')
|
|
248
|
+
chainlit_run([code_ui_path])
|
|
249
|
+
else:
|
|
250
|
+
print("ERROR: Code UI is not installed. Please install it with 'pip install \"praisonai\[code]\"' to use the code UI.")
|
|
251
|
+
|
|
252
|
+
def create_gradio_interface(self):
|
|
253
|
+
"""
|
|
254
|
+
Create a Gradio interface for generating agents and performing tasks.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
self (PraisonAI): An instance of the PraisonAI class.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
None: This method does not return any value. It launches the Gradio interface.
|
|
261
|
+
|
|
262
|
+
Raises:
|
|
263
|
+
None: This method does not raise any exceptions.
|
|
264
|
+
|
|
265
|
+
Example:
|
|
266
|
+
>>> praison_ai.create_gradio_interface()
|
|
267
|
+
"""
|
|
268
|
+
if GRADIO_AVAILABLE:
|
|
269
|
+
def generate_crew_and_kickoff_interface(auto_args, framework):
|
|
270
|
+
"""
|
|
271
|
+
Generate a crew and kick off tasks based on the provided auto arguments and framework.
|
|
272
|
+
|
|
273
|
+
Args:
|
|
274
|
+
auto_args (list): Topic.
|
|
275
|
+
framework (str): The framework to use for generating agents.
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
str: A string representing the result of generating the crew and kicking off tasks.
|
|
279
|
+
|
|
280
|
+
Raises:
|
|
281
|
+
None: This method does not raise any exceptions.
|
|
282
|
+
|
|
283
|
+
Example:
|
|
284
|
+
>>> result = generate_crew_and_kickoff_interface("Create a movie about Cat in Mars", "crewai")
|
|
285
|
+
>>> print(result)
|
|
286
|
+
"""
|
|
287
|
+
self.framework = framework
|
|
288
|
+
self.agent_file = "test.yaml"
|
|
289
|
+
generator = AutoGenerator(topic=auto_args , framework=self.framework)
|
|
290
|
+
self.agent_file = generator.generate()
|
|
291
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
292
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
293
|
+
return result
|
|
294
|
+
|
|
295
|
+
gr.Interface(
|
|
296
|
+
fn=generate_crew_and_kickoff_interface,
|
|
297
|
+
inputs=[gr.Textbox(lines=2, label="Auto Args"), gr.Dropdown(choices=["crewai", "autogen"], label="Framework")],
|
|
298
|
+
outputs="textbox",
|
|
299
|
+
title="Praison AI Studio",
|
|
300
|
+
description="Create Agents and perform tasks",
|
|
301
|
+
theme="default"
|
|
302
|
+
).launch()
|
|
303
|
+
else:
|
|
304
|
+
print("ERROR: Gradio is not installed. Please install it with 'pip install gradio' to use this feature.")
|
|
305
|
+
|
|
306
|
+
def create_chainlit_interface(self):
|
|
307
|
+
"""
|
|
308
|
+
Create a Chainlit interface for generating agents and performing tasks.
|
|
309
|
+
|
|
310
|
+
This function sets up a Chainlit application that listens for messages.
|
|
311
|
+
When a message is received, it runs PraisonAI with the provided message as the topic.
|
|
312
|
+
The generated agents are then used to perform tasks.
|
|
313
|
+
|
|
314
|
+
Returns:
|
|
315
|
+
None: This function does not return any value. It starts the Chainlit application.
|
|
316
|
+
"""
|
|
317
|
+
if CHAINLIT_AVAILABLE:
|
|
318
|
+
import praisonai
|
|
319
|
+
os.environ["CHAINLIT_PORT"] = "8082"
|
|
320
|
+
# Get the path to the 'public' folder within the package
|
|
321
|
+
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
|
|
322
|
+
if not os.path.exists("public"): # Check if the folder exists in the current directory
|
|
323
|
+
if os.path.exists(public_folder):
|
|
324
|
+
shutil.copytree(public_folder, 'public', dirs_exist_ok=True)
|
|
325
|
+
logging.info("Public folder copied successfully!")
|
|
326
|
+
else:
|
|
327
|
+
logging.info("Public folder not found in the package.")
|
|
328
|
+
else:
|
|
329
|
+
logging.info("Public folder already exists.")
|
|
330
|
+
chainlit_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'chainlit_ui.py')
|
|
331
|
+
chainlit_run([chainlit_ui_path])
|
|
332
|
+
else:
|
|
333
|
+
print("ERROR: Chainlit is not installed. Please install it with 'pip install \"praisonai\[ui]\"' to use the UI.")
|
|
334
|
+
|
|
335
|
+
if __name__ == "__main__":
|
|
336
|
+
praison_ai = PraisonAI()
|
|
337
|
+
praison_ai.main()
|