Skip to content

Commit

Permalink
Merge pull request #50 from MervinPraison/develop
Browse files Browse the repository at this point in the history
v0.0.28
  • Loading branch information
MervinPraison authored Jun 18, 2024
2 parents e0ea6f8 + 38caf04 commit 5ddb2d1
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs.sh
other

.chainlit
.files

site
# Ignore Sphinx build directory
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==0.0.27 gunicorn markdown
RUN pip install flask praisonai==0.0.28 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
163 changes: 152 additions & 11 deletions praisonai/chainlit_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,56 @@
]
agent_file = "test.yaml"

actions=[
cl.Action(name="run", value="run", label="✅ Run"),
cl.Action(name="modify", value="modify", label="🔧 Modify"),
]

@cl.action_callback("run")
async def on_run(action):
await main(cl.Message(content=""))

@cl.action_callback("modify")
async def on_modify(action):
await cl.Message(content="Modify the agents and tools from below settings").send()


@cl.set_chat_profiles
async def set_profiles(current_user: cl.User):
return [
cl.ChatProfile(
name="Auto",
markdown_description="Automatically generate agents and tasks based on your input.",
starters=[
cl.Starter(
label="Create a movie script",
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.",
icon="/public/movie.svg",
),
cl.Starter(
label="Design a fantasy world",
message="Design a detailed fantasy world with unique geography, cultures, and magical systems. Start by describing the main continent and its inhabitants.",
icon="/public/fantasy.svg",
),
cl.Starter(
label="Write a futuristic political thriller",
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.",
icon="/public/thriller.svg",
),
cl.Starter(
label="Develop a new board game",
message="Develop a new, innovative board game. Describe the game's objective, rules, and unique mechanics. Create a scenario to illustrate gameplay.",
icon="/public/game.svg",
),
]
),
cl.ChatProfile(
name="Manual",
markdown_description="Manually define your agents and tasks using a YAML file.",
),
]


@cl.on_chat_start
async def start_chat():
cl.user_session.set(
Expand All @@ -29,6 +79,7 @@ async def start_chat():
[
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
Select(
id="Framework",
label="Framework",
Expand All @@ -37,16 +88,74 @@ async def start_chat():
),
]
).send()
# await on_settings_update(settings)
cl.user_session.set("settings", settings)
chat_profile = cl.user_session.get("chat_profile")
if chat_profile=="Manual":

agent_file = "agents.yaml"
full_agent_file_path = os.path.abspath(agent_file) # Get full path
if os.path.exists(full_agent_file_path):
with open(full_agent_file_path, 'r') as f:
yaml_content = f.read()
msg = cl.Message(content=yaml_content, language="yaml")
await msg.send()


full_tools_file_path = os.path.abspath("tools.py") # Get full path
if os.path.exists(full_tools_file_path):
with open(full_tools_file_path, 'r') as f:
tools_content = f.read()
msg = cl.Message(content=tools_content, language="python")
await msg.send()

settings = await cl.ChatSettings(
[
TextInput(id="Model", label="OpenAI - Model", initial=config_list[0]['model']),
TextInput(id="BaseUrl", label="OpenAI - Base URL", initial=config_list[0]['base_url']),
TextInput(id="ApiKey", label="OpenAI - API Key", initial=config_list[0]['api_key']),
Select(
id="Framework",
label="Framework",
values=["crewai", "autogen"],
initial_index=0,
),
TextInput(id="agents", label="agents.yaml", initial=yaml_content, multiline=True),
TextInput(id="tools", label="tools.py", initial=tools_content, multiline=True),
]
).send()
cl.user_session.set("settings", settings)

res = await cl.AskActionMessage(
content="Pick an action!",
actions=actions,
).send()
if res and res.get("value") == "modify":
await cl.Message(content="Modify the agents and tools from below settings", actions=actions).send()
elif res and res.get("value") == "run":
await main(cl.Message(content="", actions=actions))

await on_settings_update(settings)

