diff --git a/OpenAI.SDK/Extensions/HttpclientExtensions.cs b/OpenAI.SDK/Extensions/HttpclientExtensions.cs index d1e7aa26..ecaa5379 100644 --- a/OpenAI.SDK/Extensions/HttpclientExtensions.cs +++ b/OpenAI.SDK/Extensions/HttpclientExtensions.cs @@ -13,7 +13,6 @@ public static async Task PostAndReadAsAsync(this HttpClien { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault }, cancellationToken); - response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken) ?? throw new InvalidOperationException(); } @@ -48,7 +47,6 @@ private static HttpResponseMessage SendRequestPreNet6(HttpClient client, HttpReq { var responseTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); var response = responseTask.GetAwaiter().GetResult(); - response.EnsureSuccessStatusCode(); return response; } @@ -64,21 +62,18 @@ private static HttpRequestMessage CreatePostEventStreamRequest(string uri, HttpC public static async Task PostFileAndReadAsAsync(this HttpClient client, string uri, HttpContent content, CancellationToken cancellationToken = default) { var response = await client.PostAsync(uri, content, cancellationToken); - response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken) ?? throw new InvalidOperationException(); } public static async Task PostFileAndReadAsStringAsync(this HttpClient client, string uri, HttpContent content, CancellationToken cancellationToken = default) { var response = await client.PostAsync(uri, content, cancellationToken); - response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync(cancellationToken) ?? throw new InvalidOperationException(); } public static async Task DeleteAndReadAsAsync(this HttpClient client, string uri, CancellationToken cancellationToken = default) { var response = await client.DeleteAsync(uri, cancellationToken); - response.EnsureSuccessStatusCode(); return await response.Content.ReadFromJsonAsync(cancellationToken: cancellationToken) ?? throw new InvalidOperationException(); } @@ -104,7 +99,6 @@ public static async Task ReadAsByteArrayAsync(this HttpContent content, public static async Task GetStreamAsync(this HttpClient client, string requestUri, CancellationToken cancellationToken) { var response = await client.GetAsync(requestUri, cancellationToken); - response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStreamAsync(cancellationToken); } diff --git a/OpenAI.SDK/Managers/OpenAIFile.cs b/OpenAI.SDK/Managers/OpenAIFile.cs index ec93830a..301c6f77 100644 --- a/OpenAI.SDK/Managers/OpenAIFile.cs +++ b/OpenAI.SDK/Managers/OpenAIFile.cs @@ -45,8 +45,6 @@ public async Task RetrieveFile(string fileId, CancellationToken ca { var response = await _httpClient.GetAsync(_endpointProvider.FileRetrieveContent(fileId), cancellationToken); - response.EnsureSuccessStatusCode(); - if (typeof(T) == typeof(string)) { return new FileContentResponse diff --git a/OpenAI.SDK/OpenAI.csproj b/OpenAI.SDK/OpenAI.csproj index 7d669a1c..c1c93cdd 100644 --- a/OpenAI.SDK/OpenAI.csproj +++ b/OpenAI.SDK/OpenAI.csproj @@ -11,7 +11,7 @@ OpenAI-Betalgo.png true OpenAI SDK by Betalgo - 7.3.0 + 7.3.1 Tolga Kayhan, Betalgo Betalgo Up Ltd. OpenAI ChatGPT, Whisper, GPT-4 and DALLĀ·E dotnet SDK diff --git a/Readme.md b/Readme.md index 6f58a40e..147c6097 100644 --- a/Readme.md +++ b/Readme.md @@ -224,6 +224,11 @@ I will always be using the latest libraries, and future releases will frequently I am incredibly busy. If I forgot your name, please accept my apologies and let me know so I can add it to the list. ## Changelog +### Version 7.3.1 +- **Reverting a breking change which will be also Breaking Changes(only for 7.3.0):** + - Reverting the usage of `EnsureStatusCode()` which caused the loss of error information. Initially, I thought it would help in implementing HTTP retry tools, but now I believe it is a bad idea for two reasons. + 1. You can't simply retry if the request wasn't successful because it could fail for various reasons. For example, you might have used too many tokens in your request, causing OpenAI to reject the response, or you might have tried to use a nonexistent model. It would be better to use the Error object in your retry rules. All responses are already derived from this base object. + 2. We will lose error response data. ### Version 7.3.0 - Updated Moderation categories as reported by @dmki. - **Breaking Changes:**