From c95d7a499b648f0750a424e79b806c6dd538f927 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Jan 2025 14:55:14 +0530 Subject: [PATCH 1/5] Used new extract endpoint --- .../ai_lead_generation_agent/ai_lead_generation_agent.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py index 002d01d..8560f45 100644 --- a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py +++ b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py @@ -8,7 +8,6 @@ from pydantic import BaseModel, Field from typing import List from composio_phidata import Action, ComposioToolSet -# Define a schema for a single user interaction (question or answer) class QuoraUserInteractionSchema(BaseModel): username: str = Field(description="The username of the user who posted the question or answer") bio: str = Field(description="The bio or description of the user") From f732c7b787e1f417e952ab53d67ca0ea94b51284 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Jan 2025 14:59:42 +0530 Subject: [PATCH 2/5] Used new extract endpoint1 --- .../ai_lead_generation_agent.py | 144 ++++++++++++------ 1 file changed, 99 insertions(+), 45 deletions(-) diff --git a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py index 8560f45..5eaaf99 100644 --- a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py +++ b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py @@ -8,13 +8,14 @@ from pydantic import BaseModel, Field from typing import List from composio_phidata import Action, ComposioToolSet +# Define a schema for a single user interaction (question or answer) class QuoraUserInteractionSchema(BaseModel): username: str = Field(description="The username of the user who posted the question or answer") bio: str = Field(description="The bio or description of the user") post_type: str = Field(description="The type of post, either 'question' or 'answer'") timestamp: str = Field(description="When the question or answer was posted") upvotes: int = Field(default=0, description="Number of upvotes received") - links: List[str] = Field(default_factory=list, description="Any links included in the post") + links: List[str] = Field(default_factory=list, description="The link to the user's profile or the question/answer post") # Define a schema for the entire page, containing multiple interactions class QuoraPageSchema(BaseModel): @@ -50,32 +51,50 @@ def search_for_urls(company_description, firecrawl_api_key, num_links): print(f"Failed to retrieve data. Status code: {response.status_code}") return [] -# Step 2: Extract user info from URLs using Firecrawl's LLM extract +# Step 2: Extract user info from URLs using Firecrawl's scrape endpoint def extract_user_info_from_urls(urls, firecrawl_api_key): - print("\nStep 2: Extracting user info from URLs using Firecrawl's LLM extract...") + print("\nStep 2: Extracting user info from URLs using Firecrawl's scrape endpoint...") user_info_list = [] firecrawl_app = FirecrawlApp(api_key=firecrawl_api_key) - for website_url in urls: - print(f"Extracting user info from: {website_url}") - - # Use Firecrawl's LLM extract to get structured data - data = firecrawl_app.scrape_url(website_url, { - 'formats': ['extract'], - 'extract': { + + try: + # Use the new scrape endpoint with all URLs at once + response = firecrawl_app.extract( + urls, + { + 'prompt': 'Extract all user information including username, bio, post type (question/answer), timestamp, upvotes, and links to user profile or Quora posts. Focus on identifying potential leads who are asking questions or providing answers related to the topic.', 'schema': QuoraPageSchema.model_json_schema(), } - }) + ) - # Extract the interactions from the response - extracted_data = data.get("extract", {}) - interactions = extracted_data.get("interactions", []) + print("Raw response:", response) # Debug print - # Store the results - user_info_list.append({ - "website_url": website_url, - "user_info": interactions - }) - print(f"Extracted {len(interactions)} interactions from {website_url}.") + # Process the extracted data from the new response format + if response.get('success') and response.get('status') == 'completed': + # Get all interactions from the data + interactions = response.get('data', {}).get('interactions', []) + + if interactions: + # Store all interactions with their source URL + for url in urls: + user_info_list.append({ + "website_url": url, + "user_info": interactions # Each URL gets all interactions since they're combined + }) + + print(f"Extracted {len(interactions)} user interactions") + print("Sample users found:") + for user in interactions[:3]: # Show first 3 users as sample + print(f"- {user['username']} ({user['post_type']}) - {user['bio'][:50]}...") + else: + print("Failed to get successful response or incomplete status") + if response: + print("Response status:", response.get('status')) + print("Success flag:", response.get('success')) + + except Exception as e: + print(f"Error during extraction: {str(e)}") + return user_info_list # Step 3: Format the extracted user info into a flattened JSON structure @@ -128,24 +147,51 @@ def write_to_google_sheets(flattened_data, composio_api_key, openai_api_key): # Create the Google Sheets agent google_sheets_agent = create_google_sheets_agent(composio_api_key, openai_api_key) - # Create a new Google Sheet from the flattened JSON data - print("Creating a new Google Sheet with the flattened JSON data...") - create_sheet_response = google_sheets_agent.run( - f"Create a new Google Sheet with the following data:\n" - f"Title: Quora User Info\n" - f"Sheet Name: Sheet1\n" - f"Sheet JSON: {flattened_data}" - ) - print("Create Sheet Response:", create_sheet_response.content) - - # Extract the Google Sheets link from the response - if "https://docs.google.com/spreadsheets/d/" in create_sheet_response.content: - google_sheets_link = create_sheet_response.content.split("https://docs.google.com/spreadsheets/d/")[1].split(" ")[0] - google_sheets_link = f"https://docs.google.com/spreadsheets/d/{google_sheets_link}" - return google_sheets_link + try: + # Create a new Google Sheet from the flattened JSON data + print("Creating a new Google Sheet with the flattened JSON data...") + create_sheet_response = google_sheets_agent.run( + f"Create a new Google Sheet with the following data:\n" + f"Title: Quora User Info\n" + f"Sheet Name: Sheet1\n" + f"Sheet JSON: {flattened_data}" + ) + print("Create Sheet Response:", create_sheet_response.content) + + # Extract the Google Sheets link from the response + if "https://docs.google.com/spreadsheets/d/" in create_sheet_response.content: + google_sheets_link = create_sheet_response.content.split("https://docs.google.com/spreadsheets/d/")[1].split(" ")[0] + google_sheets_link = f"https://docs.google.com/spreadsheets/d/{google_sheets_link}" + return google_sheets_link + except Exception as e: + print(f"Error creating Google Sheet: {str(e)}") return None -# Streamlit UI +def create_prompt_transformation_agent(openai_api_key): + """Create a Phidata agent that transforms user queries into concise company descriptions.""" + return Agent( + model=OpenAIChat(id="gpt-4-turbo", api_key=openai_api_key), + system_prompt="""You are an expert at transforming detailed user queries into concise company descriptions. +Your task is to extract the core business/product focus in 3-4 words. + +Examples: +Input: "Generate leads looking for AI-powered customer support chatbots for e-commerce stores." +Output: "AI customer support chatbots" + +Input: "Find people interested in voice cloning technology for creating audiobooks and podcasts" +Output: "voice cloning technology" + +Input: "Looking for users who need automated video editing software with AI capabilities" +Output: "AI video editing software" + +Input: "Need to find businesses interested in implementing machine learning solutions for fraud detection" +Output: "ML fraud detection" + +Always focus on the core product/service and keep it concise but clear.""", + markdown=True + ) + +# Modify the Streamlit UI def main(): st.title("🎯 AI Lead Generation Agent") st.info("This firecrawl powered agent helps you generate leads from Quora by searching for relevant posts and extracting user information.") @@ -156,27 +202,35 @@ def main(): firecrawl_api_key = st.text_input("Firecrawl API Key", type="password") st.caption(" Get your Firecrawl API key from [Firecrawl's website](https://www.firecrawl.dev/app/api-keys)") openai_api_key = st.text_input("OpenAI API Key", type="password") - st.caption(" Get your Composio API key from [Composio's website](https://composio.ai)") - composio_api_key = st.text_input("Composio API Key", type="password") st.caption(" Get your OpenAI API key from [OpenAI's website](https://platform.openai.com/api-keys)") + composio_api_key = st.text_input("Composio API Key", type="password") + st.caption(" Get your Composio API key from [Composio's website](https://composio.ai)") - # Add a numeric input for the number of links num_links = st.number_input("Number of links to search", min_value=1, max_value=10, value=3) - # Reset button if st.button("Reset"): st.session_state.clear() st.experimental_rerun() - # Main input for company description - company_description = st.text_input("Enter your company description or the niche you want to find leads in:", placeholder="e.g. AI voice cloning, Video Generation AI tools") + # Main input for detailed query + user_query = st.text_area( + "Describe what kind of leads you're looking for:", + placeholder="e.g., Looking for users who need automated video editing software with AI capabilities", + help="Be specific about the product/service and target audience. The AI will convert this into a focused search query." + ) if st.button("Generate Leads"): - if not all([firecrawl_api_key, openai_api_key, composio_api_key, company_description]): - st.error("Please fill in all the API keys and the company description.") + if not all([firecrawl_api_key, openai_api_key, composio_api_key, user_query]): + st.error("Please fill in all the API keys and describe what leads you're looking for.") else: + # First, transform the user query into a concise company description + with st.spinner("Processing your query..."): + transform_agent = create_prompt_transformation_agent(openai_api_key) + company_description = transform_agent.run(f"Transform this query into a concise 3-4 word company description: {user_query}") + st.write("🎯 Searching for:", company_description.content) + with st.spinner("Searching for relevant URLs..."): - urls = search_for_urls(company_description, firecrawl_api_key, num_links) # Pass num_links to search_for_urls + urls = search_for_urls(company_description.content, firecrawl_api_key, num_links) if urls: st.subheader("Quora Links Used:") From 6f4c8331b581b61b0b335d01a34f3ea3b1c94a58 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Jan 2025 15:51:40 +0530 Subject: [PATCH 3/5] fixed an error --- .../ai_lead_generation_agent.py | 88 ++++++++++--------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py index 5eaaf99..1740923 100644 --- a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py +++ b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py @@ -7,6 +7,7 @@ from firecrawl import FirecrawlApp from pydantic import BaseModel, Field from typing import List from composio_phidata import Action, ComposioToolSet +import json # Define a schema for a single user interaction (question or answer) class QuoraUserInteractionSchema(BaseModel): @@ -15,7 +16,7 @@ class QuoraUserInteractionSchema(BaseModel): post_type: str = Field(description="The type of post, either 'question' or 'answer'") timestamp: str = Field(description="When the question or answer was posted") upvotes: int = Field(default=0, description="Number of upvotes received") - links: List[str] = Field(default_factory=list, description="The link to the user's profile or the question/answer post") + links: List[str] = Field(default_factory=list, description="Any links included in the post") # Define a schema for the entire page, containing multiple interactions class QuoraPageSchema(BaseModel): @@ -53,58 +54,58 @@ def search_for_urls(company_description, firecrawl_api_key, num_links): # Step 2: Extract user info from URLs using Firecrawl's scrape endpoint def extract_user_info_from_urls(urls, firecrawl_api_key): - print("\nStep 2: Extracting user info from URLs using Firecrawl's scrape endpoint...") + print("\nStep 2: Extracting user info from URLs using Firecrawl's extract endpoint...") user_info_list = [] firecrawl_app = FirecrawlApp(api_key=firecrawl_api_key) try: - # Use the new scrape endpoint with all URLs at once - response = firecrawl_app.extract( - urls, - { - 'prompt': 'Extract all user information including username, bio, post type (question/answer), timestamp, upvotes, and links to user profile or Quora posts. Focus on identifying potential leads who are asking questions or providing answers related to the topic.', - 'schema': QuoraPageSchema.model_json_schema(), - } - ) - - print("Raw response:", response) # Debug print - - # Process the extracted data from the new response format - if response.get('success') and response.get('status') == 'completed': - # Get all interactions from the data - interactions = response.get('data', {}).get('interactions', []) + # Process URLs one by one to maintain URL-interaction mapping + for url in urls: + print(f"\nProcessing URL: {url}") + response = firecrawl_app.extract( + [url], # Process single URL + { + 'prompt': 'Extract all user information including username, bio, post type (question/answer), timestamp, upvotes, and any links from Quora posts. Focus on identifying potential leads who are asking questions or providing answers related to the topic.', + 'schema': QuoraPageSchema.model_json_schema(), + } + ) - if interactions: - # Store all interactions with their source URL - for url in urls: - user_info_list.append({ - "website_url": url, - "user_info": interactions # Each URL gets all interactions since they're combined - }) + # Process the extracted data for this URL + if response.get('success') and response.get('status') == 'completed': + interactions = response.get('data', {}).get('interactions', []) - print(f"Extracted {len(interactions)} user interactions") - print("Sample users found:") - for user in interactions[:3]: # Show first 3 users as sample - print(f"- {user['username']} ({user['post_type']}) - {user['bio'][:50]}...") - else: - print("Failed to get successful response or incomplete status") - if response: - print("Response status:", response.get('status')) - print("Success flag:", response.get('success')) + if interactions: + user_info_list.append({ + "website_url": url, # Store interactions with their source URL + "user_info": interactions + }) + print(f"Extracted {len(interactions)} interactions from {url}") + print("Sample users:") + for user in interactions[:2]: # Show first 2 users as sample + print(f"- {user['username']} ({user['post_type']}) - {user['bio'][:50]}...") + else: + print(f"No interactions found for {url}") + else: + print(f"Failed to get successful response for {url}") except Exception as e: print(f"Error during extraction: {str(e)}") + print(f"\nTotal URLs processed: {len(urls)}") + print(f"URLs with successful extractions: {len(user_info_list)}") + return user_info_list # Step 3: Format the extracted user info into a flattened JSON structure def format_user_info_to_flattened_json(user_info_list): print("\nStep 3: Formatting the extracted user info into a flattened JSON structure...") + print(f"Processing data from {len(user_info_list)} URLs") flattened_data = [] for info in user_info_list: website_url = info["website_url"] user_info = info["user_info"] + print(f"\nProcessing {len(user_info)} interactions from {website_url}") for interaction in user_info: flattened_interaction = { @@ -114,11 +115,12 @@ def format_user_info_to_flattened_json(user_info_list): "Post Type": interaction.get("post_type", ""), "Timestamp": interaction.get("timestamp", ""), "Upvotes": interaction.get("upvotes", 0), - "Links": ", ".join(interaction.get("links", [])), # Convert list of links to a single string + "Links": ", ".join(interaction.get("links", [])), } flattened_data.append(flattened_interaction) - print(f"Formatted {len(flattened_data)} interactions into flattened JSON.") + print(f"\nTotal flattened interactions: {len(flattened_data)}") + print(flattened_data) return flattened_data # Step 4: Create a new Phidata agent to interact with Google Sheets @@ -150,12 +152,15 @@ def write_to_google_sheets(flattened_data, composio_api_key, openai_api_key): try: # Create a new Google Sheet from the flattened JSON data print("Creating a new Google Sheet with the flattened JSON data...") - create_sheet_response = google_sheets_agent.run( - f"Create a new Google Sheet with the following data:\n" - f"Title: Quora User Info\n" - f"Sheet Name: Sheet1\n" - f"Sheet JSON: {flattened_data}" + + message = ( + "Create a new Google Sheet with this data. " + "The sheet should have these columns: Website URL, Username, Bio, Post Type, Timestamp, Upvotes, and Links in the same order as mentioned. " + "Here's the data in JSON format:\n\n" + f"{json.dumps(flattened_data, indent=2)}" ) + + create_sheet_response = google_sheets_agent.run(message) print("Create Sheet Response:", create_sheet_response.content) # Extract the Google Sheets link from the response @@ -165,12 +170,13 @@ def write_to_google_sheets(flattened_data, composio_api_key, openai_api_key): return google_sheets_link except Exception as e: print(f"Error creating Google Sheet: {str(e)}") + print(f"Data sample: {str(flattened_data[:2])}") # Print sample for debugging return None def create_prompt_transformation_agent(openai_api_key): """Create a Phidata agent that transforms user queries into concise company descriptions.""" return Agent( - model=OpenAIChat(id="gpt-4-turbo", api_key=openai_api_key), + model=OpenAIChat(id="gpt-4o-mini", api_key=openai_api_key), system_prompt="""You are an expert at transforming detailed user queries into concise company descriptions. Your task is to extract the core business/product focus in 3-4 words. From accd097fcd06de1835bb626f53cdbae49f5006c1 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Jan 2025 16:17:14 +0530 Subject: [PATCH 4/5] final code --- .../ai_lead_generation_agent.py | 88 ++++--------------- 1 file changed, 16 insertions(+), 72 deletions(-) diff --git a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py index 1740923..dd48829 100644 --- a/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py +++ b/ai_agent_tutorials/ai_lead_generation_agent/ai_lead_generation_agent.py @@ -9,7 +9,6 @@ from typing import List from composio_phidata import Action, ComposioToolSet import json -# Define a schema for a single user interaction (question or answer) class QuoraUserInteractionSchema(BaseModel): username: str = Field(description="The username of the user who posted the question or answer") bio: str = Field(description="The bio or description of the user") @@ -18,13 +17,10 @@ class QuoraUserInteractionSchema(BaseModel): upvotes: int = Field(default=0, description="Number of upvotes received") links: List[str] = Field(default_factory=list, description="Any links included in the post") -# Define a schema for the entire page, containing multiple interactions class QuoraPageSchema(BaseModel): interactions: List[QuoraUserInteractionSchema] = Field(description="List of all user interactions (questions and answers) on the page") -# Step 1: Search for relevant URLs using Firecrawl -def search_for_urls(company_description, firecrawl_api_key, num_links): - print("Step 1: Searching for relevant URLs using Firecrawl...") +def search_for_urls(company_description: str, firecrawl_api_key: str, num_links: int) -> List[str]: url = "https://api.firecrawl.dev/v1/search" headers = { "Authorization": f"Bearer {firecrawl_api_key}", @@ -33,7 +29,7 @@ def search_for_urls(company_description, firecrawl_api_key, num_links): query1 = f"quora websites where people are looking for {company_description} services" payload = { "query": query1, - "limit": num_links, # Use the num_links parameter here + "limit": num_links, "lang": "en", "location": "United States", "timeout": 60000, @@ -43,69 +39,41 @@ def search_for_urls(company_description, firecrawl_api_key, num_links): data = response.json() if data.get("success"): results = data.get("data", []) - print(f"Found {len(results)} relevant URLs.") 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: Extract user info from URLs using Firecrawl's scrape endpoint -def extract_user_info_from_urls(urls, firecrawl_api_key): - print("\nStep 2: Extracting user info from URLs using Firecrawl's extract endpoint...") +def extract_user_info_from_urls(urls: List[str], firecrawl_api_key: str) -> List[dict]: user_info_list = [] firecrawl_app = FirecrawlApp(api_key=firecrawl_api_key) try: - # Process URLs one by one to maintain URL-interaction mapping for url in urls: - print(f"\nProcessing URL: {url}") response = firecrawl_app.extract( - [url], # Process single URL + [url], { 'prompt': 'Extract all user information including username, bio, post type (question/answer), timestamp, upvotes, and any links from Quora posts. Focus on identifying potential leads who are asking questions or providing answers related to the topic.', 'schema': QuoraPageSchema.model_json_schema(), } ) - # Process the extracted data for this URL if response.get('success') and response.get('status') == 'completed': interactions = response.get('data', {}).get('interactions', []) - if interactions: user_info_list.append({ - "website_url": url, # Store interactions with their source URL + "website_url": url, "user_info": interactions }) - print(f"Extracted {len(interactions)} interactions from {url}") - print("Sample users:") - for user in interactions[:2]: # Show first 2 users as sample - print(f"- {user['username']} ({user['post_type']}) - {user['bio'][:50]}...") - else: - print(f"No interactions found for {url}") - else: - print(f"Failed to get successful response for {url}") - - except Exception as e: - print(f"Error during extraction: {str(e)}") - - print(f"\nTotal URLs processed: {len(urls)}") - print(f"URLs with successful extractions: {len(user_info_list)}") + except Exception: + pass return user_info_list -# Step 3: Format the extracted user info into a flattened JSON structure -def format_user_info_to_flattened_json(user_info_list): - print("\nStep 3: Formatting the extracted user info into a flattened JSON structure...") - print(f"Processing data from {len(user_info_list)} URLs") +def format_user_info_to_flattened_json(user_info_list: List[dict]) -> List[dict]: flattened_data = [] for info in user_info_list: website_url = info["website_url"] user_info = info["user_info"] - print(f"\nProcessing {len(user_info)} interactions from {website_url}") for interaction in user_info: flattened_interaction = { @@ -119,40 +87,25 @@ def format_user_info_to_flattened_json(user_info_list): } flattened_data.append(flattened_interaction) - print(f"\nTotal flattened interactions: {len(flattened_data)}") - print(flattened_data) return flattened_data -# Step 4: Create a new Phidata agent to interact with Google Sheets -def create_google_sheets_agent(composio_api_key, openai_api_key): - print("\nStep 4: Creating a new Phidata agent to interact with Google Sheets...") - # Initialize Composio Toolset +def create_google_sheets_agent(composio_api_key: str, openai_api_key: str) -> Agent: composio_toolset = ComposioToolSet(api_key=composio_api_key) - - # Get the Google Sheets tool google_sheets_tool = composio_toolset.get_tools(actions=[Action.GOOGLESHEETS_SHEET_FROM_JSON])[0] - # Create the agent google_sheets_agent = Agent( model=OpenAIChat(id="gpt-4o-mini", api_key=openai_api_key), tools=[google_sheets_tool], - show_tool_calls=True, # Enable verbose tool call output for debugging + show_tool_calls=True, system_prompt="You are an expert at creating and updating Google Sheets. You will be given user information in JSON format, and you need to write it into a new Google Sheet.", markdown=True ) - print("Google Sheets agent created successfully.") return google_sheets_agent -# Step 5: Write formatted user info to Google Sheets -def write_to_google_sheets(flattened_data, composio_api_key, openai_api_key): - print("\nStep 5: Writing formatted user info to Google Sheets...") - # Create the Google Sheets agent +def write_to_google_sheets(flattened_data: List[dict], composio_api_key: str, openai_api_key: str) -> str: google_sheets_agent = create_google_sheets_agent(composio_api_key, openai_api_key) try: - # Create a new Google Sheet from the flattened JSON data - print("Creating a new Google Sheet with the flattened JSON data...") - message = ( "Create a new Google Sheet with this data. " "The sheet should have these columns: Website URL, Username, Bio, Post Type, Timestamp, Upvotes, and Links in the same order as mentioned. " @@ -161,20 +114,15 @@ def write_to_google_sheets(flattened_data, composio_api_key, openai_api_key): ) create_sheet_response = google_sheets_agent.run(message) - print("Create Sheet Response:", create_sheet_response.content) - # Extract the Google Sheets link from the response if "https://docs.google.com/spreadsheets/d/" in create_sheet_response.content: google_sheets_link = create_sheet_response.content.split("https://docs.google.com/spreadsheets/d/")[1].split(" ")[0] - google_sheets_link = f"https://docs.google.com/spreadsheets/d/{google_sheets_link}" - return google_sheets_link - except Exception as e: - print(f"Error creating Google Sheet: {str(e)}") - print(f"Data sample: {str(flattened_data[:2])}") # Print sample for debugging + return f"https://docs.google.com/spreadsheets/d/{google_sheets_link}" + except Exception: + pass return None -def create_prompt_transformation_agent(openai_api_key): - """Create a Phidata agent that transforms user queries into concise company descriptions.""" +def create_prompt_transformation_agent(openai_api_key: str) -> Agent: return Agent( model=OpenAIChat(id="gpt-4o-mini", api_key=openai_api_key), system_prompt="""You are an expert at transforming detailed user queries into concise company descriptions. @@ -182,7 +130,7 @@ Your task is to extract the core business/product focus in 3-4 words. Examples: Input: "Generate leads looking for AI-powered customer support chatbots for e-commerce stores." -Output: "AI customer support chatbots" +Output: "AI customer support chatbots for e commerce" Input: "Find people interested in voice cloning technology for creating audiobooks and podcasts" Output: "voice cloning technology" @@ -197,12 +145,10 @@ Always focus on the core product/service and keep it concise but clear.""", markdown=True ) -# Modify the Streamlit UI def main(): st.title("🎯 AI Lead Generation Agent") st.info("This firecrawl powered agent helps you generate leads from Quora by searching for relevant posts and extracting user information.") - # Sidebar for API keys and number of links with st.sidebar: st.header("API Keys") firecrawl_api_key = st.text_input("Firecrawl API Key", type="password") @@ -218,7 +164,6 @@ def main(): st.session_state.clear() st.experimental_rerun() - # Main input for detailed query user_query = st.text_area( "Describe what kind of leads you're looking for:", placeholder="e.g., Looking for users who need automated video editing software with AI capabilities", @@ -229,7 +174,6 @@ def main(): if not all([firecrawl_api_key, openai_api_key, composio_api_key, user_query]): st.error("Please fill in all the API keys and describe what leads you're looking for.") else: - # First, transform the user query into a concise company description with st.spinner("Processing your query..."): transform_agent = create_prompt_transformation_agent(openai_api_key) company_description = transform_agent.run(f"Transform this query into a concise 3-4 word company description: {user_query}") From 91415a893a9fd4f4695d51c55bc1c1e2d46837bc Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Jan 2025 16:18:31 +0530 Subject: [PATCH 5/5] readme changes --- ai_agent_tutorials/ai_lead_generation_agent/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ai_agent_tutorials/ai_lead_generation_agent/README.md b/ai_agent_tutorials/ai_lead_generation_agent/README.md index 6c9500c..93da1f7 100644 --- a/ai_agent_tutorials/ai_lead_generation_agent/README.md +++ b/ai_agent_tutorials/ai_lead_generation_agent/README.md @@ -1,10 +1,10 @@ -## 🎯 AI Lead Generation Agent +## 🎯 AI Lead Generation Agent - Powered by Firecrawl's Extract Endpoint -The AI Lead Generation Agent automates the process of finding and qualifying potential leads from Quora. It uses Firecrawl's search and LLM extraction endpoints to identify relevant user profiles, extract valuable information, and organize it into a structured format in Google Sheets. This agent helps sales and marketing teams efficiently build targeted lead lists while saving hours of manual research. +The AI Lead Generation Agent automates the process of finding and qualifying potential leads from Quora. It uses Firecrawl's search and the new Extract endpoint to identify relevant user profiles, extract valuable information, and organize it into a structured format in Google Sheets. This agent helps sales and marketing teams efficiently build targeted lead lists while saving hours of manual research. ### Features - **Targeted Search**: Uses Firecrawl's search endpoint to find relevant Quora URLs based on your search criteria -- **Intelligent Extraction**: Leverages Firecrawl's LLM extract functionality to pull user information from Quora profiles +- **Intelligent Extraction**: Leverages Firecrawl's new Extract endpoint to pull user information from Quora profiles - **Automated Processing**: Formats extracted user information into a clean, structured format - **Google Sheets Integration**: Automatically creates and populates Google Sheets with lead information - **Customizable Criteria**: Allows you to define specific search parameters to find your ideal leads for your niche