fix(openai.py): fix exception raised

This commit is contained in:
Krrish Dholakia 2024-08-24 23:15:39 -07:00
parent e2d75a100a
commit 20be76123b

View file

@ -1160,11 +1160,18 @@ class OpenAIChatCompletion(BaseLLM):
"complete_input_dict": data,
},
)
headers, response = self.make_sync_openai_chat_completion_request(
openai_client=openai_client,
data=data,
timeout=timeout,
)
try:
headers, response = self.make_sync_openai_chat_completion_request(
openai_client=openai_client,
data=data,
timeout=timeout,
)
except Exception as e:
status_code = getattr(e, "status_code", 500)
error_headers = getattr(e, "headers", None)
raise OpenAIError(
status_code=status_code, message=str(e), headers=error_headers
)
logging_obj.model_call_details["response_headers"] = headers
streamwrapper = CustomStreamWrapper(
@ -1263,6 +1270,7 @@ class OpenAIChatCompletion(BaseLLM):
error_headers = getattr(e, "headers", None)
if response is not None and hasattr(response, "text"):
error_headers = getattr(e, "headers", None)
raise OpenAIError(
status_code=500,
message=f"{str(e)}\n\nOriginal Response: {response.text}",