99load_dotenv ()
1010import autogen
1111import gradio as gr
12+ import chainlit as cl
13+ import asyncio
14+ import uvicorn
15+ from chainlit .cli import cli as chainlit_cli
16+ from chainlit .server import app
1217import argparse
1318from .auto import AutoGenerator
1419from .agents_generator import AgentsGenerator
@@ -72,9 +77,8 @@ def main(self):
7277
7378 self .framework = args .framework or self .framework
7479
75- ui = args .ui
7680 if args .agent_file :
77- if args .agent_file .startswith ("tests.test" ): # Argument used for testing purposes
81+ if args .agent_file .startswith ("tests.test" ): # Argument used for testing purposes. eg: python -m unittest tests.test
7882 print ("test" )
7983 else :
8084 self .agent_file = args .agent_file
@@ -100,8 +104,13 @@ def main(self):
100104 print ("File {} created successfully" .format (self .agent_file ))
101105 return "File {} created successfully" .format (self .agent_file )
102106
103- if ui :
104- self .create_gradio_interface ()
107+ if args .ui :
108+ if args .ui == "gradio" :
109+ self .create_gradio_interface ()
110+ elif args .ui == "chainlit" :
111+ self .create_chainlit_interface ()
112+ else :
113+ self .create_chainlit_interface ()
105114 else :
106115 agents_generator = AgentsGenerator (self .agent_file , self .framework , self .config_list )
107116 result = agents_generator .generate_crew_and_kickoff ()
@@ -126,12 +135,11 @@ def parse_args(self):
126135 """
127136 parser = argparse .ArgumentParser (prog = "praisonai" , description = "praisonAI command-line interface" )
128137 parser .add_argument ("--framework" , choices = ["crewai" , "autogen" ], help = "Specify the framework" )
129- parser .add_argument ("--ui" , action = "store_true " , help = "Enable UI mode " )
138+ parser .add_argument ("--ui" , nargs = '?' , const = 'chainlit' , default = "chainlit " , help = "Specify the UI framework (gradio or chainlit). Default chainlit " )
130139 parser .add_argument ("--auto" , nargs = argparse .REMAINDER , help = "Enable auto mode and pass arguments for it" )
131140 parser .add_argument ("--init" , nargs = argparse .REMAINDER , help = "Enable auto mode and pass arguments for it" )
132141 parser .add_argument ("agent_file" , nargs = "?" , help = "Specify the agent file" )
133142 parser .add_argument ("--deploy" , action = "store_true" , help = "Deploy the application" ) # New argument
134-
135143 args , unknown_args = parser .parse_known_args ()
136144
137145 if unknown_args and unknown_args [0 ] == '-b' and unknown_args [1 ] == 'api:app' :
@@ -191,8 +199,23 @@ def generate_crew_and_kickoff_interface(auto_args, framework):
191199 description = "Create Agents and perform tasks" ,
192200 theme = "default"
193201 ).launch ()
202+
203+ def create_chainlit_interface (self ):
204+ """
205+ Create a Chainlit interface for generating agents and performing tasks.
206+
207+ This function sets up a Chainlit application that listens for messages.
208+ When a message is received, it runs PraisonAI with the provided message as the topic.
209+ The generated agents are then used to perform tasks.
210+
211+ Returns:
212+ None: This function does not return any value. It starts the Chainlit application.
213+ """
214+ from chainlit .cli import chainlit_run # Import chainlit_run
215+ os .environ ["CHAINLIT_PORT" ] = "8082"
216+ chainlit_run (["praisonai/chainlit_ui.py" ])
217+
194218
195219if __name__ == "__main__" :
196220 praison_ai = PraisonAI ()
197- praison_ai .main ()
198-
221+ praison_ai .main ()
0 commit comments