mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-08 08:11:07 -10:00
v0.0.38 Adding Ability for Each Agent to use Different LLM - CrewAI
This commit is contained in:
1 parent
c4bd11f877
commit
62e2e3f557
16 files changed
+935
-241
No files matched your search
+6
-1
@@ -38,5 +38,10 @@ docs/_build/.buildinfo
|
||||
docs/_build/.buildinfo/*
|
||||
docs/_build/.buildinfo/.buildinfo
|
||||
|
||||
praisonai/doc
|
||||
|
||||
# agentops
|
||||
trained_agents_data.pkl
|
||||
trained_agents_data.pkl
|
||||
|
||||
# crewAI
|
||||
crewAI
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FROM python:3.11-slim
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN pip install flask praisonai==0.0.37 gunicorn markdown
|
||||
RUN pip install flask praisonai==0.0.38 gunicorn markdown
|
||||
EXPOSE 8080
|
||||
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
|
||||
@@ -329,3 +329,6 @@ OPENAI_API_KEY=your-mistral-api-key
|
||||
- Submit a pull request via GitHub's web interface.
|
||||
- Await feedback from project maintainers.
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://docs.praison.ai)
|
||||
@@ -0,0 +1,58 @@
|
||||
framework: crewai
|
||||
topic: research about the causes of lung disease
|
||||
roles:
|
||||
research_analyst:
|
||||
backstory: Experienced in analyzing scientific data related to respiratory health.
|
||||
goal: Analyze data on lung diseases
|
||||
role: Research Analyst
|
||||
llm:
|
||||
model: "groq/llama3-70b-8192"
|
||||
function_calling_llm:
|
||||
model: "google/gemini-1.5-flash-001"
|
||||
allow_delegation: False
|
||||
max_execution_time:
|
||||
max_iter:
|
||||
max_rpm:
|
||||
verbose: True
|
||||
cache: True
|
||||
system_template:
|
||||
prompt_template:
|
||||
response_template:
|
||||
tasks:
|
||||
data_analysis:
|
||||
description: Gather and analyze data on the causes and risk factors of lung
|
||||
diseases.
|
||||
expected_output: Report detailing key findings on lung disease causes.
|
||||
tools:
|
||||
- 'InternetSearchTool'
|
||||
medical_writer:
|
||||
backstory: Skilled in translating complex medical information into accessible
|
||||
content.
|
||||
goal: Compile comprehensive content on lung disease causes
|
||||
role: Medical Writer
|
||||
llm:
|
||||
model: "anthropic/claude-3-haiku-20240307"
|
||||
function_calling_llm:
|
||||
model: "openai/gpt-4o"
|
||||
tasks:
|
||||
content_creation:
|
||||
description: Create detailed content summarizing the research findings on
|
||||
lung disease causes.
|
||||
expected_output: Document outlining various causes and risk factors of lung
|
||||
diseases.
|
||||
tools:
|
||||
- ''
|
||||
editor:
|
||||
backstory: Proficient in editing medical content for accuracy and clarity.
|
||||
goal: Review and refine content on lung disease causes
|
||||
role: Editor
|
||||
llm:
|
||||
model: "cohere/command-r"
|
||||
tasks:
|
||||
content_review:
|
||||
description: Edit and refine the compiled content on lung disease causes for
|
||||
accuracy and coherence.
|
||||
expected_output: Finalized document on lung disease causes ready for dissemination.
|
||||
tools:
|
||||
- ''
|
||||
dependencies: []
|
||||
+31
-34
@@ -1,42 +1,39 @@
|
||||
framework: autogen
|
||||
topic: create movie script about cat in mars
|
||||
topic: research about the causes of lung disease
|
||||
roles:
|
||||
researcher:
|
||||
backstory: Skilled in finding and organizing information, with a focus on research
|
||||
efficiency.
|
||||
goal: Gather information about Mars and cats
|
||||
role: Researcher
|
||||
research_analyst:
|
||||
backstory: Experienced in analyzing scientific data related to respiratory health.
|
||||
goal: Analyze data on lung diseases
|
||||
role: Research Analyst
|
||||
tasks:
|
||||
gather_research:
|
||||
description: Research and gather information about Mars, its environment,
|
||||
and cats, including their behavior and characteristics.
|
||||
expected_output: Document with research findings, including interesting facts
|
||||
and information.
|
||||
data_analysis:
|
||||
description: Gather and analyze data on the causes and risk factors of lung
|
||||
diseases.
|
||||
expected_output: Report detailing key findings on lung disease causes.
|
||||
tools:
|
||||
- 'InternetSearchTool'
|
||||
medical_writer:
|
||||
backstory: Skilled in translating complex medical information into accessible
|
||||
content.
|
||||
goal: Compile comprehensive content on lung disease causes
|
||||
role: Medical Writer
|
||||
tasks:
|
||||
content_creation:
|
||||
description: Create detailed content summarizing the research findings on
|
||||
lung disease causes.
|
||||
expected_output: Document outlining various causes and risk factors of lung
|
||||
diseases.
|
||||
tools:
|
||||
- ''
|
||||
world_builder:
|
||||
backstory: Expert in building rich, immersive worlds, with a focus on environment
|
||||
and setting.
|
||||
goal: Create a rich and immersive environment for the movie script
|
||||
role: World Builder
|
||||
editor:
|
||||
backstory: Proficient in editing medical content for accuracy and clarity.
|
||||
goal: Review and refine content on lung disease causes
|
||||
role: Editor
|
||||
tasks:
|
||||
world_building:
|
||||
description: Using the research, create a rich and immersive environment for
|
||||
the movie script, including Martian landscapes and cat habitats.
|
||||
expected_output: Document with world-building details, including settings,
|
||||
landscapes, and habitats.
|
||||
content_review:
|
||||
description: Edit and refine the compiled content on lung disease causes for
|
||||
accuracy and coherence.
|
||||
expected_output: Finalized document on lung disease causes ready for dissemination.
|
||||
tools:
|
||||
- ''
|
||||
scriptwriter:
|
||||
backstory: Expert in dialogue and script structure, translating concepts into
|
||||
scripts.
|
||||
goal: Write a movie script about a cat in Mars
|
||||
role: Scriptwriter
|
||||
tasks:
|
||||
scriptwriting_task:
|
||||
description: Using the research and world-building details, write a movie
|
||||
script about a cat in Mars, including dialogue and scenes.
|
||||
expected_output: Production-ready script with dialogue and scene details.
|
||||
tools:
|
||||
- ''
|
||||
dependencies: []
|
||||
dependencies: []
|
||||
@@ -110,7 +110,7 @@ Loads environment variables from .env file or system and sets them.</p>
|
||||
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.37 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==0.0.38 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
Generated
+585
-194
File diff suppressed because it is too large.
Load diff
@@ -18,6 +18,7 @@ from praisonai_tools import (
|
||||
YoutubeVideoSearchTool
|
||||
)
|
||||
from .inbuilt_tools import *
|
||||
from .inc import PraisonAIModel
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
import importlib
|
||||
@@ -270,7 +271,7 @@ class AgentsGenerator:
|
||||
result = "### Output ###\n"+response[-1].summary if hasattr(response[-1], 'summary') else ""
|
||||
if agentops_exists:
|
||||
agentops.end_session("Success")
|
||||
else:
|
||||
else: # framework=crewai
|
||||
if agentops_exists:
|
||||
agentops.init(os.environ.get("AGENTOPS_API_KEY"), tags=["crewai"])
|
||||
for role, details in config['roles'].items():
|
||||
@@ -280,7 +281,40 @@ class AgentsGenerator:
|
||||
|
||||
# Adding tools to the agent if exists
|
||||
agent_tools = [tools_dict[tool] for tool in details.get('tools', []) if tool in tools_dict]
|
||||
agent = Agent(role=role_filled, goal=goal_filled, backstory=backstory_filled, tools=agent_tools, allow_delegation=False)
|
||||
|
||||
llm_model = details.get('llm') # Get the llm configuration
|
||||
if llm_model:
|
||||
llm = PraisonAIModel(
|
||||
model=llm_model.get("model", os.environ.get("MODEL_NAME", "openai/gpt-4o")),
|
||||
).get_model()
|
||||
else:
|
||||
llm = PraisonAIModel().get_model()
|
||||
|
||||
function_calling_llm_model = details.get('function_calling_llm')
|
||||
if function_calling_llm_model:
|
||||
function_calling_llm = PraisonAIModel(
|
||||
model=function_calling_llm_model.get("model", os.environ.get("MODEL_NAME", "openai/gpt-4o")),
|
||||
).get_model()
|
||||
else:
|
||||
function_calling_llm = PraisonAIModel().get_model()
|
||||
|
||||
agent = Agent(
|
||||
role=role_filled,
|
||||
goal=goal_filled,
|
||||
backstory=backstory_filled,
|
||||
tools=agent_tools,
|
||||
allow_delegation=details.get('allow_delegation', False),
|
||||
llm=llm,
|
||||
function_calling_llm=function_calling_llm,
|
||||
max_iter=details.get('max_iter', 15),
|
||||
max_rpm=details.get('max_rpm'),
|
||||
max_execution_time=details.get('max_execution_time'),
|
||||
verbose=details.get('verbose', True),
|
||||
cache=details.get('cache', True),
|
||||
system_template=details.get('system_template'),
|
||||
prompt_template=details.get('prompt_template'),
|
||||
response_template=details.get('response_template'),
|
||||
)
|
||||
|
||||
# Set agent callback if provided
|
||||
if self.agent_callback:
|
||||
|
||||
@@ -6,6 +6,8 @@ import os
|
||||
import json
|
||||
import yaml
|
||||
from rich import print
|
||||
import logging
|
||||
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper(), format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Define Pydantic models outside of the generate method
|
||||
class TaskDetails(BaseModel):
|
||||
|
||||
@@ -10,6 +10,8 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
from contextlib import redirect_stdout
|
||||
from io import StringIO
|
||||
import logging
|
||||
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper(), format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
framework = "crewai"
|
||||
config_list = [
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class CloudDeployer:
|
||||
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.37 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==0.0.38 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# praisonai/inc/__init__.py
|
||||
from .models import PraisonAIModel
|
||||
@@ -0,0 +1,124 @@
|
||||
# praisonai/inc/models.py
|
||||
import os
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper(), format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Conditionally import modules based on availability
|
||||
try:
|
||||
from langchain_openai import ChatOpenAI # pip install langchain-openai
|
||||
OPENAI_AVAILABLE = True
|
||||
except ImportError:
|
||||
OPENAI_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from langchain_google_genai import ChatGoogleGenerativeAI # pip install langchain-google-genai
|
||||
GOOGLE_GENAI_AVAILABLE = True
|
||||
except ImportError:
|
||||
GOOGLE_GENAI_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from langchain_anthropic import ChatAnthropic # pip install langchain-anthropic
|
||||
ANTHROPIC_AVAILABLE = True
|
||||
except ImportError:
|
||||
ANTHROPIC_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from langchain_cohere import ChatCohere # pip install langchain-cohere
|
||||
COHERE_AVAILABLE = True
|
||||
except ImportError:
|
||||
COHERE_AVAILABLE = False
|
||||
|
||||
class PraisonAIModel:
|
||||
def __init__(self, model=None, api_key_var=None, base_url=None):
|
||||
"""
|
||||
Initializes the PraisonAIModel with the provided parameters or environment variables.
|
||||
|
||||
Args:
|
||||
model (str, optional): The name of the OpenAI model. Defaults to None.
|
||||
api_key_var (str, optional): The OpenAI API key. Defaults to None.
|
||||
base_url (str, optional): The base URL for the OpenAI API. Defaults to None.
|
||||
"""
|
||||
self.model = model or os.getenv("OPENAI_MODEL_NAME", "gpt-4o")
|
||||
if self.model.startswith("openai/"):
|
||||
self.api_key_var = "OPENAI_API_KEY"
|
||||
self.base_url = base_url or "https://api.openai.com/v1"
|
||||
self.model_name = self.model.replace("openai/", "")
|
||||
elif self.model.startswith("groq/"):
|
||||
self.api_key_var = "GROQ_API_KEY"
|
||||
self.base_url = base_url or "https://api.groq.com/openai/v1"
|
||||
self.model_name = self.model.replace("groq/", "")
|
||||
elif self.model.startswith("cohere/"):
|
||||
self.api_key_var = "COHERE_API_KEY"
|
||||
self.base_url = ""
|
||||
self.model_name = self.model.replace("cohere/", "")
|
||||
elif self.model.startswith("ollama/"):
|
||||
self.api_key_var = "OLLAMA_API_KEY"
|
||||
self.base_url = base_url or "http://localhost:11434/v1"
|
||||
self.model_name = self.model.replace("ollama/", "")
|
||||
elif self.model.startswith("anthropic/"):
|
||||
self.api_key_var = "ANTHROPIC_API_KEY"
|
||||
self.base_url = ""
|
||||
self.model_name = self.model.replace("anthropic/", "")
|
||||
elif self.model.startswith("google/"):
|
||||
self.api_key_var = "GOOGLE_API_KEY"
|
||||
self.base_url = ""
|
||||
self.model_name = self.model.replace("google/", "")
|
||||
else:
|
||||
self.api_key_var = api_key_var or "OPENAI_API_KEY"
|
||||
self.base_url = base_url or os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1")
|
||||
self.model_name = self.model
|
||||
logger.debug(f"Initialized PraisonAIModel with model {self.model_name}, api_key_var {self.api_key_var}, and base_url {self.base_url}")
|
||||
self.api_key = os.environ.get(self.api_key_var, "nokey")
|
||||
|
||||
def get_model(self):
|
||||
"""
|
||||
Returns an instance of the langchain Chat client with the configured parameters.
|
||||
|
||||
Returns:
|
||||
Chat: An instance of the langchain Chat client.
|
||||
"""
|
||||
if self.model.startswith("google/"):
|
||||
if GOOGLE_GENAI_AVAILABLE:
|
||||
return ChatGoogleGenerativeAI(
|
||||
model=self.model_name,
|
||||
google_api_key=self.api_key
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"Required Langchain Integration 'langchain-google-genai' not found. "
|
||||
"Please install with 'pip install langchain-google-genai'"
|
||||
)
|
||||
elif self.model.startswith("cohere/"):
|
||||
if COHERE_AVAILABLE:
|
||||
return ChatCohere(
|
||||
model=self.model_name,
|
||||
cohere_api_key=self.api_key,
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"Required Langchain Integration 'langchain-cohere' not found. "
|
||||
"Please install with 'pip install langchain-cohere'"
|
||||
)
|
||||
elif self.model.startswith("anthropic/"):
|
||||
if ANTHROPIC_AVAILABLE:
|
||||
return ChatAnthropic(
|
||||
model=self.model_name,
|
||||
anthropic_api_key=self.api_key,
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"Required Langchain Integration 'langchain-anthropic' not found. "
|
||||
"Please install with 'pip install langchain-anthropic'"
|
||||
)
|
||||
elif OPENAI_AVAILABLE:
|
||||
return ChatOpenAI(
|
||||
model=self.model_name,
|
||||
api_key=self.api_key,
|
||||
base_url=self.base_url,
|
||||
)
|
||||
else:
|
||||
raise ImportError(
|
||||
"Required Langchain Integration 'langchain-openai' not found. "
|
||||
"Please install with 'pip install langchain-openai'"
|
||||
)
|
||||
+17
-4
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "PraisonAI"
|
||||
version = "0.0.37"
|
||||
version = "0.0.38"
|
||||
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 = ""
|
||||
@@ -20,11 +20,15 @@ pyautogen = ">=0.2.19"
|
||||
crewai = ">=0.32.0"
|
||||
markdown = ">=3.5"
|
||||
praisonai-tools = ">=0.0.7"
|
||||
pyparsing = ">=3.0.0"
|
||||
pyparsing = ">=3.0.0" # Added to fix a colab issue. Temp Fix.
|
||||
chainlit = {version = "^1.1.301", optional = true}
|
||||
gradio = {version = ">=4.26.0", optional = true}
|
||||
flask = {version = ">=3.0.0", optional = true}
|
||||
agentops = {version = "==0.2.3", optional = true}
|
||||
agentops = {version = ">=0.2.6", optional = true}
|
||||
langchain-google-genai = {version = ">=1.0.4", optional = true}
|
||||
langchain-anthropic = {version = ">=0.1.13", optional = true}
|
||||
langchain-openai = {version = ">=0.1.7", optional = true}
|
||||
langchain-cohere = {version = ">=0.1.4", optional = true}
|
||||
|
||||
[tool.poetry.group.docs.dependencies]
|
||||
mkdocs = "*"
|
||||
@@ -66,12 +70,17 @@ unittest2 = "*"
|
||||
chainlit = "^1.1.301"
|
||||
gradio = ">=4.26.0"
|
||||
flask = ">=3.0.0"
|
||||
agentops = "==0.2.3"
|
||||
agentops = ">=0.2.6"
|
||||
langchain-google-genai = ">=1.0.4"
|
||||
langchain-anthropic = ">=0.1.13"
|
||||
langchain-openai = ">=0.1.7"
|
||||
langchain-cohere = ">=0.1.4"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
|
||||
[tool.poetry.scripts]
|
||||
praisonai = "praisonai.__main__:main"
|
||||
|
||||
@@ -80,3 +89,7 @@ ui = ["chainlit"]
|
||||
gradio = ["gradio"]
|
||||
api = ["flask"]
|
||||
agentops = ["agentops"]
|
||||
google = ["langchain-google-genai"]
|
||||
openai = ["langchain-openai"]
|
||||
anthropic = ["langchain-anthropic"]
|
||||
cohere = ["langchain-cohere"]
|
||||
@@ -0,0 +1,57 @@
|
||||
framework: crewai
|
||||
topic: research about the causes of lung disease
|
||||
roles:
|
||||
research_analyst:
|
||||
backstory: Experienced in analyzing scientific data related to respiratory health.
|
||||
goal: Analyze data on lung diseases
|
||||
role: Research Analyst
|
||||
llm:
|
||||
model: "groq/llama3-70b-8192"
|
||||
function_calling_llm:
|
||||
model: "google/gemini-1.5-flash-001"
|
||||
allow_delegation: False
|
||||
max_execution_time:
|
||||
max_iter:
|
||||
max_rpm:
|
||||
verbose: True
|
||||
cache: True
|
||||
system_template:
|
||||
prompt_template:
|
||||
response_template:
|
||||
tasks:
|
||||
data_analysis:
|
||||
description: Gather and analyze data on the causes and risk factors of lung
|
||||
diseases.
|
||||
expected_output: Report detailing key findings on lung disease causes.
|
||||
tools:
|
||||
- 'InternetSearchTool'
|
||||
medical_writer:
|
||||
backstory: Skilled in translating complex medical information into accessible
|
||||
content.
|
||||
goal: Compile comprehensive content on lung disease causes
|
||||
role: Medical Writer
|
||||
llm:
|
||||
model: "anthropic/claude-3-haiku-20240307"
|
||||
function_calling_llm:
|
||||
model: "openai/gpt-4o"
|
||||
tasks:
|
||||
content_creation:
|
||||
description: Create detailed content summarizing the research findings on
|
||||
lung disease causes.
|
||||
expected_output: Document outlining various causes and risk factors of lung
|
||||
diseases.
|
||||
tools:
|
||||
- ''
|
||||
editor:
|
||||
backstory: Proficient in editing medical content for accuracy and clarity.
|
||||
goal: Review and refine content on lung disease causes
|
||||
role: Editor
|
||||
llm:
|
||||
model: "cohere/command-r"
|
||||
tasks:
|
||||
content_review:
|
||||
description: Edit and refine the compiled content on lung disease causes for
|
||||
accuracy and coherence.
|
||||
expected_output: Finalized document on lung disease causes ready for dissemination.
|
||||
tools:
|
||||
- ''
|
||||
+9
-3
@@ -11,10 +11,15 @@ import collections.abc
|
||||
collections.MutableMapping = collections.abc.MutableMapping
|
||||
|
||||
class TestPraisonAIFramework(unittest.TestCase):
|
||||
def test_main_with_agents_advanced(self):
|
||||
praison_ai = PraisonAI(agent_file='tests/agents-advanced.yaml')
|
||||
result = praison_ai.main()
|
||||
self.assertIn('### Task Output ###', result)
|
||||
|
||||
def test_main_with_autogen_framework(self):
|
||||
praison_ai = PraisonAI(agent_file='tests/autogen-agents.yaml')
|
||||
result = praison_ai.main()
|
||||
self.assertIn('### Task Output ###', result)
|
||||
self.assertTrue('### Task Output ###' in result or '### Output ###' in result)
|
||||
|
||||
def test_main_with_custom_framework(self):
|
||||
praison_ai = PraisonAI(agent_file='tests/crewai-agents.yaml')
|
||||
@@ -30,6 +35,7 @@ class TestPraisonAIFramework(unittest.TestCase):
|
||||
praison_ai = PraisonAI(agent_file='tests/inbuilt-tool-agents.yaml')
|
||||
result = praison_ai.main()
|
||||
self.assertIn('### Task Output ###', result)
|
||||
|
||||
|
||||
class TestPraisonAICommandLine(unittest.TestCase):
|
||||
def run_command(self, command):
|
||||
@@ -63,5 +69,5 @@ class TestExamples(unittest.TestCase):
|
||||
self.assertIsNotNone(result) # Adjust this assertion according to what auto() is expected to do
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('unittest_report.xml', 'wb') as output:
|
||||
unittest.main(testRunner=XMLTestRunner(output=output))
|
||||
runner = XMLTestRunner(output='test-reports')
|
||||
unittest.main(testRunner=runner, exit=False)
|
||||
Reference in new issue
Block a user