completed code upto CRM

This commit is contained in:
Madhu 2025-01-16 00:35:11 +05:30
parent 80bf1b6cba
commit 538735b62a
2 changed files with 141 additions and 2 deletions

View file

@ -0,0 +1,120 @@
import requests
from phi.agent import Agent
from phi.tools.firecrawl import FirecrawlTools
from phi.model.openai import OpenAIChat
# Step 1: Search for relevant URLs using Firecrawl
def search_for_urls():
url = "https://api.firecrawl.dev/v1/search"
headers = {
"Authorization": "Bearer fc-", # Replace with your Firecrawl API key
"Content-Type": "application/json"
}
company_description = "voice cloning open source models or api"
query1 = f"quora websites where people are looking for {company_description} services"
payload = {
"query": query1,
"limit": 3, # Adjust the limit as needed
"lang": "en",
"location": "United States",
"timeout": 60000,
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
data = response.json()
if data.get("success"):
results = data.get("data", [])
return [result["url"] for result in results]
else:
print("Search request was not successful.")
print(data.get("warning", "No warning provided."))
else:
print(f"Failed to retrieve data. Status code: {response.status_code}")
return []
# Step 2: Set up the Firecrawl Agent
firecrawl_tools = FirecrawlTools(
api_key="fc-", # Replace with your Firecrawl API key
scrape=True, # Enable scraping to extract detailed content
crawl=True, # Enable crawling
limit=5 # Limit the number of pages to crawl
)
# First Agent: Crawls the website and retrieves content
firecrawl_agent = Agent(
model=OpenAIChat(id="gpt-4o-mini", api_key="sk-proj-"), # Replace with your OpenAI API key
tools=[firecrawl_tools], # Add Firecrawl tools
show_tool_calls=False, # Disable verbose tool call output
markdown=True
)
# Second Agent: Processes verbose output and extracts user information
extraction_agent = Agent(
model=OpenAIChat(id="gpt-4o-mini", api_key="sk-proj-"), # Replace with your OpenAI API key
show_tool_calls=False,
system_prompt="You are an expert at extracting user information from responses. You are given a long response of extracted and crawled website information and you need to extract the user information only. Focus on extracting information about both the question asker and the answerers, as they are potential leads.",
markdown=True
)
# Step 3: Define a function to analyze user info directly from URLs
def analyze_user_info_from_urls(urls):
user_info_list = []
for website_url in urls:
print(f"Analyzing website: {website_url}")
# Step 3.1: Directly instruct the first agent to crawl and analyze the website
analysis_prompt = (
f"Visit the website {website_url} using Firecrawl and analyze its content to extract the following information:\n"
"1. Username of the person asking the question.\n"
"2. The content of their question.\n"
"3. Usernames of people answering the question.\n"
"4. The content of their answers.\n"
"5. Any additional relevant information (e.g., timestamp, upvotes, links, user bio, location).\n\n"
"Return the extracted information in a structured format."
)
# Step 3.2: Run the first agent with the analysis prompt
analysis_response = firecrawl_agent.run(analysis_prompt)
analysis_result = analysis_response.content
# Step 3.3: Use the second agent to extract only the user information
extraction_prompt = (
f"Extract only the following user information from the content below:\n"
"1. Username (for both question asker and answerers)\n"
"2. Post content (question or answer)\n"
"3. Timestamp\n"
"4. Upvotes\n"
"5. Links (if available)\n"
"6. Any additional relevant information (e.g., user bio, location)\n\n"
f"Content:\n{analysis_result}"
)
extraction_response = extraction_agent.run(extraction_prompt)
extracted_info = extraction_response.content
# Step 3.4: Store the results
user_info_list.append({
"website_url": website_url,
"user_info": extracted_info
})
return user_info_list
# Step 4: Main workflow
def main():
# Step 4.1: Search for relevant URLs
urls = search_for_urls()
print("Relevant URLs Found:")
for url in urls:
print(url)
# Step 4.2: Analyze user info directly from the URLs
user_info_list = analyze_user_info_from_urls(urls)
# Step 4.3: Print the extracted information in a detailed format
print("\nExtracted User Information:")
for info in user_info_list:
print(f"Website: {info['website_url']}")
print(f"User Info:\n{info['user_info']}\n")
# Run the main workflow
if __name__ == "__main__":
main()

View file

@ -14,8 +14,6 @@ company_name = "Rollout AI"
company_description = "voice cloning open source models or api"
keywords = "https://rollout.site"
# Craft the query
query = f" website blogs, forums, and reddit communities URL to {company_description}, where i can find people looking for similar services"
query1 = f" reddit and quora websites where people are looking for {company_description} services"
# Set the payload
@ -45,3 +43,24 @@ if response.status_code == 200:
else:
print(f"Failed to retrieve data. Status code: {response.status_code}")
firecrawl_tools = FirecrawlTools(
api_key=st.session_state.firecrawl_api_key,
scrape=False,
crawl=True,
limit=5
)
firecrawl_agent = Agent(
model=OpenAIChat(id="gpt-4o-mini", api_key=st.session_state.openai_api_key),
tools=[firecrawl_tools, DuckDuckGo()],
show_tool_calls=True,
markdown=True
)
analysis_agent = Agent(
model=OpenAIChat(id="gpt-4o-mini", api_key=st.session_state.openai_api_key),
show_tool_calls=True,
markdown=True
)