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

Missing FireCrawlWebSearchTool() #22

Open
marscod opened this issue Jan 8, 2025 · 2 comments
Open

Missing FireCrawlWebSearchTool() #22

marscod opened this issue Jan 8, 2025 · 2 comments

Comments

@marscod
Copy link

marscod commented Jan 8, 2025

Thank you for the great work!
It seems the following function wasn't pushed:

ImportError: cannot import name 'FireCrawlWebSearchTool' from 'src.agentic_rag.tools.custom_tool'

@Avi-avidan
Copy link

Loved the demo. I am having the same issue with the missing FireCrawlWebSearchTool class. thanks.

@Avi-avidan
Copy link

@marscod
this is probably not the most elegant, but I have implemented the missing class, so if you add these lines to agengic_rag/tools/custom_tools.py you should have everything working as expected. I didnt open a PR since we know this code is already implemented and just currently missing from the repo.

`
import requests
from pydantic import PrivateAttr

class FireCrawlWebSearchTool(BaseTool):
name: str = "WebSearchTool"
description: str = "Search the open web for the given query."
args_schema: Type[BaseModel] = DocumentSearchToolInput
api_key: str = 'None'
base_url: str = 'None'

def __init__(self):
    super().__init__()
    # Ensure the API key exists
    self.api_key = os.getenv("FIRECRAWL_API_KEY")
    if not self.api_key:
        raise ValueError("FIRECRAWL_API_KEY environment variable is not set.")
    
    # Base URL for Firecrawl API
    self.base_url = "https://api.firecrawl.dev/v1/search"

def _run(self, query, limit=5, lang="en", country="us", formats=["markdown"]):
    """
    Perform a web search using Firecrawl with the specified query.

    :param query: The search query string.
    :param limit: Number of search results to return (default is 5).
    :param lang: Language of the search results (default is 'en').
    :param country: Country code for search results (default is 'us').
    :param formats: List of formats to scrape content into (default is ['markdown']).
    :return: JSON response with the search results.
    """
    headers = {
        "Authorization": f"Bearer {self.api_key}",
        "Content-Type": "application/json"
    }

    payload = {
        "query": query,
        "limit": limit,
        "lang": lang,
        "country": country,
        "scrapeOptions": {
            "formats": formats
        }
    }

    try:
        response = requests.post(self.base_url, headers=headers, json=payload)
        response.raise_for_status()  # Raise an exception for HTTP errors
        results = response.json()
        if results['success']:
            separator = "\n___\n"
            md_data = separator.join([d['markdown'] for d in results['data']])
            return md_data
        else:
            return 'failed to fetch web search results'
    except requests.exceptions.RequestException as e:
        return {"error": str(e)}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants