Final_Assignment_Template / tools /web_search_tool.py
shreyassahu22's picture
Upload 10 files
4b58858 verified
Raw
History Blame Contribute Delete
494 Bytes
from langchain_tavily import TavilySearch
from langchain.tools import tool
from dotenv import load_dotenv
load_dotenv()
search_tool = TavilySearch(max_results=5)
@tool
def web_search_tool(question: str) -> str:
"""Searches the web for an answer to a user's question.
Args:
question: User question
"""
try:
search_results = search_tool.invoke(question)
return search_results
except Exception as e:
return f"Error searching web: {str(e)}"