handle search errors (#70)

better error handling when serpapi raises an error (usually invalid key)
pull/72/head
Harrison Chase 2 years ago committed by GitHub
parent a7d14cad00
commit dce26dfcec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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():

Loading…
Cancel
Save