File size: 1,014 Bytes
18b1329
 
459ee0b
4762752
31e629b
4762752
 
 
 
 
 
18b1329
 
 
5f155b2
 
 
 
 
 
18b1329
31e629b
 
4762752
31e629b
18b1329
31e629b
5f155b2
31e629b
5f155b2
18b1329
31e629b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from langchain_core.tools import tool
from langchain_community.tools import DuckDuckGoSearchResults
from helpers.helper import clean_input
import logging

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)

@tool
def internet_search(query: str) -> str:
    """Performs an internet search using DuckDuckGo.
    Args:
        query: The search query to look up
    Returns:
        A string containing the search results
    """
    try:
        # Clean the query by removing special tokens
        cleaned_query = clean_input(query)
        logging.info(f"\n Internet search tool with query: {cleaned_query}")

        search = DuckDuckGoSearchResults()
        results = search.run(cleaned_query)
        if not results:
            return f"No results found for query: '{cleaned_query}'"
        return results
    except Exception as e:
        return f"Error: Failed to perform internet search - {str(e)}"