Skip to content

The agent engineering platform.

Update serpapi.py Support baidu list type answer_box (#6386)

Gavinb0d80c4b3e12
diff --git a/langchain/utilities/serpapi.py b/langchain/utilities/serpapi.py
index 2843a7d092..6f267e2e7e 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():