OpenAI-DotNet
OpenAI-DotNet copied to clipboard
Dedicated exceptions for specific events
I see there's some code that's been added that populates the headers for rate limiting, but they're unusable as our current implementations require a successful status code response before we set the response data. If the response is not a success status code (200-299) we throw an exception.
Currently the BaseResponse
looks the following way.
I suggest if we do decide to tackle this, to create a custom OpenAIClientRateLimitException
that end-users can inspect and access all those related headers, which should also end up cleaning the BaseResponse
a bit. The cleaning part though would introduce breaking changes if we do decide to follow through with it.
Alternative but much more destructive, would be to move all of the properties related to rate limiting from BaseResponse
in their own class and remove their nullability - if the object exists, then they too exist - and possibly make BaseResponse
generic to encapsulate the actual response received from Open AI, along with anything else we deem worthy.
This makes using the API a bit more cumbersome and entirely changes how users interact with it. You'd need to access 1 more property to get to what you're most interested it. The benefits are that it removes the need for throwing exceptions for normal execution flow, as well as users writing try/catches for normal execution flow. There's nothing uncommon or exceptional about requests with a status code of 400-499. A 500+ status code is an exceptional event though, as it indicates an unexpected server-side error and the client can do nothing to change its outcome.
First approach is much more manageable for implementation. It all depends on how much we value performance, versus simplicity and in which direction we should focus our time and effort on.
P.S: I'm willing to help out with anything you guys decide to do on this.