Skip to content

Commit

Permalink
Merge pull request #396 from betalgo/dev
Browse files Browse the repository at this point in the history
7.3.1
  • Loading branch information
kayhantolga authored Oct 19, 2023
2 parents 74db2ed + 40be624 commit 9f80263
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
6 changes: 0 additions & 6 deletions OpenAI.SDK/Extensions/HttpclientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static async Task<TResponse> PostAndReadAsAsync<TResponse>(this HttpClien
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
}, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -64,21 +62,18 @@ private static HttpRequestMessage CreatePostEventStreamRequest(string uri, HttpC
public static async Task<TResponse> PostFileAndReadAsAsync<TResponse>(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<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

public static async Task<string> 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<TResponse> DeleteAndReadAsAsync<TResponse>(this HttpClient client, string uri, CancellationToken cancellationToken = default)
{
var response = await client.DeleteAsync(uri, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

Expand All @@ -104,7 +99,6 @@ public static async Task<byte[]> ReadAsByteArrayAsync(this HttpContent content,
public static async Task<Stream> GetStreamAsync(this HttpClient client, string requestUri, CancellationToken cancellationToken)
{
var response = await client.GetAsync(requestUri, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStreamAsync(cancellationToken);
}

Expand Down
2 changes: 0 additions & 2 deletions OpenAI.SDK/Managers/OpenAIFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public async Task<FileResponse> RetrieveFile(string fileId, CancellationToken ca
{
var response = await _httpClient.GetAsync(_endpointProvider.FileRetrieveContent(fileId), cancellationToken);

response.EnsureSuccessStatusCode();

if (typeof(T) == typeof(string))
{
return new FileContentResponse<T?>
Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>OpenAI SDK by Betalgo</Title>
<Version>7.3.0</Version>
<Version>7.3.1</Version>
<Authors>Tolga Kayhan, Betalgo</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>OpenAI ChatGPT, Whisper, GPT-4 and DALL·E dotnet SDK</Product>
Expand Down
5 changes: 5 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down

0 comments on commit 9f80263

Please sign in to comment.