Skip to content

Commit aed83fc

Browse files
Merge pull request #50 from MervinPraison/develop
v0.0.28
2 parents 1d03143 + cbdbb3a commit aed83fc

File tree

9 files changed

+168
-14
lines changed

9 files changed

+168
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ docs.sh
2020
other
2121

2222
.chainlit
23+
.files
2324

2425
site
2526
# Ignore Sphinx build directory

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.27 gunicorn markdown
4+
RUN pip install flask praisonai==0.0.28 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

praisonai/chainlit_ui.py

Lines changed: 152 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,56 @@
1919
]
2020
agent_file = "test.yaml"
2121

22+
actions=[
23+
cl.Action(name="run", value="run", label="✅ Run"),
24+
cl.Action(name="modify", value="modify", label="🔧 Modify"),
25+
]
26+
27+
@cl.action_callback("run")
28+
async def on_run(action):
29+
await main(cl.Message(content=""))
30+
31+
@cl.action_callback("modify")
32+
async def on_modify(action):
33+
await cl.Message(content="Modify the agents and tools from below settings").send()
34+
35+
36+
@cl.set_chat_profiles
37+
async def set_profiles(current_user: cl.User):
38+
return [
39+
cl.ChatProfile(
40+
name="Auto",
41+
markdown_description="Automatically generate agents and tasks based on your input.",
42+
starters=[
43+
cl.Starter(
44+
label="Create a movie script",
45+
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.",
46+
icon="/public/movie.svg",
47+
),
48+
cl.Starter(
49+
label="Design a fantasy world",
50+
message="Design a detailed fantasy world with unique geography, cultures, and magical systems. Start by describing the main continent and its inhabitants.",
51+
icon="/public/fantasy.svg",
52+
),
53+
cl.Starter(
54+
label="Write a futuristic political thriller",
55+
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.",
56+
icon="/public/thriller.svg",
57+
),
58+
cl.Starter(
59+
label="Develop a new board game",
60+
message="Develop a new, innovative board game. Describe the game's objective, rules, and unique mechanics. Create a scenario to illustrate gameplay.",
61+
icon="/public/game.svg",
62+
),
63+
]
64+
),
65+
cl.ChatProfile(
66+
name="Manual",
67+
markdown_description="Manually define your agents and tasks using a YAML file.",
68+
),
69+
]
70+
71+
2272
@cl.on_chat_start
2373
async def start_chat():
2474
cl.user_session.set(
@@ -29,6 +79,7 @@ async def start_chat():
2979
[
3080
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
3181
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
82+
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
3283
Select(
3384
id="Framework",
3485
label="Framework",
@@ -37,16 +88,74 @@ async def start_chat():
3788
),
3889
]
3990
).send()
40-
# await on_settings_update(settings)
91+
cl.user_session.set("settings", settings)
92+
chat_profile = cl.user_session.get("chat_profile")
93+
if chat_profile=="Manual":
94+
95+
agent_file = "agents.yaml"
96+
full_agent_file_path = os.path.abspath(agent_file) # Get full path
97+
if os.path.exists(full_agent_file_path):
98+
with open(full_agent_file_path, 'r') as f:
99+
yaml_content = f.read()
100+
msg = cl.Message(content=yaml_content, language="yaml")
101+
await msg.send()
102+
103+
104+
full_tools_file_path = os.path.abspath("tools.py") # Get full path
105+
if os.path.exists(full_tools_file_path):
106+
with open(full_tools_file_path, 'r') as f:
107+
tools_content = f.read()
108+
msg = cl.Message(content=tools_content, language="python")
109+
await msg.send()
110+
111+
settings = await cl.ChatSettings(
112+
[
113+
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
114+
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
115+
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
116+
Select(
117+
id="Framework",
118+
label="Framework",
119+
values=["crewai", "autogen"],
120+
initial_index=0,
121+
),
122+
TextInput(id="agents", label="agents.yaml", initial=yaml_content, multiline=True),
123+
TextInput(id="tools", label="tools.py", initial=tools_content, multiline=True),
124+
]
125+
).send()
126+
cl.user_session.set("settings", settings)
127+
128+
res = await cl.AskActionMessage(
129+
content="Pick an action!",
130+
actions=actions,
131+
).send()
132+
if res and res.get("value") == "modify":
133+
await cl.Message(content="Modify the agents and tools from below settings", actions=actions).send()
134+
elif res and res.get("value") == "run":
135+
await main(cl.Message(content="", actions=actions))
136+
137+
await on_settings_update(settings)
41138

