From b0d80c4b3e128f27bd1b9df48ed4afbe17950fec Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 20 Jun 2023 13:48:18 +0800 Subject: [PATCH] Update serpapi.py Support baidu list type answer_box (#6386) Support baidu list type answer_box From [this document](https://serpapi.com/baidu-answer-box), we can know that the answer_box attribute returned by the Baidu interface is a list, and the list contains only one Object, but an error will occur when the current code is executed. So when answer_box is a list, we reset res["answer_box"] so that the code can execute successfully. --- langchain/utilities/serpapi.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/langchain/utilities/serpapi.py b/langchain/utilities/serpapi.py index 2843a7d0..6f267e2e 100644 --- a/langchain/utilities/serpapi.py +++ b/langchain/utilities/serpapi.py @@ -129,6 +129,8 @@ class SerpAPIWrapper(BaseModel): """Process response from SerpAPI.""" if "error" in res.keys(): raise ValueError(f"Got error from SerpAPI: {res['error']}") + if "answer_box" in res.keys() and type(res["answer_box"]) == list: + res["answer_box"] = res["answer_box"][0] if "answer_box" in res.keys() and "answer" in res["answer_box"].keys(): toret = res["answer_box"]["answer"] elif "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():