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/cli.py
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
# praisonai/cli.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import argparse
|
|
5
|
+
from .version import __version__
|
|
6
|
+
import yaml
|
|
7
|
+
import os
|
|
8
|
+
from rich import print
|
|
9
|
+
from dotenv import load_dotenv
|
|
10
|
+
load_dotenv()
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
import logging
|
|
14
|
+
import importlib
|
|
15
|
+
|
|
16
|
+
from .auto import AutoGenerator
|
|
17
|
+
from .agents_generator import AgentsGenerator
|
|
18
|
+
from .inbuilt_tools import *
|
|
19
|
+
from .inc.config import generate_config
|
|
20
|
+
|
|
21
|
+
# Optional module imports with availability checks
|
|
22
|
+
CHAINLIT_AVAILABLE = False
|
|
23
|
+
GRADIO_AVAILABLE = False
|
|
24
|
+
CALL_MODULE_AVAILABLE = False
|
|
25
|
+
CREWAI_AVAILABLE = False
|
|
26
|
+
AUTOGEN_AVAILABLE = False
|
|
27
|
+
PRAISONAI_AVAILABLE = False
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
# Create necessary directories and set CHAINLIT_APP_ROOT
|
|
31
|
+
if "CHAINLIT_APP_ROOT" not in os.environ:
|
|
32
|
+
chainlit_root = os.path.join(os.path.expanduser("~"), ".praison")
|
|
33
|
+
os.environ["CHAINLIT_APP_ROOT"] = chainlit_root
|
|
34
|
+
else:
|
|
35
|
+
chainlit_root = os.environ["CHAINLIT_APP_ROOT"]
|
|
36
|
+
|
|
37
|
+
os.makedirs(chainlit_root, exist_ok=True)
|
|
38
|
+
os.makedirs(os.path.join(chainlit_root, ".files"), exist_ok=True)
|
|
39
|
+
|
|
40
|
+
from chainlit.cli import chainlit_run
|
|
41
|
+
CHAINLIT_AVAILABLE = True
|
|
42
|
+
except ImportError:
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
import gradio as gr
|
|
47
|
+
GRADIO_AVAILABLE = True
|
|
48
|
+
except ImportError:
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
import praisonai.api.call as call_module
|
|
53
|
+
CALL_MODULE_AVAILABLE = True
|
|
54
|
+
except ImportError:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
from crewai import Agent, Task, Crew
|
|
59
|
+
CREWAI_AVAILABLE = True
|
|
60
|
+
except ImportError:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
import autogen
|
|
65
|
+
AUTOGEN_AVAILABLE = True
|
|
66
|
+
except ImportError:
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
from praisonaiagents import Agent as PraisonAgent, Task as PraisonTask, PraisonAIAgents
|
|
71
|
+
PRAISONAI_AVAILABLE = True
|
|
72
|
+
except ImportError:
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO'), format='%(asctime)s - %(levelname)s - %(message)s')
|
|
76
|
+
logging.getLogger('alembic').setLevel(logging.ERROR)
|
|
77
|
+
logging.getLogger('gradio').setLevel(logging.ERROR)
|
|
78
|
+
logging.getLogger('gradio').setLevel(os.environ.get('GRADIO_LOGLEVEL', 'WARNING'))
|
|
79
|
+
logging.getLogger('rust_logger').setLevel(logging.WARNING)
|
|
80
|
+
logging.getLogger('duckduckgo').setLevel(logging.ERROR)
|
|
81
|
+
logging.getLogger('_client').setLevel(logging.ERROR)
|
|
82
|
+
|
|
83
|
+
def stream_subprocess(command, env=None):
|
|
84
|
+
"""
|
|
85
|
+
Execute a subprocess command and stream the output to the terminal in real-time.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
command (list): A list containing the command and its arguments.
|
|
89
|
+
env (dict, optional): Environment variables for the subprocess.
|
|
90
|
+
"""
|
|
91
|
+
process = subprocess.Popen(
|
|
92
|
+
command,
|
|
93
|
+
stdout=subprocess.PIPE,
|
|
94
|
+
stderr=subprocess.STDOUT,
|
|
95
|
+
text=True,
|
|
96
|
+
bufsize=1,
|
|
97
|
+
universal_newlines=True,
|
|
98
|
+
env=env
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
for line in iter(process.stdout.readline, ''):
|
|
102
|
+
print(line, end='')
|
|
103
|
+
sys.stdout.flush() # Ensure output is flushed immediately
|
|
104
|
+
|
|
105
|
+
process.stdout.close()
|
|
106
|
+
return_code = process.wait()
|
|
107
|
+
|
|
108
|
+
if return_code != 0:
|
|
109
|
+
raise subprocess.CalledProcessError(return_code, command)
|
|
110
|
+
|
|
111
|
+
class PraisonAI:
|
|
112
|
+
def __init__(self, agent_file="agents.yaml", framework="", auto=False, init=False, agent_yaml=None, tools=None):
|
|
113
|
+
"""
|
|
114
|
+
Initialize the PraisonAI object with default parameters.
|
|
115
|
+
"""
|
|
116
|
+
self.agent_yaml = agent_yaml
|
|
117
|
+
self.config_list = [
|
|
118
|
+
{
|
|
119
|
+
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
|
120
|
+
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
|
121
|
+
'api_key': os.environ.get("OPENAI_API_KEY")
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
self.agent_file = agent_file
|
|
125
|
+
self.framework = framework
|
|
126
|
+
self.auto = auto
|
|
127
|
+
self.init = init
|
|
128
|
+
self.tools = tools or [] # Store tool class names as a list
|
|
129
|
+
|
|
130
|
+
def run(self):
|
|
131
|
+
"""
|
|
132
|
+
Run the PraisonAI application.
|
|
133
|
+
"""
|
|
134
|
+
self.main()
|
|
135
|
+
|
|
136
|
+
def main(self):
|
|
137
|
+
"""
|
|
138
|
+
The main function of the PraisonAI object. It parses the command-line arguments,
|
|
139
|
+
initializes the necessary attributes, and then calls the appropriate methods based on the
|
|
140
|
+
provided arguments.
|
|
141
|
+
"""
|
|
142
|
+
args = self.parse_args()
|
|
143
|
+
invocation_cmd = "praisonai"
|
|
144
|
+
version_string = f"PraisonAI version {__version__}"
|
|
145
|
+
|
|
146
|
+
self.framework = args.framework or self.framework
|
|
147
|
+
|
|
148
|
+
if args.command:
|
|
149
|
+
if args.command.startswith("tests.test"): # Argument used for testing purposes
|
|
150
|
+
print("test")
|
|
151
|
+
else:
|
|
152
|
+
self.agent_file = args.command
|
|
153
|
+
|
|
154
|
+
if args.deploy:
|
|
155
|
+
from .deploy import CloudDeployer
|
|
156
|
+
deployer = CloudDeployer()
|
|
157
|
+
deployer.run_commands()
|
|
158
|
+
return
|
|
159
|
+
|
|
160
|
+
if getattr(args, 'chat', False):
|
|
161
|
+
self.create_chainlit_chat_interface()
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
if getattr(args, 'code', False):
|
|
165
|
+
self.create_code_interface()
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
if getattr(args, 'realtime', False):
|
|
169
|
+
self.create_realtime_interface()
|
|
170
|
+
return
|
|
171
|
+
|
|
172
|
+
if getattr(args, 'call', False):
|
|
173
|
+
call_args = []
|
|
174
|
+
if args.public:
|
|
175
|
+
call_args.append('--public')
|
|
176
|
+
call_module.main(call_args)
|
|
177
|
+
return
|
|
178
|
+
|
|
179
|
+
if args.command == 'train':
|
|
180
|
+
package_root = os.path.dirname(os.path.abspath(__file__))
|
|
181
|
+
config_yaml_destination = os.path.join(os.getcwd(), 'config.yaml')
|
|
182
|
+
|
|
183
|
+
# Create config.yaml only if it doesn't exist or --model or --dataset is provided
|
|
184
|
+
if not os.path.exists(config_yaml_destination) or args.model or args.dataset:
|
|
185
|
+
config = generate_config(
|
|
186
|
+
model_name=args.model,
|
|
187
|
+
hf_model_name=args.hf,
|
|
188
|
+
ollama_model_name=args.ollama,
|
|
189
|
+
dataset=[{
|
|
190
|
+
"name": args.dataset
|
|
191
|
+
}]
|
|
192
|
+
)
|
|
193
|
+
with open('config.yaml', 'w') as f:
|
|
194
|
+
yaml.dump(config, f, default_flow_style=False, indent=2)
|
|
195
|
+
|
|
196
|
+
# Overwrite huggingface_save and ollama_save if --hf or --ollama are provided
|
|
197
|
+
if args.hf:
|
|
198
|
+
config["huggingface_save"] = "true"
|
|
199
|
+
if args.ollama:
|
|
200
|
+
config["ollama_save"] = "true"
|
|
201
|
+
|
|
202
|
+
if 'init' in sys.argv:
|
|
203
|
+
from praisonai.setup.setup_conda_env import main as setup_conda_main
|
|
204
|
+
setup_conda_main()
|
|
205
|
+
print("All packages installed")
|
|
206
|
+
return
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
result = subprocess.check_output(['conda', 'env', 'list'])
|
|
210
|
+
if 'praison_env' in result.decode('utf-8'):
|
|
211
|
+
print("Conda environment 'praison_env' found.")
|
|
212
|
+
else:
|
|
213
|
+
raise subprocess.CalledProcessError(1, 'grep')
|
|
214
|
+
except subprocess.CalledProcessError:
|
|
215
|
+
print("Conda environment 'praison_env' not found. Setting it up...")
|
|
216
|
+
from praisonai.setup.setup_conda_env import main as setup_conda_main
|
|
217
|
+
setup_conda_main()
|
|
218
|
+
print("All packages installed.")
|
|
219
|
+
|
|
220
|
+
train_args = sys.argv[2:] # Get all arguments after 'train'
|
|
221
|
+
train_script_path = os.path.join(package_root, 'train.py')
|
|
222
|
+
|
|
223
|
+
# Set environment variables
|
|
224
|
+
env = os.environ.copy()
|
|
225
|
+
env['PYTHONUNBUFFERED'] = '1'
|
|
226
|
+
|
|
227
|
+
stream_subprocess(['conda', 'run', '--no-capture-output', '--name', 'praison_env', 'python', '-u', train_script_path, 'train'], env=env)
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
if args.auto or self.auto:
|
|
231
|
+
temp_topic = args.auto if args.auto else self.auto
|
|
232
|
+
if isinstance(temp_topic, list):
|
|
233
|
+
temp_topic = ' '.join(temp_topic)
|
|
234
|
+
self.topic = temp_topic
|
|
235
|
+
|
|
236
|
+
self.agent_file = "test.yaml"
|
|
237
|
+
generator = AutoGenerator(topic=self.topic, framework=self.framework, agent_file=self.agent_file)
|
|
238
|
+
self.agent_file = generator.generate()
|
|
239
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
240
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
241
|
+
print(result)
|
|
242
|
+
return result
|
|
243
|
+
elif args.init or self.init:
|
|
244
|
+
temp_topic = args.init if args.init else self.init
|
|
245
|
+
if isinstance(temp_topic, list):
|
|
246
|
+
temp_topic = ' '.join(temp_topic)
|
|
247
|
+
self.topic = temp_topic
|
|
248
|
+
|
|
249
|
+
self.agent_file = "agents.yaml"
|
|
250
|
+
generator = AutoGenerator(topic=self.topic, framework=self.framework, agent_file=self.agent_file)
|
|
251
|
+
self.agent_file = generator.generate()
|
|
252
|
+
print(f"File {self.agent_file} created successfully")
|
|
253
|
+
return f"File {self.agent_file} created successfully"
|
|
254
|
+
|
|
255
|
+
if args.ui:
|
|
256
|
+
if args.ui == "gradio":
|
|
257
|
+
self.create_gradio_interface()
|
|
258
|
+
elif args.ui == "chainlit":
|
|
259
|
+
self.create_chainlit_interface()
|
|
260
|
+
else:
|
|
261
|
+
# Modify code to allow default UI
|
|
262
|
+
agents_generator = AgentsGenerator(
|
|
263
|
+
self.agent_file,
|
|
264
|
+
self.framework,
|
|
265
|
+
self.config_list,
|
|
266
|
+
agent_yaml=self.agent_yaml,
|
|
267
|
+
tools=self.tools
|
|
268
|
+
)
|
|
269
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
270
|
+
print(result)
|
|
271
|
+
return result
|
|
272
|
+
else:
|
|
273
|
+
agents_generator = AgentsGenerator(
|
|
274
|
+
self.agent_file,
|
|
275
|
+
self.framework,
|
|
276
|
+
self.config_list,
|
|
277
|
+
agent_yaml=self.agent_yaml,
|
|
278
|
+
tools=self.tools
|
|
279
|
+
)
|
|
280
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
281
|
+
print(result)
|
|
282
|
+
return result
|
|
283
|
+
|
|
284
|
+
def parse_args(self):
|
|
285
|
+
"""
|
|
286
|
+
Parse the command-line arguments for the PraisonAI CLI.
|
|
287
|
+
"""
|
|
288
|
+
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
|
|
289
|
+
parser.add_argument("--framework", choices=["crewai", "autogen", "praisonai"], help="Specify the framework")
|
|
290
|
+
parser.add_argument("--ui", choices=["chainlit", "gradio"], help="Specify the UI framework (gradio or chainlit).")
|
|
291
|
+
parser.add_argument("--auto", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
|
|
292
|
+
parser.add_argument("--init", nargs=argparse.REMAINDER, help="Initialize agents with optional topic")
|
|
293
|
+
parser.add_argument("command", nargs="?", help="Command to run")
|
|
294
|
+
parser.add_argument("--deploy", action="store_true", help="Deploy the application")
|
|
295
|
+
parser.add_argument("--model", type=str, help="Model name")
|
|
296
|
+
parser.add_argument("--hf", type=str, help="Hugging Face model name")
|
|
297
|
+
parser.add_argument("--ollama", type=str, help="Ollama model name")
|
|
298
|
+
parser.add_argument("--dataset", type=str, help="Dataset name for training", default="yahma/alpaca-cleaned")
|
|
299
|
+
parser.add_argument("--realtime", action="store_true", help="Start the realtime voice interaction interface")
|
|
300
|
+
parser.add_argument("--call", action="store_true", help="Start the PraisonAI Call server")
|
|
301
|
+
parser.add_argument("--public", action="store_true", help="Use ngrok to expose the server publicly (only with --call)")
|
|
302
|
+
args, unknown_args = parser.parse_known_args()
|
|
303
|
+
|
|
304
|
+
if unknown_args and unknown_args[0] == '-b' and unknown_args[1] == 'api:app':
|
|
305
|
+
args.command = 'agents.yaml'
|
|
306
|
+
if args.command == 'api:app' or args.command == '/app/api:app':
|
|
307
|
+
args.command = 'agents.yaml'
|
|
308
|
+
if args.command == 'ui':
|
|
309
|
+
args.ui = 'chainlit'
|
|
310
|
+
if args.command == 'chat':
|
|
311
|
+
args.ui = 'chainlit'
|
|
312
|
+
args.chat = True
|
|
313
|
+
if args.command == 'code':
|
|
314
|
+
args.ui = 'chainlit'
|
|
315
|
+
args.code = True
|
|
316
|
+
if args.command == 'realtime':
|
|
317
|
+
args.realtime = True
|
|
318
|
+
if args.command == 'call':
|
|
319
|
+
args.call = True
|
|
320
|
+
|
|
321
|
+
# Handle both command and flag versions for call
|
|
322
|
+
if args.command == 'call' or args.call:
|
|
323
|
+
if not CALL_MODULE_AVAILABLE:
|
|
324
|
+
print("[red]ERROR: Call feature is not installed. Install with:[/red]")
|
|
325
|
+
print("\npip install \"praisonai[call]\"\n")
|
|
326
|
+
sys.exit(1)
|
|
327
|
+
|
|
328
|
+
call_args = []
|
|
329
|
+
if args.public:
|
|
330
|
+
call_args.append('--public')
|
|
331
|
+
call_module.main(call_args)
|
|
332
|
+
sys.exit(0)
|
|
333
|
+
|
|
334
|
+
# Handle special commands first
|
|
335
|
+
special_commands = ['chat', 'code', 'call', 'realtime', 'train', 'ui']
|
|
336
|
+
|
|
337
|
+
if args.command in special_commands:
|
|
338
|
+
if args.command == 'chat':
|
|
339
|
+
if not CHAINLIT_AVAILABLE:
|
|
340
|
+
print("[red]ERROR: Chat UI is not installed. Install with:[/red]")
|
|
341
|
+
print("\npip install \"praisonai[chat]\"\n")
|
|
342
|
+
sys.exit(1)
|
|
343
|
+
try:
|
|
344
|
+
self.create_chainlit_chat_interface()
|
|
345
|
+
except ModuleNotFoundError as e:
|
|
346
|
+
missing_module = str(e).split("'")[1]
|
|
347
|
+
print(f"[red]ERROR: Missing dependency {missing_module}. Install with:[/red]")
|
|
348
|
+
print(f"\npip install \"praisonai[chat]\"\n")
|
|
349
|
+
sys.exit(1)
|
|
350
|
+
sys.exit(0)
|
|
351
|
+
|
|
352
|
+
elif args.command == 'code':
|
|
353
|
+
if not CHAINLIT_AVAILABLE:
|
|
354
|
+
print("[red]ERROR: Code UI is not installed. Install with:[/red]")
|
|
355
|
+
print("\npip install \"praisonai[code]\"\n")
|
|
356
|
+
sys.exit(1)
|
|
357
|
+
try:
|
|
358
|
+
self.create_code_interface()
|
|
359
|
+
except ModuleNotFoundError as e:
|
|
360
|
+
missing_module = str(e).split("'")[1]
|
|
361
|
+
print(f"[red]ERROR: Missing dependency {missing_module}. Install with:[/red]")
|
|
362
|
+
print(f"\npip install \"praisonai[code]\"\n")
|
|
363
|
+
sys.exit(1)
|
|
364
|
+
sys.exit(0)
|
|
365
|
+
|
|
366
|
+
elif args.command == 'call':
|
|
367
|
+
if not CALL_MODULE_AVAILABLE:
|
|
368
|
+
print("[red]ERROR: Call feature is not installed. Install with:[/red]")
|
|
369
|
+
print("\npip install \"praisonai[call]\"\n")
|
|
370
|
+
sys.exit(1)
|
|
371
|
+
call_module.main()
|
|
372
|
+
sys.exit(0)
|
|
373
|
+
|
|
374
|
+
elif args.command == 'realtime':
|
|
375
|
+
if not CHAINLIT_AVAILABLE:
|
|
376
|
+
print("[red]ERROR: Realtime UI is not installed. Install with:[/red]")
|
|
377
|
+
print("\npip install \"praisonai[realtime]\"\n")
|
|
378
|
+
sys.exit(1)
|
|
379
|
+
self.create_realtime_interface()
|
|
380
|
+
sys.exit(0)
|
|
381
|
+
|
|
382
|
+
elif args.command == 'train':
|
|
383
|
+
print("[red]ERROR: Train feature is not installed. Install with:[/red]")
|
|
384
|
+
print("\npip install \"praisonai[train]\"\n")
|
|
385
|
+
sys.exit(1)
|
|
386
|
+
|
|
387
|
+
elif args.command == 'ui':
|
|
388
|
+
if not CHAINLIT_AVAILABLE:
|
|
389
|
+
print("[red]ERROR: UI is not installed. Install with:[/red]")
|
|
390
|
+
print("\npip install \"praisonai[ui]\"\n")
|
|
391
|
+
sys.exit(1)
|
|
392
|
+
self.create_chainlit_interface()
|
|
393
|
+
sys.exit(0)
|
|
394
|
+
|
|
395
|
+
# Only check framework availability for agent-related operations
|
|
396
|
+
if not args.command and (args.init or args.auto or args.framework):
|
|
397
|
+
if not CREWAI_AVAILABLE and not AUTOGEN_AVAILABLE and not PRAISONAI_AVAILABLE:
|
|
398
|
+
print("[red]ERROR: No framework is installed. Please install at least one framework:[/red]")
|
|
399
|
+
print("\npip install \"praisonai\\[crewai]\" # For CrewAI")
|
|
400
|
+
print("pip install \"praisonai\\[autogen]\" # For AutoGen")
|
|
401
|
+
print("pip install \"praisonai\\[crewai,autogen]\" # For both frameworks\n")
|
|
402
|
+
print("pip install praisonaiagents # For PraisonAIAgents\n")
|
|
403
|
+
sys.exit(1)
|
|
404
|
+
|
|
405
|
+
return args
|
|
406
|
+
|
|
407
|
+
def create_chainlit_chat_interface(self):
|
|
408
|
+
"""
|
|
409
|
+
Create a Chainlit interface for the chat application.
|
|
410
|
+
"""
|
|
411
|
+
if CHAINLIT_AVAILABLE:
|
|
412
|
+
import praisonai
|
|
413
|
+
os.environ["CHAINLIT_PORT"] = "8084"
|
|
414
|
+
root_path = os.path.join(os.path.expanduser("~"), ".praison")
|
|
415
|
+
if "CHAINLIT_APP_ROOT" not in os.environ:
|
|
416
|
+
os.environ["CHAINLIT_APP_ROOT"] = root_path
|
|
417
|
+
chat_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'chat.py')
|
|
418
|
+
chainlit_run([chat_ui_path])
|
|
419
|
+
else:
|
|
420
|
+
print("ERROR: Chat UI is not installed. Please install it with 'pip install \"praisonai[chat]\"' to use the chat UI.")
|
|
421
|
+
|
|
422
|
+
def create_code_interface(self):
|
|
423
|
+
"""
|
|
424
|
+
Create a Chainlit interface for the code application.
|
|
425
|
+
"""
|
|
426
|
+
if CHAINLIT_AVAILABLE:
|
|
427
|
+
import praisonai
|
|
428
|
+
os.environ["CHAINLIT_PORT"] = "8086"
|
|
429
|
+
root_path = os.path.join(os.path.expanduser("~"), ".praison")
|
|
430
|
+
if "CHAINLIT_APP_ROOT" not in os.environ:
|
|
431
|
+
os.environ["CHAINLIT_APP_ROOT"] = root_path
|
|
432
|
+
public_folder = os.path.join(os.path.dirname(__file__), 'public')
|
|
433
|
+
if not os.path.exists(os.path.join(root_path, "public")):
|
|
434
|
+
if os.path.exists(public_folder):
|
|
435
|
+
shutil.copytree(public_folder, os.path.join(root_path, "public"), dirs_exist_ok=True)
|
|
436
|
+
logging.info("Public folder copied successfully!")
|
|
437
|
+
else:
|
|
438
|
+
logging.info("Public folder not found in the package.")
|
|
439
|
+
else:
|
|
440
|
+
logging.info("Public folder already exists.")
|
|
441
|
+
code_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'code.py')
|
|
442
|
+
chainlit_run([code_ui_path])
|
|
443
|
+
else:
|
|
444
|
+
print("ERROR: Code UI is not installed. Please install it with 'pip install \"praisonai[code]\"' to use the code UI.")
|
|
445
|
+
|
|
446
|
+
def create_gradio_interface(self):
|
|
447
|
+
"""
|
|
448
|
+
Create a Gradio interface for generating agents and performing tasks.
|
|
449
|
+
"""
|
|
450
|
+
if GRADIO_AVAILABLE:
|
|
451
|
+
def generate_crew_and_kickoff_interface(auto_args, framework):
|
|
452
|
+
self.framework = framework
|
|
453
|
+
self.agent_file = "test.yaml"
|
|
454
|
+
generator = AutoGenerator(topic=auto_args, framework=self.framework)
|
|
455
|
+
self.agent_file = generator.generate()
|
|
456
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
457
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
458
|
+
return result
|
|
459
|
+
|
|
460
|
+
gr.Interface(
|
|
461
|
+
fn=generate_crew_and_kickoff_interface,
|
|
462
|
+
inputs=[gr.Textbox(lines=2, label="Auto Args"), gr.Dropdown(choices=["crewai", "autogen"], label="Framework")],
|
|
463
|
+
outputs="textbox",
|
|
464
|
+
title="Praison AI Studio",
|
|
465
|
+
description="Create Agents and perform tasks",
|
|
466
|
+
theme="default"
|
|
467
|
+
).launch()
|
|
468
|
+
else:
|
|
469
|
+
print("ERROR: Gradio is not installed. Please install it with 'pip install gradio' to use this feature.")
|
|
470
|
+
|
|
471
|
+
def create_chainlit_interface(self):
|
|
472
|
+
"""
|
|
473
|
+
Create a Chainlit interface for generating agents and performing tasks.
|
|
474
|
+
"""
|
|
475
|
+
if CHAINLIT_AVAILABLE:
|
|
476
|
+
import praisonai
|
|
477
|
+
os.environ["CHAINLIT_PORT"] = "8082"
|
|
478
|
+
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
|
|
479
|
+
if not os.path.exists("public"):
|
|
480
|
+
if os.path.exists(public_folder):
|
|
481
|
+
shutil.copytree(public_folder, 'public', dirs_exist_ok=True)
|
|
482
|
+
logging.info("Public folder copied successfully!")
|
|
483
|
+
else:
|
|
484
|
+
logging.info("Public folder not found in the package.")
|
|
485
|
+
else:
|
|
486
|
+
logging.info("Public folder already exists.")
|
|
487
|
+
chainlit_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'agents.py')
|
|
488
|
+
chainlit_run([chainlit_ui_path])
|
|
489
|
+
else:
|
|
490
|
+
print("ERROR: Chainlit is not installed. Please install it with 'pip install \"praisonai[ui]\"' to use the UI.")
|
|
491
|
+
|
|
492
|
+
def create_realtime_interface(self):
|
|
493
|
+
"""
|
|
494
|
+
Create a Chainlit interface for the realtime voice interaction application.
|
|
495
|
+
"""
|
|
496
|
+
if CHAINLIT_AVAILABLE:
|
|
497
|
+
import praisonai
|
|
498
|
+
os.environ["CHAINLIT_PORT"] = "8088"
|
|
499
|
+
root_path = os.path.join(os.path.expanduser("~"), ".praison")
|
|
500
|
+
if "CHAINLIT_APP_ROOT" not in os.environ:
|
|
501
|
+
os.environ["CHAINLIT_APP_ROOT"] = root_path
|
|
502
|
+
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
|
|
503
|
+
if not os.path.exists(os.path.join(root_path, "public")):
|
|
504
|
+
if os.path.exists(public_folder):
|
|
505
|
+
shutil.copytree(public_folder, os.path.join(root_path, "public"), dirs_exist_ok=True)
|
|
506
|
+
logging.info("Public folder copied successfully!")
|
|
507
|
+
else:
|
|
508
|
+
logging.info("Public folder not found in the package.")
|
|
509
|
+
else:
|
|
510
|
+
logging.info("Public folder already exists.")
|
|
511
|
+
realtime_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'realtime.py')
|
|
512
|
+
chainlit_run([realtime_ui_path])
|
|
513
|
+
else:
|
|
514
|
+
print("ERROR: Realtime UI is not installed. Please install it with 'pip install \"praisonai[realtime]\"' to use the realtime UI.")
|
|
515
|
+
|
|
516
|
+
if __name__ == "__main__":
|
|
517
|
+
praison_ai = PraisonAI()
|
|
518
|
+
praison_ai.main()
|
praisonai/deploy.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import os
|
|
3
|
+
from dotenv import load_dotenv
|
|
4
|
+
|
|
5
|
+
class CloudDeployer:
|
|
6
|
+
"""
|
|
7
|
+
A class for deploying a cloud-based application.
|
|
8
|
+
|
|
9
|
+
Attributes:
|
|
10
|
+
None
|
|
11
|
+
|
|
12
|
+
Methods:
|
|
13
|
+
__init__(self):
|
|
14
|
+
Loads environment variables from .env file or system and sets them.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
def __init__(self):
|
|
18
|
+
"""
|
|
19
|
+
Loads environment variables from .env file or system and sets them.
|
|
20
|
+
|
|
21
|
+
Parameters:
|
|
22
|
+
self: An instance of the CloudDeployer class.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
None
|
|
26
|
+
|
|
27
|
+
Raises:
|
|
28
|
+
None
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
# Load environment variables from .env file or system
|
|
32
|
+
load_dotenv()
|
|
33
|
+
self.set_environment_variables()
|
|
34
|
+
|
|
35
|
+
def create_dockerfile(self):
|
|
36
|
+
"""
|
|
37
|
+
Creates a Dockerfile for the application.
|
|
38
|
+
|
|
39
|
+
Parameters:
|
|
40
|
+
self: An instance of the CloudDeployer class.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
None
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
None
|
|
47
|
+
|
|
48
|
+
This method creates a Dockerfile in the current directory with the specified content.
|
|
49
|
+
The Dockerfile is used to build a Docker image for the application.
|
|
50
|
+
The content of the Dockerfile includes instructions to use the Python 3.11-slim base image,
|
|
51
|
+
set the working directory to /app, copy the current directory contents into the container,
|
|
52
|
+
install the required Python packages (flask, praisonai, gunicorn, and markdown),
|
|
53
|
+
expose port 8080, and run the application using Gunicorn.
|
|
54
|
+
"""
|
|
55
|
+
with open("Dockerfile", "w") as file:
|
|
56
|
+
file.write("FROM python:3.11-slim\n")
|
|
57
|
+
file.write("WORKDIR /app\n")
|
|
58
|
+
file.write("COPY . .\n")
|
|
59
|
+
file.write("RUN pip install flask praisonai==2.0.61 gunicorn markdown\n")
|
|
60
|
+
file.write("EXPOSE 8080\n")
|
|
61
|
+
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
|
62
|
+
|
|
63
|
+
def create_api_file(self):
|
|
64
|
+
"""
|
|
65
|
+
Creates an API file for the application.
|
|
66
|
+
|
|
67
|
+
Parameters:
|
|
68
|
+
self (CloudDeployer): An instance of the CloudDeployer class.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
None
|
|
72
|
+
|
|
73
|
+
This method creates an API file named "api.py" in the current directory. The file contains a basic Flask application that uses the PraisonAI library to run a simple agent and returns the output as an HTML page. The application listens on the root path ("/") and uses the Markdown library to format the output.
|
|
74
|
+
"""
|
|
75
|
+
with open("api.py", "w") as file:
|
|
76
|
+
file.write("from flask import Flask\n")
|
|
77
|
+
file.write("from praisonai import PraisonAI\n")
|
|
78
|
+
file.write("import markdown\n\n")
|
|
79
|
+
file.write("app = Flask(__name__)\n\n")
|
|
80
|
+
file.write("def basic():\n")
|
|
81
|
+
file.write(" praisonai = PraisonAI(agent_file=\"agents.yaml\")\n")
|
|
82
|
+
file.write(" return praisonai.run()\n\n")
|
|
83
|
+
file.write("@app.route('/')\n")
|
|
84
|
+
file.write("def home():\n")
|
|
85
|
+
file.write(" output = basic()\n")
|
|
86
|
+
file.write(" html_output = markdown.markdown(output)\n")
|
|
87
|
+
file.write(" return f'<html><body>{html_output}</body></html>'\n\n")
|
|
88
|
+
file.write("if __name__ == \"__main__\":\n")
|
|
89
|
+
file.write(" app.run(debug=True)\n")
|
|
90
|
+
|
|
91
|
+
def set_environment_variables(self):
|
|
92
|
+
"""Sets environment variables with fallback to .env values or defaults."""
|
|
93
|
+
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
|
94
|
+
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "Enter your API key")
|
|
95
|
+
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
|
96
|
+
|
|
97
|
+
def run_commands(self):
|
|
98
|
+
"""
|
|
99
|
+
Sets environment variables with fallback to .env values or defaults.
|
|
100
|
+
|
|
101
|
+
Parameters:
|
|
102
|
+
None
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
None
|
|
106
|
+
|
|
107
|
+
Raises:
|
|
108
|
+
None
|
|
109
|
+
|
|
110
|
+
This method sets environment variables for the application. It uses the `os.environ` dictionary to set the following environment variables:
|
|
111
|
+
|
|
112
|
+
- `OPENAI_MODEL_NAME`: The name of the OpenAI model to use. If not specified in the .env file, it defaults to "gpt-4o".
|
|
113
|
+
- `OPENAI_API_KEY`: The API key for accessing the OpenAI API. If not specified in the .env file, it defaults to "Enter your API key".
|
|
114
|
+
- `OPENAI_API_BASE`: The base URL for the OpenAI API. If not specified in the .env file, it defaults to "https://api.openai.com/v1".
|
|
115
|
+
"""
|
|
116
|
+
self.create_api_file()
|
|
117
|
+
self.create_dockerfile()
|
|
118
|
+
"""Runs a sequence of shell commands for deployment, continues on error."""
|
|
119
|
+
commands = [
|
|
120
|
+
"yes | gcloud auth configure-docker us-central1-docker.pkg.dev",
|
|
121
|
+
"gcloud artifacts repositories create praisonai-repository --repository-format=docker --location=us-central1",
|
|
122
|
+
"docker build --platform linux/amd64 -t gcr.io/$(gcloud config get-value project)/praisonai-app:latest .",
|
|
123
|
+
"docker tag gcr.io/$(gcloud config get-value project)/praisonai-app:latest us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest",
|
|
124
|
+
"docker push us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest",
|
|
125
|
+
"gcloud run deploy praisonai-service --image us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest --platform managed --region us-central1 --allow-unauthenticated --set-env-vars OPENAI_MODEL_NAME=${OPENAI_MODEL_NAME},OPENAI_API_KEY=${OPENAI_API_KEY},OPENAI_API_BASE=${OPENAI_API_BASE}"
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
for cmd in commands:
|
|
129
|
+
try:
|
|
130
|
+
subprocess.run(cmd, shell=True, check=True)
|
|
131
|
+
except subprocess.CalledProcessError as e:
|
|
132
|
+
print(f"ERROR: Command '{e.cmd}' failed with exit status {e.returncode}")
|
|
133
|
+
print(f"Continuing with the next command...")
|
|
134
|
+
|
|
135
|
+
# Usage
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
deployer = CloudDeployer()
|
|
138
|
+
deployer.run_commands()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Only try to import autogen_tools if either CrewAI or AutoGen is available
|
|
2
|
+
CREWAI_AVAILABLE = False
|
|
3
|
+
AUTOGEN_AVAILABLE = False
|
|
4
|
+
PRAISONAI_TOOLS_AVAILABLE = False
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from crewai import Agent, Task, Crew
|
|
8
|
+
CREWAI_AVAILABLE = True
|
|
9
|
+
except ImportError:
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import autogen
|
|
14
|
+
AUTOGEN_AVAILABLE = True
|
|
15
|
+
except ImportError:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
# Only try to import tools if a framework is available
|
|
19
|
+
if CREWAI_AVAILABLE or AUTOGEN_AVAILABLE:
|
|
20
|
+
try:
|
|
21
|
+
from .autogen_tools import *
|
|
22
|
+
PRAISONAI_TOOLS_AVAILABLE = True
|
|
23
|
+
except ImportError:
|
|
24
|
+
pass
|