42139
@cl.on_settings_update
43140
async def on_settings_update(settings):
44141
"""Handle updates to the ChatSettings form."""
45142
global config_list, framework
46143
config_list[0]['model'] = settings["Model"]
47144
config_list[0]['base_url'] = settings["BaseUrl"]
145+
config_list[0]['api_key'] = settings["ApiKey"]
146+
os.environ["OPENAI_API_KEY"] = config_list[0]['api_key']
147+
os.environ["OPENAI_MODEL_NAME"] = config_list[0]['model']
148+
os.environ["OPENAI_API_BASE"] = config_list[0]['base_url']
48149
framework = settings["Framework"]
49-
print("Settings updated:", settings)
150+
151+
if "agents" in settings:
152+
with open("agents.yaml", "w") as f:
153+
f.write(settings["agents"])
154+
if "tools" in settings:
155+
with open("tools.py", "w") as f:
156+
f.write(settings["tools"])
157+
158+
print("Settings updated")
50159

51160
@cl.on_chat_resume
52161
async def on_chat_resume(thread: ThreadDict):
@@ -59,20 +168,52 @@ async def on_chat_resume(thread: ThreadDict):
59168
message_history.append({"role": "assistant", "content": message["content"]})
60169
cl.user_session.set("message_history", message_history)
61170

171+
# @cl.step(type="tool")
172+
# async def tool(data: Optional[str] = None, language: Optional[str] = None):
173+
# return cl.Message(content=data, language=language)
174+
62175
@cl.on_message
63176
async def main(message: cl.Message):
64177
"""Run PraisonAI with the provided message as the topic."""
65178
message_history = cl.user_session.get("message_history")
66179
message_history.append({"role": "user", "content": message.content})
67180
topic = message.content
68-
agent_file = "test.yaml"
69-
generator = AutoGenerator(topic=topic, framework=framework, config_list=config_list)
70-
agent_file = generator.generate()
71-
agents_generator = AgentsGenerator(agent_file, framework, config_list)
72-
result = agents_generator.generate_crew_and_kickoff()
73-
msg = cl.Message(content=result)
74-
await msg.send()
75-
message_history.append({"role": "assistant", "content": message.content})
181+
chat_profile = cl.user_session.get("chat_profile")
182+
183+
if chat_profile == "Auto":
184+
agent_file = "agents.yaml"
185+
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
186+
agent_file = generator.generate()
187+
agents_generator = AgentsGenerator(agent_file, framework, config_list)
188+
result = agents_generator.generate_crew_and_kickoff()
189+
msg = cl.Message(content=result)
190+
await msg.send()
191+
message_history.append({"role": "assistant", "content": message.content})
192+
else: # chat_profile == "Manual"
193+
agent_file = "agents.yaml"
194+
full_agent_file_path = os.path.abspath(agent_file) # Get full path
195+
full_tools_file_path = os.path.abspath("tools.py")
196+
if os.path.exists(full_agent_file_path):
197+
with open(full_agent_file_path, 'r') as f:
198+
yaml_content = f.read()
199+
# tool_res = await tool()
200+
msg_agents = cl.Message(content=yaml_content, language="yaml")
201+
await msg_agents.send()
202+
if os.path.exists(full_tools_file_path):
203+
with open(full_tools_file_path, 'r') as f:
204+
tools_content = f.read()
205+
msg_tools = cl.Message(content=tools_content, language="python")
206+
await msg_tools.send()
207+
else:
208+
# If the file doesn't exist, follow the same process as "Auto"
209+
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
210+
agent_file = generator.generate()
211+
212+
agents_generator = AgentsGenerator(agent_file, framework, config_list)
213+
result = agents_generator.generate_crew_and_kickoff()
214+
msg = cl.Message(content=result, actions=actions)
215+
await msg.send()
216+
message_history.append({"role": "assistant", "content": message.content})
76217

77218
# Load environment variables from .env file
78219
load_dotenv()
@@ -90,4 +231,4 @@ def auth_callback(username: str, password: str):
90231
identifier=username, metadata={"role": "ADMIN", "provider": "credentials"}
91232
)
92233
else:
93-
return None
234+
return None

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.27 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==0.0.28 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

public/fantasy.svg

Lines changed: 3 additions & 0 deletions
Loading

public/game.svg

Lines changed: 3 additions & 0 deletions
Loading

public/movie.svg

Lines changed: 3 additions & 0 deletions
Loading

public/thriller.svg

Lines changed: 3 additions & 0 deletions
Loading

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PraisonAI"
3-
version = "0.0.27"
3+
version = "0.0.28"
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 = ""

0 commit comments

Comments
 (0)