Skip to content

Commit

Permalink
valid serper response status code
Browse files Browse the repository at this point in the history
  • Loading branch information
HanXudong committed Apr 18, 2024
1 parent aedf0ce commit b7d4dfc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions factcheck/core/Retriever/SerperEvidenceRetrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,12 @@ def _request_serper_api(self, questions):
questions_data = [{"q": question, "autocorrect": False} for question in questions]
payload = json.dumps(questions_data)
response = None
try:
response = requests.request("POST", url, headers=headers, data=payload)
except Exception as e:
logger.info(f"Warning, Serper API error: {e}.")
return response
response = requests.request("POST", url, headers=headers, data=payload)

if response.status_code == 200:
return response
elif response.status_code == 403:
raise Exception("Failed to authenticate. Check your API key.")
else:
raise Exception(f"Error occurred: {response.text}")

0 comments on commit b7d4dfc

Please sign in to comment.