in bugbounty_gpt/handlers/openai_handler.py [0:0]
def _handle_response(response):
"""
Handles the response from the OpenAI API.
:param response: The response object from the OpenAI API.
:return: A tuple containing the judgment category and explanation, or an error response if something goes wrong.
"""
try:
response_text = response.choices[0].message.content
judgement, explanation = response_text.rsplit('\n', 1)
sanitized_judgement = OpenAIHandler._classifications_sanitization(judgement)
if sanitized_judgement in VALID_CATEGORIES:
return sanitized_judgement, explanation.strip()
else:
return DEFAULT_CATEGORY, explanation.strip()
except Exception as error:
return OpenAIHandler._handle_response_error(error)