Skip to content

Commit

Permalink
OpenAI-DotNet 7.7.4 (#254)
Browse files Browse the repository at this point in the history
- Fixed Threads.RunResponse.WaitForStatusChangeAsync timeout
  • Loading branch information
StephenHodgson authored Feb 29, 2024
1 parent 453a796 commit 8ae5380
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion OpenAI-DotNet/OpenAI-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet-
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
<IncludeSymbols>True</IncludeSymbols>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<Version>7.7.3</Version>
<Version>7.7.4</Version>
<PackageReleaseNotes>
Version 7.7.4
- Fixed Threads.RunResponse.WaitForStatusChangeAsync timeout
Version 7.7.3
- Updated ChatRequest toolChoice to only send type and name of function, reducing token usage
Version 7.7.2
Expand Down
4 changes: 2 additions & 2 deletions OpenAI-DotNet/Threads/MessageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public sealed class MessageResponse : BaseResponse
public string Id { get; private set; }

/// <summary>
/// The object type, which is always thread.
/// The object type, which is always message.
/// </summary>
[JsonInclude]
[JsonPropertyName("object")]
public string Object { get; private set; }

/// <summary>
/// The Unix timestamp (in seconds) for when the thread was created.
/// The Unix timestamp (in seconds) for when the message was created.
/// </summary>
[JsonInclude]
[JsonPropertyName("created_at")]
Expand Down
9 changes: 6 additions & 3 deletions OpenAI-DotNet/Threads/ThreadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ public static async Task<RunResponse> ModifyAsync(this RunResponse run, IReadOnl
/// <returns><see cref="RunResponse"/>.</returns>
public static async Task<RunResponse> WaitForStatusChangeAsync(this RunResponse run, int? pollingInterval = null, int? timeout = null, CancellationToken cancellationToken = default)
{
using var cts = timeout is null or < 0 ? new CancellationTokenSource(TimeSpan.FromSeconds(timeout ?? 30)) : new CancellationTokenSource();
using CancellationTokenSource cts = timeout.HasValue && timeout < 0
? new CancellationTokenSource()
: new CancellationTokenSource(TimeSpan.FromSeconds(timeout ?? 30));
using var chainedCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, cancellationToken);
RunResponse result;
do
{
result = await run.UpdateAsync(cancellationToken: chainedCts.Token).ConfigureAwait(false);
await Task.Delay(pollingInterval ?? 500, chainedCts.Token).ConfigureAwait(false);
await Task.Delay(pollingInterval ?? 500, chainedCts.Token);
cancellationToken.ThrowIfCancellationRequested();
result = await run.UpdateAsync(cancellationToken: chainedCts.Token);
} while (result.Status is RunStatus.Queued or RunStatus.InProgress or RunStatus.Cancelling);
return result;
}
Expand Down

0 comments on commit 8ae5380

Please sign in to comment.