@cl.on_settings_update
async def on_settings_update(settings):
"""Handle updates to the ChatSettings form."""
global config_list, framework
config_list[0]['model'] = settings["Model"]
config_list[0]['base_url'] = settings["BaseUrl"]
config_list[0]['api_key'] = settings["ApiKey"]
os.environ["OPENAI_API_KEY"] = config_list[0]['api_key']
os.environ["OPENAI_MODEL_NAME"] = config_list[0]['model']
os.environ["OPENAI_API_BASE"] = config_list[0]['base_url']
framework = settings["Framework"]
print("Settings updated:", settings)

if "agents" in settings:
with open("agents.yaml", "w") as f:
f.write(settings["agents"])
if "tools" in settings:
with open("tools.py", "w") as f:
f.write(settings["tools"])

print("Settings updated")

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

# @cl.step(type="tool")
# async def tool(data: Optional[str] = None, language: Optional[str] = None):
# return cl.Message(content=data, language=language)

@cl.on_message
async def main(message: cl.Message):
"""Run PraisonAI with the provided message as the topic."""
message_history = cl.user_session.get("message_history")
message_history.append({"role": "user", "content": message.content})
topic = message.content
agent_file = "test.yaml"
generator = AutoGenerator(topic=topic, framework=framework, config_list=config_list)
agent_file = generator.generate()
agents_generator = AgentsGenerator(agent_file, framework, config_list)
result = agents_generator.generate_crew_and_kickoff()
msg = cl.Message(content=result)
await msg.send()
message_history.append({"role": "assistant", "content": message.content})
chat_profile = cl.user_session.get("chat_profile")

if chat_profile == "Auto":
agent_file = "agents.yaml"
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
agent_file = generator.generate()
agents_generator = AgentsGenerator(agent_file, framework, config_list)
result = agents_generator.generate_crew_and_kickoff()
msg = cl.Message(content=result)
await msg.send()
message_history.append({"role": "assistant", "content": message.content})
else: # chat_profile == "Manual"
agent_file = "agents.yaml"
full_agent_file_path = os.path.abspath(agent_file) # Get full path
full_tools_file_path = os.path.abspath("tools.py")
if os.path.exists(full_agent_file_path):
with open(full_agent_file_path, 'r') as f:
yaml_content = f.read()
# tool_res = await tool()
msg_agents = cl.Message(content=yaml_content, language="yaml")
await msg_agents.send()
if os.path.exists(full_tools_file_path):
with open(full_tools_file_path, 'r') as f:
tools_content = f.read()
msg_tools = cl.Message(content=tools_content, language="python")
await msg_tools.send()
else:
# If the file doesn't exist, follow the same process as "Auto"
generator = AutoGenerator(topic=topic, agent_file=agent_file, framework=framework, config_list=config_list)
agent_file = generator.generate()

agents_generator = AgentsGenerator(agent_file, framework, config_list)
result = agents_generator.generate_crew_and_kickoff()
msg = cl.Message(content=result, actions=actions)
await msg.send()
message_history.append({"role": "assistant", "content": message.content})

# Load environment variables from .env file
load_dotenv()
Expand All @@ -90,4 +231,4 @@ def auth_callback(username: str, password: str):
identifier=username, metadata={"role": "ADMIN", "provider": "credentials"}
)
else:
return None
return None
2 changes: 1 addition & 1 deletion praisonai/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_dockerfile(self):
file.write("FROM python:3.11-slim\n")
file.write("WORKDIR /app\n")
file.write("COPY . .\n")
file.write("RUN pip install flask praisonai==0.0.27 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==0.0.28 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')

Expand Down
3 changes: 3 additions & 0 deletions public/fantasy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/game.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/movie.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/thriller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "PraisonAI"
version = "0.0.27"
version = "0.0.28"
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."
authors = ["Mervin Praison"]
license = ""
Expand Down

0 comments on commit 5ddb2d1

Please sign in to comment.