PraisonAI 0.0.16__tar.gz → 0.0.18__tar.gz
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.
- {praisonai-0.0.16 → praisonai-0.0.18}/PKG-INFO +2 -2
- praisonai-0.0.18/praisonai/agents_generator.py +221 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/auto.py +14 -8
- praisonai-0.0.18/praisonai/cli.py +164 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/deploy.py +28 -0
- praisonai-0.0.18/praisonai/tools/__init__.py +2 -0
- praisonai-0.0.18/praisonai/tools/autogen_tools.py +147 -0
- praisonai-0.0.18/praisonai/tools/base_tool.py +146 -0
- praisonai-0.0.18/praisonai/tools/find_params.py +116 -0
- praisonai-0.0.18/praisonai/tools/tools-autogen-decorator-example-1.py +38 -0
- praisonai-0.0.18/praisonai/tools/tools-autogen-example-1.py +44 -0
- praisonai-0.0.18/praisonai/tools/tools-autogen-example-2.py +35 -0
- praisonai-0.0.18/praisonai/tools/tools-autogen-example.py +23 -0
- praisonai-0.0.18/praisonai/tools/tools-crewai-example.py +134 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/pyproject.toml +4 -6
- praisonai-0.0.16/praisonai/cli.py +0 -202
- {praisonai-0.0.16 → praisonai-0.0.18}/README.md +0 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/__init__.py +0 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/__main__.py +0 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/test.py +0 -0
- {praisonai-0.0.16 → praisonai-0.0.18}/praisonai/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: praisonAI
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.18
|
|
4
4
|
Summary: 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.
|
|
5
5
|
Author: Mervin Praison
|
|
6
6
|
Requires-Python: >=3.10,<3.13
|
|
@@ -8,9 +8,9 @@ Classifier: Programming Language :: Python :: 3
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3.10
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
-
Provides-Extra: tools
|
|
12
11
|
Requires-Dist: Flask (>=3.0.0)
|
|
13
12
|
Requires-Dist: crewai (>=0.22.5)
|
|
13
|
+
Requires-Dist: crewai-tools (>=0.1.1,<0.2.0)
|
|
14
14
|
Requires-Dist: gradio (>=4.20.0)
|
|
15
15
|
Requires-Dist: markdown (>=3.5)
|
|
16
16
|
Requires-Dist: pyautogen (>=0.2.19)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# agents_generator.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from .version import __version__
|
|
5
|
+
import yaml, os
|
|
6
|
+
from rich import print
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
from crewai import Agent, Task, Crew
|
|
9
|
+
load_dotenv()
|
|
10
|
+
import autogen
|
|
11
|
+
import gradio as gr
|
|
12
|
+
import argparse
|
|
13
|
+
from .auto import AutoGenerator
|
|
14
|
+
from crewai_tools import *
|
|
15
|
+
from .tools import *
|
|
16
|
+
|
|
17
|
+
class AgentsGenerator:
|
|
18
|
+
def __init__(self, agent_file, framework, config_list):
|
|
19
|
+
self.agent_file = agent_file
|
|
20
|
+
self.framework = framework
|
|
21
|
+
self.config_list = config_list
|
|
22
|
+
|
|
23
|
+
def generate_crew_and_kickoff(self):
|
|
24
|
+
if self.agent_file == '/app/api:app' or self.agent_file == 'api:app':
|
|
25
|
+
self.agent_file = 'agents.yaml'
|
|
26
|
+
try:
|
|
27
|
+
with open(self.agent_file, 'r') as f:
|
|
28
|
+
config = yaml.safe_load(f)
|
|
29
|
+
except FileNotFoundError:
|
|
30
|
+
print(f"File not found: {self.agent_file}")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
topic = config['topic']
|
|
34
|
+
tools_dict = {
|
|
35
|
+
'CodeDocsSearchTool': CodeDocsSearchTool(),
|
|
36
|
+
'CSVSearchTool': CSVSearchTool(),
|
|
37
|
+
'DirectorySearchTool': DirectorySearchTool(),
|
|
38
|
+
'DOCXSearchTool': DOCXSearchTool(),
|
|
39
|
+
'DirectoryReadTool': DirectoryReadTool(),
|
|
40
|
+
'FileReadTool': FileReadTool(),
|
|
41
|
+
# 'GithubSearchTool': GithubSearchTool(),
|
|
42
|
+
# 'SeperDevTool': SeperDevTool(),
|
|
43
|
+
'TXTSearchTool': TXTSearchTool(),
|
|
44
|
+
'JSONSearchTool': JSONSearchTool(),
|
|
45
|
+
'MDXSearchTool': MDXSearchTool(),
|
|
46
|
+
'PDFSearchTool': PDFSearchTool(),
|
|
47
|
+
# 'PGSearchTool': PGSearchTool(),
|
|
48
|
+
'RagTool': RagTool(),
|
|
49
|
+
'ScrapeElementFromWebsiteTool': ScrapeElementFromWebsiteTool(),
|
|
50
|
+
'ScrapeWebsiteTool': ScrapeWebsiteTool(),
|
|
51
|
+
'WebsiteSearchTool': WebsiteSearchTool(),
|
|
52
|
+
'XMLSearchTool': XMLSearchTool(),
|
|
53
|
+
'YoutubeChannelSearchTool': YoutubeChannelSearchTool(),
|
|
54
|
+
'YoutubeVideoSearchTool': YoutubeVideoSearchTool()
|
|
55
|
+
}
|
|
56
|
+
# config['tools'] = [tools_dict[tool] for tool in config.get('tools', []) if tool in tools_dict]
|
|
57
|
+
framework = self.framework or config.get('framework')
|
|
58
|
+
|
|
59
|
+
agents = {}
|
|
60
|
+
tasks = []
|
|
61
|
+
if framework == "autogen":
|
|
62
|
+
# Load the LLM configuration dynamically
|
|
63
|
+
# print(self.config_list)
|
|
64
|
+
llm_config = {"config_list": self.config_list}
|
|
65
|
+
|
|
66
|
+
# Assuming the user proxy agent is set up as per your requirements
|
|
67
|
+
user_proxy = autogen.UserProxyAgent(
|
|
68
|
+
name="User",
|
|
69
|
+
human_input_mode="NEVER",
|
|
70
|
+
is_termination_msg=lambda x: (x.get("content") or "").rstrip().rstrip(".").lower().endswith("terminate") or "TERMINATE" in (x.get("content") or ""),
|
|
71
|
+
code_execution_config={
|
|
72
|
+
"work_dir": "coding",
|
|
73
|
+
"use_docker": False,
|
|
74
|
+
},
|
|
75
|
+
# additional setup for the user proxy agent
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
for role, details in config['roles'].items():
|
|
79
|
+
agent_name = details['role'].format(topic=topic).replace("{topic}", topic)
|
|
80
|
+
agent_goal = details['goal'].format(topic=topic)
|
|
81
|
+
# Creating an AssistantAgent for each role dynamically
|
|
82
|
+
agents[role] = autogen.AssistantAgent(
|
|
83
|
+
name=agent_name,
|
|
84
|
+
llm_config=llm_config,
|
|
85
|
+
system_message=details['backstory'].format(topic=topic)+". Must Reply \"TERMINATE\" in the end when everything is done.",
|
|
86
|
+
)
|
|
87
|
+
for tool in details.get('tools', []):
|
|
88
|
+
if tool in tools_dict:
|
|
89
|
+
tool_class = globals()[f'autogen_{type(tools_dict[tool]).__name__}']
|
|
90
|
+
tool_class(agents[role], user_proxy)
|
|
91
|
+
|
|
92
|
+
# Preparing tasks for initiate_chats
|
|
93
|
+
for task_name, task_details in details.get('tasks', {}).items():
|
|
94
|
+
description_filled = task_details['description'].format(topic=topic)
|
|
95
|
+
expected_output_filled = task_details['expected_output'].format(topic=topic)
|
|
96
|
+
|
|
97
|
+
chat_task = {
|
|
98
|
+
"recipient": agents[role],
|
|
99
|
+
"message": description_filled,
|
|
100
|
+
"summary_method": "last_msg",
|
|
101
|
+
# Additional fields like carryover can be added based on dependencies
|
|
102
|
+
}
|
|
103
|
+
tasks.append(chat_task)
|
|
104
|
+
|
|
105
|
+
response = user_proxy.initiate_chats(tasks)
|
|
106
|
+
result = "### Output ###\n"+response[-1].summary if hasattr(response[-1], 'summary') else ""
|
|
107
|
+
else:
|
|
108
|
+
for role, details in config['roles'].items():
|
|
109
|
+
role_filled = details['role'].format(topic=topic)
|
|
110
|
+
goal_filled = details['goal'].format(topic=topic)
|
|
111
|
+
backstory_filled = details['backstory'].format(topic=topic)
|
|
112
|
+
|
|
113
|
+
# Adding tools to the agent if exists
|
|
114
|
+
agent_tools = [tools_dict[tool] for tool in details.get('tools', []) if tool in tools_dict]
|
|
115
|
+
agent = Agent(role=role_filled, goal=goal_filled, backstory=backstory_filled, tools=agent_tools, allow_delegation=False)
|
|
116
|
+
agents[role] = agent
|
|
117
|
+
|
|
118
|
+
for task_name, task_details in details.get('tasks', {}).items():
|
|
119
|
+
description_filled = task_details['description'].format(topic=topic)
|
|
120
|
+
expected_output_filled = task_details['expected_output'].format(topic=topic)
|
|
121
|
+
|
|
122
|
+
task = Task(description=description_filled, expected_output=expected_output_filled, agent=agent)
|
|
123
|
+
tasks.append(task)
|
|
124
|
+
# print(agents)
|
|
125
|
+
crew = Crew(
|
|
126
|
+
agents=list(agents.values()),
|
|
127
|
+
tasks=tasks,
|
|
128
|
+
verbose=2
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
response = crew.kickoff()
|
|
132
|
+
result = f"### Task Output ###\n{response}"
|
|
133
|
+
return result
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# # AutoGen Tools example below
|
|
137
|
+
# from typing import Any, Optional
|
|
138
|
+
# import os
|
|
139
|
+
# from autogen import ConversableAgent
|
|
140
|
+
# from autogen_tools import autogen_ScrapeWebsiteTool
|
|
141
|
+
|
|
142
|
+
# assistant = ConversableAgent(
|
|
143
|
+
# name="Assistant",
|
|
144
|
+
# system_message="You are a helpful AI assistant. "
|
|
145
|
+
# "You can help with website scraping. "
|
|
146
|
+
# "Return 'TERMINATE' when the task is done.",
|
|
147
|
+
# llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
|
|
148
|
+
# )
|
|
149
|
+
|
|
150
|
+
# user_proxy = ConversableAgent(
|
|
151
|
+
# name="User",
|
|
152
|
+
# llm_config=False,
|
|
153
|
+
# is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
|
|
154
|
+
# human_input_mode="NEVER",
|
|
155
|
+
# )
|
|
156
|
+
|
|
157
|
+
# autogen_ScrapeWebsiteTool(assistant, user_proxy)
|
|
158
|
+
|
|
159
|
+
# chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Nodejs website.")
|
|
160
|
+
|
|
161
|
+
# # CrewAI Tools example below
|
|
162
|
+
# import os
|
|
163
|
+
# from crewai import Agent, Task, Crew
|
|
164
|
+
# # Importing crewAI tools
|
|
165
|
+
# from crewai_tools import (
|
|
166
|
+
# DirectoryReadTool,
|
|
167
|
+
# FileReadTool,
|
|
168
|
+
# SerperDevTool,
|
|
169
|
+
# WebsiteSearchTool
|
|
170
|
+
# )
|
|
171
|
+
|
|
172
|
+
# # Set up API keys
|
|
173
|
+
# os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
|
|
174
|
+
# os.environ["OPENAI_API_KEY"] = "Your Key"
|
|
175
|
+
|
|
176
|
+
# # Instantiate tools
|
|
177
|
+
# docs_tool = DirectoryReadTool(directory='./blog-posts')
|
|
178
|
+
# file_tool = FileReadTool()
|
|
179
|
+
# search_tool = SerperDevTool()
|
|
180
|
+
# web_rag_tool = WebsiteSearchTool()
|
|
181
|
+
|
|
182
|
+
# # Create agents
|
|
183
|
+
# researcher = Agent(
|
|
184
|
+
# role='Market Research Analyst',
|
|
185
|
+
# goal='Provide up-to-date market analysis of the AI industry',
|
|
186
|
+
# backstory='An expert analyst with a keen eye for market trends.',
|
|
187
|
+
# tools=[search_tool, web_rag_tool],
|
|
188
|
+
# verbose=True
|
|
189
|
+
# )
|
|
190
|
+
|
|
191
|
+
# writer = Agent(
|
|
192
|
+
# role='Content Writer',
|
|
193
|
+
# goal='Craft engaging blog posts about the AI industry',
|
|
194
|
+
# backstory='A skilled writer with a passion for technology.',
|
|
195
|
+
# tools=[docs_tool, file_tool],
|
|
196
|
+
# verbose=True
|
|
197
|
+
# )
|
|
198
|
+
|
|
199
|
+
# # Define tasks
|
|
200
|
+
# research = Task(
|
|
201
|
+
# description='Research the latest trends in the AI industry and provide a summary.',
|
|
202
|
+
# expected_output='A summary of the top 3 trending developments in the AI industry with a unique perspective on their significance.',
|
|
203
|
+
# agent=researcher
|
|
204
|
+
# )
|
|
205
|
+
|
|
206
|
+
# write = Task(
|
|
207
|
+
# description='Write an engaging blog post about the AI industry, based on the research analyst’s summary. Draw inspiration from the latest blog posts in the directory.',
|
|
208
|
+
# expected_output='A 4-paragraph blog post formatted in markdown with engaging, informative, and accessible content, avoiding complex jargon.',
|
|
209
|
+
# agent=writer,
|
|
210
|
+
# output_file='blog-posts/new_post.md' # The final blog post will be saved here
|
|
211
|
+
# )
|
|
212
|
+
|
|
213
|
+
# # Assemble a crew
|
|
214
|
+
# crew = Crew(
|
|
215
|
+
# agents=[researcher, writer],
|
|
216
|
+
# tasks=[research, write],
|
|
217
|
+
# verbose=2
|
|
218
|
+
# )
|
|
219
|
+
|
|
220
|
+
# # Execute tasks
|
|
221
|
+
# crew.kickoff()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from openai import OpenAI
|
|
2
2
|
from pydantic import BaseModel
|
|
3
|
-
from typing import Dict
|
|
3
|
+
from typing import Dict, List
|
|
4
4
|
import instructor
|
|
5
5
|
import os
|
|
6
6
|
import json
|
|
@@ -17,12 +17,13 @@ class RoleDetails(BaseModel):
|
|
|
17
17
|
goal: str
|
|
18
18
|
backstory: str
|
|
19
19
|
tasks: Dict[str, TaskDetails]
|
|
20
|
+
tools: List[str]
|
|
20
21
|
|
|
21
22
|
class TeamStructure(BaseModel):
|
|
22
23
|
roles: Dict[str, RoleDetails]
|
|
23
24
|
|
|
24
25
|
class AutoGenerator:
|
|
25
|
-
def __init__(self, topic="Movie Story writing about AI",
|
|
26
|
+
def __init__(self, topic="Movie Story writing about AI", agent_file="test.yaml", framework="crewai"):
|
|
26
27
|
self.config_list = [
|
|
27
28
|
{
|
|
28
29
|
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
|
@@ -30,7 +31,7 @@ class AutoGenerator:
|
|
|
30
31
|
}
|
|
31
32
|
]
|
|
32
33
|
self.topic = topic
|
|
33
|
-
self.
|
|
34
|
+
self.agent_file = agent_file
|
|
34
35
|
self.framework = framework
|
|
35
36
|
self.client = instructor.patch(
|
|
36
37
|
OpenAI(
|
|
@@ -52,7 +53,7 @@ class AutoGenerator:
|
|
|
52
53
|
)
|
|
53
54
|
json_data = json.loads(response.model_dump_json())
|
|
54
55
|
self.convert_and_save(json_data)
|
|
55
|
-
full_path = os.path.abspath(self.
|
|
56
|
+
full_path = os.path.abspath(self.agent_file)
|
|
56
57
|
return full_path
|
|
57
58
|
|
|
58
59
|
def convert_and_save(self, json_data):
|
|
@@ -61,7 +62,7 @@ class AutoGenerator:
|
|
|
61
62
|
Args:
|
|
62
63
|
json_data (dict): The JSON data representing the team structure.
|
|
63
64
|
topic (str, optional): The topic to be inserted into the YAML. Defaults to "Artificial Intelligence".
|
|
64
|
-
|
|
65
|
+
agent_file (str, optional): The name of the YAML file to save. Defaults to "test.yaml".
|
|
65
66
|
"""
|
|
66
67
|
|
|
67
68
|
yaml_data = {
|
|
@@ -76,7 +77,9 @@ class AutoGenerator:
|
|
|
76
77
|
"backstory": "" + role_details['backstory'],
|
|
77
78
|
"goal": role_details['goal'],
|
|
78
79
|
"role": role_details['role'],
|
|
79
|
-
"tasks": {}
|
|
80
|
+
"tasks": {},
|
|
81
|
+
# "tools": role_details.get('tools', []),
|
|
82
|
+
"tools": ['']
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
for task_id, task_details in role_details['tasks'].items():
|
|
@@ -86,7 +89,7 @@ class AutoGenerator:
|
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
# Save to YAML file, maintaining the order
|
|
89
|
-
with open(self.
|
|
92
|
+
with open(self.agent_file, 'w') as f:
|
|
90
93
|
yaml.dump(yaml_data, f, allow_unicode=True, sort_keys=False)
|
|
91
94
|
|
|
92
95
|
def get_user_content(self):
|
|
@@ -96,6 +99,8 @@ The team will work in sequence. First role will pass the output to the next role
|
|
|
96
99
|
The last role will generate the final output.
|
|
97
100
|
Think step by step.
|
|
98
101
|
With maximum 3 roles, each with 1 task. Include role goals, backstories, task descriptions, and expected outputs.
|
|
102
|
+
List of Available Tools: CodeDocsSearchTool, CSVSearchTool, DirectorySearchTool, DOCXSearchTool, DirectoryReadTool, FileReadTool, TXTSearchTool, JSONSearchTool, MDXSearchTool, PDFSearchTool, RagTool, ScrapeElementFromWebsiteTool, ScrapeWebsiteTool, WebsiteSearchTool, XMLSearchTool, YoutubeChannelSearchTool, YoutubeVideoSearchTool.
|
|
103
|
+
Only use Available Tools. Do Not use any other tools.
|
|
99
104
|
Example Below:
|
|
100
105
|
Use below example to understand the structure of the output.
|
|
101
106
|
The final role you create should satisfy the provided task: """ + self.topic + """.
|
|
@@ -105,9 +110,10 @@ The final role you create should satisfy the provided task: """ + self.topic + "
|
|
|
105
110
|
"role": "Narrative Designer",
|
|
106
111
|
"goal": "Create AI storylines",
|
|
107
112
|
"backstory": "Skilled in narrative development for AI, with a focus on story resonance.",
|
|
113
|
+
"tools": ["ScrapeWebsiteTool"],
|
|
108
114
|
"tasks": {
|
|
109
115
|
"story_concept_development": {
|
|
110
|
-
"description": "Craft a unique AI story concept with depth and engagement.",
|
|
116
|
+
"description": "Craft a unique AI story concept with depth and engagement using concept from this page the content https://www.asthebirdfliesblog.com/posts/how-to-write-book-story-development .",
|
|
111
117
|
"expected_output": "Document with narrative arcs, character bios, and settings."
|
|
112
118
|
}
|
|
113
119
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# praisonai/cli.py
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from .version import __version__
|
|
5
|
+
import yaml, os
|
|
6
|
+
from rich import print
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
from crewai import Agent, Task, Crew
|
|
9
|
+
load_dotenv()
|
|
10
|
+
import autogen
|
|
11
|
+
import gradio as gr
|
|
12
|
+
import argparse
|
|
13
|
+
from .auto import AutoGenerator
|
|
14
|
+
from .agents_generator import AgentsGenerator
|
|
15
|
+
from crewai_tools import *
|
|
16
|
+
from .tools import *
|
|
17
|
+
|
|
18
|
+
class PraisonAI:
|
|
19
|
+
def __init__(self, agent_file="agents.yaml", framework="crewai", auto=False, init=False):
|
|
20
|
+
self.config_list = [
|
|
21
|
+
{
|
|
22
|
+
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
|
23
|
+
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
self.agent_file = agent_file
|
|
27
|
+
self.framework = framework
|
|
28
|
+
self.auto = auto
|
|
29
|
+
self.init = init
|
|
30
|
+
|
|
31
|
+
def main(self):
|
|
32
|
+
args = self.parse_args()
|
|
33
|
+
if args is None:
|
|
34
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
35
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
36
|
+
return result
|
|
37
|
+
if args.deploy:
|
|
38
|
+
from .deploy import CloudDeployer
|
|
39
|
+
deployer = CloudDeployer()
|
|
40
|
+
deployer.run_commands()
|
|
41
|
+
return
|
|
42
|
+
invocation_cmd = "praisonai"
|
|
43
|
+
version_string = f"PraisonAI version {__version__}"
|
|
44
|
+
|
|
45
|
+
if args.framework:
|
|
46
|
+
self.framework = args.framework
|
|
47
|
+
|
|
48
|
+
ui = args.ui
|
|
49
|
+
|
|
50
|
+
if args.agent_file:
|
|
51
|
+
if args.agent_file == "tests.test": # Argument used for testing purposes
|
|
52
|
+
full_path = os.path.abspath("agents.yaml")
|
|
53
|
+
else:
|
|
54
|
+
full_path = os.path.abspath(args.agent_file)
|
|
55
|
+
self.agent_file = full_path
|
|
56
|
+
else:
|
|
57
|
+
full_path = os.path.abspath(self.agent_file)
|
|
58
|
+
self.agent_file = full_path
|
|
59
|
+
|
|
60
|
+
if args.auto or args.init:
|
|
61
|
+
temp_topic = ' '.join(args.auto) if args.auto else ' '.join(args.init)
|
|
62
|
+
self.topic = temp_topic
|
|
63
|
+
elif self.auto or self.init: # Use the auto attribute if args.auto is not provided
|
|
64
|
+
self.topic = self.auto
|
|
65
|
+
|
|
66
|
+
if args.auto or self.auto:
|
|
67
|
+
self.agent_file = "test.yaml"
|
|
68
|
+
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
|
|
69
|
+
self.agent_file = generator.generate()
|
|
70
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
71
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
72
|
+
return result
|
|
73
|
+
elif args.init or self.init:
|
|
74
|
+
self.agent_file = "agents.yaml"
|
|
75
|
+
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
|
|
76
|
+
self.agent_file = generator.generate()
|
|
77
|
+
print("File {} created successfully".format(self.agent_file))
|
|
78
|
+
return "File {} created successfully".format(self.agent_file)
|
|
79
|
+
|
|
80
|
+
if ui:
|
|
81
|
+
self.create_gradio_interface()
|
|
82
|
+
else:
|
|
83
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
84
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
85
|
+
return result
|
|
86
|
+
|
|
87
|
+
def parse_args(self):
|
|
88
|
+
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
|
|
89
|
+
parser.add_argument("--framework", choices=["crewai", "autogen"], default="crewai", help="Specify the framework")
|
|
90
|
+
parser.add_argument("--ui", action="store_true", help="Enable UI mode")
|
|
91
|
+
parser.add_argument("--auto", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
|
|
92
|
+
parser.add_argument("--init", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
|
|
93
|
+
parser.add_argument("agent_file", nargs="?", help="Specify the agent file")
|
|
94
|
+
parser.add_argument("--deploy", action="store_true", help="Deploy the application") # New argument
|
|
95
|
+
|
|
96
|
+
args, unknown_args = parser.parse_known_args()
|
|
97
|
+
|
|
98
|
+
if unknown_args and unknown_args[0] == '-b' and unknown_args[1] == 'api:app':
|
|
99
|
+
args.agent_file = 'agents.yaml'
|
|
100
|
+
if args.agent_file == 'api:app' or args.agent_file == '/app/api:app':
|
|
101
|
+
args.agent_file = 'agents.yaml'
|
|
102
|
+
|
|
103
|
+
return args
|
|
104
|
+
|
|
105
|
+
def create_gradio_interface(self):
|
|
106
|
+
def generate_crew_and_kickoff_interface(auto_args, framework):
|
|
107
|
+
self.framework = framework
|
|
108
|
+
self.agent_file = "test.yaml"
|
|
109
|
+
generator = AutoGenerator(topic=auto_args , framework=self.framework)
|
|
110
|
+
self.agent_file = generator.generate()
|
|
111
|
+
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
|
112
|
+
result = agents_generator.generate_crew_and_kickoff()
|
|
113
|
+
return result
|
|
114
|
+
|
|
115
|
+
gr.Interface(
|
|
116
|
+
fn=generate_crew_and_kickoff_interface,
|
|
117
|
+
inputs=[gr.Textbox(lines=2, label="Auto Args"), gr.Dropdown(choices=["crewai", "autogen"], label="Framework")],
|
|
118
|
+
outputs="textbox",
|
|
119
|
+
title="Praison AI Studio",
|
|
120
|
+
description="Create Agents and perform tasks",
|
|
121
|
+
theme="default"
|
|
122
|
+
).launch()
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
praison_ai = PraisonAI()
|
|
126
|
+
praison_ai.main()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## agents.yaml
|
|
131
|
+
# framework: autogen
|
|
132
|
+
# topic: create movie script about cat in mars
|
|
133
|
+
# roles:
|
|
134
|
+
# concept_developer:
|
|
135
|
+
# backstory: Experienced in creating captivating and original story concepts.
|
|
136
|
+
# goal: Generate a unique concept for a movie script about a cat in Mars
|
|
137
|
+
# role: Concept Developer
|
|
138
|
+
# tools:
|
|
139
|
+
# - search_tool
|
|
140
|
+
# tasks:
|
|
141
|
+
# concept_generation:
|
|
142
|
+
# description: Develop a unique and engaging concept for a movie script about
|
|
143
|
+
# a cat in Mars.
|
|
144
|
+
# expected_output: A detailed concept document for the movie script.
|
|
145
|
+
# scriptwriter:
|
|
146
|
+
# backstory: Expert in dialogue and script structure, translating concepts into
|
|
147
|
+
# scripts.
|
|
148
|
+
# goal: Write a script based on the movie concept
|
|
149
|
+
# role: Scriptwriter
|
|
150
|
+
# tasks:
|
|
151
|
+
# scriptwriting_task:
|
|
152
|
+
# description: Turn the movie concept into a script, including dialogue and
|
|
153
|
+
# scenes.
|
|
154
|
+
# expected_output: A production-ready script for the movie about a cat in Mars.
|
|
155
|
+
# director:
|
|
156
|
+
# backstory: Experienced in visualizing scripts and creating compelling storyboards.
|
|
157
|
+
# goal: Create a storyboard and visualize the script
|
|
158
|
+
# role: Director
|
|
159
|
+
# tasks:
|
|
160
|
+
# storyboard_creation:
|
|
161
|
+
# description: Create a storyboard for the movie script about a cat in Mars.
|
|
162
|
+
# expected_output: A detailed storyboard for the movie about a cat in Mars.
|
|
163
|
+
# dependencies: []
|
|
164
|
+
|
|
@@ -8,6 +8,32 @@ class CloudDeployer:
|
|
|
8
8
|
load_dotenv()
|
|
9
9
|
self.set_environment_variables()
|
|
10
10
|
|
|
11
|
+
def create_dockerfile(self):
|
|
12
|
+
with open("Dockerfile", "w") as file:
|
|
13
|
+
file.write("FROM python:3.11-slim\n")
|
|
14
|
+
file.write("WORKDIR /app\n")
|
|
15
|
+
file.write("COPY . .\n")
|
|
16
|
+
file.write("RUN pip install flask praisonai==0.0.18 gunicorn markdown\n")
|
|
17
|
+
file.write("EXPOSE 8080\n")
|
|
18
|
+
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
|
19
|
+
|
|
20
|
+
def create_api_file(self):
|
|
21
|
+
with open("api.py", "w") as file:
|
|
22
|
+
file.write("from flask import Flask\n")
|
|
23
|
+
file.write("from praisonai import PraisonAI\n")
|
|
24
|
+
file.write("import markdown\n\n")
|
|
25
|
+
file.write("app = Flask(__name__)\n\n")
|
|
26
|
+
file.write("def basic():\n")
|
|
27
|
+
file.write(" praison_ai = PraisonAI(agent_file=\"agents.yaml\")\n")
|
|
28
|
+
file.write(" return praison_ai.main()\n\n")
|
|
29
|
+
file.write("@app.route('/')\n")
|
|
30
|
+
file.write("def home():\n")
|
|
31
|
+
file.write(" output = basic()\n")
|
|
32
|
+
file.write(" html_output = markdown.markdown(output)\n")
|
|
33
|
+
file.write(" return f'<html><body>{html_output}</body></html>'\n\n")
|
|
34
|
+
file.write("if __name__ == \"__main__\":\n")
|
|
35
|
+
file.write(" app.run(debug=True)\n")
|
|
36
|
+
|
|
11
37
|
def set_environment_variables(self):
|
|
12
38
|
"""Sets environment variables with fallback to .env values or defaults."""
|
|
13
39
|
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4-turbo-preview")
|
|
@@ -15,6 +41,8 @@ class CloudDeployer:
|
|
|
15
41
|
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
|
16
42
|
|
|
17
43
|
def run_commands(self):
|
|
44
|
+
self.create_api_file()
|
|
45
|
+
self.create_dockerfile()
|
|
18
46
|
"""Runs a sequence of shell commands for deployment, continues on error."""
|
|
19
47
|
commands = [
|
|
20
48
|
"yes | gcloud auth configure-docker us-central1-docker.pkg.dev",
|