mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 23:54:14 +00:00
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.
This commit is contained in:
parent
384fa43fc3
commit
b0d80c4b3e
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user