Skip to content

Commit 9c0c72b

Browse files
Merge pull request #45 from MervinPraison/develop
v0.0.23
2 parents 4575575 + 0c8b8ea commit 9c0c72b

File tree

10 files changed

+151
-66
lines changed

10 files changed

+151
-66
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==0.0.22 gunicorn markdown
4+
RUN pip install flask praisonai==0.0.23 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

chainlit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Welcome to Praison AI! 🚀🤖

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = 'PraisonAI'
1010
copyright = '2024, Mervin Praison'
1111
author = 'Mervin Praison'
12-
release = '0.0.22'
12+
release = '0.0.23'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/requirements.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ mkdocs-jupyter
88
pymdown-extensions
99
Pygments
1010
pdoc3
11-
xmlrunner
11+
xmlrunner
12+
unittest2

docs/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ crewai_tools
2020
duckduckgo_search
2121
praisonai_tools
2222
open-interpreter
23-
xmlrunner
23+
xmlrunner
24+
unittest2

poetry.lock

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

praisonai/chainlit_ui.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from praisonai.agents_generator import AgentsGenerator
2+
from praisonai.auto import AutoGenerator
3+
import chainlit as cl
4+
import os
5+
from chainlit.types import ThreadDict
6+
from typing import Optional
7+
8+
framework = "crewai"
9+
config_list = [
10+
{
11+
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
12+
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
13+
}
14+
]
15+
agent_file = "test.yaml"
16+
17+
@cl.on_chat_start
18+
async def start_chat():
19+
cl.user_session.set(
20+
"message_history",
21+
[{"role": "system", "content": "You are a helpful assistant."}],
22+
)
23+
24+
@cl.on_chat_resume
25+
async def on_chat_resume(thread: ThreadDict):
26+
message_history = cl.user_session.get("message_history", [])
27+
root_messages = [m for m in thread["steps"] if m["parentId"] is None]
28+
for message in root_messages:
29+
if message["type"] == "user_message":
30+
message_history.append({"role": "user", "content": message["output"]})
31+
elif message["type"] == "ai_message":
32+
message_history.append({"role": "assistant", "content": message["content"]})
33+
cl.user_session.set("message_history", message_history)
34+
35+
@cl.on_message
36+
async def main(message: cl.Message):
37+
"""Run PraisonAI with the provided message as the topic."""
38+
message_history = cl.user_session.get("message_history")
39+
message_history.append({"role": "user", "content": message.content})
40+
topic = message.content
41+
agent_file = "test.yaml"
42+
generator = AutoGenerator(topic=topic, framework=framework)
43+
agent_file = generator.generate()
44+
agents_generator = AgentsGenerator(agent_file, framework, config_list)
45+
result = agents_generator.generate_crew_and_kickoff()
46+
msg = cl.Message(content=result)
47+
await msg.send()
48+
message_history.append({"role": "assistant", "content": message.content})
49+
50+
@cl.password_auth_callback
51+
def auth_callback(username: str, password: str):
52+
# Fetch the user matching username from your database
53+
# and compare the hashed password with the value stored in the database
54+
if (username, password) == ("admin", "admin"):
55+
return cl.User(
56+
identifier="admin", metadata={"role": "admin", "provider": "credentials"}
57+
)
58+
else:
59+
return None

praisonai/cli.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
load_dotenv()
1010
import autogen
1111
import 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
1217
import argparse
1318
from .auto import AutoGenerator
1419
from .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

195219
if __name__ == "__main__":
196220
praison_ai = PraisonAI()
197-
praison_ai.main()
198-
221+
praison_ai.main()

praisonai/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_dockerfile(self):
5656
file.write("FROM python:3.11-slim\n")
5757
file.write("WORKDIR /app\n")
5858
file.write("COPY . .\n")
59-
file.write("RUN pip install flask praisonai==0.0.22 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==0.0.23 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PraisonAI"
3-
version = "0.0.22"
3+
version = "0.0.23"
44
description = "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."
55
authors = ["Mervin Praison"]
66
license = ""
@@ -18,7 +18,7 @@ python = ">=3.10,<3.13"
1818
rich = ">=13.7"
1919
pyautogen = ">=0.2.19"
2020
crewai = ">=0.30.4"
21-
gradio = ">=4.20.0"
21+
gradio = ">=4.26.0"
2222
Flask = ">=3.0.0"
2323
markdown = ">=3.5"
2424
crewai-tools = "^0.2.6"

0 commit comments

Comments
 (0)