From 0cf934ce7d8150dddf4a2514d6e7729a16d55b0f Mon Sep 17 00:00:00 2001 From: Dianliang233 Date: Mon, 24 Apr 2023 12:29:49 +0800 Subject: [PATCH] Fix NoneType has no len() in DDG tool (#3334) Per https://github.com/deedy5/duckduckgo_search/blob/46ac914daa614843cfa2ee3dd4663a5862e775a2/duckduckgo_search/ddg.py#L109, ddg function actually returns None when there is no result. --- langchain/utilities/duckduckgo_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langchain/utilities/duckduckgo_search.py b/langchain/utilities/duckduckgo_search.py index 30e8a66e..547847b9 100644 --- a/langchain/utilities/duckduckgo_search.py +++ b/langchain/utilities/duckduckgo_search.py @@ -49,7 +49,7 @@ class DuckDuckGoSearchAPIWrapper(BaseModel): time=self.time, max_results=self.max_results, ) - if len(results) == 0: + if results is None or len(results) == 0: return "No good DuckDuckGo Search Result was found" snippets = [result["body"] for result in results] return " ".join(snippets) @@ -77,7 +77,7 @@ class DuckDuckGoSearchAPIWrapper(BaseModel): max_results=num_results, ) - if len(results) == 0: + if results is None or len(results) == 0: return [{"Result": "No good DuckDuckGo Search Result was found"}] def to_metadata(result: Dict) -> Dict: