Skip to content

Commit 152310d

Browse files
OpenAI-DotNet 8.8.3 (#495)
- Fix regression ObjectDisposedException from OpenAIBaseEndpoint refactoring - Add Azure Blob Batch API compatible fields for CreateBatchRequest - Added DurationUsage - Updated ConversationItemInputAudioTranscriptionResponse to include logprobs and usage --------- Co-authored-by: Alec Chan <34929371+aechan@users.noreply.github.com>
1 parent 948cf95 commit 152310d

File tree

10 files changed

+208
-15
lines changed

10 files changed

+208
-15
lines changed

OpenAI-DotNet-Tests/TestFixture_14_Responses.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ async Task StreamCallback(string @event, IServerSentEvent sseEvent)
193193
Assert.IsNotEmpty(functionToolCall.Name);
194194
Assert.IsTrue(functionToolCall.Name.Contains(nameof(DateTimeUtility.GetDateTime)));
195195
Assert.NotNull(functionToolCall.Arguments);
196-
conversation.Add(functionToolCall);
196+
197+
if (conversation.All(i => i.Id != functionToolCall.Id))
198+
{
199+
conversation.Add(functionToolCall);
200+
}
201+
197202
var output = await functionToolCall.InvokeFunctionAsync();
198203
conversation.Add(output);
199204
break;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace OpenAI.Batch
4+
{
5+
public sealed class BatchOutputFolder
6+
{
7+
public BatchOutputFolder(string url)
8+
{
9+
Url = url;
10+
}
11+
12+
/// <summary>
13+
/// The URL of the blob storage folder where the batch output will be written.
14+
/// </summary>
15+
[JsonPropertyName("url")]
16+
public string Url { get; }
17+
18+
public static implicit operator BatchOutputFolder(string url) => new(url);
19+
}
20+
}

OpenAI-DotNet/Batch/BatchResponse.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ public DateTime? CancelledAt
186186
[JsonPropertyName("metadata")]
187187
public IReadOnlyDictionary<string, object> Metadata { get; private set; }
188188

189+
/// <summary>
190+
/// The URL of the blob storage location where any errors encountered during processing will be written.
191+
/// </summary>
192+
[JsonInclude]
193+
[JsonPropertyName("error_blob")]
194+
public string ErrorBlob { get; private set; }
195+
196+
/// <summary>
197+
/// The URL of the blob storage location where the batch output will be written.
198+
/// </summary>
199+
[JsonInclude]
200+
[JsonPropertyName("output_blob")]
201+
public string OutputBlob { get; private set; }
202+
203+
/// <summary>
204+
/// The URL of the blob storage location where the batch input was read from.
205+
/// </summary>
206+
[JsonInclude]
207+
[JsonPropertyName("input_blob")]
208+
public string InputBlob { get; private set; }
209+
189210
public override string ToString() => Id;
190211

191212
public static implicit operator string(BatchResponse response) => response?.ToString();

OpenAI-DotNet/Batch/CreateBatchRequest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@ public sealed class CreateBatchRequest
2525
/// <param name="metadata">
2626
/// Optional custom metadata for the batch.
2727
/// </param>
28-
public CreateBatchRequest(string inputFileId, string endpoint, IReadOnlyDictionary<string, object> metadata = null)
28+
/// <param name="inputBlob">Azure blob</param>
29+
/// <param name="outputFolder"><see cref="BatchOutputFolder"/>.</param>
30+
public CreateBatchRequest(
31+
string inputFileId,
32+
string endpoint,
33+
IReadOnlyDictionary<string, object> metadata = null,
34+
string inputBlob = null,
35+
BatchOutputFolder outputFolder = null)
2936
{
3037
InputFileId = inputFileId;
3138
Endpoint = endpoint;
3239
CompletionWindow = DefaultCompletionWindow;
3340
Metadata = metadata;
41+
InputBlob = inputBlob;
42+
OutputFolder = outputFolder;
3443
}
3544

3645
[JsonPropertyName("input_file_id")]
@@ -43,6 +52,15 @@ public CreateBatchRequest(string inputFileId, string endpoint, IReadOnlyDictiona
4352
public string CompletionWindow { get; }
4453

4554
[JsonPropertyName("metadata")]
55+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
4656
public IReadOnlyDictionary<string, object> Metadata { get; }
57+
58+
[JsonPropertyName("input_blob")]
59+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
60+
public string InputBlob { get; }
61+
62+
[JsonPropertyName("output_folder")]
63+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
64+
public BatchOutputFolder OutputFolder { get; }
4765
}
4866
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed under the MIT License. See LICENSE in the project root for license information.
2+
3+
using OpenAI.Extensions;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
7+
namespace OpenAI
8+
{
9+
public sealed class DurationUsage
10+
{
11+
[JsonInclude]
12+
[JsonPropertyName("seconds")]
13+
public float Seconds { get; }
14+
15+
[JsonInclude]
16+
[JsonPropertyName("type")]
17+
public string Type { get; }
18+
19+
public override string ToString()
20+
=> JsonSerializer.Serialize(this, ResponseExtensions.DebugJsonOptions);
21+
}
22+
}

OpenAI-DotNet/Common/OpenAIBaseEndpoint.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,24 @@ public bool EnableDebug
5252
internal virtual IReadOnlyDictionary<string, IEnumerable<string>> Headers => null;
5353

5454
protected Task<HttpResponseMessage> GetAsync(string uri, CancellationToken cancellationToken)
55-
{
56-
using var message = new HttpRequestMessage(HttpMethod.Get, uri);
57-
return SendAsync(message, cancellationToken);
58-
}
55+
=> SendAsync(new(HttpMethod.Get, uri), cancellationToken);
5956

6057
protected Task<HttpResponseMessage> PostAsync(string uri, HttpContent content, CancellationToken cancellationToken)
6158
{
62-
using var message = new HttpRequestMessage(HttpMethod.Post, uri);
59+
var message = new HttpRequestMessage(HttpMethod.Post, uri);
6360
message.Content = content;
6461
return SendAsync(message, cancellationToken);
6562
}
6663

6764
protected Task<HttpResponseMessage> PatchAsync(string uri, HttpContent content, CancellationToken cancellationToken)
6865
{
69-
using var message = new HttpRequestMessage(HttpMethod.Patch, uri);
66+
var message = new HttpRequestMessage(HttpMethod.Patch, uri);
7067
message.Content = content;
7168
return SendAsync(message, cancellationToken);
7269
}
7370

7471
protected Task<HttpResponseMessage> DeleteAsync(string uri, CancellationToken cancellationToken)
75-
{
76-
using var message = new HttpRequestMessage(HttpMethod.Delete, uri);
77-
return SendAsync(message, cancellationToken);
78-
}
72+
=> SendAsync(new(HttpMethod.Delete, uri), cancellationToken);
7973

8074
protected Task<Stream> GetStreamAsync(string uri, CancellationToken cancellationToken)
8175
=> HttpClient.GetStreamAsync(uri, cancellationToken);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using System.Text.Json.Serialization;
66

7-
namespace OpenAI.Responses
7+
namespace OpenAI
88
{
99
public sealed class Prompt
1010
{

OpenAI-DotNet/OpenAI-DotNet.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet-
2929
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
3030
<IncludeSymbols>true</IncludeSymbols>
3131
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
32-
<Version>8.8.2</Version>
32+
<Version>8.8.3</Version>
3333
<PackageReleaseNotes>
34+
Version 8.8.3
35+
- Fix regression ObjectDisposedException from OpenAIBaseEndpoint refactoring
36+
- Add Azure Blob Batch API compatible fields for CreateBatchRequest
37+
- Added DurationUsage
38+
- Updated ConversationItemInputAudioTranscriptionResponse to include logprobs and usage
39+
- Update Realtime.SessionConfiguration with Prompt and Speed parameters
40+
- Move Realtime.Prompt to common namespace
3441
Version 8.8.2
3542
- Add file_url for responses api
3643
- Added NoiseReductionSettings for RealtimeConfiguration

OpenAI-DotNet/Realtime/ConversationItemInputAudioTranscriptionResponse.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Licensed under the MIT License. See LICENSE in the project root for license information.
22

3+
using System.Collections.Generic;
34
using System.Text.Json.Serialization;
45

56
namespace OpenAI.Realtime
@@ -23,6 +24,13 @@ public sealed class ConversationItemInputAudioTranscriptionResponse : BaseRealti
2324
[JsonPropertyName("item_id")]
2425
public string ItemId { get; private set; }
2526

27+
/// <summary>
28+
/// The log probabilities of the transcription.
29+
/// </summary>
30+
[JsonInclude]
31+
[JsonPropertyName("logprobs")]
32+
public IReadOnlyList<LogProbInfo> LogProbs { get; }
33+
2634
/// <summary>
2735
/// The index of the content part containing the audio.
2836
/// </summary>
@@ -37,6 +45,10 @@ public sealed class ConversationItemInputAudioTranscriptionResponse : BaseRealti
3745
[JsonPropertyName("transcript")]
3846
public string Transcript { get; private set; }
3947

48+
[JsonInclude]
49+
[JsonPropertyName("usage")]
50+
public object Usage { get; }
51+
4052
/// <summary>
4153
/// Details of the transcription error.
4254
/// </summary>
@@ -49,5 +61,8 @@ public sealed class ConversationItemInputAudioTranscriptionResponse : BaseRealti
4961

5062
[JsonIgnore]
5163
public bool IsFailed => Type.Contains("failed");
64+
65+
public string PrintUsage()
66+
=> Usage?.ToString() ?? "";
5267
}
5368
}

0 commit comments

Comments
 (0)