sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
9.25k stars 1.42k forks source link

Return response body as byte slice for RequestError type #873

Closed AyushSawant18588 closed 1 month ago

AyushSawant18588 commented 1 month ago

Describe the change When the inference engine returns an error response that is not of type openai.ErrorResponse, a decode error occurs, leading to the loss of the original error message from the inference engine. To address this issue, this PR implements a change in the go-openai client that ensures the error from the inference engine is included in the openai.RequestError response. This enhancement preserves the original error information, providing clearer insights into the underlying issues.

Describe your solution Introduced a new field called Body of type []byte in the openai.RequestError struct. This field stores the byte slice of the error response body received from the inference engine when the error response does not conform to the openai.ErrorResponse type. This enhancement allows to retain the original error message. Now that the byte slice of the error response body is included, clients using this library can unmarshal it on their end to obtain the correct error message.

Issue: https://github.com/sashabaranov/go-openai/issues/874

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.04%. Comparing base (774fc9d) to head (9caa8d3). Report is 61 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #873 +/- ## ========================================== + Coverage 98.46% 99.04% +0.58% ========================================== Files 24 26 +2 Lines 1364 1462 +98 ========================================== + Hits 1343 1448 +105 + Misses 15 8 -7 Partials 6 6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

johnugeorge commented 1 month ago

@sashabaranov Can you please look into this?