Skip to content

Commit

Permalink
fix duckduckgo rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
billvsme committed Jan 2, 2024
1 parent ac694df commit b328d58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion law_ai/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from langchain.text_splitter import RecursiveCharacterTextSplitter, TextSplitter
from langchain.chains import LLMChain
from langchain.retrievers.multi_query import MultiQueryRetriever
from duckduckgo_search.exceptions import DuckDuckGoSearchException

from .prompt import MULTI_QUERY_PROMPT_TEMPLATE
from .utils import get_model
Expand All @@ -36,7 +37,10 @@ def _get_relevant_documents(
run_manager: CallbackManagerForRetrieverRun,
) -> List[Document]:

results = self.search.results(query, self.num_search_results)
try:
results = self.search.results(query, self.num_search_results)
except DuckDuckGoSearchException:
results = []

docs = []
for res in results:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ langchain==0.0.319
openai==0.28.1
chromadb==0.4.14
tiktoken==0.5.1
duckduckgo-search==4.1.0
duckduckgo-search==4.1.1
gradio==3.50.0

0 comments on commit b328d58

Please sign in to comment.