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 84315de87a97e..736987f368adc 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 @@ -8,6 +8,9 @@ public static partial class AzureOpenAIModelFactory public static Azure.AI.OpenAI.EmbeddingItem EmbeddingItem(System.Collections.Generic.IEnumerable embedding = null, 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.ImageLocation ImageLocation(System.Uri url = null, Azure.ResponseError error = null) { throw null; } + public static Azure.AI.OpenAI.ImageOperationResponse ImageOperationResponse(string id = null, long created = (long)0, long? expires = default(long?), Azure.AI.OpenAI.ImageResponse result = null, Azure.AI.OpenAI.State status = default(Azure.AI.OpenAI.State), Azure.ResponseError error = null) { throw null; } + public static Azure.AI.OpenAI.ImageResponse ImageResponse(long created = (long)0, System.Collections.Generic.IEnumerable data = null) { throw null; } } public partial class ChatChoice { @@ -158,6 +161,55 @@ internal EmbeddingsUsage() { } public int PromptTokens { get { throw null; } } public int TotalTokens { get { throw null; } } } + public partial class ImageGenerationOptions + { + public ImageGenerationOptions(string prompt) { } + public int? N { get { throw null; } set { } } + public string Prompt { get { throw null; } } + public Azure.AI.OpenAI.ImageSize? Size { get { throw null; } set { } } + public string User { get { throw null; } set { } } + } + public partial class ImageLocation + { + internal ImageLocation() { } + public Azure.ResponseError Error { get { throw null; } } + public System.Uri Url { get { throw null; } } + } + public partial class ImageOperationResponse + { + internal ImageOperationResponse() { } + public long Created { get { throw null; } } + public Azure.ResponseError Error { get { throw null; } } + public long? Expires { get { throw null; } } + public string Id { get { throw null; } } + public Azure.AI.OpenAI.ImageResponse Result { get { throw null; } } + public Azure.AI.OpenAI.State Status { get { throw null; } } + } + public partial class ImageResponse + { + internal ImageResponse() { } + public long Created { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Data { get { throw null; } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct ImageSize : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ImageSize(string value) { throw null; } + public static Azure.AI.OpenAI.ImageSize Size1024x1024 { get { throw null; } } + public static Azure.AI.OpenAI.ImageSize Size256x256 { get { throw null; } } + public static Azure.AI.OpenAI.ImageSize Size512x512 { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.ImageSize other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.ImageSize left, Azure.AI.OpenAI.ImageSize right) { throw null; } + public static implicit operator Azure.AI.OpenAI.ImageSize (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.ImageSize left, Azure.AI.OpenAI.ImageSize right) { throw null; } + public override string ToString() { throw null; } + } public partial class OpenAIClient { protected OpenAIClient() { } @@ -180,16 +232,43 @@ public OpenAIClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredent public virtual System.Threading.Tasks.Task> GetCompletionsStreamingAsync(string deploymentOrModelName, Azure.AI.OpenAI.CompletionsOptions completionsOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetEmbeddings(string deploymentOrModelName, Azure.AI.OpenAI.EmbeddingsOptions embeddingsOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetEmbeddingsAsync(string deploymentOrModelName, Azure.AI.OpenAI.EmbeddingsOptions embeddingsOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation StartGenerateImage(Azure.WaitUntil waitUntil, Azure.AI.OpenAI.ImageGenerationOptions imageGenerationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Operation StartGenerateImage(Azure.WaitUntil waitUntil, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } + public virtual System.Threading.Tasks.Task> StartGenerateImageAsync(Azure.WaitUntil waitUntil, Azure.AI.OpenAI.ImageGenerationOptions imageGenerationOptions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> StartGenerateImageAsync(Azure.WaitUntil waitUntil, Azure.Core.RequestContent content, Azure.RequestContext context = null) { throw null; } } public partial class OpenAIClientOptions : Azure.Core.ClientOptions { - public OpenAIClientOptions(Azure.AI.OpenAI.OpenAIClientOptions.ServiceVersion version = Azure.AI.OpenAI.OpenAIClientOptions.ServiceVersion.V2023_03_15_Preview) { } + public OpenAIClientOptions(Azure.AI.OpenAI.OpenAIClientOptions.ServiceVersion version = Azure.AI.OpenAI.OpenAIClientOptions.ServiceVersion.V2023_06_01_Preview) { } public enum ServiceVersion { V2022_12_01 = 1, - V2023_03_15_Preview = 2, + V2023_05_15 = 2, + V2023_06_01_Preview = 3, } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct State : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public State(string value) { throw null; } + public static Azure.AI.OpenAI.State Canceled { get { throw null; } } + public static Azure.AI.OpenAI.State Deleted { get { throw null; } } + public static Azure.AI.OpenAI.State Failed { get { throw null; } } + public static Azure.AI.OpenAI.State NotRunning { get { throw null; } } + public static Azure.AI.OpenAI.State Running { get { throw null; } } + public static Azure.AI.OpenAI.State Succeeded { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.State other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.AI.OpenAI.State left, Azure.AI.OpenAI.State right) { throw null; } + public static implicit operator Azure.AI.OpenAI.State (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.State left, Azure.AI.OpenAI.State right) { throw null; } + public override string ToString() { throw null; } + } public partial class StreamingChatChoice { internal StreamingChatChoice() { } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs index 1271d67b8a165..933d2f9bdcddf 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Azure; namespace Azure.AI.OpenAI { @@ -73,5 +74,38 @@ public static CompletionsUsage CompletionsUsage(int completionTokens = default, { return new CompletionsUsage(completionTokens, promptTokens, totalTokens); } + + /// Initializes a new instance of ImageOperationResponse. + /// The ID of the operation. + /// A timestamp when this job or item was created (in unix epochs). + /// A timestamp when this operation and its associated images expire and will be deleted (in unix epochs). + /// The result of the operation if the operation succeeded. + /// The status of the operation. + /// The error if the operation failed. + /// A new instance for mocking. + public static ImageOperationResponse ImageOperationResponse(string id = null, long created = default, long? expires = null, ImageResponse result = null, State status = default, ResponseError error = null) + { + return new ImageOperationResponse(id, created, expires, result, status, error); + } + + /// Initializes a new instance of ImageResponse. + /// 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 ImageResponse ImageResponse(long created = default, IEnumerable data = null) + { + data ??= new List(); + + return new ImageResponse(created, data?.ToList()); + } + + /// Initializes a new instance of ImageLocation. + /// The URL that provides temporary access to download the generated image. + /// The error if the operation failed. + /// A new instance for mocking. + public static ImageLocation ImageLocation(Uri url = null, ResponseError error = null) + { + return new ImageLocation(url, error); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml b/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml index a98717f007b73..842a2cf3b0af7 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml @@ -167,5 +167,137 @@ var result = client.GetChatCompletions("", chatCompletionsOptions) + + +This sample shows how to call StartGenerateImageAsync with required parameters. +"); + +var imageGenerationOptions = new ImageGenerationOptions("") +{ + N = 1234, + Size = ImageSize.Size256x256, + User = "", +}; +var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, imageGenerationOptions); +]]> + + + + +This sample shows how to call StartGenerateImage with required parameters. +"); + +var imageGenerationOptions = new ImageGenerationOptions("") +{ + N = 1234, + Size = ImageSize.Size256x256, + User = "", +}; +var operation = client.StartGenerateImage(WaitUntil.Completed, imageGenerationOptions); +]]> + + + + +This sample shows how to call StartGenerateImageAsync with required parameters and request content, and how to parse the result. +"); + +var data = new { + prompt = "", +}; + +var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call StartGenerateImageAsync with all parameters and request content, and how to parse the result. +"); + +var data = new { + prompt = "", + n = 1234, + size = "256x256", + user = "", +}; + +var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("expires").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("url").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +]]> + + + + +This sample shows how to call StartGenerateImage with required parameters and request content, and how to parse the result. +"); + +var data = new { + prompt = "", +}; + +var operation = client.StartGenerateImage(WaitUntil.Completed, RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call StartGenerateImage with all parameters and request content, and how to parse the result. +"); + +var data = new { + prompt = "", + n = 1234, + size = "256x256", + user = "", +}; + +var operation = client.StartGenerateImage(WaitUntil.Completed, RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("expires").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("created").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("url").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +]]> + + \ No newline at end of file diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs new file mode 100644 index 0000000000000..775804bae5c69 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + public partial class ImageGenerationOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("prompt"u8); + writer.WriteStringValue(Prompt); + if (Optional.IsDefined(N)) + { + writer.WritePropertyName("n"u8); + writer.WriteNumberValue(N.Value); + } + if (Optional.IsDefined(Size)) + { + writer.WritePropertyName("size"u8); + writer.WriteStringValue(Size.Value.ToString()); + } + if (Optional.IsDefined(User)) + { + writer.WritePropertyName("user"u8); + writer.WriteStringValue(User); + } + writer.WriteEndObject(); + } + + /// 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/ImageGenerationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs new file mode 100644 index 0000000000000..ce843e3ed65ac --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// Represents the request data used to generate images. + public partial class ImageGenerationOptions + { + /// Initializes a new instance of ImageGenerationOptions. + /// A description of the desired images. + /// is null. + public ImageGenerationOptions(string prompt) + { + Argument.AssertNotNull(prompt, nameof(prompt)); + + Prompt = prompt; + } + + /// Initializes a new instance of ImageGenerationOptions. + /// A description of the desired images. + /// The number of images to generate (defaults to 1). + /// The desired size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 (defaults to 1024x1024). + /// A unique identifier representing your end-user, which can help to monitor and detect abuse. + internal ImageGenerationOptions(string prompt, int? n, ImageSize? size, string user) + { + Prompt = prompt; + N = n; + Size = size; + User = user; + } + + /// A description of the desired images. + public string Prompt { get; } + /// The number of images to generate (defaults to 1). + public int? N { get; set; } + /// The desired size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 (defaults to 1024x1024). + public ImageSize? Size { get; set; } + /// A unique identifier representing your end-user, which can help to monitor and detect abuse. + public string User { 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 new file mode 100644 index 0000000000000..74a64abb87666 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + public partial class ImageLocation + { + internal static ImageLocation DeserializeImageLocation(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional url = default; + Optional error = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("url"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + url = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + } + return new ImageLocation(url.Value, error.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ImageLocation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeImageLocation(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs new file mode 100644 index 0000000000000..9004f0bc5ad21 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageLocation.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; + +namespace Azure.AI.OpenAI +{ + /// The image url if successful, and an error otherwise. + public partial class ImageLocation + { + /// Initializes a new instance of ImageLocation. + internal ImageLocation() + { + } + + /// Initializes a new instance of ImageLocation. + /// The URL that provides temporary access to download the generated image. + /// The error if the operation failed. + internal ImageLocation(Uri url, ResponseError error) + { + Url = url; + Error = error; + } + + /// The URL that provides temporary access to download the generated image. + public Uri Url { get; } + /// The error if the operation failed. + public ResponseError Error { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.Serialization.cs new file mode 100644 index 0000000000000..6baa0e24dde72 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.Serialization.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + public partial class ImageOperationResponse + { + internal static ImageOperationResponse DeserializeImageOperationResponse(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + long created = default; + Optional expires = default; + Optional result = default; + State status = default; + Optional error = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("created"u8)) + { + created = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("expires"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + expires = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("result"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result = ImageResponse.DeserializeImageResponse(property.Value); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new State(property.Value.GetString()); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + } + return new ImageOperationResponse(id, created, Optional.ToNullable(expires), result.Value, status, error.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ImageOperationResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeImageOperationResponse(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.cs new file mode 100644 index 0000000000000..dcde89dfe8874 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageOperationResponse.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// The result of the operation if the operation succeeded. + public partial class ImageOperationResponse + { + /// Initializes a new instance of ImageOperationResponse. + /// The ID of the operation. + /// A timestamp when this job or item was created (in unix epochs). + /// The status of the operation. + /// is null. + internal ImageOperationResponse(string id, long created, State status) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Created = created; + Status = status; + } + + /// Initializes a new instance of ImageOperationResponse. + /// The ID of the operation. + /// A timestamp when this job or item was created (in unix epochs). + /// A timestamp when this operation and its associated images expire and will be deleted (in unix epochs). + /// The result of the operation if the operation succeeded. + /// The status of the operation. + /// The error if the operation failed. + internal ImageOperationResponse(string id, long created, long? expires, ImageResponse result, State status, ResponseError error) + { + Id = id; + Created = created; + Expires = expires; + Result = result; + Status = status; + Error = error; + } + + /// The ID of the operation. + public string Id { get; } + /// A timestamp when this job or item was created (in unix epochs). + public long Created { get; } + /// A timestamp when this operation and its associated images expire and will be deleted (in unix epochs). + public long? Expires { get; } + /// The result of the operation if the operation succeeded. + public ImageResponse Result { get; } + /// The status of the operation. + public State Status { get; } + /// The error if the operation failed. + public ResponseError Error { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.Serialization.cs new file mode 100644 index 0000000000000..e81de4f042307 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.Serialization.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + public partial class ImageResponse + { + internal static ImageResponse DeserializeImageResponse(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + long created = default; + IReadOnlyList data = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("created"u8)) + { + created = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ImageLocation.DeserializeImageLocation(item)); + } + data = array; + continue; + } + } + return new ImageResponse(created, data); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ImageResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeImageResponse(document.RootElement); + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.cs new file mode 100644 index 0000000000000..f94d7bd6ed395 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageResponse.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// The result of the operation if the operation succeeded. + public partial class ImageResponse + { + /// Initializes a new instance of ImageResponse. + /// A timestamp when this job or item was created (in unix epochs). + /// The images generated by the operator. + /// is null. + internal ImageResponse(long created, IEnumerable data) + { + Argument.AssertNotNull(data, nameof(data)); + + Created = created; + Data = data.ToList(); + } + + /// Initializes a new instance of ImageResponse. + /// A timestamp when this job or item was created (in unix epochs). + /// The images generated by the operator. + internal ImageResponse(long created, IReadOnlyList data) + { + Created = created; + Data = data; + } + + /// A timestamp when this job or item was created (in unix epochs). + public long Created { get; } + /// The images generated by the operator. + public IReadOnlyList Data { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageSize.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageSize.cs new file mode 100644 index 0000000000000..f31735bb95970 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageSize.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI +{ + /// The desired size of the generated images. Must be one of 256x256, 512x512, or 1024x1024. + public readonly partial struct ImageSize : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ImageSize(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Size256x256Value = "256x256"; + private const string Size512x512Value = "512x512"; + private const string Size1024x1024Value = "1024x1024"; + + /// Image size of 256x256. + public static ImageSize Size256x256 { get; } = new ImageSize(Size256x256Value); + /// Image size of 512x512. + public static ImageSize Size512x512 { get; } = new ImageSize(Size512x512Value); + /// Image size of 1024x1024. + public static ImageSize Size1024x1024 { get; } = new ImageSize(Size1024x1024Value); + /// Determines if two values are the same. + public static bool operator ==(ImageSize left, ImageSize right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ImageSize left, ImageSize right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator ImageSize(string value) => new ImageSize(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ImageSize other && Equals(other); + /// + public bool Equals(ImageSize other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClient.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClient.cs index 075a6ef2d8dae..113d0dcbef011 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClient.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClient.cs @@ -37,6 +37,133 @@ protected OpenAIClient() { } + /// Starts the generation of a batch of images from a text caption. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Represents the request data used to generate images. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task> StartGenerateImageAsync(WaitUntil waitUntil, ImageGenerationOptions imageGenerationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(imageGenerationOptions, nameof(imageGenerationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = await StartGenerateImageAsync(waitUntil, imageGenerationOptions.ToRequestContent(), context).ConfigureAwait(false); + return ProtocolOperationHelpers.Convert(response, ImageOperationResponse.FromResponse, ClientDiagnostics, "OpenAIClient.StartGenerateImage"); + } + + /// Starts the generation of a batch of images from a text caption. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Represents the request data used to generate images. + /// The cancellation token to use. + /// is null. + /// + public virtual Operation StartGenerateImage(WaitUntil waitUntil, ImageGenerationOptions imageGenerationOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(imageGenerationOptions, nameof(imageGenerationOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = StartGenerateImage(waitUntil, imageGenerationOptions.ToRequestContent(), context); + return ProtocolOperationHelpers.Convert(response, ImageOperationResponse.FromResponse, ClientDiagnostics, "OpenAIClient.StartGenerateImage"); + } + + /// + /// [Protocol Method] Starts the generation of a batch of images from a text caption + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual async Task> StartGenerateImageAsync(WaitUntil waitUntil, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("OpenAIClient.StartGenerateImage"); + scope.Start(); + try + { + using HttpMessage message = CreateStartGenerateImageRequest(content, context); + return await ProtocolOperationHelpers.ProcessMessageAsync(_pipeline, message, ClientDiagnostics, "OpenAIClient.StartGenerateImage", OperationFinalStateVia.Location, context, waitUntil).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Starts the generation of a batch of images from a text caption + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual Operation StartGenerateImage(WaitUntil waitUntil, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("OpenAIClient.StartGenerateImage"); + scope.Start(); + try + { + using HttpMessage message = CreateStartGenerateImageRequest(content, context); + return ProtocolOperationHelpers.ProcessMessage(_pipeline, message, ClientDiagnostics, "OpenAIClient.StartGenerateImage", OperationFinalStateVia.Location, context, waitUntil); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateStartGenerateImageRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier202); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendRaw("/openai", false); + uri.AppendPath("/images/generations:submit", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { @@ -50,5 +177,7 @@ internal static RequestContext FromCancellationToken(CancellationToken cancellat private static ResponseClassifier _responseClassifier200; private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + private static ResponseClassifier _responseClassifier202; + private static ResponseClassifier ResponseClassifier202 => _responseClassifier202 ??= new StatusCodeClassifier(stackalloc ushort[] { 202 }); } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs index 738e64701d54e..451fe6345eac6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs @@ -13,15 +13,17 @@ namespace Azure.AI.OpenAI /// Client options for OpenAIClient. public partial class OpenAIClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V2023_03_15_Preview; + private const ServiceVersion LatestVersion = ServiceVersion.V2023_06_01_Preview; /// The version of the service to use. public enum ServiceVersion { /// Service version "2022-12-01". V2022_12_01 = 1, - /// Service version "2023-03-15-preview". - V2023_03_15_Preview = 2, + /// Service version "2023-05-15". + V2023_05_15 = 2, + /// Service version "2023-06-01-preview". + V2023_06_01_Preview = 3, } internal string Version { get; } @@ -32,7 +34,8 @@ public OpenAIClientOptions(ServiceVersion version = LatestVersion) Version = version switch { ServiceVersion.V2022_12_01 => "2022-12-01", - ServiceVersion.V2023_03_15_Preview => "2023-03-15-preview", + ServiceVersion.V2023_05_15 => "2023-05-15", + ServiceVersion.V2023_06_01_Preview => "2023-06-01-preview", _ => throw new NotSupportedException() }; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/State.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/State.cs new file mode 100644 index 0000000000000..0ec2cd983d2a4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/State.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI +{ + /// The state of a job or item. + public readonly partial struct State : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public State(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string NotRunningValue = "notRunning"; + private const string RunningValue = "running"; + private const string SucceededValue = "succeeded"; + private const string CanceledValue = "canceled"; + private const string FailedValue = "failed"; + private const string DeletedValue = "deleted"; + + /// The operation was created and is queued to be processed in the future. + public static State NotRunning { get; } = new State(NotRunningValue); + /// The operation has started to be processed. + public static State Running { get; } = new State(RunningValue); + /// The operation has successfully be processed and is ready for consumption. + public static State Succeeded { get; } = new State(SucceededValue); + /// The operation has been canceled and is incomplete. + public static State Canceled { get; } = new State(CanceledValue); + /// The operation has completed processing with a failure and cannot be further consumed. + public static State Failed { get; } = new State(FailedValue); + /// The entity has been deleted but may still be referenced by other entities predating the deletion. + public static State Deleted { get; } = new State(DeletedValue); + /// Determines if two values are the same. + public static bool operator ==(State left, State right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(State left, State right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator State(string value) => new State(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is State other && Equals(other); + /// + public bool Equals(State other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/tests/Generated/Samples/Samples_OpenAIClient.cs b/sdk/openai/Azure.AI.OpenAI/tests/Generated/Samples/Samples_OpenAIClient.cs index 89bf7a0e369d5..120e3034bf966 100644 --- a/sdk/openai/Azure.AI.OpenAI/tests/Generated/Samples/Samples_OpenAIClient.cs +++ b/sdk/openai/Azure.AI.OpenAI/tests/Generated/Samples/Samples_OpenAIClient.cs @@ -92,5 +92,128 @@ public async Task Example_GetChatCompletions_Convenience_Async() }; var result = await client.GetChatCompletionsAsync("", chatCompletionsOptions); } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_StartGenerateImage() + { + var client = new OpenAIClient(""); + + var data = new + { + prompt = "", + }; + + var operation = client.StartGenerateImage(WaitUntil.Completed, RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_StartGenerateImage_AllParameters() + { + var client = new OpenAIClient(""); + + var data = new + { + prompt = "", + n = 1234, + size = "256x256", + user = "", + }; + + var operation = client.StartGenerateImage(WaitUntil.Completed, RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("expires").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("url").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_StartGenerateImage_Async() + { + var client = new OpenAIClient(""); + + var data = new + { + prompt = "", + }; + + var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_StartGenerateImage_AllParameters_Async() + { + var client = new OpenAIClient(""); + + var data = new + { + prompt = "", + n = 1234, + size = "256x256", + user = "", + }; + + var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("expires").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("created").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("url").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("data")[0].GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_StartGenerateImage_Convenience_Async() + { + var client = new OpenAIClient(""); + + var imageGenerationOptions = new ImageGenerationOptions("") + { + N = 1234, + Size = ImageSize.Size256x256, + User = "", + }; + var operation = await client.StartGenerateImageAsync(WaitUntil.Completed, imageGenerationOptions); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml index 92ca017d7149f..05296c06b9cfe 100644 --- a/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml @@ -1,3 +1,5 @@ +additionalDirectories: [] directory: specification/cognitiveservices/OpenAI.Inference -commit: 6af0ff9b1a10e4d498699eab53cc1e6b797bda8c +commit: a44ca17a21f018983700776fccd3e001f24dd3c8 repo: Azure/azure-rest-api-specs +