Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More spec update staging: *after* chat audio, etc. #334

Draft
wants to merge 3 commits into
base: user/travisw/chat-audio-with-content-part-squish
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .dotnet/api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ public class ChatCompletionOptions : IJsonModel<ChatCompletionOptions>, IPersist
public IDictionary<int, int> LogitBiases { get; }
public int? MaxOutputTokenCount { get; set; }
public IDictionary<string, string> Metadata { get; }
public ChatMessageContent PredictedContent { get; set; }
public float? PresencePenalty { get; set; }
public ChatResponseFormat ResponseFormat { get; set; }
public long? Seed { get; set; }
Expand Down Expand Up @@ -1582,8 +1583,10 @@ public enum ChatMessageRole {
public override readonly string ToString();
}
public class ChatOutputTokenUsageDetails : IJsonModel<ChatOutputTokenUsageDetails>, IPersistableModel<ChatOutputTokenUsageDetails> {
public int AcceptedPredictionTokenCount { get; }
public int AudioTokenCount { get; }
public int ReasoningTokenCount { get; }
public int RejectedPredictionTokenCount { get; }
ChatOutputTokenUsageDetails IJsonModel<ChatOutputTokenUsageDetails>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<ChatOutputTokenUsageDetails>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
ChatOutputTokenUsageDetails IPersistableModel<ChatOutputTokenUsageDetails>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand All @@ -1605,11 +1608,13 @@ public class ChatResponseFormat : IJsonModel<ChatResponseFormat>, IPersistableMo
private readonly int _dummyPrimitive;
public ChatResponseVoice(string value);
public static ChatResponseVoice Alloy { get; }
public static ChatResponseVoice Ash { get; }
public static ChatResponseVoice Ballad { get; }
public static ChatResponseVoice Coral { get; }
public static ChatResponseVoice Echo { get; }
public static ChatResponseVoice Fable { get; }
public static ChatResponseVoice Nova { get; }
public static ChatResponseVoice Onyx { get; }
public static ChatResponseVoice Sage { get; }
public static ChatResponseVoice Shimmer { get; }
public static ChatResponseVoice Verse { get; }
public readonly bool Equals(ChatResponseVoice other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
Expand Down Expand Up @@ -1708,7 +1713,7 @@ public class FunctionChatMessage : ChatMessage, IJsonModel<FunctionChatMessage>,
public static class OpenAIChatModelFactory {
public static ChatCompletion ChatCompletion(string id = null, ChatFinishReason finishReason = ChatFinishReason.Stop, ChatMessageContent content = null, string refusal = null, IEnumerable<ChatToolCall> toolCalls = null, ChatMessageRole role = ChatMessageRole.System, ChatFunctionCall functionCall = null, IEnumerable<ChatTokenLogProbabilityDetails> contentTokenLogProbabilities = null, IEnumerable<ChatTokenLogProbabilityDetails> refusalTokenLogProbabilities = null, DateTimeOffset createdAt = default, string model = null, string systemFingerprint = null, ChatTokenUsage usage = null, BinaryData audioBytes = null, string audioCorrelationId = null, string audioTranscript = null, DateTimeOffset? audioExpiresAt = null);
public static ChatInputTokenUsageDetails ChatInputTokenUsageDetails(int audioTokenCount = 0, int cachedTokenCount = 0);
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = 0, int audioTokenCount = 0);
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = 0, int audioTokenCount = 0, int acceptedPredictionTokenCount = 0, int rejectedPredictionTokenCount = 0);
public static ChatTokenLogProbabilityDetails ChatTokenLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null, IEnumerable<ChatTokenTopLogProbabilityDetails> topLogProbabilities = null);
public static ChatTokenTopLogProbabilityDetails ChatTokenTopLogProbabilityDetails(string token = null, float logProbability = 0, ReadOnlyMemory<byte>? utf8Bytes = null);
public static ChatTokenUsage ChatTokenUsage(int outputTokenCount = 0, int inputTokenCount = 0, int totalTokenCount = 0, ChatOutputTokenUsageDetails outputTokenDetails = null, ChatInputTokenUsageDetails inputTokenDetails = null);
Expand Down Expand Up @@ -1967,6 +1972,9 @@ public class OpenAIFileClient {
public virtual Task<ClientResult<OpenAIFile>> UploadFileAsync(string filePath, FileUploadPurpose purpose);
}
public class OpenAIFileCollection : ObjectModel.ReadOnlyCollection<OpenAIFile>, IJsonModel<OpenAIFileCollection>, IPersistableModel<OpenAIFileCollection> {
public string FirstId { get; }
public bool HasMore { get; }
public string LastId { get; }
OpenAIFileCollection IJsonModel<OpenAIFileCollection>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
void IJsonModel<OpenAIFileCollection>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options);
OpenAIFileCollection IPersistableModel<OpenAIFileCollection>.Create(BinaryData data, ModelReaderWriterOptions options);
Expand All @@ -1975,7 +1983,7 @@ public class OpenAIFileCollection : ObjectModel.ReadOnlyCollection<OpenAIFile>,
}
public static class OpenAIFilesModelFactory {
public static FileDeletionResult FileDeletionResult(string fileId = null, bool deleted = false);
public static OpenAIFileCollection OpenAIFileCollection(IEnumerable<OpenAIFile> items = null);
public static OpenAIFileCollection OpenAIFileCollection(IEnumerable<OpenAIFile> items = null, string firstId = null, string lastId = null, bool hasMore = false);
public static OpenAIFile OpenAIFileInfo(string id = null, int? sizeInBytes = null, DateTimeOffset createdAt = default, string filename = null, FilePurpose purpose = FilePurpose.Assistants, FileStatus status = FileStatus.Uploaded, string statusDetails = null);
}
}
Expand Down
37 changes: 37 additions & 0 deletions .dotnet/src/Custom/Chat/ChatCompletionOptions.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,41 @@ private static void DeserializeLogitBiasesValue(JsonProperty property, ref IDict
logitBias = dictionary;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SerializePredictedContentValue(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
if (PredictedContent is not null)
{
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
writer.WriteStringValue(InternalPredictionContentType.Content.ToString());
writer.WritePropertyName("content"u8);
writer.WriteObjectValue(PredictedContent, options);
writer.WriteEndObject();
}
else
{
writer.WriteNullValue();
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DeserializePredictedContentValue(JsonProperty property, ref ChatMessageContent predictedContent)
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
predictedContent = null;
}
else
{
foreach (JsonProperty predictionProperty in property.Value.EnumerateObject())
{
if (predictionProperty.NameEquals("content"u8))
{
ChatMessage.DeserializeContentValue(predictionProperty, ref predictedContent);
}
}
}
}
}
4 changes: 4 additions & 0 deletions .dotnet/src/Custom/Chat/ChatCompletionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace OpenAI.Chat;
[CodeGenSerialization(nameof(Messages), SerializationValueHook = nameof(SerializeMessagesValue))]
[CodeGenSerialization(nameof(StopSequences), SerializationValueHook = nameof(SerializeStopSequencesValue), DeserializationValueHook = nameof(DeserializeStopSequencesValue))]
[CodeGenSerialization(nameof(LogitBiases), SerializationValueHook = nameof(SerializeLogitBiasesValue), DeserializationValueHook = nameof(DeserializeLogitBiasesValue))]
[CodeGenSerialization(nameof(PredictedContent), SerializationValueHook = nameof(SerializePredictedContentValue), DeserializationValueHook = nameof(DeserializePredictedContentValue))]
public partial class ChatCompletionOptions
{
// CUSTOM:
Expand Down Expand Up @@ -187,4 +188,7 @@ public ChatAudioOptions AudioOptions
: [InternalCreateChatCompletionRequestModality.Text, InternalCreateChatCompletionRequestModality.Audio];
}
}

