firecrawl agent implementation
This commit is contained in:
parent
98c5222a6f
commit
20c49d8f72
6 changed files with 80 additions and 3 deletions
Binary file not shown.
|
|
@ -1,6 +1,5 @@
|
||||||
from exa_py import Exa
|
from exa_py import Exa
|
||||||
|
|
||||||
# Initialize Exa with your API key
|
|
||||||
exa = Exa(api_key="EXA_API_KEY")
|
exa = Exa(api_key="EXA_API_KEY")
|
||||||
|
|
||||||
def get_competitor_urls(url=None, description=None):
|
def get_competitor_urls(url=None, description=None):
|
||||||
|
|
@ -27,6 +26,5 @@ def get_competitor_urls(url=None, description=None):
|
||||||
# Extracting and return only the competitor URLs
|
# Extracting and return only the competitor URLs
|
||||||
competitor_urls = [item.url for item in result.results]
|
competitor_urls = [item.url for item in result.results]
|
||||||
return competitor_urls
|
return competitor_urls
|
||||||
# return result
|
|
||||||
|
|
||||||
print(get_competitor_urls(description="Competitors of a company that works on AI Neuro Health Tech"))
|
print(get_competitor_urls(description="Competitors of a company that works on AI Neuro Health Tech"))
|
||||||
41
ai_agent_tutorials/ai_competitors_analysis_team/fire.py
Normal file
41
ai_agent_tutorials/ai_competitors_analysis_team/fire.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
from phi.agent import Agent
|
||||||
|
from phi.tools.firecrawl import FirecrawlTools
|
||||||
|
from phi.model.openai import OpenAIChat
|
||||||
|
|
||||||
|
firecrawl_tools = FirecrawlTools(
|
||||||
|
api_key="",
|
||||||
|
scrape=False,
|
||||||
|
crawl=True,
|
||||||
|
limit=5
|
||||||
|
)
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
model=OpenAIChat(id="gpt-4o-mini", api_key=""),
|
||||||
|
tools=[firecrawl_tools],
|
||||||
|
show_tool_calls=True,
|
||||||
|
markdown=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def extract_competitor_info(competitor_url: str):
|
||||||
|
crawl_response = agent.run(f"Crawl and summarize {competitor_url}")
|
||||||
|
crawled_data = crawl_response.content
|
||||||
|
|
||||||
|
structured_info = agent.run(
|
||||||
|
f"""Extract the following information from the crawled data:
|
||||||
|
- Product pricing and features - exact pricing numbers from their pricing page
|
||||||
|
- Technology stack information
|
||||||
|
- Marketing messaging/positioning
|
||||||
|
- Customer testimonials/case studies
|
||||||
|
|
||||||
|
Crawled Data:
|
||||||
|
{crawled_data}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
return structured_info.content
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
competitor_url = "https://www.equal.in"
|
||||||
|
competitor_info = extract_competitor_info(competitor_url)
|
||||||
|
print(f"Competitor: {competitor_url}")
|
||||||
|
print(competitor_info)
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
from firecrawl import FirecrawlApp
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
# Define a simple schema for testing
|
||||||
|
class SimpleSchema(BaseModel):
|
||||||
|
title: Optional[str] = Field(description="Title of the webpage.")
|
||||||
|
description: Optional[str] = Field(description="Meta description of the webpage.")
|
||||||
|
|
||||||
|
# Initialize the FirecrawlApp with your API key
|
||||||
|
app = FirecrawlApp(api_key='fc-') # Replace with your API key
|
||||||
|
|
||||||
|
def extract_competitor_info(competitor_url: str):
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Use Firecrawl to scrape and extract data
|
||||||
|
data = app.scrape_url(competitor_url, {
|
||||||
|
'formats': ['extract'],
|
||||||
|
'extract': {
|
||||||
|
'schema': SimpleSchema.model_json_schema(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return data.get("extract", {})
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Competitor URL to analyze
|
||||||
|
competitor_url = "https://www.equal.in" # Replace with your competitor URL
|
||||||
|
|
||||||
|
# Extract competitor information
|
||||||
|
competitor_info = extract_competitor_info(competitor_url)
|
||||||
|
|
||||||
|
# Print the structured information
|
||||||
|
print(f"Competitor: {competitor_url}")
|
||||||
|
print(competitor_info)
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
exa-py==1.0.6
|
exa-py==1.0.6
|
||||||
|
firecrawl-py==1.9.0
|
||||||
Loading…
Reference in a new issue