Compare commits

...
23 Commits
Author SHA1 Message Date
devin-ai-integration[bot] 27d6fef28d Implement exponential backoff strategy for rate limiting 2024-04-24 07:15:41 +00:00
devin-ai-integration[bot] 375ffb0365 Implement exponential backoff strategy for rate limiting 2024-04-24 06:56:43 +00:00
devin-ai-integration[bot] 502bff110b Add debug print statement for OPENAI_API_KEY 2024-04-24 06:50:01 +00:00
devin-ai-integration[bot] 3ea8ff4cb7 Add check for OPENAI_API_KEY environment variable 2024-04-24 06:44:30 +00:00
Mervin Praison dd5ffe2454 Merge pull request #14 from MervinPraison/feature/PRAISON-1-add-tools
changing version number
2024-04-02 23:00:44 +05:30
MervinPraison 08742f5dda changing version number 2024-04-02 23:00:00 +05:30
Mervin Praison cf601070a4 Merge pull request #13 from MervinPraison/feature/PRAISON-1-add-tools
Feature/praison 1 add tools
2024-04-02 22:58:06 +05:30
MervinPraison 9f0429f559 Adding AutoGen and CrewAI Tools integration 2024-04-02 22:56:46 +05:30
MervinPraison ea54abf3d1 Adding AutoGen Tools integration 2024-04-02 13:09:25 +05:30
MervinPraison 4447d64fb6 Adding CrewAI Tools integration 2024-04-02 12:30:06 +05:30
MervinPraison 548e96dcf0 Variable name changes 2024-03-30 20:28:01 +05:30
MervinPraison c97cfa2f5c Version 0.0.17 2024-03-26 08:18:13 +00:00
MervinPraison a8e60930d7 Version 0.0.16 2024-03-26 07:12:57 +00:00
MervinPraison 8c155949db Version 0.0.15 2024-03-26 01:12:23 +00:00
MervinPraison 3ef6eddb61 Version 0.0.11 2024-03-25 23:47:11 +00:00
MervinPraison 93f3b23222 Version 0.0.10 2024-03-25 23:39:08 +00:00
MervinPraison 8e1c393abf Version 0.0.8 2024-03-25 20:52:52 +00:00
MervinPraison 5b9bcc99c9 Version 0.0. 2024-03-25 19:30:53 +00:00
Mervin Praison 1124cf1288 Merge pull request #3 from MervinPraison/main
Main
2024-03-24 06:21:44 +00:00
MervinPraison 04f9c313e2 Version 0.0.6 2024-03-23 17:24:43 +00:00
MervinPraison ee5c7840fb Merge remote-tracking branch 'origin/main' 2024-03-23 16:21:37 +00:00
Mervin Praison 0fc656116f Merge pull request #2 from MervinPraison/main
Merge pull request #1 from MervinPraison/develop
2024-03-21 14:30:05 +00:00
MervinPraison 827a98281d removing test 2024-03-21 14:26:21 +00:00
36 changed files with 5922 additions and 354 deletions

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
OPENAI_MODEL_NAME="gpt-4-turbo-preview"
OPENAI_API_KEY="Enter your API key"
OPENAI_API_BASE="https://api.openai.com/v1"
+5 -1
View File
@@ -9,4 +9,8 @@ dist/
assets/*
.idea
.DS_Store
.pytest_cache
.pytest_cache
praisonAI.egg-info
flagged
test.yaml
db
+6
View File
@@ -0,0 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==0.0.18 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
+189 -1
View File
@@ -8,8 +8,196 @@ Praison AI, leveraging both AutoGen and CrewAI or any other agent framework, rep
pip install praisonai
```
## Initialise
```bash
praisonai --init create a movie script about dog in moon
```
This will automatically create agents.yaml file in the current directory.
To initialse with a specific agent framework:
```bash
praisonai --framework autogen --init create movie script about cat in mars
```
## Run
```bash
praisonai
```
```
or
```bash
python -m praisonai
```
### Specify the agent framework
```bash
praisonai --framework autogen
```
### Full Automatic Mode
```bash
praisonai --auto create a movie script about Dog in Moon
```
## Test
```bash
python -m unittest tests.test
```
## Agents Playbook
### Simple Playbook
```yaml
framework: crewai
topic: Artificial Intelligence
roles:
screenwriter:
backstory: 'Skilled in crafting scripts with engaging dialogue about {topic}.'
goal: Create scripts from concepts.
role: Screenwriter
tasks:
scriptwriting_task:
description: 'Develop scripts with compelling characters and dialogue about {topic}.'
expected_output: 'Complete script ready for production.'
```
### Detailed Playbook
```yaml
framework: crewai
topic: Artificial Intelligence
roles:
movie_concept_creator:
backstory: 'Creative thinker with a deep understanding of cinematic storytelling,
capable of using AI-generated storylines to create unique and compelling movie
ideas.'
goal: Generate engaging movie concepts using AI storylines
role: Movie Concept Creator
tasks:
movie_concept_development:
description: 'Develop movie concepts from AI-generated storylines, ensuring
they are engaging and have strong narrative arcs.'
expected_output: 'Well-structured movie concept document with character
bios, settings, and plot outlines.'
screenwriter:
backstory: 'Expert in writing engaging dialogue and script structure, able to
turn movie concepts into production-ready scripts.'
goal: Write compelling scripts based on movie concepts
role: Screenwriter
tasks:
scriptwriting_task:
description: 'Turn movie concepts into polished scripts with well-developed
characters, strong dialogue, and effective scene transitions.'
expected_output: 'Production-ready script with a beginning, middle, and
end, along with character development and engaging dialogues.'
editor:
backstory: 'Adept at identifying inconsistencies, improving language usage,
and maintaining the overall flow of the script.'
goal: Refine the scripts and ensure continuity of the movie storyline
role: Editor
tasks:
editing_task:
description: 'Review, edit, and refine the scripts to ensure they are cohesive
and follow a well-structured narrative.'
expected_output: 'A polished final draft of the script with no inconsistencies,
strong character development, and effective dialogue.'
dependencies: []
```
## Include praisonai package in your project
```python
from praisonai import PraisonAI
def basic(): # Basic Mode
praison_ai = PraisonAI(agent_file="agents.yaml")
praison_ai.main()
def advanced(): # Advanced Mode with options
praison_ai = PraisonAI(
agent_file="agents.yaml",
framework="autogen",
)
praison_ai.main()
def auto(): # Full Automatic Mode
praison_ai = PraisonAI(
auto="Create a movie script about car in mars",
framework="autogen"
)
print(praison_ai.framework)
praison_ai.main()
if __name__ == "__main__":
basic()
advanced()
auto()
```
## Deploy
```bash
gcloud init
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_API_KEY="Enter your API key"
export OPENAI_API_BASE="https://api.openai.com/v1"
yes | gcloud auth configure-docker us-central1-docker.pkg.dev
gcloud artifacts repositories create praisonai-repository --repository-format=docker --location=us-central1
PROJECT_ID=$(gcloud config get-value project)
TAG="latest"
docker build --platform linux/amd64 -t gcr.io/${PROJECT_ID}/praisonai-app:${TAG} .
docker tag gcr.io/${PROJECT_ID}/praisonai-app:${TAG} us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG}
docker push us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG}
gcloud run deploy praisonai-service \
--image us-central1-docker.pkg.dev/${PROJECT_ID}/praisonai-repository/praisonai-app:${TAG} \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars OPENAI_MODEL_NAME=${OPENAI_MODEL_NAME},OPENAI_API_KEY=${OPENAI_API_KEY},OPENAI_API_BASE=${OPENAI_API_BASE}
## Other Models
Ollama
OPENAI_API_BASE='http://localhost:11434/v1'
OPENAI_MODEL_NAME='mistral'
OPENAI_API_KEY='NA'
FastChat¶
OPENAI_API_BASE="http://localhost:8001/v1"
OPENAI_MODEL_NAME='oh-2.5m7b-q51'
OPENAI_API_KEY=NA
LM Studio¶
OPENAI_API_BASE="http://localhost:8000/v1"
OPENAI_MODEL_NAME=NA
OPENAI_API_KEY=NA
Mistral API¶
OPENAI_API_BASE=https://api.mistral.ai/v1
OPENAI_MODEL_NAME="mistral-small"
OPENAI_API_KEY=your-mistral-api-key
## Contributing
- Fork on GitHub: Use the "Fork" button on the repository page.
- Clone your fork: `git clone https://github.com/yourusername/praisonAI.git`
- Create a branch: `git checkout -b new-feature`
- Make changes and commit: `git commit -am "Add some feature"`
- Push to your fork: `git push origin new-feature`
- Submit a pull request via GitHub's web interface.
- Await feedback from project maintainers.
+39 -38
View File
@@ -1,41 +1,42 @@
framework: "autogen"
topic: "Artificial Intelligence"
framework: crewai
topic: create a movie about cat in mars based on https://blog.celtx.com/how-to-write-a-good-story/
roles:
narrative_designer:
role: "Narrative Designer"
goal: "Craft engaging storylines and narratives for {topic}"
backstory: >
You're a creative visionary skilled in weaving complex narratives and
developing engaging story worlds within {topic}. Your expertise lies in
conceptualizing the overarching story and ensuring it resonates with the audience.
story_developer:
backstory: Experienced in crafting compelling narratives for a diverse audience.
goal: Develop an engaging storyline for a movie about cats in Mars
role: Story Developer
tasks:
story_concept_development:
description: >
Develop a compelling story concept for {topic}, focusing on originality,
thematic depth, and audience engagement. Outline the main narrative arcs,
characters, and settings.
expected_output: >
A comprehensive document outlining the story concept, including key narrative
arcs, character bios, and settings descriptions.
scriptwriter:
role: "Scriptwriter"
goal: "Transform story concepts into detailed scripts for {topic}"
backstory: >
With a flair for dialogue and a deep understanding of pacing and structure,
you excel at bringing narratives to life through scriptwriting. Your work
turns story concepts into blueprints for compelling {topic} experiences.
storyline_creation:
description: Create a captivating storyline for a movie about cats in Mars
inspired by the blog post at https://blog.celtx.com/how-to-write-a-good-story/
expected_output: Detailed storyline with key plot points, character motivations,
and setting descriptions.
tools:
- 'ScrapeWebsiteTool'
screenwriter:
backstory: Proficient in translating complex narratives into engaging screenplay
format.
goal: Transform the storyline into a script
role: Screenwriter
tasks:
scriptwriting_task:
description: >
Based on the narrative concept, write a detailed script for {topic}.
Include dialogue, stage directions, and scene descriptions that bring
the story to life.
expected_output: >
A detailed script ready for production, including dialogue, stage
directions, and scene descriptions.
dependencies:
- task: scriptwriting_task
depends_on: story_concept_development
script_creation:
description: Transform the developed storyline into a script for the movie
about cats in Mars.
expected_output: Complete script with dialogues, scenes, and stage directions
ready for production.
tools:
- ''
director:
backstory: Experienced in visual storytelling and bringing scripts to life on
screen.
goal: Oversee the production of the movie
role: Director
tasks:
movie_production:
description: Take the script and lead the team to produce the movie 'Cats
in Mars' based on the provided content and script.
expected_output: Completed movie ready for distribution with compelling visuals
and engaging storytelling.
tools:
- ''
dependencies: []
+18
View File
@@ -0,0 +1,18 @@
from flask import Flask
from praisonai import PraisonAI
import markdown
app = Flask(__name__)
def basic():
praison_ai = PraisonAI(agent_file="agents.yaml")
return praison_ai.main()
@app.route('/')
def home():
output = basic()
html_output = markdown.markdown(output)
return f'<html><body>{html_output}</body></html>'
if __name__ == "__main__":
app.run(debug=True)
+25
View File
@@ -0,0 +1,25 @@
from praisonai import PraisonAI
def basic():
praison_ai = PraisonAI(agent_file="agents.yaml")
praison_ai.main()
def advanced():
praison_ai = PraisonAI(
agent_file="agents.yaml",
framework="autogen",
)
praison_ai.main()
def auto():
praison_ai = PraisonAI(
auto="Create a movie script about car in mars",
framework="autogen"
)
print(praison_ai.framework)
praison_ai.main()
if __name__ == "__main__":
basic()
advanced()
auto()
Generated
+4081 -213
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -1 +1,2 @@
from .cli import PraisonAI
from .version import __version__
+7 -1
View File
@@ -1,4 +1,10 @@
from .cli import main
# __main__.py
from .cli import PraisonAI
def main():
praison_ai = PraisonAI()
praison_ai.main()
if __name__ == "__main__":
main()
+221
View File
@@ -0,0 +1,221 @@
# agents_generator.py
import sys
from .version import __version__
import yaml, os
from rich import print
from dotenv import load_dotenv
from crewai import Agent, Task, Crew
load_dotenv()
import autogen
import gradio as gr
import argparse
from .auto import AutoGenerator
from crewai_tools import *
from .tools import *
class AgentsGenerator:
def __init__(self, agent_file, framework, config_list):
self.agent_file = agent_file
self.framework = framework
self.config_list = config_list
def generate_crew_and_kickoff(self):
if self.agent_file == '/app/api:app' or self.agent_file == 'api:app':
self.agent_file = 'agents.yaml'
try:
with open(self.agent_file, 'r') as f:
config = yaml.safe_load(f)
except FileNotFoundError:
print(f"File not found: {self.agent_file}")
return
topic = config['topic']
tools_dict = {
'CodeDocsSearchTool': CodeDocsSearchTool(),
'CSVSearchTool': CSVSearchTool(),
'DirectorySearchTool': DirectorySearchTool(),
'DOCXSearchTool': DOCXSearchTool(),
'DirectoryReadTool': DirectoryReadTool(),
'FileReadTool': FileReadTool(),
# 'GithubSearchTool': GithubSearchTool(),
# 'SeperDevTool': SeperDevTool(),
'TXTSearchTool': TXTSearchTool(),
'JSONSearchTool': JSONSearchTool(),
'MDXSearchTool': MDXSearchTool(),
'PDFSearchTool': PDFSearchTool(),
# 'PGSearchTool': PGSearchTool(),
'RagTool': RagTool(),
'ScrapeElementFromWebsiteTool': ScrapeElementFromWebsiteTool(),
'ScrapeWebsiteTool': ScrapeWebsiteTool(),
'WebsiteSearchTool': WebsiteSearchTool(),
'XMLSearchTool': XMLSearchTool(),
'YoutubeChannelSearchTool': YoutubeChannelSearchTool(),
'YoutubeVideoSearchTool': YoutubeVideoSearchTool()
}
# config['tools'] = [tools_dict[tool] for tool in config.get('tools', []) if tool in tools_dict]
framework = self.framework or config.get('framework')
agents = {}
tasks = []
if framework == "autogen":
# Load the LLM configuration dynamically
# print(self.config_list)
llm_config = {"config_list": self.config_list}
# Assuming the user proxy agent is set up as per your requirements
user_proxy = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: (x.get("content") or "").rstrip().rstrip(".").lower().endswith("terminate") or "TERMINATE" in (x.get("content") or ""),
code_execution_config={
"work_dir": "coding",
"use_docker": False,
},
# additional setup for the user proxy agent
)
for role, details in config['roles'].items():
agent_name = details['role'].format(topic=topic).replace("{topic}", topic)
agent_goal = details['goal'].format(topic=topic)
# Creating an AssistantAgent for each role dynamically
agents[role] = autogen.AssistantAgent(
name=agent_name,
llm_config=llm_config,
system_message=details['backstory'].format(topic=topic)+". Must Reply \"TERMINATE\" in the end when everything is done.",
)
for tool in details.get('tools', []):
if tool in tools_dict:
tool_class = globals()[f'autogen_{type(tools_dict[tool]).__name__}']
tool_class(agents[role], user_proxy)
# Preparing tasks for initiate_chats
for task_name, task_details in details.get('tasks', {}).items():
description_filled = task_details['description'].format(topic=topic)
expected_output_filled = task_details['expected_output'].format(topic=topic)
chat_task = {
"recipient": agents[role],
"message": description_filled,
"summary_method": "last_msg",
# Additional fields like carryover can be added based on dependencies
}
tasks.append(chat_task)
response = user_proxy.initiate_chats(tasks)
result = "### Output ###\n"+response[-1].summary if hasattr(response[-1], 'summary') else ""
else:
for role, details in config['roles'].items():
role_filled = details['role'].format(topic=topic)
goal_filled = details['goal'].format(topic=topic)
backstory_filled = details['backstory'].format(topic=topic)
# 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)
agents[role] = agent
for task_name, task_details in details.get('tasks', {}).items():
description_filled = task_details['description'].format(topic=topic)
expected_output_filled = task_details['expected_output'].format(topic=topic)
task = Task(description=description_filled, expected_output=expected_output_filled, agent=agent)
tasks.append(task)
# print(agents)
crew = Crew(
agents=list(agents.values()),
tasks=tasks,
verbose=2
)
response = crew.kickoff()
result = f"### Task Output ###\n{response}"
return result
# # AutoGen Tools example below
# from typing import Any, Optional
# import os
# from autogen import ConversableAgent
# from autogen_tools import autogen_ScrapeWebsiteTool
# assistant = ConversableAgent(
# name="Assistant",
# system_message="You are a helpful AI assistant. "
# "You can help with website scraping. "
# "Return 'TERMINATE' when the task is done.",
# llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
# )
# user_proxy = ConversableAgent(
# name="User",
# llm_config=False,
# is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
# human_input_mode="NEVER",
# )
# autogen_ScrapeWebsiteTool(assistant, user_proxy)
# chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Nodejs website.")
# # CrewAI Tools example below
# import os
# from crewai import Agent, Task, Crew
# # Importing crewAI tools
# from crewai_tools import (
# DirectoryReadTool,
# FileReadTool,
# SerperDevTool,
# WebsiteSearchTool
# )
# # Set up API keys
# os.environ["SERPER_API_KEY"] = "Your Key" # serper.dev API key
# os.environ["OPENAI_API_KEY"] = "Your Key"
# # Instantiate tools
# docs_tool = DirectoryReadTool(directory='./blog-posts')
# file_tool = FileReadTool()
# search_tool = SerperDevTool()
# web_rag_tool = WebsiteSearchTool()
# # Create agents
# researcher = Agent(
# role='Market Research Analyst',
# goal='Provide up-to-date market analysis of the AI industry',
# backstory='An expert analyst with a keen eye for market trends.',
# tools=[search_tool, web_rag_tool],
# verbose=True
# )
# writer = Agent(
# role='Content Writer',
# goal='Craft engaging blog posts about the AI industry',
# backstory='A skilled writer with a passion for technology.',
# tools=[docs_tool, file_tool],
# verbose=True
# )
# # Define tasks
# research = Task(
# description='Research the latest trends in the AI industry and provide a summary.',
# expected_output='A summary of the top 3 trending developments in the AI industry with a unique perspective on their significance.',
# agent=researcher
# )
# write = Task(
# 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.',
# expected_output='A 4-paragraph blog post formatted in markdown with engaging, informative, and accessible content, avoiding complex jargon.',
# agent=writer,
# output_file='blog-posts/new_post.md' # The final blog post will be saved here
# )
# # Assemble a crew
# crew = Crew(
# agents=[researcher, writer],
# tasks=[research, write],
# verbose=2
# )
# # Execute tasks
# crew.kickoff()
+155
View File
@@ -0,0 +1,155 @@
from openai import OpenAI
from pydantic import BaseModel
from typing import Dict, List
import instructor
import os
import json
import yaml
from rich import print
# Define Pydantic models outside of the generate method
class TaskDetails(BaseModel):
description: str
expected_output: str
class RoleDetails(BaseModel):
role: str
goal: str
backstory: str
tasks: Dict[str, TaskDetails]
tools: List[str]
class TeamStructure(BaseModel):
roles: Dict[str, RoleDetails]
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"),
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
}
]
self.topic = topic
self.agent_file = agent_file
self.framework = framework
if not os.getenv("OPENAI_API_KEY"):
raise EnvironmentError("The OPENAI_API_KEY environment variable is not set.")
self.client = instructor.patch(
OpenAI(
base_url=self.config_list[0]['base_url'],
api_key=os.getenv("OPENAI_API_KEY"),
),
mode=instructor.Mode.JSON,
)
import time
def generate(self):
retry_delay = 1 # Start with a 1 second delay
max_retries = 5 # Maximum number of retries
retries = 0
while retries < max_retries:
try:
response = self.client.chat.completions.create(
model=self.config_list[0]['model'],
response_model=TeamStructure,
messages=[
{"role": "system", "content": "You are a helpful assistant designed to output complex team structures."},
{"role": "user", "content": self.get_user_content()}
]
)
json_data = json.loads(response.model_dump_json())
self.convert_and_save(json_data)
full_path = os.path.abspath(self.agent_file)
return full_path
except openai.error.RateLimitError:
print(f"RateLimitError: Retrying in {retry_delay} seconds...")
time.sleep(retry_delay)
retry_delay *= 2 # Exponential backoff
retries += 1
raise Exception("Max retries exceeded for API call")
def convert_and_save(self, json_data):
"""Converts the provided JSON data into the desired YAML format and saves it to a file.
Args:
json_data (dict): The JSON data representing the team structure.
topic (str, optional): The topic to be inserted into the YAML. Defaults to "Artificial Intelligence".
agent_file (str, optional): The name of the YAML file to save. Defaults to "test.yaml".
"""
yaml_data = {
"framework": self.framework,
"topic": self.topic,
"roles": {},
"dependencies": []
}
for role_id, role_details in json_data['roles'].items():
yaml_data['roles'][role_id] = {
"backstory": "" + role_details['backstory'],
"goal": role_details['goal'],
"role": role_details['role'],
"tasks": {},
# "tools": role_details.get('tools', []),
"tools": ['']
}
for task_id, task_details in role_details['tasks'].items():
yaml_data['roles'][role_id]['tasks'][task_id] = {
"description": "" + task_details['description'],
"expected_output": "" + task_details['expected_output']
}
# Save to YAML file, maintaining the order
with open(self.agent_file, 'w') as f:
yaml.dump(yaml_data, f, allow_unicode=True, sort_keys=False)
def get_user_content(self):
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.
The last role will generate the final output.
Think step by step.
With maximum 3 roles, each with 1 task. Include role goals, backstories, task descriptions, and expected outputs.
List of Available Tools: CodeDocsSearchTool, CSVSearchTool, DirectorySearchTool, DOCXSearchTool, DirectoryReadTool, FileReadTool, TXTSearchTool, JSONSearchTool, MDXSearchTool, PDFSearchTool, RagTool, ScrapeElementFromWebsiteTool, ScrapeWebsiteTool, WebsiteSearchTool, XMLSearchTool, YoutubeChannelSearchTool, YoutubeVideoSearchTool.
Only use Available Tools. Do Not use any other tools.
Example Below:
Use below example to understand the structure of the output.
The final role you create should satisfy the provided task: """ + self.topic + """.
{
"roles": {
"narrative_designer": {
"role": "Narrative Designer",
"goal": "Create AI storylines",
"backstory": "Skilled in narrative development for AI, with a focus on story resonance.",
"tools": ["ScrapeWebsiteTool"],
"tasks": {
"story_concept_development": {
"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 .",
"expected_output": "Document with narrative arcs, character bios, and settings."
}
}
},
"scriptwriter": {
"role": "Scriptwriter",
"goal": "Write scripts from AI concepts",
"backstory": "Expert in dialogue and script structure, translating concepts into scripts.",
"tasks": {
"scriptwriting_task": {
"description": "Turn narrative concepts into scripts, including dialogue and scenes.",
"expected_output": "Production-ready script with dialogue and scene details."
}
}
}
}
}
"""
return user_content
# generator = AutoGenerator(framework="crewai", topic="Create a snake game in python")
# print(generator.generate())
+149 -91
View File
@@ -1,3 +1,5 @@
# praisonai/cli.py
import sys
from .version import __version__
import yaml, os
@@ -5,110 +7,166 @@ from rich import print
from dotenv import load_dotenv
from crewai import Agent, Task, Crew
load_dotenv()
print(f"Loaded environment variables: OPENAI_MODEL_NAME={os.environ.get('OPENAI_MODEL_NAME')}, OPENAI_API_KEY={os.environ.get('OPENAI_API_KEY')}, OPENAI_API_BASE={os.environ.get('OPENAI_API_BASE')}")
import autogen
config_list = [
{
'model': os.environ.get("OPENAI_MODEL_NAME", "gpt-3.5-turbo"),
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
}
]
import gradio as gr
import argparse
from .auto import AutoGenerator
from .agents_generator import AgentsGenerator
from crewai_tools import *
from .tools import *
def generate_crew_and_kickoff(agent_file, framework=None):
with open(agent_file, 'r') as f:
config = yaml.safe_load(f)
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"),
'base_url': os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1"),
}
]
self.agent_file = agent_file
self.framework = framework
self.auto = auto
self.init = init
topic = config['topic']
framework = framework or config.get('framework')
def main(self):
args = self.parse_args()
if args is None:
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
result = agents_generator.generate_crew_and_kickoff()
return result
if args.deploy:
from .deploy import CloudDeployer
deployer = CloudDeployer()
deployer.run_commands()
return
invocation_cmd = "praisonai"
version_string = f"PraisonAI version {__version__}"
agents = {}
tasks = []
if framework == "autogen":
# Load the LLM configuration dynamically
print(config_list)
llm_config = {"config_list": config_list}
for role, details in config['roles'].items():
agent_name = details['role'].format(topic=topic).replace("{topic}", topic)
agent_goal = details['goal'].format(topic=topic)
# Creating an AssistantAgent for each role dynamically
agents[role] = autogen.AssistantAgent(
name=agent_name,
llm_config=llm_config,
system_message=details['backstory'].format(topic=topic)+". Reply \"TERMINATE\" in the end when everything is done.",
)
if args.framework:
self.framework = args.framework
# Preparing tasks for initiate_chats
for task_name, task_details in details.get('tasks', {}).items():
description_filled = task_details['description'].format(topic=topic)
expected_output_filled = task_details['expected_output'].format(topic=topic)
chat_task = {
"recipient": agents[role],
"message": description_filled,
"summary_method": "last_msg", # Customize as needed
# Additional fields like carryover can be added based on dependencies
}
tasks.append(chat_task)
ui = args.ui
# Assuming the user proxy agent is set up as per your requirements
user = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: (x.get("content") or "").rstrip().endswith("TERMINATE"),
code_execution_config={
"work_dir": "coding",
"use_docker": False,
},
# additional setup for the user proxy agent
)
response = user.initiate_chats(tasks)
result = "### Output ###\n"+response[-1].summary if hasattr(response[-1], 'summary') else ""
else:
for role, details in config['roles'].items():
role_filled = details['role'].format(topic=topic)
goal_filled = details['goal'].format(topic=topic)
backstory_filled = details['backstory'].format(topic=topic)
# Assume tools are loaded and handled here as per your requirements
agent = Agent(role=role_filled, goal=goal_filled, backstory=backstory_filled)
agents[role] = agent
if args.agent_file:
if args.agent_file == "tests.test": # Argument used for testing purposes
full_path = os.path.abspath("agents.yaml")
else:
full_path = os.path.abspath(args.agent_file)
self.agent_file = full_path
else:
full_path = os.path.abspath(self.agent_file)
self.agent_file = full_path
for task_name, task_details in details.get('tasks', {}).items():
description_filled = task_details['description'].format(topic=topic)
expected_output_filled = task_details['expected_output'].format(topic=topic)
if args.auto or args.init:
temp_topic = ' '.join(args.auto) if args.auto else ' '.join(args.init)
self.topic = temp_topic
elif self.auto or self.init: # Use the auto attribute if args.auto is not provided
self.topic = self.auto
task = Task(description=description_filled, expected_output=expected_output_filled, agent=agent)
tasks.append(task)
if args.auto or self.auto:
if not os.environ.get('OPENAI_API_KEY'):
print("Error: OPENAI_API_KEY is not set. Please check your .env file.")
sys.exit(1)
print(f"Debug: OPENAI_API_KEY={os.environ.get('OPENAI_API_KEY')}")
self.agent_file = "test.yaml"
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
self.agent_file = generator.generate()
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
result = agents_generator.generate_crew_and_kickoff()
return result
elif args.init or self.init:
if not os.environ.get('OPENAI_API_KEY'):
print("Error: OPENAI_API_KEY is not set. Please check your .env file.")
sys.exit(1)
print(f"Debug: OPENAI_API_KEY={os.environ.get('OPENAI_API_KEY')}")
self.agent_file = "agents.yaml"
generator = AutoGenerator(topic=self.topic , framework=self.framework, agent_file=self.agent_file)
self.agent_file = generator.generate()
print("File {} created successfully".format(self.agent_file))
return "File {} created successfully".format(self.agent_file)
crew = Crew(
agents=list(agents.values()),
tasks=tasks,
verbose=2
)
if ui:
self.create_gradio_interface()
else:
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
result = agents_generator.generate_crew_and_kickoff()
return result
result = crew.kickoff()
return result
def parse_args(self):
parser = argparse.ArgumentParser(prog="praisonai", description="praisonAI command-line interface")
parser.add_argument("--framework", choices=["crewai", "autogen"], default="crewai", help="Specify the framework")
parser.add_argument("--ui", action="store_true", help="Enable UI mode")
parser.add_argument("--auto", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
parser.add_argument("--init", nargs=argparse.REMAINDER, help="Enable auto mode and pass arguments for it")
parser.add_argument("agent_file", nargs="?", help="Specify the agent file")
parser.add_argument("--deploy", action="store_true", help="Deploy the application") # New argument
def main(args=None):
if args is None:
args = sys.argv[1:] # Skip the script name
args, unknown_args = parser.parse_known_args()
invocation_cmd = "praisonai"
version_string = f"PraisonAI version {__version__}"
framework = "crewai" # Default framework
if unknown_args and unknown_args[0] == '-b' and unknown_args[1] == 'api:app':
args.agent_file = 'agents.yaml'
if args.agent_file == 'api:app' or args.agent_file == '/app/api:app':
args.agent_file = 'agents.yaml'
if "--framework" in args:
framework_index = args.index("--framework")
framework = args[framework_index + 1]
args = args[:framework_index] + args[framework_index + 2:]
return args
if args:
agent_file = args[-1] # Assuming the last argument is the agent file
else:
agent_file = "agents.yaml"
def create_gradio_interface(self):
def generate_crew_and_kickoff_interface(auto_args, framework):
self.framework = framework
self.agent_file = "test.yaml"
generator = AutoGenerator(topic=auto_args , framework=self.framework)
self.agent_file = generator.generate()
agents_generator = AgentsGenerator(self.agent_file, self.framework, self.config_list)
result = agents_generator.generate_crew_and_kickoff()
return result
gr.Interface(
fn=generate_crew_and_kickoff_interface,
inputs=[gr.Textbox(lines=2, label="Auto Args"), gr.Dropdown(choices=["crewai", "autogen"], label="Framework")],
outputs="textbox",
title="Praison AI Studio",
description="Create Agents and perform tasks",
theme="default"
).launch()
result = generate_crew_and_kickoff(agent_file, framework)
print(result)
if __name__ == "__main__":
main()
praison_ai = PraisonAI()
praison_ai.main()
## agents.yaml
# framework: autogen
# topic: create movie script about cat in mars
# roles:
# concept_developer:
# backstory: Experienced in creating captivating and original story concepts.
# goal: Generate a unique concept for a movie script about a cat in Mars
# role: Concept Developer
# tools:
# - search_tool
# tasks:
# concept_generation:
# description: Develop a unique and engaging concept for a movie script about
# a cat in Mars.
# expected_output: A detailed concept document for the movie script.
# scriptwriter:
# backstory: Expert in dialogue and script structure, translating concepts into
# scripts.
# goal: Write a script based on the movie concept
# role: Scriptwriter
# tasks:
# scriptwriting_task:
# description: Turn the movie concept into a script, including dialogue and
# scenes.
# expected_output: A production-ready script for the movie about a cat in Mars.
# director:
# backstory: Experienced in visualizing scripts and creating compelling storyboards.
# goal: Create a storyboard and visualize the script
# role: Director
# tasks:
# storyboard_creation:
# description: Create a storyboard for the movie script about a cat in Mars.
# expected_output: A detailed storyboard for the movie about a cat in Mars.
# dependencies: []
+66
View File
@@ -0,0 +1,66 @@
import subprocess
import os
from dotenv import load_dotenv
class CloudDeployer:
def __init__(self):
# Load environment variables from .env file or system
load_dotenv()
self.set_environment_variables()
def create_dockerfile(self):
with open("Dockerfile", "w") as file:
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.18 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
def create_api_file(self):
with open("api.py", "w") as file:
file.write("from flask import Flask\n")
file.write("from praisonai import PraisonAI\n")
file.write("import markdown\n\n")
file.write("app = Flask(__name__)\n\n")
file.write("def basic():\n")
file.write(" praison_ai = PraisonAI(agent_file=\"agents.yaml\")\n")
file.write(" return praison_ai.main()\n\n")
file.write("@app.route('/')\n")
file.write("def home():\n")
file.write(" output = basic()\n")
file.write(" html_output = markdown.markdown(output)\n")
file.write(" return f'<html><body>{html_output}</body></html>'\n\n")
file.write("if __name__ == \"__main__\":\n")
file.write(" app.run(debug=True)\n")
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_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")
def run_commands(self):
self.create_api_file()
self.create_dockerfile()
"""Runs a sequence of shell commands for deployment, continues on error."""
commands = [
"yes | gcloud auth configure-docker us-central1-docker.pkg.dev",
"gcloud artifacts repositories create praisonai-repository --repository-format=docker --location=us-central1",
"docker build --platform linux/amd64 -t gcr.io/$(gcloud config get-value project)/praisonai-app:latest .",
"docker tag gcr.io/$(gcloud config get-value project)/praisonai-app:latest us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest",
"docker push us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest",
"gcloud run deploy praisonai-service --image us-central1-docker.pkg.dev/$(gcloud config get-value project)/praisonai-repository/praisonai-app:latest --platform managed --region us-central1 --allow-unauthenticated --set-env-vars OPENAI_MODEL_NAME=${OPENAI_MODEL_NAME},OPENAI_API_KEY=${OPENAI_API_KEY},OPENAI_API_BASE=${OPENAI_API_BASE}"
]
for cmd in commands:
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"ERROR: Command '{e.cmd}' failed with exit status {e.returncode}")
print(f"Continuing with the next command...")
# Usage
if __name__ == "__main__":
deployer = CloudDeployer()
deployer.run_commands()
+2
View File
@@ -0,0 +1,2 @@
from .base_tool import BaseTool, Tool, tool
from .autogen_tools import *
+147
View File
@@ -0,0 +1,147 @@
from crewai_tools import (
CodeDocsSearchTool, CSVSearchTool, DirectorySearchTool, DOCXSearchTool, DirectoryReadTool,
FileReadTool, TXTSearchTool, JSONSearchTool, MDXSearchTool, PDFSearchTool, RagTool,
ScrapeElementFromWebsiteTool, ScrapeWebsiteTool, WebsiteSearchTool, XMLSearchTool, YoutubeChannelSearchTool,
YoutubeVideoSearchTool
)
from typing import Any
from autogen import register_function
def autogen_CodeDocsSearchTool(assistant, user_proxy):
def register_code_docs_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(docs_url: str, search_query: str) -> Any:
tool_instance = tool_class(docs_url=docs_url, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_code_docs_search_tool(CodeDocsSearchTool, "code_docs_search_tool", "Search a Code Docs content(search_query: 'string', docs_url: 'string') - A tool that can be used to semantic search a query from a Code Docs content.", assistant, user_proxy)
def autogen_CSVSearchTool(assistant, user_proxy):
def register_csv_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(csv: str, search_query: str) -> Any:
tool_instance = tool_class(csv=csv, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_csv_search_tool(CSVSearchTool, "csv_search_tool", "Search a CSV's content(search_query: 'string', csv: 'string') - A tool that can be used to semantic search a query from a CSV's content.", assistant, user_proxy)
def autogen_DirectorySearchTool(assistant, user_proxy):
def register_directory_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(directory: str, search_query: str) -> Any:
tool_instance = tool_class(directory=directory, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_directory_search_tool(DirectorySearchTool, "directory_search_tool", "Search a directory's content(search_query: 'string', directory: 'string') - A tool that can be used to semantic search a query from a directory's content.", assistant, user_proxy)
def autogen_DOCXSearchTool(assistant, user_proxy):
def register_docx_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(docx: str, search_query: str) -> Any:
tool_instance = tool_class(docx=docx, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_docx_search_tool(DOCXSearchTool, "docx_search_tool", "Search a DOCX's content(search_query: 'string', docx: 'string') - A tool that can be used to semantic search a query from a DOCX's content.", assistant, user_proxy)
# DirectoryReadTool
def autogen_DirectoryReadTool(assistant, user_proxy):
def register_directory_read_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(directory: str) -> Any:
tool_instance = tool_class(directory=directory)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_directory_read_tool(DirectoryReadTool, "directory_read_tool", "List files in directory(directory: 'string') - A tool that can be used to recursively list a directory's content.", assistant, user_proxy)
# FileReadTool
def autogen_FileReadTool(assistant, user_proxy):
def register_file_read_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(file_path: str) -> Any:
tool_instance = tool_class(file_path=file_path)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_file_read_tool(FileReadTool, "file_read_tool", "Read a file's content(file_path: 'string') - A tool that can be used to read a file's content.", assistant, user_proxy)
# TXTSearchTool
def autogen_TXTSearchTool(assistant, user_proxy):
def register_txt_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(txt: str, search_query: str) -> Any:
tool_instance = tool_class(txt=txt, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_txt_search_tool(TXTSearchTool, "txt_search_tool", "Search a txt's content(search_query: 'string', txt: 'string') - A tool that can be used to semantic search a query from a txt's content.", assistant, user_proxy)
def autogen_JSONSearchTool(assistant, user_proxy):
def register_json_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(json_path: str, search_query: str) -> Any:
tool_instance = tool_class(json_path=json_path, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_json_search_tool(JSONSearchTool, "json_search_tool", "Search a JSON's content(search_query: 'string', json_path: 'string') - A tool that can be used to semantic search a query from a JSON's content.", assistant, user_proxy)
def autogen_MDXSearchTool(assistant, user_proxy):
def register_mdx_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(mdx: str, search_query: str) -> Any:
tool_instance = tool_class(mdx=mdx, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_mdx_search_tool(MDXSearchTool, "mdx_search_tool", "Search a MDX's content(search_query: 'string', mdx: 'string') - A tool that can be used to semantic search a query from a MDX's content.", assistant, user_proxy)
def autogen_PDFSearchTool(assistant, user_proxy):
def register_pdf_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(pdf: str, search_query: str) -> Any:
tool_instance = tool_class(pdf=pdf, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_pdf_search_tool(PDFSearchTool, "pdf_search_tool", "Search a PDF's content(search_query: 'string', pdf: 'string') - A tool that can be used to semantic search a query from a PDF's content.", assistant, user_proxy)
def autogen_RagTool(assistant, user_proxy):
def register_rag_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(query: str, data: Any) -> Any:
tool_instance = tool_class(query=query, data=data)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_rag_tool(RagTool, "rag_tool", "Knowledge base(query: 'string', data: Any) - A knowledge base that can be used to answer questions.", assistant, user_proxy)
def autogen_ScrapeElementFromWebsiteTool(assistant, user_proxy):
def register_scrape_element_from_website_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(website_url: str, element_query: str) -> Any:
tool_instance = tool_class(website_url=website_url, element_query=element_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_scrape_element_from_website_tool(ScrapeElementFromWebsiteTool, "scrape_element_from_website_tool", "Scrape an element from a website(element_query: 'string', website_url: 'string') - A tool that can be used to scrape an element from a website.", assistant, user_proxy)
def autogen_ScrapeWebsiteTool(assistant, user_proxy):
def register_scrape_website_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(website_url: str) -> Any:
tool_instance = tool_class(website_url=website_url)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_scrape_website_tool(ScrapeWebsiteTool, "scrape_website_tool", "Read website content(website_url: 'string') - A tool that can be used to read content from a specified website.", assistant, user_proxy)
def autogen_WebsiteSearchTool(assistant, user_proxy):
def register_website_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(website: str, search_query: str) -> Any:
tool_instance = tool_class(website=website, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_website_search_tool(WebsiteSearchTool, "website_search_tool", "Search in a specific website(search_query: 'string', website: 'string') - A tool that can be used to semantic search a query from a specific URL content.", assistant, user_proxy)
def autogen_XMLSearchTool(assistant, user_proxy):
def register_xml_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(xml: str, search_query: str) -> Any:
tool_instance = tool_class(xml=xml, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_xml_search_tool(XMLSearchTool, "xml_search_tool", "Search a XML's content(search_query: 'string', xml: 'string') - A tool that can be used to semantic search a query from a XML's content.", assistant, user_proxy)
def autogen_YoutubeChannelSearchTool(assistant, user_proxy):
def register_youtube_channel_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(youtube_channel_handle: str, search_query: str) -> Any:
tool_instance = tool_class(youtube_channel_handle=youtube_channel_handle, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_youtube_channel_search_tool(YoutubeChannelSearchTool, "youtube_channel_search_tool", "Search a Youtube Channels content(search_query: 'string', youtube_channel_handle: 'string') - A tool that can be used to semantic search a query from a Youtube Channels content.", assistant, user_proxy)
def autogen_YoutubeVideoSearchTool(assistant, user_proxy):
def register_youtube_video_search_tool(tool_class, tool_name, tool_description, assistant, user_proxy):
def tool_func(youtube_video_url: str, search_query: str) -> Any:
tool_instance = tool_class(youtube_video_url=youtube_video_url, search_query=search_query)
return tool_instance.run()
register_function(tool_func, caller=assistant, executor=user_proxy, name=tool_name, description=tool_description)
register_youtube_video_search_tool(YoutubeVideoSearchTool, "youtube_video_search_tool", "Search a Youtube Video content(search_query: 'string', youtube_video_url: 'string') - A tool that can be used to semantic search a query from a Youtube Video content.", assistant, user_proxy)
+146
View File
@@ -0,0 +1,146 @@
from abc import ABC, abstractmethod
from typing import Any, Callable, Optional, Type
from langchain_core.tools import StructuredTool
from pydantic import BaseModel, ConfigDict, Field, validator
from pydantic.v1 import BaseModel as V1BaseModel
class BaseTool(BaseModel, ABC):
class _ArgsSchemaPlaceholder(V1BaseModel):
pass
model_config = ConfigDict()
name: str
"""The unique name of the tool that clearly communicates its purpose."""
description: str
"""Used to tell the model how/when/why to use the tool."""
args_schema: Type[V1BaseModel] = Field(default_factory=_ArgsSchemaPlaceholder)
"""The schema for the arguments that the tool accepts."""
description_updated: bool = False
"""Flag to check if the description has been updated."""
cache_function: Optional[Callable] = lambda _args, _result: True
"""Function that will be used to determine if the tool should be cached, should return a boolean. If None, the tool will be cached."""
@validator("args_schema", always=True, pre=True)
def _default_args_schema(cls, v: Type[V1BaseModel]) -> Type[V1BaseModel]:
if not isinstance(v, cls._ArgsSchemaPlaceholder):
return v
return type(
f"{cls.__name__}Schema",
(V1BaseModel,),
{
"__annotations__": {
k: v for k, v in cls._run.__annotations__.items() if k != "return"
},
},
)
def model_post_init(self, __context: Any) -> None:
self._generate_description()
super().model_post_init(__context)
def run(
self,
*args: Any,
**kwargs: Any,
) -> Any:
print(f"Using Tool: {self.name}")
return self._run(*args, **kwargs)
@abstractmethod
def _run(
self,
*args: Any,
**kwargs: Any,
) -> Any:
"""Here goes the actual implementation of the tool."""
def to_langchain(self) -> StructuredTool:
self._set_args_schema()
return StructuredTool(
name=self.name,
description=self.description,
args_schema=self.args_schema,
func=self._run,
)
def _set_args_schema(self):
if self.args_schema is None:
class_name = f"{self.__class__.__name__}Schema"
self.args_schema = type(
class_name,
(V1BaseModel,),
{
"__annotations__": {
k: v
for k, v in self._run.__annotations__.items()
if k != "return"
},
},
)
def _generate_description(self):
args = []
for arg, attribute in self.args_schema.schema()["properties"].items():
if "type" in attribute:
args.append(f"{arg}: '{attribute['type']}'")
description = self.description.replace("\n", " ")
self.description = f"{self.name}({', '.join(args)}) - {description}"
class Tool(BaseTool):
func: Callable
"""The function that will be executed when the tool is called."""
def _run(self, *args: Any, **kwargs: Any) -> Any:
return self.func(*args, **kwargs)
def to_langchain(
tools: list[BaseTool | StructuredTool],
) -> list[StructuredTool]:
return [t.to_langchain() if isinstance(t, BaseTool) else t for t in tools]
def tool(*args):
"""
Decorator to create a tool from a function.
"""
def _make_with_name(tool_name: str) -> Callable:
def _make_tool(f: Callable) -> BaseTool:
if f.__doc__ is None:
raise ValueError("Function must have a docstring")
if f.__annotations__ is None:
raise ValueError("Function must have type annotations")
class_name = "".join(tool_name.split()).title()
args_schema = type(
class_name,
(V1BaseModel,),
{
"__annotations__": {
k: v for k, v in f.__annotations__.items() if k != "return"
},
},
)
return Tool(
name=tool_name,
description=f.__doc__,
func=f,
args_schema=args_schema,
)
return _make_tool
if len(args) == 1 and callable(args[0]):
return _make_with_name(args[0].__name__)(args[0])
if len(args) == 1 and isinstance(args[0], str):
return _make_with_name(args[0])
raise ValueError("Invalid arguments")
+116
View File
@@ -0,0 +1,116 @@
from crewai_tools import (
CodeDocsSearchTool, CSVSearchTool, DirectorySearchTool, DOCXSearchTool, DirectoryReadTool,
FileReadTool, TXTSearchTool, JSONSearchTool, MDXSearchTool, PDFSearchTool, RagTool,
ScrapeElementFromWebsiteTool, ScrapeWebsiteTool, WebsiteSearchTool, XMLSearchTool, YoutubeChannelSearchTool,
YoutubeVideoSearchTool
)
import inspect
# Assuming the tool classes are imported correctly as in the original request
tools_classes = {
'CodeDocsSearchTool': CodeDocsSearchTool,
'CSVSearchTool': CSVSearchTool,
'DirectorySearchTool': DirectorySearchTool,
'DOCXSearchTool': DOCXSearchTool,
'DirectoryReadTool': DirectoryReadTool,
'FileReadTool': FileReadTool,
'TXTSearchTool': TXTSearchTool,
'JSONSearchTool': JSONSearchTool,
'MDXSearchTool': MDXSearchTool,
'PDFSearchTool': PDFSearchTool,
'RagTool': RagTool,
'ScrapeElementFromWebsiteTool': ScrapeElementFromWebsiteTool,
'ScrapeWebsiteTool': ScrapeWebsiteTool,
'WebsiteSearchTool': WebsiteSearchTool,
'XMLSearchTool': XMLSearchTool,
'YoutubeChannelSearchTool': YoutubeChannelSearchTool,
'YoutubeVideoSearchTool': YoutubeVideoSearchTool,
}
for tool_name, tool_class in tools_classes.items():
# Inspect the constructor (__init__) to get its parameters, excluding 'self'
constructor_params = inspect.signature(tool_class.__init__).parameters
param_names = [p for p in constructor_params if p != 'self']
# Attempt to instantiate the tool with dummy or default values for parameters
try:
# Creating a dummy parameters dict with None or empty values based on parameter name
dummy_params = {param: None if param != 'website_url' else 'http://example.com' for param in param_names}
instance = tool_class(**dummy_params)
tool_description = getattr(instance, "description", "No description attribute")
except Exception as e:
tool_description = f"Error instantiating tool for description extraction: {str(e)}"
# Printing tool class name, its constructor parameters, and description
print(f"Tool Class: {tool_name}")
print(f"Constructor Parameters: {', '.join(param_names)}")
print(f"Description: {tool_description}\n")
# Tool Class: CodeDocsSearchTool
# Constructor Parameters: docs_url, kwargs
# Description: Search a Code Docs content(search_query: 'string', docs_url: 'string') - A tool that can be used to semantic search a query from a Code Docs content.
# Tool Class: CSVSearchTool
# Constructor Parameters: csv, kwargs
# Description: Search a CSV's content(search_query: 'string', csv: 'string') - A tool that can be used to semantic search a query from a CSV's content.
# Tool Class: DirectorySearchTool
# Constructor Parameters: directory, kwargs
# Description: Search a directory's content(search_query: 'string', directory: 'string') - A tool that can be used to semantic search a query from a directory's content.
# Tool Class: DOCXSearchTool
# Constructor Parameters: docx, kwargs
# Description: Search a DOCX's content(search_query: 'string', docx: 'string') - A tool that can be used to semantic search a query from a DOCX's content.
# Tool Class: DirectoryReadTool
# Constructor Parameters: directory, kwargs
# Description: List files in directory(directory: 'string') - A tool that can be used to recursively list a directory's content.
# Tool Class: FileReadTool
# Constructor Parameters: file_path, kwargs
# Description: Read a file's content(file_path: 'string') - A tool that can be used to read a file's content.
# Tool Class: TXTSearchTool
# Constructor Parameters: txt, kwargs
# Description: Search a txt's content(search_query: 'string', txt: 'string') - A tool that can be used to semantic search a query from a txt's content.
# Tool Class: JSONSearchTool
# Constructor Parameters: json_path, kwargs
# Description: Search a JSON's content(search_query: 'string', json_path: 'string') - A tool that can be used to semantic search a query from a JSON's content.
# Tool Class: MDXSearchTool
# Constructor Parameters: mdx, kwargs
# Description: Search a MDX's content(search_query: 'string', mdx: 'string') - A tool that can be used to semantic search a query from a MDX's content.
# Tool Class: PDFSearchTool
# Constructor Parameters: pdf, kwargs
# Description: Search a PDF's content(query: 'string', pdf: 'string') - A tool that can be used to semantic search a query from a PDF's content.
# Tool Class: RagTool
# Constructor Parameters: data
# Description: Knowledge base(query: 'string') - A knowledge base that can be used to answer questions.
# Tool Class: ScrapeElementFromWebsiteTool
# Constructor Parameters: website_url, cookies, css_element, kwargs
# Description: Read a website content() - A tool that can be used to read http://example.com's content.
# Tool Class: ScrapeWebsiteTool
# Constructor Parameters: website_url, cookies, kwargs
# Description: Read website content() - A tool that can be used to read http://example.com's content.
# Tool Class: WebsiteSearchTool
# Constructor Parameters: website, kwargs
# Description: Search in a specific website(search_query: 'string', website: 'string') - A tool that can be used to semantic search a query from a specific URL content.
# Tool Class: XMLSearchTool
# Constructor Parameters: xml, kwargs
# Description: Search a XML's content(search_query: 'string', xml: 'string') - A tool that can be used to semantic search a query from a XML's content.
# Tool Class: YoutubeChannelSearchTool
# Constructor Parameters: youtube_channel_handle, kwargs
# Description: Search a Youtube Channels content(search_query: 'string', youtube_channel_handle: 'string') - A tool that can be used to semantic search a query from a Youtube Channels content.
# Tool Class: YoutubeVideoSearchTool
# Constructor Parameters: youtube_video_url, kwargs
# Description: Search a Youtube Video content(search_query: 'string', youtube_video_url: 'string') - A tool that can be used to semantic search a query from a Youtube Video content.
@@ -0,0 +1,38 @@
from typing import Any, Optional
import os
from autogen import ConversableAgent
from scrape_website_tool.scrape_website_tool import ScrapeWebsiteTool
assistant = ConversableAgent(
name="Assistant",
system_message="You are a helpful AI assistant. "
"You can help with website scraping. "
"Return 'TERMINATE' when the task is done.",
llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
)
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="NEVER",
)
from autogen import register_function
from typing import Any
def register_tool(tool_class, tool_name, tool_description):
def tool_func(website_url: str) -> Any:
tool_instance = tool_class(website_url=website_url)
return tool_instance.run()
register_function(
tool_func,
caller=assistant, # The assistant agent can suggest calls to the tool.
executor=user_proxy, # The user proxy agent can execute the tool calls.
name=tool_name, # By default, the function name is used as the tool name.
description=tool_description, # A description of the tool.
)
register_tool(ScrapeWebsiteTool, "scrape_website_tool", "A tool for scraping specific websites")
chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Nodejs website.")
@@ -0,0 +1,44 @@
from typing import Annotated, Literal
import os
from autogen import ConversableAgent
Operator = Literal["+", "-", "*", "/"]
def calculator(a: int, b: int, operator: Annotated[Operator, "operator"]) -> int:
if operator == "+":
return a + b
elif operator == "-":
return a - b
elif operator == "*":
return a * b
elif operator == "/":
return int(a / b)
else:
raise ValueError("Invalid operator")
assistant = ConversableAgent(
name="Assistant",
system_message="You are a helpful AI assistant. "
"You can help with simple calculations. "
"Return 'TERMINATE' when the task is done.",
llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
)
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="NEVER",
)
from autogen import register_function
# Register the calculator function to the agent and user proxy to add a calculator tool.
register_function(
calculator,
caller=assistant, # The assistant agent can suggest calls to the calculator.
executor=user_proxy, # The user proxy agent can execute the calculator calls.
name="calculator", # By default, the function name is used as the tool name.
description="A simple calculator", # A description of the tool.
)
chat_result = user_proxy.initiate_chat(assistant, message="What is (44232 + 13312 / (232 - 32)) * 5?")
@@ -0,0 +1,35 @@
from typing import Any, Optional
import os
from autogen import ConversableAgent
from scrape_website_tool.scrape_website_tool import ScrapeWebsiteTool
def scrape_website_tool(website_url: str) -> Any:
scrape_tool = ScrapeWebsiteTool(website_url=website_url)
return scrape_tool.run()
assistant = ConversableAgent(
name="Assistant",
system_message="You are a helpful AI assistant. "
"You can help with website scraping. "
"Return 'TERMINATE' when the task is done.",
llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
)
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="NEVER",
)
from autogen import register_function
# Register the ScrapeWebsiteTool function to the agent and user proxy to add a website scraping tool.
register_function(
scrape_website_tool,
caller=assistant, # The assistant agent can suggest calls to the scrape website tool.
executor=user_proxy, # The user proxy agent can execute the scrape website tool calls.
name="scrape_website_tool", # By default, the function name is used as the tool name.
description="A tool for scraping specific websites", # A description of the tool.
)
chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Python website.")
+23
View File
@@ -0,0 +1,23 @@
from typing import Any, Optional
import os
from autogen import ConversableAgent
from autogen_tools import autogen_ScrapeWebsiteTool
assistant = ConversableAgent(
name="Assistant",
system_message="You are a helpful AI assistant. "
"You can help with website scraping. "
"Return 'TERMINATE' when the task is done.",
llm_config={"config_list": [{"model": "gpt-3.5-turbo", "api_key": os.environ["OPENAI_API_KEY"]}]},
)
user_proxy = ConversableAgent(
name="User",
llm_config=False,
is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
human_input_mode="NEVER",
)
autogen_ScrapeWebsiteTool(assistant, user_proxy)
chat_result = user_proxy.initiate_chat(assistant, message="Scrape the official Nodejs website.")
+134
View File
@@ -0,0 +1,134 @@
import os
from crewai import Agent, Task, Crew
from crewai_tools import (
DirectoryReadTool,
FileReadTool,
SerperDevTool,
WebsiteSearchTool
)
os.environ["SERPER_API_KEY"] = "Your Key"
os.environ["OPENAI_API_KEY"] = "Your Key"
docs_tool = DirectoryReadTool(directory='./blog-posts')
file_tool = FileReadTool()
search_tool = SerperDevTool()
web_rag_tool = WebsiteSearchTool()
researcher = Agent(
role='Market Research Analyst',
goal='Provide up-to-date market analysis of the AI industry',
backstory='An expert analyst with a keen eye for market trends.',
tools=[search_tool, web_rag_tool],
verbose=True
)
writer = Agent(
role='Content Writer',
goal='Craft engaging blog posts about the AI industry',
backstory='A skilled writer with a passion for technology.',
tools=[docs_tool, file_tool],
verbose=True
)
research = Task(
description='Research the latest trends in the AI industry and provide a summary.',
expected_output='A summary of the top 3 trending developments in the AI industry with a unique perspective on their significance.',
agent=researcher
)
write = Task(
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.',
expected_output='A 4-paragraph blog post formatted in markdown with engaging, informative, and accessible content, avoiding complex jargon.',
agent=writer,
output_file='blog-posts/new_post.md'
)
crew = Crew(
agents=[researcher, writer],
tasks=[research, write],
verbose=2
)
crew.kickoff()
from crewai_tools import DirectoryReadTool
tool = DirectoryReadTool()
toos = DirectoryReadTool(directory='./directory')
from crewai_tools import BaseTool
class MyCustomTool(BaseTool):
name: str = "Name of my tool"
description: str = "Clear description for what this tool is useful for, you agent will need this information to use it."
def _run(self, argument: str) -> str:
return "Result from custom tool"
from crewai_tools import tool
@tool("Name of my tool")
def my_tool(question: str) -> str:
return "Result from my tool"
import json
import requests
from crewai import Agent
from crewai.tools import tool
from unstructured.partition.html import partition_html
@tool("Integration with a given API")
def integration_tool(argument: str) -> str:
return "Results from integration tool"
agent = Agent(
role='Research Analyst',
goal='Provide up-to-date market analysis',
backstory='An expert analyst with a keen eye for market trends.',
tools=[integration_tool]
)
from crewai import Agent
from langchain.agents import Tool
from langchain.utilities import GoogleSerperAPIWrapper
os.environ["SERPER_API_KEY"] = "Your Key"
search = GoogleSerperAPIWrapper()
serper_tool = Tool(
name="Intermediate Answer",
func=search.run,
description="Useful for search-based queries",
)
agent = Agent(
role='Research Analyst',
goal='Provide up-to-date market analysis',
backstory='An expert analyst with a keen eye for market trends.',
tools=[serper_tool]
)
# Tool Description
# CodeDocsSearchTool A RAG tool optimized for searching through code documentation and related technical documents.
# CSVSearchTool A RAG tool designed for searching within CSV files, tailored to handle structured data.
# DirectorySearchTool A RAG tool for searching within directories, useful for navigating through file systems.
# DOCXSearchTool A RAG tool aimed at searching within DOCX documents, ideal for processing Word files.
# DirectoryReadTool Facilitates reading and processing of directory structures and their contents.
# FileReadTool Enables reading and extracting data from files, supporting various file formats.
# GithubSearchTool A RAG tool for searching within GitHub repositories, useful for code and documentation search.
# SeperDevTool A specialized tool for development purposes, with specific functionalities under development.
# TXTSearchTool A RAG tool focused on searching within text (.txt) files, suitable for unstructured data.
# JSONSearchTool A RAG tool designed for searching within JSON files, catering to structured data handling.
# MDXSearchTool A RAG tool tailored for searching within Markdown (MDX) files, useful for documentation.
# PDFSearchTool A RAG tool aimed at searching within PDF documents, ideal for processing scanned documents.
# PGSearchTool A RAG tool optimized for searching within PostgreSQL databases, suitable for database queries.
# RagTool A general-purpose RAG tool capable of handling various data sources and types.
# ScrapeElementFromWebsiteTool Enables scraping specific elements from websites, useful for targeted data extraction.
# ScrapeWebsiteTool Facilitates scraping entire websites, ideal for comprehensive data collection.
# WebsiteSearchTool A RAG tool for searching website content, optimized for web data extraction.
# XMLSearchTool A RAG tool designed for searching within XML files, suitable for structured data formats.
# YoutubeChannelSearchTool A RAG tool for searching within YouTube channels, useful for video content analysis.
# YoutubeVideoSearchTool A RAG tool aimed at searching within YouTube videos, ideal for video data extraction.
+20 -8
View File
@@ -1,23 +1,35 @@
[tool.poetry]
name = "PraisonAI"
version = "0.0.1"
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."
name = "praisonAI"
version = "0.0.18"
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 = ""
readme = "README.md"
[tool.poetry.urls]
Homepage = "https://github.com/mervinpraison/PraisonAI"
Repository = "https://github.com/mervinpraison/PraisonAI"
Homepage = "https://github.com/mervinpraison/praisonAI"
Repository = "https://github.com/mervinpraison/praisonAI"
[tool.setuptools]
packages = ["praisonAI"]
[tool.poetry.dependencies]
python = ">=3.10,<3.13"
rich = ">=13.7"
pyautogen = ">=0.2.19"
crewai = ">=0.22.5"
gradio = ">=4.20.0"
Flask = ">=3.0.0"
markdown = ">=3.5"
crewai-tools = "^0.1.1"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
pytest = "^8.0.0"
pre-commit = "^3.7"
[tool.poetry.extras]
tools = ["crewai-tools"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
praisonai = "praisonai.__main__:main"
+2 -1
View File
@@ -1,3 +1,4 @@
rich>=13.7
pyautogen>=0.2.19
crewai>=0.22.5
crewai>=0.22.5
gradio>=4.20.0
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
# Check the first argument provided to the script for platform selection
if [ "$1" = "groq" ]; then
# Check for a second argument for the model name, default to mixtral-8x7b-32768 if not provided
MODEL_NAME=${2:-mixtral-8x7b-32768}
# Set environment variables for Groq configuration with dynamic model name
export OPENAI_MODEL_NAME=$MODEL_NAME
export OPENAI_API_BASE=https://api.groq.com/openai/v1
export OPENAI_API_KEY=$(echo $GROQ_API_KEY)
echo "Groq configuration initiated with model $MODEL_NAME."
elif [ "$1" = "openai" ] || [ -z "$1" ]; then
# Check for a second argument for the model name, default to gpt-3.5-turbo if not provided
MODEL_NAME=${2:-gpt-3.5-turbo}
# Set environment variables for OpenAI configuration with dynamic model name
export OPENAI_MODEL_NAME=$MODEL_NAME
export OPENAI_API_BASE=https://api.openai.com/v1
export OPENAI_API_KEY=$(echo $OAI_API_KEY)
echo "OpenAI configuration initiated with model $MODEL_NAME."
fi
View File
Whitespace-only changes.
+11
View File
@@ -0,0 +1,11 @@
from praisonai import PraisonAI
def advanced():
praison_ai = PraisonAI(
agent_file="agents.yaml",
framework="autogen",
)
praison_ai.main()
if __name__ == "__main__":
advanced()
+41
View File
@@ -0,0 +1,41 @@
framework: "crewai"
topic: "Artificial Intelligence"
roles:
narrative_designer:
role: "Narrative Designer"
goal: "Craft engaging storylines and narratives for {topic}"
backstory: >
You're a creative visionary skilled in weaving complex narratives and
developing engaging story worlds within {topic}. Your expertise lies in
conceptualizing the overarching story and ensuring it resonates with the audience.
tasks:
story_concept_development:
description: >
Develop a compelling story concept for {topic}, focusing on originality,
thematic depth, and audience engagement. Outline the main narrative arcs,
characters, and settings.
expected_output: >
A comprehensive document outlining the story concept, including key narrative
arcs, character bios, and settings descriptions.
scriptwriter:
role: "Scriptwriter"
goal: "Transform story concepts into detailed scripts for {topic}"
backstory: >
With a flair for dialogue and a deep understanding of pacing and structure,
you excel at bringing narratives to life through scriptwriting. Your work
turns story concepts into blueprints for compelling {topic} experiences.
tasks:
scriptwriting_task:
description: >
Based on the narrative concept, write a detailed script for {topic}.
Include dialogue, stage directions, and scene descriptions that bring
the story to life.
expected_output: >
A detailed script ready for production, including dialogue, stage
directions, and scene descriptions.
dependencies:
- task: scriptwriting_task
depends_on: story_concept_development
+12
View File
@@ -0,0 +1,12 @@
from praisonai import PraisonAI
def auto():
praison_ai = PraisonAI(
auto="Create a movie script about car in mars",
framework="autogen"
)
print(praison_ai.framework)
praison_ai.main()
if __name__ == "__main__":
auto()
+41
View File
@@ -0,0 +1,41 @@
framework: "autogen"
topic: "Artificial Intelligence"
roles:
narrative_designer:
role: "Narrative Designer"
goal: "Craft engaging storylines and narratives for {topic}"
backstory: >
You're a creative visionary skilled in weaving complex narratives and
developing engaging story worlds within {topic}. Your expertise lies in
conceptualizing the overarching story and ensuring it resonates with the audience.
tasks:
story_concept_development:
description: >
Develop a compelling story concept for {topic}, focusing on originality,
thematic depth, and audience engagement. Outline the main narrative arcs,
characters, and settings.
expected_output: >
A comprehensive document outlining the story concept, including key narrative
arcs, character bios, and settings descriptions.
scriptwriter:
role: "Scriptwriter"
goal: "Transform story concepts into detailed scripts for {topic}"
backstory: >
With a flair for dialogue and a deep understanding of pacing and structure,
you excel at bringing narratives to life through scriptwriting. Your work
turns story concepts into blueprints for compelling {topic} experiences.
tasks:
scriptwriting_task:
description: >
Based on the narrative concept, write a detailed script for {topic}.
Include dialogue, stage directions, and scene descriptions that bring
the story to life.
expected_output: >
A detailed script ready for production, including dialogue, stage
directions, and scene descriptions.
dependencies:
- task: scriptwriting_task
depends_on: story_concept_development
+8
View File
@@ -0,0 +1,8 @@
from praisonai import PraisonAI
def main():
praison_ai = PraisonAI(agent_file="agents.yaml")
praison_ai.main()
if __name__ == "__main__":
main()
+41
View File
@@ -0,0 +1,41 @@
framework: "crewai"
topic: "Artificial Intelligence"
roles:
narrative_designer:
role: "Narrative Designer"
goal: "Craft engaging storylines and narratives for {topic}"
backstory: >
You're a creative visionary skilled in weaving complex narratives and
developing engaging story worlds within {topic}. Your expertise lies in
conceptualizing the overarching story and ensuring it resonates with the audience.
tasks:
story_concept_development:
description: >
Develop a compelling story concept for {topic}, focusing on originality,
thematic depth, and audience engagement. Outline the main narrative arcs,
characters, and settings.
expected_output: >
A comprehensive document outlining the story concept, including key narrative
arcs, character bios, and settings descriptions.
scriptwriter:
role: "Scriptwriter"
goal: "Transform story concepts into detailed scripts for {topic}"
backstory: >
With a flair for dialogue and a deep understanding of pacing and structure,
you excel at bringing narratives to life through scriptwriting. Your work
turns story concepts into blueprints for compelling {topic} experiences.
tasks:
scriptwriting_task:
description: >
Based on the narrative concept, write a detailed script for {topic}.
Include dialogue, stage directions, and scene descriptions that bring
the story to life.
expected_output: >
A detailed script ready for production, including dialogue, stage
directions, and scene descriptions.
dependencies:
- task: scriptwriting_task
depends_on: story_concept_development
+21
View File
@@ -0,0 +1,21 @@
# tests/debug.py
import tracemalloc
import logging
import warnings
import sys
import traceback
# Enable Tracemalloc
tracemalloc.start()
# Configure Logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)d - %(message)s')
# Function to Log Warnings with Traceback
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
log = file if hasattr(file, 'write') else sys.stderr
traceback.print_stack(file=log)
log.write(warnings.formatwarning(message, category, filename, lineno, line))
# Override showwarning
warnings.showwarning = warn_with_traceback
+47
View File
@@ -0,0 +1,47 @@
# tests/test.py
# from .debug import * # Uncomment this line to import the debug.py file for debugging
import unittest
import os
from praisonai.cli import PraisonAI
from .advanced_example import advanced
from .basic_example import main
from .auto_example import auto
class TestGenerateCrewAndKickoff(unittest.TestCase):
def test_generate_crew_and_kickoff_with_autogen_framework(self):
praison_ai = PraisonAI(agent_file='tests/autogen-agents.yaml')
result = praison_ai.generate_crew_and_kickoff()
# Assert the result
self.assertIn('### Task Output ###', result)
def test_generate_crew_and_kickoff_with_custom_framework(self):
praison_ai = PraisonAI(agent_file='tests/crewai-agents.yaml')
result = praison_ai.generate_crew_and_kickoff()
# Assert the result
self.assertIn('### Task Output ###', result)
class TestPraisonAICommand(unittest.TestCase):
def test_praisonai_command(self):
command = "praisonai --framework autogen --auto create movie script about cat in mars"
result = os.popen(command).read()
self.assertIn('### Task Output ###', result)
class TestPraisonAIInitCommand(unittest.TestCase):
def test_praisonai_init_command(self):
command = "praisonai --framework autogen --init create movie script about cat in mars"
result = os.popen(command).read()
self.assertIn('### Task Output ###', result)
class TestBasicExample(unittest.TestCase):
def test_basic_example(self):
main()
class TestAdvancedExample(unittest.TestCase):
def test_advanced_example(self):
advanced()
class TestAutoExample(unittest.TestCase):
def test_auto_example(self):
auto()
if __name__ == '__main__':
unittest.main()
+8
View File
@@ -0,0 +1,8 @@
from duckduckgo_search import DDGS
@tool("Internet Search Tool")
def internet_search_tool(query: str) -> list:
"""Search Internet for relevant information based on a query."""
ddgs = DDGS()
results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5)
return results