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

added fallback to tavily search #306

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions gpt_researcher/retrievers/tavily_search/tavily_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# libraries
import os
from tavily import TavilyClient
from duckduckgo_search import DDGS


class TavilySearch():
Expand Down Expand Up @@ -39,8 +40,12 @@ def search(self, max_results=7):
Returns:

"""
# Search the query
results = self.client.search(self.query, search_depth="advanced", max_results=max_results)
# Return the results
search_response = [{"href": obj["url"], "body": obj["content"]} for obj in results.get("results", [])]
try:
# Search the query
results = self.client.search(self.query, search_depth="advanced", max_results=max_results)
# Return the results
search_response = [{"href": obj["url"], "body": obj["content"]} for obj in results.get("results", [])]
except Exception as e: # Fallback in case overload on Tavily Search API
ddg = DDGS()
search_response = ddg.text(self.query, region='wt-wt', max_results=max_results)
return search_response