handle search errors (#70)

better error handling when serpapi raises an error (usually invalid key)
This commit is contained in:
Harrison Chase 2022-11-06 15:40:21 -08:00 committed by GitHub
parent a7d14cad00
commit dce26dfcec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,7 +94,8 @@ class SerpAPIChain(Chain, BaseModel):
with HiddenPrints():
search = self.search_engine(params)
res = search.get_dict()
if "error" in res.keys():
raise ValueError(f"Got error from SerpAPI: {res['error']}")
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():