[CodeGenMember("Prediction")]
public ChatMessageContent PredictedContent { get; set; }
}
6 changes: 6 additions & 0 deletions .dotnet/src/Custom/Chat/ChatOutputTokenUsageDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public partial class ChatOutputTokenUsageDetails

[CodeGenMember("AudioTokens")]
public int AudioTokenCount { get; }

[CodeGenMember("AcceptedPredictionTokens")]
public int AcceptedPredictionTokenCount { get; }

[CodeGenMember("RejectedPredictionTokens")]
public int RejectedPredictionTokenCount { get; }
}
5 changes: 5 additions & 0 deletions .dotnet/src/Custom/Chat/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ internal partial class InternalChatCompletionResponseMessageAudio { }
[CodeGenModel("ChatCompletionMessageAudioChunk")]
internal partial class InternalChatCompletionMessageAudioChunk { }

[CodeGenModel("PredictionContent")]
internal partial class InternalPredictionContent { }

[CodeGenModel("PredictionContentType")]
internal readonly partial struct InternalPredictionContentType { }
4 changes: 3 additions & 1 deletion .dotnet/src/Custom/Chat/OpenAIChatModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ public static ChatInputTokenUsageDetails ChatInputTokenUsageDetails(int audioTok

/// <summary> Initializes a new instance of <see cref="OpenAI.Chat.ChatOutputTokenUsageDetails"/>. </summary>
/// <returns> A new <see cref="OpenAI.Chat.ChatOutputTokenusageDetails"/> instance for mocking. </returns>
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = default, int audioTokenCount = default)
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = default, int audioTokenCount = default, int acceptedPredictionTokenCount = default, int rejectedPredictionTokenCount = 0)
{
return new ChatOutputTokenUsageDetails(
audioTokenCount: audioTokenCount,
reasoningTokenCount: reasoningTokenCount,
acceptedPredictionTokenCount: acceptedPredictionTokenCount,
rejectedPredictionTokenCount: rejectedPredictionTokenCount,
serializedAdditionalRawData: null);
}

Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Files/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ namespace OpenAI.Files;
[CodeGenModel("DeleteFileResponseObject")]
internal readonly partial struct InternalDeleteFileResponseObject { }

