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..81e613ca20047 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 @@ -30,6 +30,8 @@ public ChatCompletionsOptions() { } public ChatCompletionsOptions(System.Collections.Generic.IEnumerable messages) { } public int? ChoiceCount { get { throw null; } set { } } public float? FrequencyPenalty { get { throw null; } set { } } + public Azure.AI.OpenAI.FunctionCallPreset? FunctionCall { get { throw null; } set { } } + public System.Collections.Generic.IList Functions { get { throw null; } } public int? MaxTokens { get { throw null; } set { } } public System.Collections.Generic.IList Messages { get { throw null; } } public float? NucleusSamplingFactor { get { throw null; } set { } } @@ -44,6 +46,8 @@ public partial class ChatMessage public ChatMessage(Azure.AI.OpenAI.ChatRole role) { } public ChatMessage(Azure.AI.OpenAI.ChatRole role, string content) { } public string Content { get { throw null; } set { } } + public Azure.AI.OpenAI.FunctionCall FunctionCall { get { throw null; } set { } } + public string Name { get { throw null; } set { } } public Azure.AI.OpenAI.ChatRole Role { get { throw null; } set { } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] @@ -53,6 +57,7 @@ public ChatMessage(Azure.AI.OpenAI.ChatRole role, string content) { } private readonly int _dummyPrimitive; public ChatRole(string value) { throw null; } public static Azure.AI.OpenAI.ChatRole Assistant { get { throw null; } } + public static Azure.AI.OpenAI.ChatRole Function { get { throw null; } } public static Azure.AI.OpenAI.ChatRole System { get { throw null; } } public static Azure.AI.OpenAI.ChatRole User { get { throw null; } } public bool Equals(Azure.AI.OpenAI.ChatRole other) { throw null; } @@ -88,6 +93,7 @@ internal Completions() { } private readonly int _dummyPrimitive; public CompletionsFinishReason(string value) { throw null; } public static Azure.AI.OpenAI.CompletionsFinishReason ContentFiltered { get { throw null; } } + public static Azure.AI.OpenAI.CompletionsFinishReason FunctionCall { get { throw null; } } public static Azure.AI.OpenAI.CompletionsFinishReason Stopped { get { throw null; } } public static Azure.AI.OpenAI.CompletionsFinishReason TokenLimitReached { get { throw null; } } public bool Equals(Azure.AI.OpenAI.CompletionsFinishReason other) { throw null; } @@ -158,6 +164,37 @@ internal EmbeddingsUsage() { } public int PromptTokens { get { throw null; } } public int TotalTokens { get { throw null; } } } + public partial class FunctionCall + { + public FunctionCall(string name, string arguments) { } + public string Arguments { get { throw null; } set { } } + public string Name { get { throw null; } set { } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct FunctionCallPreset : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public FunctionCallPreset(string value) { throw null; } + public static Azure.AI.OpenAI.FunctionCallPreset Auto { get { throw null; } } + public static Azure.AI.OpenAI.FunctionCallPreset None { get { throw null; } } + public bool Equals(Azure.AI.OpenAI.FunctionCallPreset 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.FunctionCallPreset left, Azure.AI.OpenAI.FunctionCallPreset right) { throw null; } + public static implicit operator Azure.AI.OpenAI.FunctionCallPreset (string value) { throw null; } + public static bool operator !=(Azure.AI.OpenAI.FunctionCallPreset left, Azure.AI.OpenAI.FunctionCallPreset right) { throw null; } + public override string ToString() { throw null; } + } + public partial class FunctionDefinition + { + public FunctionDefinition(string name) { } + public string Description { get { throw null; } set { } } + public string Name { get { throw null; } } + public System.BinaryData Parameters { get { throw null; } set { } } + } public partial class OpenAIClient { protected OpenAIClient() { } @@ -183,11 +220,13 @@ public OpenAIClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredent } 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_07_01_Preview) { } public enum ServiceVersion { V2022_12_01 = 1, - V2023_03_15_Preview = 2, + V2023_05_15 = 2, + V2023_06_01_Preview = 3, + V2023_07_01_Preview = 4, } } public partial class 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..ad5be4e17de13 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 { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs index 9ee651254c6d1..48e4d97902f6c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs @@ -27,6 +27,13 @@ public partial class ChatCompletionsOptions /// the behavior of the assistant, followed by alternating messages between the User and /// Assistant roles. /// + /// A list of functions the model may generate JSON inputs for. + /// + /// Controls how the model responds to function calls. "none" means the model does not call a function, + /// and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. + /// Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. + /// "none" is the default when no functions are present. "auto" is the default if functions are present. + /// /// The maximum number of tokens to generate. /// /// The sampling temperature to use that controls the apparent creativity of generated completions. @@ -79,9 +86,11 @@ public partial class ChatCompletionsOptions /// Not applicable to Azure OpenAI, where deployment information should be included in the Azure /// resource URI that's connected to. /// - internal ChatCompletionsOptions(IList messages, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary internalStringKeyedTokenSelectionBiases, string user, int? choiceCount, IList stopSequences, float? presencePenalty, float? frequencyPenalty, bool? internalShouldStreamResponse, string internalNonAzureModelName) + internal ChatCompletionsOptions(IList messages, IList functions, FunctionCallPreset? functionCall, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary internalStringKeyedTokenSelectionBiases, string user, int? choiceCount, IList stopSequences, float? presencePenalty, float? frequencyPenalty, bool? internalShouldStreamResponse, string internalNonAzureModelName) { Messages = messages; + Functions = functions; + FunctionCall = functionCall; MaxTokens = maxTokens; Temperature = temperature; NucleusSamplingFactor = nucleusSamplingFactor; @@ -102,5 +111,14 @@ internal ChatCompletionsOptions(IList messages, int? maxTokens, flo /// Assistant roles. /// public IList Messages { get; } + /// A list of functions the model may generate JSON inputs for. + public IList Functions { get; } + /// + /// Controls how the model responds to function calls. "none" means the model does not call a function, + /// and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. + /// Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. + /// "none" is the default when no functions are present. "auto" is the default if functions are present. + /// + public FunctionCallPreset? FunctionCall { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.Serialization.cs index 5d5a5b2aa3592..6248864eacbc6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.Serialization.cs @@ -23,6 +23,16 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("content"u8); writer.WriteStringValue(Content); } + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(FunctionCall)) + { + writer.WritePropertyName("function_call"u8); + writer.WriteObjectValue(FunctionCall); + } writer.WriteEndObject(); } @@ -34,6 +44,8 @@ internal static ChatMessage DeserializeChatMessage(JsonElement element) } ChatRole role = default; Optional content = default; + Optional name = default; + Optional functionCall = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("role"u8)) @@ -46,8 +58,22 @@ internal static ChatMessage DeserializeChatMessage(JsonElement element) content = property.Value.GetString(); continue; } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("function_call"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + functionCall = FunctionCall.DeserializeFunctionCall(property.Value); + continue; + } } - return new ChatMessage(role, content.Value); + return new ChatMessage(role, content.Value, name.Value, functionCall.Value); } /// Deserializes the model from a raw response. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.cs index e15a2eb083614..858e117931524 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessage.cs @@ -17,9 +17,34 @@ public ChatMessage(ChatRole role) Role = role; } + /// Initializes a new instance of ChatMessage. + /// The role associated with this message payload. + /// The text associated with this message payload. + /// + /// The name of the author of this message. `name` is required if role is `function`, and it should be the name of the + /// function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of + /// 64 characters. + /// + /// The name and arguments of a function that should be called, as generated by the model. + internal ChatMessage(ChatRole role, string content, string name, FunctionCall functionCall) + { + Role = role; + Content = content; + Name = name; + FunctionCall = functionCall; + } + /// The role associated with this message payload. public ChatRole Role { get; set; } /// The text associated with this message payload. public string Content { get; set; } + /// + /// The name of the author of this message. `name` is required if role is `function`, and it should be the name of the + /// function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of + /// 64 characters. + /// + public string Name { get; set; } + /// The name and arguments of a function that should be called, as generated by the model. + public FunctionCall FunctionCall { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRole.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRole.cs index 9c4c08bfe6d5a..479889b3f4ed1 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRole.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRole.cs @@ -25,6 +25,7 @@ public ChatRole(string value) private const string SystemValue = "system"; private const string AssistantValue = "assistant"; private const string UserValue = "user"; + private const string FunctionValue = "function"; /// The role that instructs or sets the behavior of the assistant. public static ChatRole System { get; } = new ChatRole(SystemValue); @@ -32,6 +33,8 @@ public ChatRole(string value) public static ChatRole Assistant { get; } = new ChatRole(AssistantValue); /// The role that provides input for chat completions. public static ChatRole User { get; } = new ChatRole(UserValue); + /// The role that provides function results for char completions. + public static ChatRole Function { get; } = new ChatRole(FunctionValue); /// Determines if two values are the same. public static bool operator ==(ChatRole left, ChatRole right) => left.Equals(right); /// Determines if two values are not the same. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsFinishReason.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsFinishReason.cs index 1bd3d0f5f847c..dc427b9585277 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsFinishReason.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsFinishReason.cs @@ -14,6 +14,7 @@ namespace Azure.AI.OpenAI public readonly partial struct CompletionsFinishReason : IEquatable { private readonly string _value; + private const string FunctionCallValue = "function_call"; /// Completions ended normally and reached its end of token generation. public static CompletionsFinishReason Stopped { get; } = new CompletionsFinishReason(StoppedValue); @@ -24,6 +25,8 @@ namespace Azure.AI.OpenAI /// moderation policies. /// public static CompletionsFinishReason ContentFiltered { get; } = new CompletionsFinishReason(ContentFilteredValue); + /// Completion ended normally, with the model requesting a function to be called. + public static CompletionsFinishReason FunctionCall { get; } = new CompletionsFinishReason(FunctionCallValue); /// Determines if two values are the same. public static bool operator ==(CompletionsFinishReason left, CompletionsFinishReason right) => left.Equals(right); /// Determines if two values are not the same. 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..390303c10f53c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Docs/OpenAIClient.xml @@ -114,9 +114,20 @@ var chatCompletionsOptions = new ChatCompletionsOptions(new ChatMessage[] new ChatMessage(ChatRole.System) { Content = "", + Name = "", + FunctionCall = new FunctionCall("", ""), } }) { + Functions = +{ + new FunctionDefinition("") +{ + Description = "", + Parameters = BinaryData.FromString(""), + } + }, + FunctionCall = FunctionCallPreset.Auto, MaxTokens = 1234, Temperature = 3.14f, NucleusSamplingFactor = 3.14f, @@ -144,9 +155,20 @@ var chatCompletionsOptions = new ChatCompletionsOptions(new ChatMessage[] new ChatMessage(ChatRole.System) { Content = "", + Name = "", + FunctionCall = new FunctionCall("", ""), } }) { + Functions = +{ + new FunctionDefinition("") +{ + Description = "", + Parameters = BinaryData.FromString(""), + } + }, + FunctionCall = FunctionCallPreset.Auto, MaxTokens = 1234, Temperature = 3.14f, NucleusSamplingFactor = 3.14f, @@ -167,5 +189,13 @@ var result = client.GetChatCompletions("", chatCompletionsOptions) + + + + + + + + \ No newline at end of file diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs new file mode 100644 index 0000000000000..66e19e41a66da --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs @@ -0,0 +1,66 @@ +// 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 FunctionCall : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + writer.WriteEndObject(); + } + + internal static FunctionCall DeserializeFunctionCall(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string arguments = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + } + return new FunctionCall(name, arguments); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FunctionCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFunctionCall(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/FunctionCall.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs new file mode 100644 index 0000000000000..1cdb28a6107cd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// The name and arguments of a function that should be called, as generated by the model. + public partial class FunctionCall + { + /// Initializes a new instance of FunctionCall. + /// The name of the function to call. + /// + /// The arguments to call the function with, as generated by the model in JSON format. + /// Note that the model does not always generate valid JSON, and may hallucinate parameters + /// not defined by your function schema. Validate the arguments in your code before calling + /// your function. + /// + /// or is null. + public FunctionCall(string name, string arguments) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(arguments, nameof(arguments)); + + Name = name; + Arguments = arguments; + } + + /// The name of the function to call. + public string Name { get; set; } + /// + /// The arguments to call the function with, as generated by the model in JSON format. + /// Note that the model does not always generate valid JSON, and may hallucinate parameters + /// not defined by your function schema. Validate the arguments in your code before calling + /// your function. + /// + public string Arguments { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCallPreset.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCallPreset.cs new file mode 100644 index 0000000000000..06ce683555b76 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCallPreset.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI +{ + /// Preset values to control how the mode; responds to function calls. + public readonly partial struct FunctionCallPreset : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public FunctionCallPreset(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + private const string NoneValue = "none"; + + /// Means the model can pick between an end-user or calling a function. + public static FunctionCallPreset Auto { get; } = new FunctionCallPreset(AutoValue); + /// Means the model does not call a function, and responds to the end-user. + public static FunctionCallPreset None { get; } = new FunctionCallPreset(NoneValue); + /// Determines if two values are the same. + public static bool operator ==(FunctionCallPreset left, FunctionCallPreset right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(FunctionCallPreset left, FunctionCallPreset right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator FunctionCallPreset(string value) => new FunctionCallPreset(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is FunctionCallPreset other && Equals(other); + /// + public bool Equals(FunctionCallPreset 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/FunctionDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs new file mode 100644 index 0000000000000..aa5f68a4499a4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs @@ -0,0 +1,45 @@ +// 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 FunctionDefinition : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (Optional.IsDefined(Parameters)) + { + writer.WritePropertyName("parameters"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Parameters); +#else + JsonSerializer.Serialize(writer, JsonDocument.Parse(Parameters.ToString()).RootElement); +#endif + } + 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/FunctionDefinition.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs new file mode 100644 index 0000000000000..366067c7bc747 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// + /// The definition of a function that can be called by the model. + /// See the [guide](/docs/guides/gpt/function-calling) for examples. + /// + public partial class FunctionDefinition + { + /// Initializes a new instance of FunctionDefinition. + /// + /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, + /// with a maximum length of 64. + /// + /// is null. + public FunctionDefinition(string name) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + } + + /// Initializes a new instance of FunctionDefinition. + /// + /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, + /// with a maximum length of 64. + /// + /// The description of what the function does. + /// + /// The parameters the functions accepts, described as a JSON Schema object. + /// See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) + /// for documentation about the format. + /// + internal FunctionDefinition(string name, string description, BinaryData parameters) + { + Name = name; + Description = description; + Parameters = parameters; + } + + /// + /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, + /// with a maximum length of 64. + /// + public string Name { get; } + /// The description of what the function does. + public string Description { get; set; } + /// + /// The parameters the functions accepts, described as a JSON Schema object. + /// See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) + /// for documentation about the format. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formated json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData Parameters { get; set; } + } +} 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..e3530d932b5e0 --- /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 +{ + internal 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..0bfc37ca7e4a4 --- /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. + internal 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..d60cfbdaa464b --- /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 +{ + internal 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..38359cdd6a312 --- /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. + internal 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..f2b83ec8afddd --- /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 +{ + internal 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..911546929bc48 --- /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. + internal 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..1e754595a2462 --- /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 +{ + internal 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..f7382868075ee --- /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. + internal 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..22bded6ea1ab1 --- /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. + internal 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..ff978483df242 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. + /// + internal 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. + /// + internal 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. + /// + internal 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. + /// + internal 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..95066fd3239c0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OpenAIClientOptions.cs @@ -13,15 +13,19 @@ 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_07_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, + /// Service version "2023-07-01-preview". + V2023_07_01_Preview = 4, } internal string Version { get; } @@ -32,7 +36,9 @@ 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", + ServiceVersion.V2023_07_01_Preview => "2023-07-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..5442cede85c73 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/State.cs @@ -0,0 +1,60 @@ +// 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. + internal 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"; + + /// 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); + /// 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..ededd85b18574 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 @@ -75,9 +75,20 @@ public async Task Example_GetChatCompletions_Convenience_Async() new ChatMessage(ChatRole.System) { Content = "", + Name = "", + FunctionCall = new FunctionCall("", ""), } }) { + Functions = +{ + new FunctionDefinition("") +{ + Description = "", + Parameters = BinaryData.FromString(""), + } + }, + FunctionCall = FunctionCallPreset.Auto, MaxTokens = 1234, Temperature = 3.14f, NucleusSamplingFactor = 3.14f, diff --git a/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI/tsp-location.yaml index 92ca017d7149f..ac5346888b812 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: 6af0ff9b1a10e4d498699eab53cc1e6b797bda8c +commit: 05b053a00adae0d411444171609b6b3ddeb5dfec +additionalDirectories: [] repo: Azure/azure-rest-api-specs +directory: specification/cognitiveservices/OpenAI.Inference +