mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-08 01:08:39 -10:00
Adding Docs and Updating
This commit is contained in:
1 parent
03c7be5357
commit
986e4a0088
15 files changed
+1295
-966
No files matched your search
+1
-1
@@ -1,3 +1,3 @@
|
||||
OPENAI_MODEL_NAME="gpt-4-turbo-preview"
|
||||
OPENAI_MODEL_NAME="gpt-4o"
|
||||
OPENAI_API_KEY="Enter your API key"
|
||||
OPENAI_API_BASE="https://api.openai.com/v1"
|
||||
@@ -19,6 +19,8 @@ watch.sh
|
||||
docs.sh
|
||||
other
|
||||
|
||||
.chainlit
|
||||
|
||||
site
|
||||
# Ignore Sphinx build directory
|
||||
docs/_build/
|
||||
|
||||
@@ -220,6 +220,12 @@ if __name__ == "__main__":
|
||||
auto()
|
||||
```
|
||||
|
||||
## Include CrewAI Tools
|
||||
|
||||
```
|
||||
pip install "praisonai[crewai-tools]"
|
||||
```
|
||||
|
||||
## Deploy
|
||||
|
||||
```bash
|
||||
@@ -228,7 +234,7 @@ gcloud services enable run.googleapis.com
|
||||
gcloud services enable containerregistry.googleapis.com
|
||||
gcloud services enable cloudbuild.googleapis.com
|
||||
|
||||
export OPENAI_MODEL_NAME="gpt-4-turbo-preview"
|
||||
export OPENAI_MODEL_NAME="gpt-4o"
|
||||
export OPENAI_API_KEY="Enter your API key"
|
||||
export OPENAI_API_BASE="https://api.openai.com/v1"
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
framework: crewai
|
||||
framework: autogen
|
||||
topic: research about the causes of lung disease
|
||||
roles:
|
||||
research_analyst:
|
||||
|
||||
@@ -54,7 +54,7 @@ class AutoGenerator:
|
||||
def __init__(self, topic="Movie Story writing about AI", agent_file="test.yaml", framework="crewai"):
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
@@ -190,7 +190,7 @@ The final role you create should satisfy the provided task: """ + se
|
||||
def __init__(self, topic="Movie Story writing about AI", agent_file="test.yaml", framework="crewai"):
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
|
||||
@@ -46,7 +46,7 @@ class PraisonAI:
|
||||
def __init__(self, agent_file="agents.yaml", framework="crewai", auto=False, init=False):
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
@@ -170,7 +170,7 @@ if __name__ == "__main__":
|
||||
def __init__(self, agent_file="agents.yaml", framework="crewai", auto=False, init=False):
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
|
||||
@@ -64,7 +64,7 @@ class CloudDeployer:
|
||||
|
||||
def set_environment_variables(self):
|
||||
"""Sets environment variables with fallback to .env values or defaults."""
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4-turbo-preview")
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
||||
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "Enter your API key")
|
||||
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
||||
|
||||
@@ -146,7 +146,7 @@ if __name__ == "__main__":
|
||||
|
||||
def set_environment_variables(self):
|
||||
"""Sets environment variables with fallback to .env values or defaults."""
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4-turbo-preview")
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
||||
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "Enter your API key")
|
||||
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
||||
|
||||
@@ -259,7 +259,7 @@ if __name__ == "__main__":
|
||||
</summary>
|
||||
<pre><code class="python">def set_environment_variables(self):
|
||||
"""Sets environment variables with fallback to .env values or defaults."""
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4-turbo-preview")
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
||||
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "Enter your API key")
|
||||
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")</code></pre>
|
||||
</details>
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ gcloud services enable run.googleapis.com
|
||||
gcloud services enable containerregistry.googleapis.com
|
||||
gcloud services enable cloudbuild.googleapis.com
|
||||
|
||||
export OPENAI_MODEL_NAME="gpt-4-turbo-preview"
|
||||
export OPENAI_MODEL_NAME="gpt-4o"
|
||||
export OPENAI_API_KEY="Enter your API key"
|
||||
export OPENAI_API_BASE="https://api.openai.com/v1"
|
||||
|
||||
|
||||
Generated
+1128
-945
File diff suppressed because it is too large.
Load diff
@@ -6,6 +6,7 @@ import yaml, os
|
||||
from rich import print
|
||||
from dotenv import load_dotenv
|
||||
from crewai import Agent, Task, Crew
|
||||
from crewai.telemetry import Telemetry
|
||||
load_dotenv()
|
||||
import autogen
|
||||
import gradio as gr
|
||||
@@ -23,7 +24,19 @@ from pathlib import Path
|
||||
import importlib
|
||||
import importlib.util
|
||||
from praisonai_tools import BaseTool
|
||||
import os
|
||||
|
||||
os.environ["OTEL_SDK_DISABLED"] = "true"
|
||||
|
||||
def noop(*args, **kwargs):
|
||||
pass
|
||||
|
||||
def disable_crewai_telemetry():
|
||||
for attr in dir(Telemetry):
|
||||
if callable(getattr(Telemetry, attr)) and not attr.startswith("__"):
|
||||
setattr(Telemetry, attr, noop)
|
||||
|
||||
disable_crewai_telemetry()
|
||||
class AgentsGenerator:
|
||||
def __init__(self, agent_file, framework, config_list):
|
||||
self.agent_file = agent_file
|
||||
@@ -179,4 +192,4 @@ class AgentsGenerator:
|
||||
|
||||
response = crew.kickoff()
|
||||
result = f"### Task Output ###\n{response}"
|
||||
return result
|
||||
return result
|
||||
+49
-2
@@ -24,9 +24,25 @@ class TeamStructure(BaseModel):
|
||||
|
||||
class AutoGenerator:
|
||||
def __init__(self, topic="Movie Story writing about AI", agent_file="test.yaml", framework="crewai"):
|
||||
"""
|
||||
Initialize the AutoGenerator class with the specified topic, agent file, and framework.
|
||||
note: autogen framework is different from this AutoGenerator class.
|
||||
|
||||
Args:
|
||||
topic (str, optional): The topic for the generated team structure. Defaults to "Movie Story writing about AI".
|
||||
agent_file (str, optional): The name of the YAML file to save the generated team structure. Defaults to "test.yaml".
|
||||
framework (str, optional): The framework for the generated team structure. Defaults to "crewai".
|
||||
|
||||
Attributes:
|
||||
config_list (list): A list containing the configuration details for the OpenAI API.
|
||||
topic (str): The specified topic for the generated team structure.
|
||||
agent_file (str): The specified name of the YAML file to save the generated team structure.
|
||||
framework (str): The specified framework for the generated team structure.
|
||||
client (instructor.Client): An instance of the instructor.Client class initialized with the specified OpenAI API configuration.
|
||||
"""
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
@@ -42,6 +58,23 @@ class AutoGenerator:
|
||||
)
|
||||
|
||||
def generate(self):
|
||||
"""
|
||||
Generates a team structure for the specified topic.
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
str: The full path of the YAML file containing the generated team structure.
|
||||
|
||||
Raises:
|
||||
Exception: If the generation process fails.
|
||||
|
||||
Usage:
|
||||
generator = AutoGenerator(framework="crewai", topic="Create a movie script about Cat in Mars")
|
||||
path = generator.generate()
|
||||
print(path)
|
||||
"""
|
||||
response = self.client.chat.completions.create(
|
||||
model=self.config_list[0]['model'],
|
||||
response_model=TeamStructure,
|
||||
@@ -93,6 +126,20 @@ class AutoGenerator:
|
||||
yaml.dump(yaml_data, f, allow_unicode=True, sort_keys=False)
|
||||
|
||||
def get_user_content(self):
|
||||
"""
|
||||
Generates a prompt for the OpenAI API to generate a team structure.
|
||||
|
||||
Args:
|
||||
None
|
||||
|
||||
Returns:
|
||||
str: The prompt for the OpenAI API.
|
||||
|
||||
Usage:
|
||||
generator = AutoGenerator(framework="crewai", topic="Create a movie script about Cat in Mars")
|
||||
prompt = generator.get_user_content()
|
||||
print(prompt)
|
||||
"""
|
||||
user_content = """Generate a team structure for \"""" + self.topic + """\" task.
|
||||
No Input data will be provided to the team.
|
||||
The team will work in sequence. First role will pass the output to the next role, and so on.
|
||||
@@ -135,5 +182,5 @@ The final role you create should satisfy the provided task: """ + self.topic + "
|
||||
return user_content
|
||||
|
||||
|
||||
# generator = AutoGenerator(framework="crewai", topic="Create a snake game in python")
|
||||
# generator = AutoGenerator(framework="crewai", topic="Create a movie script about Cat in Mars")
|
||||
# print(generator.generate())
|
||||
+81
-3
@@ -16,9 +16,25 @@ from .inbuilt_tools import *
|
||||
|
||||
class PraisonAI:
|
||||
def __init__(self, agent_file="agents.yaml", framework="crewai", auto=False, init=False):
|
||||
"""
|
||||
Initialize the PraisonAI object with default parameters.
|
||||
|
||||
Parameters:
|
||||
agent_file (str): The default agent file to use. Defaults to "agents.yaml".
|
||||
framework (str): The default framework to use. Defaults to "crewai".
|
||||
auto (bool): A flag indicating whether to enable auto mode. Defaults to False.
|
||||
init (bool): A flag indicating whether to enable initialization mode. Defaults to False.
|
||||
|
||||
Attributes:
|
||||
config_list (list): A list of configuration dictionaries for the OpenAI API.
|
||||
agent_file (str): The agent file to use.
|
||||
framework (str): The framework to use.
|
||||
auto (bool): A flag indicating whether to enable auto mode.
|
||||
init (bool): A flag indicating whether to enable initialization mode.
|
||||
"""
|
||||
self.config_list = [
|
||||
{
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4-turbo-preview"),
|
||||
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-4o"),
|
||||
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
|
||||
}
|
||||
]
|
||||
@@ -28,6 +44,19 @@ class PraisonAI:
|
||||
self.init = init
|
||||
|
||||
def main(self):
|
||||
"""
|
||||
The main function of the PraisonAI object. It parses the command-line arguments,
|
||||
initializes the necessary attributes, and then calls the appropriate methods based on the
|
||||
provided arguments.
|
||||
|
||||
Args:
|
||||
self (PraisonAI): An instance of the PraisonAI class.
|
||||
|
||||
Returns:
|
||||
Any: Depending on the arguments provided, the function may return a result from the
|
||||
AgentsGenerator, a deployment result from the CloudDeployer, or a message indicating
|
||||
the successful creation of a file.
|
||||
"""
|
||||
args = self.parse_args()
|
||||
if args is None:
|
||||
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
|
||||
@@ -40,8 +69,9 @@ class PraisonAI:
|
||||
return
|
||||
invocation_cmd = "praisonai"
|
||||
version_string = f"PraisonAI version {__version__}"
|
||||
if args.framework:
|
||||
self.framework = args.framework
|
||||
|
||||
self.framework = args.framework or self.framework
|
||||
|
||||
ui = args.ui
|
||||
if args.agent_file:
|
||||
if args.agent_file.startswith("tests.test"): # Argument used for testing purposes
|
||||
@@ -78,6 +108,22 @@ class PraisonAI:
|
||||
return result
|
||||
|
||||
def parse_args(self):
|
||||
"""
|
||||
Parse the command-line arguments for the PraisonAI CLI.
|
||||
|
||||
Args:
|
||||
self (PraisonAI): An instance of the PraisonAI class.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: An object containing the parsed command-line arguments.
|
||||
|
||||
Raises:
|
||||
argparse.ArgumentError: If the arguments provided are invalid.
|
||||
|
||||
Example:
|
||||
>>> args = praison_ai.parse_args()
|
||||
>>> print(args.agent_file) # Output: 'agents.yaml'
|
||||
"""
|
||||
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
|
||||
parser.add_argument("--framework", choices=["crewai", "autogen"], help="Specify the framework")
|
||||
parser.add_argument("--ui", action="store_true", help="Enable UI mode")
|
||||
@@ -96,7 +142,39 @@ class PraisonAI:
|
||||
return args
|
||||
|
||||
def create_gradio_interface(self):
|
||||
"""
|
||||
Create a Gradio interface for generating agents and performing tasks.
|
||||
|
||||
Args:
|
||||
self (PraisonAI): An instance of the PraisonAI class.
|
||||
|
||||
Returns:
|
||||
None: This method does not return any value. It launches the Gradio interface.
|
||||
|
||||
Raises:
|
||||
None: This method does not raise any exceptions.
|
||||
|
||||
Example:
|
||||
>>> praison_ai.create_gradio_interface()
|
||||
"""
|
||||
def generate_crew_and_kickoff_interface(auto_args, framework):
|
||||
"""
|
||||
Generate a crew and kick off tasks based on the provided auto arguments and framework.
|
||||
|
||||
Args:
|
||||
auto_args (list): Topic.
|
||||
framework (str): The framework to use for generating agents.
|
||||
|
||||
Returns:
|
||||
str: A string representing the result of generating the crew and kicking off tasks.
|
||||
|
||||
Raises:
|
||||
None: This method does not raise any exceptions.
|
||||
|
||||
Example:
|
||||
>>> result = generate_crew_and_kickoff_interface("Create a movie about Cat in Mars", "crewai")
|
||||
>>> print(result)
|
||||
"""
|
||||
self.framework = framework
|
||||
self.agent_file = "test.yaml"
|
||||
generator = AutoGenerator(topic=auto_args , framework=self.framework)
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class CloudDeployer:
|
||||
|
||||
def set_environment_variables(self):
|
||||
"""Sets environment variables with fallback to .env values or defaults."""
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4-turbo-preview")
|
||||
os.environ["OPENAI_MODEL_NAME"] = os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
||||
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY", "Enter your API key")
|
||||
os.environ["OPENAI_API_BASE"] = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1")
|
||||
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@ packages = ["PraisonAI"]
|
||||
python = ">=3.10,<3.13"
|
||||
rich = ">=13.7"
|
||||
pyautogen = ">=0.2.19"
|
||||
crewai = ">=0.22.5"
|
||||
crewai = ">=0.30.4"
|
||||
gradio = ">=4.20.0"
|
||||
Flask = ">=3.0.0"
|
||||
markdown = ">=3.5"
|
||||
crewai-tools = "^0.1.1"
|
||||
crewai-tools = "^0.2.6"
|
||||
praisonai-tools = ">=0.0.4"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
rich>=13.7
|
||||
pyautogen>=0.2.19
|
||||
crewai>=0.22.5
|
||||
crewai>=0.30.4
|
||||
gradio>=4.20.0
|
||||
Reference in new issue
Block a user