mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-08 01:08:39 -10:00
adding Docs
This commit is contained in:
1 parent
dd606e7284
commit
bf88163411
6 files changed
+362
-9
No files matched your search
@@ -35,6 +35,115 @@ PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application
|
||||
- 👁️ Vision Language Model (VLM) Support
|
||||
- 🎙️ Real-time Voice Interaction
|
||||
|
||||
## Using No Code
|
||||
|
||||
### Auto Mode:
|
||||
```bash
|
||||
pip install praisonai python-dotenv instructor
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
praisonai --auto create a movie script about Robots in Mars
|
||||
```
|
||||
|
||||
### Initialise Mode:
|
||||
```bash
|
||||
pip install praisonai python-dotenv instructor
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
praisonai --init create a movie script about Robots in Mars
|
||||
praisonai
|
||||
```
|
||||
|
||||
## Using Coding
|
||||
|
||||
Light weight package dedicated for coding:
|
||||
```bash
|
||||
pip install praisonaiagents
|
||||
```
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
```
|
||||
|
||||
Create app.py file and add the code below:
|
||||
```python
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents
|
||||
|
||||
# 1. Create agents
|
||||
researcher = Agent(
|
||||
name="Researcher",
|
||||
role="Senior Research Analyst",
|
||||
goal="Uncover cutting-edge developments in AI and data science",
|
||||
backstory="""You are an expert at a technology research group,
|
||||
skilled in identifying trends and analyzing complex data.""",
|
||||
verbose=True,
|
||||
llm="gpt-4o",
|
||||
markdown=True
|
||||
)
|
||||
writer = Agent(
|
||||
name="Writer",
|
||||
role="Tech Content Strategist",
|
||||
goal="Craft compelling content on tech advancements",
|
||||
backstory="""You are a content strategist known for
|
||||
making complex tech topics interesting and easy to understand.""",
|
||||
llm="gpt-4o",
|
||||
markdown=True
|
||||
)
|
||||
|
||||
# 2. Define Tasks
|
||||
task1 = Task(
|
||||
name="research_task",
|
||||
description="""Analyze 2024's AI advancements.
|
||||
Find major trends, new technologies, and their effects.""",
|
||||
expected_output="""A detailed report on 2024 AI advancements""",
|
||||
agent=researcher
|
||||
)
|
||||
|
||||
task2 = Task(
|
||||
name="writing_task",
|
||||
description="""Create a blog post about major AI advancements using the insights you have.
|
||||
Make it interesting, clear, and suited for tech enthusiasts.
|
||||
It should be at least 4 paragraphs long.""",
|
||||
expected_output="A blog post of at least 4 paragraphs",
|
||||
agent=writer,
|
||||
)
|
||||
|
||||
agents = PraisonAIAgents(
|
||||
agents=[researcher, writer],
|
||||
tasks=[task1, task2],
|
||||
verbose=False,
|
||||
process="hierarchical",
|
||||
manager_llm="gpt-4o"
|
||||
)
|
||||
|
||||
result = agents.start()
|
||||
```
|
||||
|
||||
Run:
|
||||
```bash
|
||||
python app.py
|
||||
```
|
||||
|
||||
## Ollama Integration
|
||||
```bash
|
||||
export OPENAI_BASE_URL=http://localhost:11434/v1
|
||||
```
|
||||
|
||||
## Groq Integration
|
||||
Replace xxxx with Groq API KEY:
|
||||
```bash
|
||||
export OPENAI_API_KEY=xxxxxxxxxxx
|
||||
export OPENAI_BASE_URL=https://api.groq.com/openai/v1
|
||||
```
|
||||
|
||||
## Logging
|
||||
```bash
|
||||
export LOGLEVEL=info
|
||||
```
|
||||
|
||||
Advanced logging:
|
||||
```bash
|
||||
export LOGLEVEL=debug
|
||||
```
|
||||
|
||||
<div align="center">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="docs/images/architecture-dark.png" />
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ roles:
|
||||
a cat being on Mars. Also, research about cat behavior and characteristics.
|
||||
expected_output: Document with research findings on Mars and cats.
|
||||
tools:
|
||||
- ''
|
||||
- 'search_tool'
|
||||
narrative_designer:
|
||||
backstory: Skilled in narrative development, with a focus on creating engaging
|
||||
stories.
|
||||
|
||||
+32
-6
@@ -3,7 +3,7 @@ import logging
|
||||
from rich.console import Console
|
||||
from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
from praisonaiagents import Agent, Task, Agents, error_logs
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents, error_logs
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
@@ -16,16 +16,42 @@ def my_callback(output):
|
||||
logging.info(f"Callback function called after task execution: {output.description}")
|
||||
logging.info(f"Task output: {output}")
|
||||
|
||||
from duckduckgo_search import DDGS
|
||||
|
||||
def internet_search_tool(query):
|
||||
"""
|
||||
Perform a search using DuckDuckGo.
|
||||
|
||||
Args:
|
||||
query (str): The search query.
|
||||
|
||||
Returns:
|
||||
list: A list of search result titles and URLs.
|
||||
"""
|
||||
try:
|
||||
results = []
|
||||
ddgs = DDGS()
|
||||
for result in ddgs.text(keywords=query, max_results=10):
|
||||
results.append({
|
||||
"title": result.get("title", ""),
|
||||
"url": result.get("href", "")
|
||||
})
|
||||
return results
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during DuckDuckGo search: {e}")
|
||||
return []
|
||||
|
||||
def main():
|
||||
# Make sure OPENAI_API_KEY is set
|
||||
if not os.environ.get("OPENAI_API_KEY"):
|
||||
raise ValueError("Please set OPENAI_API_KEY environment variable")
|
||||
|
||||
# Define tools
|
||||
search_tool = {
|
||||
internet_search_tool = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "search_tool",
|
||||
"name": "internet_search_tool",
|
||||
"description": "Use this to perform search queries",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
@@ -60,7 +86,7 @@ def main():
|
||||
skilled in identifying trends and analyzing complex data.""",
|
||||
verbose=True,
|
||||
allow_delegation=False,
|
||||
tools=[search_tool],
|
||||
tools=[internet_search_tool],
|
||||
llm="gpt-4o",
|
||||
markdown=True
|
||||
)
|
||||
@@ -84,7 +110,7 @@ def main():
|
||||
Find major trends, new technologies, and their effects.""",
|
||||
expected_output="""A detailed report on 2024 AI advancements""",
|
||||
agent=researcher,
|
||||
tools=[search_tool]
|
||||
tools=[internet_search_tool]
|
||||
)
|
||||
|
||||
task2 = Task(
|
||||
@@ -118,7 +144,7 @@ def main():
|
||||
)
|
||||
|
||||
# Create and run agents manager
|
||||
agents = Agents(
|
||||
agents = PraisonAIAgents(
|
||||
agents=[researcher, writer],
|
||||
tasks=[task1, task2, task3, task4],
|
||||
verbose=False,
|
||||
|
||||
+123
-1
@@ -10,7 +10,129 @@
|
||||
<a href="https://github.com/MervinPraison/PraisonAI"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License" /></a>
|
||||
</p>
|
||||
|
||||
Praison AI, leveraging both AutoGen and CrewAI or any other agent framework, represents a low-code, centralised framework designed to simplify the creation and orchestration of multi-agent systems for various LLM applications, emphasizing ease of use, customization, and human-agent interaction.
|
||||
PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration.
|
||||
|
||||
## Key Features
|
||||
|
||||
- 🤖 Automated AI Agents Creation
|
||||
- 🔄 Use CrewAI or AutoGen Framework
|
||||
- 💯 100+ LLM Support
|
||||
- 💻 Chat with ENTIRE Codebase
|
||||
- 🖥️ Interactive UIs
|
||||
- 📄 YAML-based Configuration
|
||||
- 🛠️ Custom Tool Integration
|
||||
- 🔍 Internet Search Capability (using Crawl4AI and Tavily)
|
||||
- 👁️ Vision Language Model (VLM) Support
|
||||
- 🎙️ Real-time Voice Interaction
|
||||
|
||||
## Using No Code
|
||||
|
||||
### Auto Mode:
|
||||
```bash
|
||||
pip install praisonai python-dotenv instructor
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
praisonai --auto create a movie script about Robots in Mars
|
||||
```
|
||||
|
||||
### Initialise Mode:
|
||||
```bash
|
||||
pip install praisonai python-dotenv instructor
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
praisonai --init create a movie script about Robots in Mars
|
||||
praisonai
|
||||
```
|
||||
|
||||
## Using Coding
|
||||
|
||||
Light weight package dedicated for coding:
|
||||
```bash
|
||||
pip install praisonaiagents
|
||||
```
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxx
|
||||
```
|
||||
|
||||
Create app.py file and add the code below:
|
||||
```python
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents
|
||||
|
||||
# 1. Create agents
|
||||
researcher = Agent(
|
||||
name="Researcher",
|
||||
role="Senior Research Analyst",
|
||||
goal="Uncover cutting-edge developments in AI and data science",
|
||||
backstory="""You are an expert at a technology research group,
|
||||
skilled in identifying trends and analyzing complex data.""",
|
||||
verbose=True,
|
||||
llm="gpt-4o",
|
||||
markdown=True
|
||||
)
|
||||
writer = Agent(
|
||||
name="Writer",
|
||||
role="Tech Content Strategist",
|
||||
goal="Craft compelling content on tech advancements",
|
||||
backstory="""You are a content strategist known for
|
||||
making complex tech topics interesting and easy to understand.""",
|
||||
llm="gpt-4o",
|
||||
markdown=True
|
||||
)
|
||||
|
||||
# 2. Define Tasks
|
||||
task1 = Task(
|
||||
name="research_task",
|
||||
description="""Analyze 2024's AI advancements.
|
||||
Find major trends, new technologies, and their effects.""",
|
||||
expected_output="""A detailed report on 2024 AI advancements""",
|
||||
agent=researcher
|
||||
)
|
||||
|
||||
task2 = Task(
|
||||
name="writing_task",
|
||||
description="""Create a blog post about major AI advancements using the insights you have.
|
||||
Make it interesting, clear, and suited for tech enthusiasts.
|
||||
It should be at least 4 paragraphs long.""",
|
||||
expected_output="A blog post of at least 4 paragraphs",
|
||||
agent=writer,
|
||||
)
|
||||
|
||||
agents = PraisonAIAgents(
|
||||
agents=[researcher, writer],
|
||||
tasks=[task1, task2],
|
||||
verbose=False,
|
||||
process="hierarchical",
|
||||
manager_llm="gpt-4o"
|
||||
)
|
||||
|
||||
result = agents.start()
|
||||
```
|
||||
|
||||
Run:
|
||||
```bash
|
||||
python app.py
|
||||
```
|
||||
|
||||
## Ollama Integration
|
||||
```bash
|
||||
export OPENAI_BASE_URL=http://localhost:11434/v1
|
||||
```
|
||||
|
||||
## Groq Integration
|
||||
Replace xxxx with Groq API KEY:
|
||||
```bash
|
||||
export OPENAI_API_KEY=xxxxxxxxxxx
|
||||
export OPENAI_BASE_URL=https://api.groq.com/openai/v1
|
||||
```
|
||||
|
||||
## Logging
|
||||
```bash
|
||||
export LOGLEVEL=info
|
||||
```
|
||||
|
||||
Advanced logging:
|
||||
```bash
|
||||
export LOGLEVEL=debug
|
||||
```
|
||||
|
||||
<div align="center">
|
||||
<picture>
|
||||
|
||||
@@ -200,6 +200,57 @@ class AgentsGenerator:
|
||||
tools_dict[name] = obj
|
||||
return tools_dict
|
||||
|
||||
def load_tools_from_tools_py(self):
|
||||
"""
|
||||
Automatically loads all tools (functions and tool definitions) from tools.py file.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing:
|
||||
- Function names as keys and function objects as values
|
||||
- Tool definition names as keys and tool definition dictionaries as values
|
||||
|
||||
Note:
|
||||
This function looks for:
|
||||
1. Regular functions
|
||||
2. Tool definition dictionaries (containing 'type' and 'function' keys)
|
||||
3. Variables named as tools or ending with '_tool'
|
||||
"""
|
||||
tools_dict = {}
|
||||
try:
|
||||
# Try to import tools.py from current directory
|
||||
spec = importlib.util.spec_from_file_location("tools", "tools.py")
|
||||
if spec is None:
|
||||
self.logger.warning("tools.py not found in current directory")
|
||||
return tools_dict
|
||||
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
# Get all module attributes
|
||||
for name, obj in inspect.getmembers(module):
|
||||
# Skip private attributes
|
||||
if name.startswith('_'):
|
||||
continue
|
||||
|
||||
# Case 1: Regular functions
|
||||
if inspect.isfunction(obj) and obj.__module__ == "tools":
|
||||
tools_dict[name] = obj
|
||||
|
||||
# Case 2: Tool definition dictionaries
|
||||
elif isinstance(obj, dict) and obj.get('type') == 'function' and 'function' in obj:
|
||||
tools_dict[name] = obj
|
||||
|
||||
# Case 3: Variables named as tools
|
||||
elif (name.endswith('_tool') or name == 'tools') and not inspect.ismodule(obj):
|
||||
tools_dict[name] = obj
|
||||
|
||||
self.logger.debug(f"Loaded {len(tools_dict)} tools from tools.py")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Error loading tools from tools.py: {e}")
|
||||
|
||||
return tools_dict
|
||||
|
||||
def generate_crew_and_kickoff(self):
|
||||
"""
|
||||
Generates a crew of agents and initiates tasks based on the provided configuration.
|
||||
@@ -271,7 +322,7 @@ class AgentsGenerator:
|
||||
elif tools_dir_path.is_dir():
|
||||
tools_dict.update(self.load_tools_from_module_class(tools_dir_path))
|
||||
self.logger.debug("tools folder exists in the root directory")
|
||||
|
||||
|
||||
framework = self.framework or config.get('framework')
|
||||
|
||||
if framework == "autogen":
|
||||
@@ -498,6 +549,8 @@ class AgentsGenerator:
|
||||
tasks = []
|
||||
tasks_dict = {}
|
||||
|
||||
tools_dict = self.load_tools_from_tools_py()
|
||||
|
||||
# Create agents from config
|
||||
for role, details in config['roles'].items():
|
||||
role_filled = details['role'].format(topic=topic)
|
||||
|
||||
@@ -1,5 +1,48 @@
|
||||
# tools.py
|
||||
|
||||
# from duckduckgo_search import DDGS
|
||||
|
||||
# def search_tool(query):
|
||||
# """
|
||||
# Perform a search using DuckDuckGo.
|
||||
|
||||
# Args:
|
||||
# query (str): The search query.
|
||||
|
||||
# Returns:
|
||||
# list: A list of search result titles and URLs.
|
||||
# """
|
||||
# try:
|
||||
# results = []
|
||||
# ddgs = DDGS()
|
||||
# for result in ddgs.text(keywords=query, max_results=10):
|
||||
# results.append({
|
||||
# "title": result.get("title", ""),
|
||||
# "url": result.get("href", "")
|
||||
# })
|
||||
# return results
|
||||
|
||||
# except Exception as e:
|
||||
# print(f"Error during DuckDuckGo search: {e}")
|
||||
# return []
|
||||
|
||||
# # Define tools
|
||||
# search_tool = {
|
||||
# "type": "function",
|
||||
# "function": {
|
||||
# "name": "search_tool",
|
||||
# "description": "Use this to perform search queries",
|
||||
# "parameters": {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "query": {"type": "string"},
|
||||
# },
|
||||
# "required": ["query"],
|
||||
# },
|
||||
# },
|
||||
# }
|
||||
|
||||
|
||||
# from duckduckgo_search import DDGS
|
||||
# from praisonai_tools import BaseTool
|
||||
# class InternetSearchTool(BaseTool):
|
||||
|
||||
Reference in new issue
Block a user