[CodeGenModel("ListFilesResponseObject")]
internal readonly partial struct InternalListFilesResponseObject { }

[CodeGenModel("OpenAIFileObject")]
internal readonly partial struct InternalOpenAIFileObject { }

Expand Down
24 changes: 21 additions & 3 deletions .dotnet/src/Custom/Files/OpenAIFileCollection.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ internal static OpenAIFileCollection DeserializeOpenAIFileCollection(JsonElement
return null;
}
IReadOnlyList<OpenAIFile> data = default;
InternalListFilesResponseObject @object = default;
string @object = default;
string firstId = default;
string lastId = default;
bool hasMore = false;
IDictionary<string, BinaryData> serializedAdditionalRawData = default;
Dictionary<string, BinaryData> rawDataDictionary = new Dictionary<string, BinaryData>();
foreach (var property in element.EnumerateObject())
Expand All @@ -57,7 +60,22 @@ internal static OpenAIFileCollection DeserializeOpenAIFileCollection(JsonElement
}
if (property.NameEquals("object"u8))
{
@object = new InternalListFilesResponseObject(property.Value.GetString());
@object = property.Value.GetString();
continue;
}
if (property.NameEquals("first_id"u8))
{
firstId = property.Value.GetString();
continue;
}
if (property.NameEquals("last_id"u8))
{
lastId = property.Value.GetString();
continue;
}
if (property.NameEquals("has_more"u8))
{
hasMore = property.Value.GetBoolean();
continue;
}
if (true)
Expand All @@ -66,7 +84,7 @@ internal static OpenAIFileCollection DeserializeOpenAIFileCollection(JsonElement
}
}
serializedAdditionalRawData = rawDataDictionary;
return new OpenAIFileCollection(data, @object, serializedAdditionalRawData);
return new OpenAIFileCollection(data, @object, firstId, lastId, hasMore, serializedAdditionalRawData);
}

}
15 changes: 11 additions & 4 deletions .dotnet/src/Custom/Files/OpenAIFileCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ namespace OpenAI.Files;
[CodeGenModel("ListFilesResponse")]
[CodeGenSuppress("Data")]
[CodeGenSuppress(nameof(OpenAIFileCollection))]
[CodeGenSuppress(nameof(OpenAIFileCollection), typeof(IReadOnlyList<OpenAIFile>), typeof(InternalListFilesResponseObject))]
[CodeGenSuppress(nameof(OpenAIFileCollection), typeof(string), typeof(IReadOnlyList<OpenAIFile>), typeof(string), typeof(string), typeof(bool))]
[CodeGenSuppress(nameof(OpenAIFileCollection), typeof(string), typeof(IEnumerable<OpenAIFile>), typeof(string), typeof(string), typeof(bool))]
public partial class OpenAIFileCollection : ReadOnlyCollection<OpenAIFile>
{
// CUSTOM: Made private. This property does not add value in the context of a strongly-typed class.
/// <summary> Gets the object. </summary>
private InternalListFilesResponseObject Object { get; } = InternalListFilesResponseObject.List;
private string Object { get; } = "list";

// CUSTOM: Recovered this field. See https://github.com/Azure/autorest.csharp/issues/4636.
/// <summary>
Expand Down Expand Up @@ -50,21 +51,27 @@ public partial class OpenAIFileCollection : ReadOnlyCollection<OpenAIFile>
/// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/>. </summary>
/// <param name="data"></param>
/// <exception cref="ArgumentNullException"> <paramref name="data"/> is null. </exception>
internal OpenAIFileCollection(IEnumerable<OpenAIFile> data)
internal OpenAIFileCollection(IEnumerable<OpenAIFile> data, string firstId, string lastId, bool hasMore)
: base([.. data])
{
Argument.AssertNotNull(data, nameof(data));
FirstId = firstId;
LastId = lastId;
HasMore = hasMore;
}

/// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/>. </summary>
/// <param name="data"></param>
/// <param name="object"></param>
/// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param>
internal OpenAIFileCollection(IReadOnlyList<OpenAIFile> data, InternalListFilesResponseObject @object, IDictionary<string, BinaryData> serializedAdditionalRawData)
internal OpenAIFileCollection(IReadOnlyList<OpenAIFile> data, string @object, string firstId, string lastId, bool hasMore, IDictionary<string, BinaryData> serializedAdditionalRawData)
: base([.. data])
{
Object = @object;
SerializedAdditionalRawData = serializedAdditionalRawData;
FirstId = firstId;
LastId = lastId;
HasMore = hasMore;
}

/// <summary> Initializes a new instance of <see cref="OpenAIFileCollection"/> for deserialization. </summary>
Expand Down
7 changes: 4 additions & 3 deletions .dotnet/src/Custom/Files/OpenAIFilesModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public static OpenAIFile OpenAIFileInfo(string id = null, int? sizeInBytes = nul

/// <summary> Initializes a new instance of <see cref="OpenAI.Files.OpenAIFileCollection"/>. </summary>
/// <returns> A new <see cref="OpenAI.Files.OpenAIFileCollection"/> instance for mocking. </returns>
public static OpenAIFileCollection OpenAIFileCollection(IEnumerable<OpenAIFile> items = null)
public static OpenAIFileCollection OpenAIFileCollection(IEnumerable<OpenAIFile> items = null, string firstId = default, string lastId = default, bool hasMore = default)
{
items ??= new List<OpenAIFile>();

return new OpenAIFileCollection(
items.ToList(),
InternalListFilesResponseObject.List,
serializedAdditionalRawData: null);
firstId,
lastId,
hasMore);
}
}
58 changes: 29 additions & 29 deletions .dotnet/src/Generated/BatchClient.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// <auto-generated/>
#nullable disable
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OpenAI.Batch
{
// Data plane generated sub-client.
public partial class BatchClient
{
private const string AuthorizationHeader = "Authorization";
private readonly ApiKeyCredential _keyCredential;
private const string AuthorizationApiKeyPrefix = "Bearer";
private readonly ClientPipeline _pipeline;
private readonly Uri _endpoint;
protected BatchClient()
{
}
private static PipelineMessageClassifier _pipelineMessageClassifier200;
private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 });
}
}
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenAI.Batch
{
// Data plane generated sub-client.
public partial class BatchClient
{
private const string AuthorizationHeader = "Authorization";
private readonly ApiKeyCredential _keyCredential;
private const string AuthorizationApiKeyPrefix = "Bearer";
private readonly ClientPipeline _pipeline;
private readonly Uri _endpoint;

protected BatchClient()
{
}

private static PipelineMessageClassifier _pipelineMessageClassifier200;
private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 });
}
}
Loading
Loading