From 5f9c9fd0b5770df4448ff9047704e7cb885da69e Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 9 Nov 2023 05:53:16 +0000 Subject: [PATCH] CodeGen from PR 26636 in Azure/azure-rest-api-specs Merge d7d3d347cd6fdb63b476c0851594be712caeb383 into ed84b11847785792767b0b84cc6f98f4ea08ca77 --- .../api/Azure.AI.OpenAI.netstandard2.0.cs | 10 +- .../Generated/AudioTranscriptionOptions.cs | 2 +- .../src/Generated/AudioTranslationOptions.cs | 2 +- .../src/Generated/AzureOpenAIModelFactory.cs | 149 ++++++++---------- .../ImageGenerationOptions.Serialization.cs | 63 ++++++++ .../ImageGenerations.Serialization.cs | 21 ++- .../src/Generated/ImageGenerations.cs | 4 +- .../Generated/ImageLocation.Serialization.cs | 19 ++- .../src/Generated/ImageLocation.cs | 4 +- sdk/openai/Azure.AI.OpenAI/tsp-location.yaml | 6 +- 10 files changed, 177 insertions(+), 103 deletions(-) diff --git a/sdk/openai/Azure.AI.OpenAI/api/Azure.AI.OpenAI.netstandard2.0.cs b/sdk/openai/Azure.AI.OpenAI/api/Azure.AI.OpenAI.netstandard2.0.cs index 8a8ed03b3049..07334a5e8649 100644 --- a/sdk/openai/Azure.AI.OpenAI/api/Azure.AI.OpenAI.netstandard2.0.cs +++ b/sdk/openai/Azure.AI.OpenAI/api/Azure.AI.OpenAI.netstandard2.0.cs @@ -205,8 +205,6 @@ public static partial class AzureOpenAIModelFactory public static Azure.AI.OpenAI.EmbeddingItem EmbeddingItem(System.ReadOnlyMemory embedding = default(System.ReadOnlyMemory), int index = 0) { throw null; } public static Azure.AI.OpenAI.Embeddings Embeddings(System.Collections.Generic.IEnumerable data = null, Azure.AI.OpenAI.EmbeddingsUsage usage = null) { throw null; } public static Azure.AI.OpenAI.EmbeddingsUsage EmbeddingsUsage(int promptTokens = 0, int totalTokens = 0) { throw null; } - public static Azure.AI.OpenAI.ImageGenerations ImageGenerations(System.DateTimeOffset created = default(System.DateTimeOffset), System.Collections.Generic.IEnumerable data = null) { throw null; } - public static Azure.AI.OpenAI.ImageLocation ImageLocation(System.Uri url = null) { throw null; } public static Azure.AI.OpenAI.PromptFilterResult PromptFilterResult(int promptIndex = 0, Azure.AI.OpenAI.ContentFilterResults contentFilterResults = null) { throw null; } public static Azure.AI.OpenAI.StreamingChatCompletionsUpdate StreamingChatCompletionsUpdate(string id, System.DateTimeOffset created, int? choiceIndex = default(int?), Azure.AI.OpenAI.ChatRole? role = default(Azure.AI.OpenAI.ChatRole?), string authorName = null, string contentUpdate = null, Azure.AI.OpenAI.CompletionsFinishReason? finishReason = default(Azure.AI.OpenAI.CompletionsFinishReason?), string functionName = null, string functionArgumentsUpdate = null, Azure.AI.OpenAI.AzureChatExtensionsMessageContext azureExtensionsContext = null) { throw null; } } @@ -437,14 +435,14 @@ public ImageGenerationOptions(string prompt) { } } public partial class ImageGenerations { - internal ImageGenerations() { } - public System.DateTimeOffset Created { get { throw null; } } + public ImageGenerations(System.DateTimeOffset created, System.Collections.Generic.IEnumerable data) { } + public System.DateTimeOffset Created { get { throw null; } set { } } public System.Collections.Generic.IReadOnlyList Data { get { throw null; } } } public partial class ImageLocation { - internal ImageLocation() { } - public System.Uri Url { get { throw null; } } + public ImageLocation(System.Uri url) { } + public System.Uri Url { get { throw null; } set { } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ImageSize : System.IEquatable diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs index f5460a934f13..5f28167f63a8 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs @@ -16,7 +16,7 @@ public partial class AudioTranscriptionOptions /// Initializes a new instance of AudioTranscriptionOptions. /// /// The audio data to transcribe. This must be the binary content of a file in one of the supported media formats: - /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm. + /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm. /// /// The requested format of the transcription response data, which will influence the content and detail of the result. /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs index 0cf8ee9d3ce5..3d7945be012c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs @@ -16,7 +16,7 @@ public partial class AudioTranslationOptions /// Initializes a new instance of AudioTranslationOptions. /// /// The audio data to translate. This must be the binary content of a file in one of the supported media formats: - /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm. + /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm. /// /// The requested format of the translation response data, which will influence the content and detail of the result. /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs index b73982221f51..e1186f2a58fd 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs @@ -15,36 +15,54 @@ namespace Azure.AI.OpenAI /// Model factory for models. public static partial class AzureOpenAIModelFactory { - /// Initializes a new instance of Embeddings. - /// Embedding values for the prompts submitted in the request. - /// Usage counts for tokens input using the embeddings API. - /// A new instance for mocking. - public static Embeddings Embeddings(IEnumerable data = null, EmbeddingsUsage usage = null) + /// Initializes a new instance of AudioTranscriptionSegment. + /// The 0-based index of this segment within a transcription. + /// The time at which this segment started relative to the beginning of the transcribed audio. + /// The time at which this segment ended relative to the beginning of the transcribed audio. + /// The transcribed text that was part of this audio segment. + /// The temperature score associated with this audio segment. + /// The average log probability associated with this audio segment. + /// The compression ratio of this audio segment. + /// The probability of no speech detection within this audio segment. + /// The token IDs matching the transcribed text in this audio segment. + /// + /// The seek position associated with the processing of this audio segment. + /// Seek positions are expressed as hundredths of seconds. + /// The model may process several segments from a single seek position, so while the seek position will never represent + /// a later time than the segment's start, the segment's start may represent a significantly later time than the + /// segment's associated seek position. + /// + /// A new instance for mocking. + public static AudioTranscriptionSegment AudioTranscriptionSegment(int id = default, TimeSpan start = default, TimeSpan end = default, string text = null, float temperature = default, float averageLogProbability = default, float compressionRatio = default, float noSpeechProbability = default, IEnumerable tokens = null, int seek = default) { - data ??= new List(); + tokens ??= new List(); - return new Embeddings(data?.ToList(), usage); + return new AudioTranscriptionSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); } - /// Initializes a new instance of EmbeddingItem. - /// - /// List of embeddings value for the input prompt. These represent a measurement of the - /// vector-based relatedness of the provided input. + /// Initializes a new instance of AudioTranslationSegment. + /// The 0-based index of this segment within a translation. + /// The time at which this segment started relative to the beginning of the translated audio. + /// The time at which this segment ended relative to the beginning of the translated audio. + /// The translated text that was part of this audio segment. + /// The temperature score associated with this audio segment. + /// The average log probability associated with this audio segment. + /// The compression ratio of this audio segment. + /// The probability of no speech detection within this audio segment. + /// The token IDs matching the translated text in this audio segment. + /// + /// The seek position associated with the processing of this audio segment. + /// Seek positions are expressed as hundredths of seconds. + /// The model may process several segments from a single seek position, so while the seek position will never represent + /// a later time than the segment's start, the segment's start may represent a significantly later time than the + /// segment's associated seek position. /// - /// Index of the prompt to which the EmbeddingItem corresponds. - /// A new instance for mocking. - public static EmbeddingItem EmbeddingItem(ReadOnlyMemory embedding = default, int index = default) + /// A new instance for mocking. + public static AudioTranslationSegment AudioTranslationSegment(int id = default, TimeSpan start = default, TimeSpan end = default, string text = null, float temperature = default, float averageLogProbability = default, float compressionRatio = default, float noSpeechProbability = default, IEnumerable tokens = null, int seek = default) { - return new EmbeddingItem(embedding, index); - } + tokens ??= new List(); - /// Initializes a new instance of EmbeddingsUsage. - /// Number of tokens sent in the original request. - /// Total number of tokens transacted in this request/response. - /// A new instance for mocking. - public static EmbeddingsUsage EmbeddingsUsage(int promptTokens = default, int totalTokens = default) - { - return new EmbeddingsUsage(promptTokens, totalTokens); + return new AudioTranslationSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); } /// Initializes a new instance of Completions. @@ -189,79 +207,36 @@ public static ChatCompletions ChatCompletions(string id = null, DateTimeOffset c return new ChatCompletions(id, created, choices?.ToList(), promptFilterResults?.ToList(), usage); } - /// Initializes a new instance of ImageGenerations. - /// A timestamp when this job or item was created (in unix epochs). - /// The images generated by the operator. - /// A new instance for mocking. - public static ImageGenerations ImageGenerations(DateTimeOffset created = default, IEnumerable data = null) - { - data ??= new List(); - - return new ImageGenerations(created, data?.ToList()); - } - - /// Initializes a new instance of ImageLocation. - /// The URL that provides temporary access to download the generated image. - /// is null. - /// A new instance for mocking. - public static ImageLocation ImageLocation(Uri url = null) + /// Initializes a new instance of Embeddings. + /// Embedding values for the prompts submitted in the request. + /// Usage counts for tokens input using the embeddings API. + /// A new instance for mocking. + public static Embeddings Embeddings(IEnumerable data = null, EmbeddingsUsage usage = null) { - if (url == null) - { - throw new ArgumentNullException(nameof(url)); - } + data ??= new List(); - return new ImageLocation(url); + return new Embeddings(data?.ToList(), usage); } - /// Initializes a new instance of AudioTranscriptionSegment. - /// The 0-based index of this segment within a transcription. - /// The time at which this segment started relative to the beginning of the transcribed audio. - /// The time at which this segment ended relative to the beginning of the transcribed audio. - /// The transcribed text that was part of this audio segment. - /// The temperature score associated with this audio segment. - /// The average log probability associated with this audio segment. - /// The compression ratio of this audio segment. - /// The probability of no speech detection within this audio segment. - /// The token IDs matching the transcribed text in this audio segment. - /// - /// The seek position associated with the processing of this audio segment. - /// Seek positions are expressed as hundredths of seconds. - /// The model may process several segments from a single seek position, so while the seek position will never represent - /// a later time than the segment's start, the segment's start may represent a significantly later time than the - /// segment's associated seek position. + /// Initializes a new instance of EmbeddingItem. + /// + /// List of embeddings value for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. /// - /// A new instance for mocking. - public static AudioTranscriptionSegment AudioTranscriptionSegment(int id = default, TimeSpan start = default, TimeSpan end = default, string text = null, float temperature = default, float averageLogProbability = default, float compressionRatio = default, float noSpeechProbability = default, IEnumerable tokens = null, int seek = default) + /// Index of the prompt to which the EmbeddingItem corresponds. + /// A new instance for mocking. + public static EmbeddingItem EmbeddingItem(ReadOnlyMemory embedding = default, int index = default) { - tokens ??= new List(); - - return new AudioTranscriptionSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); + return new EmbeddingItem(embedding, index); } - /// Initializes a new instance of AudioTranslationSegment. - /// The 0-based index of this segment within a translation. - /// The time at which this segment started relative to the beginning of the translated audio. - /// The time at which this segment ended relative to the beginning of the translated audio. - /// The translated text that was part of this audio segment. - /// The temperature score associated with this audio segment. - /// The average log probability associated with this audio segment. - /// The compression ratio of this audio segment. - /// The probability of no speech detection within this audio segment. - /// The token IDs matching the translated text in this audio segment. - /// - /// The seek position associated with the processing of this audio segment. - /// Seek positions are expressed as hundredths of seconds. - /// The model may process several segments from a single seek position, so while the seek position will never represent - /// a later time than the segment's start, the segment's start may represent a significantly later time than the - /// segment's associated seek position. - /// - /// A new instance for mocking. - public static AudioTranslationSegment AudioTranslationSegment(int id = default, TimeSpan start = default, TimeSpan end = default, string text = null, float temperature = default, float averageLogProbability = default, float compressionRatio = default, float noSpeechProbability = default, IEnumerable tokens = null, int seek = default) + /// Initializes a new instance of EmbeddingsUsage. + /// Number of tokens sent in the original request. + /// Total number of tokens transacted in this request/response. + /// A new instance for mocking. + public static EmbeddingsUsage EmbeddingsUsage(int promptTokens = default, int totalTokens = default) { - tokens ??= new List(); - - return new AudioTranslationSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); + return new EmbeddingsUsage(promptTokens, totalTokens); } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs index c5f2cc65360d..d5f5122bf9d0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI @@ -40,6 +41,68 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteEndObject(); } + internal static ImageGenerationOptions DeserializeImageGenerationOptions(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string prompt = default; + Optional n = default; + Optional size = default; + Optional responseFormat = default; + Optional user = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("prompt"u8)) + { + prompt = property.Value.GetString(); + continue; + } + if (property.NameEquals("n"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + n = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("size"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + size = new ImageSize(property.Value.GetString()); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + responseFormat = new ImageGenerationResponseFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("user"u8)) + { + user = property.Value.GetString(); + continue; + } + } + return new ImageGenerationOptions(prompt, Optional.ToNullable(n), Optional.ToNullable(size), Optional.ToNullable(responseFormat), user.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ImageGenerationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeImageGenerationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs index 551e28de47f3..4cbdfec6ec1d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs @@ -9,11 +9,22 @@ using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ImageGenerations + public partial class ImageGenerations : IUtf8JsonSerializable { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("created"u8); + writer.WriteNumberValue(Created, "U"); + writer.WritePropertyName("data"u8); + SerializeDataProperty(writer); + writer.WriteEndObject(); + } + internal static ImageGenerations DeserializeImageGenerations(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -45,5 +56,13 @@ internal static ImageGenerations FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeImageGenerations(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs index a54bb97dc258..5cbc0864c4cc 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs @@ -19,7 +19,7 @@ public partial class ImageGenerations /// A timestamp when this job or item was created (in unix epochs). /// The images generated by the operator. /// is null. - internal ImageGenerations(DateTimeOffset created, IEnumerable data) + public ImageGenerations(DateTimeOffset created, IEnumerable data) { Argument.AssertNotNull(data, nameof(data)); @@ -37,6 +37,6 @@ internal ImageGenerations(DateTimeOffset created, IReadOnlyList d } /// A timestamp when this job or item was created (in unix epochs). - public DateTimeOffset Created { get; } + public DateTimeOffset Created { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.Serialization.cs index f4fc3c356a17..f230873afa2b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.Serialization.cs @@ -8,11 +8,20 @@ using System; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ImageLocation + public partial class ImageLocation : IUtf8JsonSerializable { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("url"u8); + writer.WriteStringValue(Url.AbsoluteUri); + writer.WriteEndObject(); + } + internal static ImageLocation DeserializeImageLocation(JsonElement element) { if (element.ValueKind == JsonValueKind.Null) @@ -38,5 +47,13 @@ internal static ImageLocation FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeImageLocation(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs index 8783a2d3c5ef..e79c0f81569f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs @@ -16,7 +16,7 @@ public partial class ImageLocation /// Initializes a new instance of ImageLocation. /// The URL that provides temporary access to download the generated image. /// is null. - internal ImageLocation(Uri url) + public ImageLocation(Uri url) { Argument.AssertNotNull(url, nameof(url)); @@ -24,6 +24,6 @@ internal ImageLocation(Uri url) } /// The URL that provides temporary access to download the generated image. - public Uri Url { get; } + public Uri Url { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml index ff3fb0810607..217ecd6045ed 100644 --- a/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml @@ -1,3 +1,5 @@ -directory: specification/cognitiveservices/OpenAI.Inference -commit: a66833cbdebb0574ba012f814ab271a382a7c500 repo: Azure/azure-rest-api-specs +directory: specification/cognitiveservices/OpenAI.Inference +additionalDirectories: [] +commit: 6365dbb61c4be5f2b5afa1b499dc27d101c0233c +