forked from enne2/qbit-agent
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.8 KiB
36 lines
1.8 KiB
import os |
|
from langchain.tools.base import BaseTool |
|
from langchain.callbacks.manager import CallbackManagerForToolRun |
|
import requests |
|
from typing import Optional |
|
from langchain_community.tools import DuckDuckGoSearchRun |
|
|
|
|
|
class MediaInfoSearchTool(BaseTool): |
|
name: str = "duckduckgo_search" |
|
description: str = '''Useful for searching the web using DuckDuckGo for information about \ |
|
movies and TV shows, actors and directors. To be used only on imdb.com adding relative keyword imdb to query to filter results. |
|
Input should be a search query, and the tool will return relevant results.''' |
|
|
|
def _run(self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None) -> str: |
|
"""Perform a DuckDuckGo search.""" |
|
try: |
|
search_tool = DuckDuckGoSearchRun() |
|
return search_tool.run(query) |
|
except Exception as e: |
|
return f"Error performing DuckDuckGo search: {str(e)}" |
|
|
|
class MoviesAdviceSearchTool(BaseTool): |
|
name: str = "movies_advice_search" |
|
description: str = '''Useful for searching the web using DuckDuckGo for movie recommendations and similar content to a given title or plot. |
|
prefer searching on one (on your preference) known trustworthy sites. add relative keyword (like "reddit" for reddit.com for example) to query to filter results only on that site. |
|
Input should be a search query, and the tool will return relevant results.''' |
|
|
|
def _run(self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None) -> str: |
|
"""Perform a DuckDuckGo search.""" |
|
try: |
|
search_tool = DuckDuckGoSearchRun() |
|
search_results = search_tool.run(query) |
|
return search_results |
|
except Exception as e: |
|
return f"Error performing DuckDuckGo search: {str(e)}" |