Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update instagram_post example to crewAI 0.30.11 #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions instagram_post/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SERPER_API_KEY=KEY # https://serper.dev/ (free tier)
BROWSERLESS_API_KEY=KEY # https://www.browserless.io/ (free tier)
MODEL='openhermes'
BROWSERLESS_API_KEY=KEY # https://www.browserless.io/ (no more free tier)
SCRAPINGANT_API_KEY= # https://scrapingant.com/ (free tier) (if not set will fallback to BROWSERLESS_API_KEY)
MODEL='openhermes'

4 changes: 2 additions & 2 deletions instagram_post/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from crewai import Agent
from tools.browser_tools import BrowserTools
from tools.search_tools import SearchTools
from langchain.agents import load_tools
from langchain_community.agent_toolkits.load_tools import load_tools

from langchain.llms import Ollama
from langchain_community.llms import Ollama

class MarketingAnalysisAgents:
def __init__(self):
Expand Down
8 changes: 7 additions & 1 deletion instagram_post/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
print("## Welcome to the marketing Crew")
print('-------------------------------')
product_website = input("What is the product website you want a marketing strategy for?\n")
product_details = input("Any extra details about the product and or the instagram post you want?\n")
if not product_website:
print("## You gave an empty value, no worries, we will use the default one")
product_website = "https://heycurio.com/product/gabbo"

product_details = input("Any extra details about the product and or the instagram post you want?\n")
if not product_details:
print("## You gave an empty value, no worries, we will use the default one")
product_details = "Gabbo is robot toy built for children to help them disconnect from the digital world and connect to the real world."

# Create Agents
product_competitor_agent = agents.product_competitor_agent()
Expand Down
6 changes: 6 additions & 0 deletions instagram_post/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def product_analysis(self, agent, product_website, product_details):
Keep in mind, attention to detail is crucial for
a comprehensive analysis. It's currenlty 2024.
"""),
expected_output='A paragraph containing the features and the benefifts of the product.',
agent=agent
)

Expand All @@ -32,6 +33,7 @@ def competitor_analysis(self, agent, product_website, product_details):
Your final report MUST include BOTH all context about {product_website}
and a detailed comparison to whatever competitor they have competitors.
"""),
expected_output='A paragraph containing the description of the competitiors.',
agent=agent
)

Expand All @@ -49,6 +51,7 @@ def campaign_development(self, agent, product_website, product_details):
Your final answer MUST be ideas that will resonate with the audience and
also include ALL context you have about the product and the customer.
"""),
expected_output='A paragraph containing the strategy to sell the product.',
agent=agent
)

Expand All @@ -70,6 +73,7 @@ def instagram_ad_copy(self, agent):
Your final answer MUST be 3 options for an ad copy for instagram that
not only informs but also excites and persuades the audience.
"""),
expected_output='A paragraph containing the text of an engaging story in instagram.',
agent=agent
)

Expand All @@ -95,6 +99,7 @@ def take_photograph_task(self, agent, copy, product_website, product_details):
Your final answer must be 3 options of photographs, each with 1 paragraph
describing the photograph exactly like the examples provided above.
"""),
expected_output='A prompt for midjourney that will generate an impactful image to sell the product.',
agent=agent
)

Expand All @@ -117,5 +122,6 @@ def review_photo(self, agent, product_website, product_details):
Your final answer must be 3 reviewed options of photographs,
each with 1 paragraph description following the examples provided above.
"""),
expected_output='A paragraph containing a review of the photo used to sell the product.',
agent=agent
)
Binary file modified instagram_post/tools/__pycache__/browser_tools.cpython-311.pyc
Binary file not shown.
Binary file modified instagram_post/tools/__pycache__/search_tools.cpython-311.pyc
Binary file not shown.
26 changes: 17 additions & 9 deletions instagram_post/tools/browser_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@

import requests
from crewai import Agent, Task
from langchain.tools import tool
from unstructured.partition.html import partition_html

from langchain.llms import Ollama
from langchain_community.llms import Ollama
from langchain_core.tools import tool

class BrowserTools():

@tool("Scrape website content")
def scrape_and_summarize_website(website):
def scrape_and_summarize_website(url):
"""Useful to scrape and summarize a website content, just pass a string with
only the full url, no need for a final slash `/`, eg: https://google.com or https://clearbit.com/about-us"""
url = f"https://chrome.browserless.io/content?token={os.environ['BROWSERLESS_API_KEY']}"
payload = json.dumps({"url": website})
headers = {'cache-control': 'no-cache', 'content-type': 'application/json'}
response = requests.request("POST", url, headers=headers, data=payload)
# Check if SCRAPINGANT_API_KEY is defined and has a non-empty value
scrapingant_api_key = os.environ.get('SCRAPINGANT_API_KEY')
if scrapingant_api_key:
# Use the ScrapingAnt API if the key is available
scraping_url = f"https://api.scrapingant.com/v2/general?x-api-key={scrapingant_api_key}&url={url}"
else:
# Otherwise, use the Browserless API
browserless_api_key = os.environ['BROWSERLESS_API_KEY']
scraping_url = f"https://chrome.browserless.io/content?token={browserless_api_key}"
payload = json.dumps({"url": url})
headers = {'Cache-Control': 'no-cache', 'Content-Type': 'application/json'}
response = requests.request("POST", scraping_url, headers=headers, data=payload)
elements = partition_html(text=response.text)
content = "\n\n".join([str(el) for el in elements])
content = [content[i:i + 8000] for i in range(0, len(content), 8000)]
Expand All @@ -32,9 +39,10 @@ def scrape_and_summarize_website(website):
llm=Ollama(model=os.environ['MODEL']),
allow_delegation=False)
task = Task(
expected_output="A long summary of the product features and description.",
agent=agent,
description=
f'Analyze and make a LONG summary the content bellow, make sure to include the ALL relevant information in the summary, return only the summary nothing else.\n\nCONTENT\n----------\n{chunk}'
f'Analyze and make a LONG summary the content below, make sure to include the ALL relevant information in the summary, return only the summary nothing else.\n\nCONTENT\n----------\n{chunk}'
)
summary = task.execute()
summaries.append(summary)
Expand Down
2 changes: 1 addition & 1 deletion instagram_post/tools/search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import requests
from langchain.tools import tool
from langchain_core.tools import tool


class SearchTools():
Expand Down