From f66fed733508e403320ec624a82658c38f10f783 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Wed, 23 Oct 2024 23:16:42 +0000 Subject: [PATCH] CodeGen from PR 29763 in Azure/azure-rest-api-specs Merge aa97e50e44d2c620c92e5a4c791bb387a741d64c into 7507aafa42d29e3526d8e5aacf6233c0e9a959d0 --- .../AIInferenceClientBuilderExtensions.cs | 41 +- .../src/Generated/AIInferenceModelFactory.cs | 93 ++++- ...ns.cs => AzureAIInferenceClientOptions.cs} | 8 +- .../src/Generated/ChatCompletionsClient.cs | 20 +- .../ChatCompletionsFunctionToolCall.cs | 47 --- .../ChatCompletionsFunctionToolDefinition.cs | 39 -- ...amedFunctionToolSelection.Serialization.cs | 143 ------- ...atCompletionsNamedFunctionToolSelection.cs | 44 -- ...mpletionsNamedToolChoice.Serialization.cs} | 60 +-- .../ChatCompletionsNamedToolChoice.cs | 80 ++++ ...sNamedToolChoiceFunction.Serialization.cs} | 42 +- ...ChatCompletionsNamedToolChoiceFunction.cs} | 14 +- .../ChatCompletionsNamedToolChoiceType.cs | 48 +++ ...letionsNamedToolSelection.Serialization.cs | 126 ------ .../src/Generated/ChatCompletionsOptions.cs | 10 +- .../ChatCompletionsToolCall.Serialization.cs | 37 +- .../src/Generated/ChatCompletionsToolCall.cs | 33 +- .../Generated/ChatCompletionsToolCallType.cs | 48 +++ ....cs => ChatCompletionsToolChoicePreset.cs} | 28 +- ...CompletionsToolDefinition.Serialization.cs | 29 +- .../ChatCompletionsToolDefinition.cs | 35 +- .../ChatCompletionsToolDefinitionType.cs | 48 +++ .../Generated/ChatRequestAssistantMessage.cs | 4 - .../src/Generated/ChatResponseMessage.cs | 4 - .../src/Generated/Docs/EmbeddingsClient.xml | 217 ++++++++++ ...ation.cs => EmbedRequest.Serialization.cs} | 56 +-- ...sNamedToolSelection.cs => EmbedRequest.cs} | 36 +- .../src/Generated/EmbeddingEncodingFormat.cs | 66 +++ .../src/Generated/EmbeddingInputType.cs | 54 +++ ...tion.cs => EmbeddingItem.Serialization.cs} | 73 ++-- .../src/Generated/EmbeddingItem.cs | 128 ++++++ .../src/Generated/EmbeddingsClient.cs | 383 ++++++++++++++++++ .../EmbeddingsOptions.Serialization.cs | 201 +++++++++ .../src/Generated/EmbeddingsOptions.cs | 118 ++++++ .../EmbeddingsResult.Serialization.cs | 169 ++++++++ .../src/Generated/EmbeddingsResult.cs | 101 +++++ ...on.cs => EmbeddingsUsage.Serialization.cs} | 64 +-- .../src/Generated/EmbeddingsUsage.cs | 87 ++++ .../src/Generated/ModelType.cs | 16 +- ...StreamingChatChoiceUpdate.Serialization.cs | 4 +- .../Generated/StreamingChatChoiceUpdate.cs | 6 +- ...ChatResponseMessageUpdate.Serialization.cs | 178 ++++++++ .../StreamingChatResponseMessageUpdate.cs | 80 ++++ ...atResponseToolCallUpdate.Serialization.cs} | 66 ++- .../StreamingChatResponseToolCallUpdate.cs | 82 ++++ ...nknownChatCompletionsNamedToolSelection.cs | 28 -- .../UnknownChatCompletionsToolCall.cs | 29 -- .../UnknownChatCompletionsToolDefinition.cs | 28 -- .../Samples/Samples_EmbeddingsClient.cs | 255 ++++++++++++ sdk/ai/Azure.AI.Inference/tsp-location.yaml | 5 +- 50 files changed, 2817 insertions(+), 794 deletions(-) rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsClientOptions.cs => AzureAIInferenceClientOptions.cs} (70%) delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsFunctionToolDefinition.Serialization.cs => ChatCompletionsNamedToolChoice.Serialization.cs} (58%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsFunctionToolSelection.Serialization.cs => ChatCompletionsNamedToolChoiceFunction.Serialization.cs} (61%) rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsFunctionToolSelection.cs => ChatCompletionsNamedToolChoiceFunction.cs} (84%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceType.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCallType.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsToolSelectionPreset.cs => ChatCompletionsToolChoicePreset.cs} (59%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinitionType.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml rename sdk/ai/Azure.AI.Inference/src/Generated/{UnknownChatCompletionsNamedToolSelection.Serialization.cs => EmbedRequest.Serialization.cs} (53%) rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsNamedToolSelection.cs => EmbedRequest.cs} (58%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{UnknownChatCompletionsToolCall.Serialization.cs => EmbeddingItem.Serialization.cs} (54%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{UnknownChatCompletionsToolDefinition.Serialization.cs => EmbeddingsUsage.Serialization.cs} (54%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.Serialization.cs create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.cs rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsFunctionToolCall.Serialization.cs => StreamingChatResponseToolCallUpdate.Serialization.cs} (58%) create mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.cs create mode 100644 sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs index 3348bd6a13c2..5ef054431019 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs @@ -12,35 +12,62 @@ namespace Microsoft.Extensions.Azure { - /// Extension methods to add to client builder. + /// Extension methods to add , to client builder. public static partial class AIInferenceClientBuilderExtensions { /// Registers a instance. /// The builder to register with. /// Service host. /// A credential used to authenticate to an Azure Service. - public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) + public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) where TBuilder : IAzureClientFactoryBuilder { - return builder.RegisterClientFactory((options) => new ChatCompletionsClient(endpoint, credential, options)); + return builder.RegisterClientFactory((options) => new ChatCompletionsClient(endpoint, credential, options)); } /// Registers a instance. /// The builder to register with. /// Service host. - public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, Uri endpoint) + public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, Uri endpoint) where TBuilder : IAzureClientFactoryBuilderWithCredential { - return builder.RegisterClientFactory((options, cred) => new ChatCompletionsClient(endpoint, cred, options)); + return builder.RegisterClientFactory((options, cred) => new ChatCompletionsClient(endpoint, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// Service host. + /// A credential used to authenticate to an Azure Service. + public static IAzureClientBuilder AddEmbeddingsClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) + where TBuilder : IAzureClientFactoryBuilder + { + return builder.RegisterClientFactory((options) => new EmbeddingsClient(endpoint, credential, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// Service host. + public static IAzureClientBuilder AddEmbeddingsClient(this TBuilder builder, Uri endpoint) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new EmbeddingsClient(endpoint, cred, options)); } /// Registers a instance. /// The builder to register with. /// The configuration values. - public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, TConfiguration configuration) + public static IAzureClientBuilder AddChatCompletionsClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddEmbeddingsClient(this TBuilder builder, TConfiguration configuration) where TBuilder : IAzureClientFactoryBuilderWithConfiguration { - return builder.RegisterClientFactory(configuration); + return builder.RegisterClientFactory(configuration); } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs index ac2d15b79149..3452fd1a85d5 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs @@ -30,6 +30,16 @@ public static ChatMessageTextContentItem ChatMessageTextContentItem(string text return new ChatMessageTextContentItem("text", serializedAdditionalRawData: null, text); } + /// Initializes a new instance of . + /// The ID of the tool call. + /// The type of tool call. Currently, only `function` is supported. + /// The details of the function call requested by the AI model. + /// A new instance for mocking. + public static ChatCompletionsToolCall ChatCompletionsToolCall(string id = null, ChatCompletionsToolCallType type = default, FunctionCall function = null) + { + return new ChatCompletionsToolCall(id, type, function, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The content of the message. /// The ID of the tool call resolved by the provided content. @@ -39,20 +49,22 @@ public static ChatRequestToolMessage ChatRequestToolMessage(string content = nul return new ChatRequestToolMessage(ChatRole.Tool, serializedAdditionalRawData: null, content, toolCallId); } - /// Initializes a new instance of . + /// Initializes a new instance of . + /// The type of the tool. Currently, only `function` is supported. /// The function definition details for the function tool. - /// A new instance for mocking. - public static ChatCompletionsFunctionToolDefinition ChatCompletionsFunctionToolDefinition(FunctionDefinition function = null) + /// A new instance for mocking. + public static ChatCompletionsToolDefinition ChatCompletionsToolDefinition(ChatCompletionsToolDefinitionType type = default, FunctionDefinition function = null) { - return new ChatCompletionsFunctionToolDefinition("function", serializedAdditionalRawData: null, function); + return new ChatCompletionsToolDefinition(type, function, serializedAdditionalRawData: null); } - /// Initializes a new instance of . + /// Initializes a new instance of . + /// The type of the tool. Currently, only `function` is supported. /// The function that should be called. - /// A new instance for mocking. - public static ChatCompletionsNamedFunctionToolSelection ChatCompletionsNamedFunctionToolSelection(ChatCompletionsFunctionToolSelection function = null) + /// A new instance for mocking. + public static ChatCompletionsNamedToolChoice ChatCompletionsNamedToolChoice(ChatCompletionsNamedToolChoiceType type = default, ChatCompletionsNamedToolChoiceFunction function = null) { - return new ChatCompletionsNamedFunctionToolSelection("function", serializedAdditionalRawData: null, function); + return new ChatCompletionsNamedToolChoice(type, function, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -108,8 +120,6 @@ public static ChatChoice ChatChoice(int index = default, CompletionsFinishReason /// /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat /// completions request to resolve as configured. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . /// /// A new instance for mocking. public static ChatResponseMessage ChatResponseMessage(ChatRole role = default, string content = null, IEnumerable toolCalls = null) @@ -129,6 +139,43 @@ public static ModelInfo ModelInfo(string modelName = null, ModelType modelType = return new ModelInfo(modelName, modelType, modelProviderName, serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// Unique identifier for the embeddings result. + /// Embedding values for the prompts submitted in the request. + /// Usage counts for tokens input using the embeddings API. + /// The model ID used to generate this result. + /// A new instance for mocking. + public static EmbeddingsResult EmbeddingsResult(string id = null, IEnumerable data = null, EmbeddingsUsage usage = null, string model = null) + { + data ??= new List(); + + return new EmbeddingsResult(id, data?.ToList(), usage, model, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// List of embedding values for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. Or a base64 encoded string of the embedding vector. + /// + /// Index of the prompt to which the EmbeddingItem corresponds. + /// A new instance for mocking. + public static EmbeddingItem EmbeddingItem(BinaryData embedding = null, int index = default) + { + return new EmbeddingItem(embedding, index, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Number of tokens in the request. + /// + /// Total number of tokens transacted in this request/response. Should equal the + /// number of tokens in the request. + /// + /// A new instance for mocking. + public static EmbeddingsUsage EmbeddingsUsage(int promptTokens = default, int totalTokens = default) + { + return new EmbeddingsUsage(promptTokens, totalTokens, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// A unique identifier associated with this chat completions response. /// @@ -161,9 +208,33 @@ public static StreamingChatCompletionsUpdate StreamingChatCompletionsUpdate(stri /// The reason that this chat completions choice completed its generated. /// An update to the chat message for a given chat completions prompt. /// A new instance for mocking. - public static StreamingChatChoiceUpdate StreamingChatChoiceUpdate(int index = default, CompletionsFinishReason? finishReason = null, ChatResponseMessage delta = null) + public static StreamingChatChoiceUpdate StreamingChatChoiceUpdate(int index = default, CompletionsFinishReason? finishReason = null, StreamingChatResponseMessageUpdate delta = null) { return new StreamingChatChoiceUpdate(index, finishReason, delta, serializedAdditionalRawData: null); } + + /// Initializes a new instance of . + /// The chat role associated with the message. If present, should always be 'assistant'. + /// The content of the message. + /// + /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat + /// completions request to resolve as configured. + /// + /// A new instance for mocking. + public static StreamingChatResponseMessageUpdate StreamingChatResponseMessageUpdate(ChatRole? role = null, string content = null, IEnumerable toolCalls = null) + { + toolCalls ??= new List(); + + return new StreamingChatResponseMessageUpdate(role, content, toolCalls?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The ID of the tool call. + /// Updates to the function call requested by the AI model. + /// A new instance for mocking. + public static StreamingChatResponseToolCallUpdate StreamingChatResponseToolCallUpdate(string id = null, FunctionCall function = null) + { + return new StreamingChatResponseToolCallUpdate(id, function, serializedAdditionalRawData: null); + } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs similarity index 70% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs index e68f1c4ec7fb..46dcb4716cad 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs @@ -10,8 +10,8 @@ namespace Azure.AI.Inference { - /// Client options for ChatCompletionsClient. - public partial class ChatCompletionsClientOptions : ClientOptions + /// Client options for Azure.AI.Inference library clients. + public partial class AzureAIInferenceClientOptions : ClientOptions { private const ServiceVersion LatestVersion = ServiceVersion.V2024_05_01_Preview; @@ -24,8 +24,8 @@ public enum ServiceVersion internal string Version { get; } - /// Initializes new instance of ChatCompletionsClientOptions. - public ChatCompletionsClientOptions(ServiceVersion version = LatestVersion) + /// Initializes new instance of AzureAIInferenceClientOptions. + public AzureAIInferenceClientOptions(ServiceVersion version = LatestVersion) { Version = version switch { diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs index ec0f78d16f1c..75f8163a1def 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs @@ -42,7 +42,7 @@ protected ChatCompletionsClient() /// Service host. /// A credential used to authenticate to an Azure Service. /// or is null. - public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new ChatCompletionsClientOptions()) + public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) { } @@ -50,7 +50,7 @@ protected ChatCompletionsClient() /// Service host. /// A credential used to authenticate to an Azure Service. /// or is null. - public ChatCompletionsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new ChatCompletionsClientOptions()) + public ChatCompletionsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) { } @@ -59,11 +59,11 @@ protected ChatCompletionsClient() /// A credential used to authenticate to an Azure Service. /// The options for configuring the client. /// or is null. - public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential, ChatCompletionsClientOptions options) + public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential, AzureAIInferenceClientOptions options) { Argument.AssertNotNull(endpoint, nameof(endpoint)); Argument.AssertNotNull(credential, nameof(credential)); - options ??= new ChatCompletionsClientOptions(); + options ??= new AzureAIInferenceClientOptions(); ClientDiagnostics = new ClientDiagnostics(options, true); _keyCredential = credential; @@ -77,11 +77,11 @@ public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential, ChatCo /// A credential used to authenticate to an Azure Service. /// The options for configuring the client. /// or is null. - public ChatCompletionsClient(Uri endpoint, TokenCredential credential, ChatCompletionsClientOptions options) + public ChatCompletionsClient(Uri endpoint, TokenCredential credential, AzureAIInferenceClientOptions options) { Argument.AssertNotNull(endpoint, nameof(endpoint)); Argument.AssertNotNull(credential, nameof(credential)); - options ??= new ChatCompletionsClientOptions(); + options ??= new AzureAIInferenceClientOptions(); ClientDiagnostics = new ClientDiagnostics(options, true); _tokenCredential = credential; @@ -177,6 +177,8 @@ internal virtual Response Complete(RequestContent content, string extraParams = /// /// Returns information about the AI model. /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. /// /// The cancellation token to use. /// @@ -190,6 +192,8 @@ public virtual async Task> GetModelInfoAsync(CancellationTok /// /// Returns information about the AI model. /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. /// /// The cancellation token to use. /// @@ -203,6 +207,8 @@ public virtual Response GetModelInfo(CancellationToken cancellationTo /// /// [Protocol Method] Returns information about the AI model. /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. /// /// /// @@ -239,6 +245,8 @@ public virtual async Task GetModelInfoAsync(RequestContext context) /// /// [Protocol Method] Returns information about the AI model. /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. /// /// /// diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.cs deleted file mode 100644 index 1092f6ab4297..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// - /// A tool call to a function tool, issued by the model in evaluation of a configured function tool, that represents - /// a function invocation needed for a subsequent chat completions request to resolve. - /// - public partial class ChatCompletionsFunctionToolCall : ChatCompletionsToolCall - { - /// Initializes a new instance of . - /// The ID of the tool call. - /// The details of the function invocation requested by the tool call. - /// or is null. - public ChatCompletionsFunctionToolCall(string id, FunctionCall function) : base(id) - { - Argument.AssertNotNull(id, nameof(id)); - Argument.AssertNotNull(function, nameof(function)); - - Type = "function"; - Function = function; - } - - /// Initializes a new instance of . - /// The object type. - /// The ID of the tool call. - /// Keeps track of any properties unknown to the library. - /// The details of the function invocation requested by the tool call. - internal ChatCompletionsFunctionToolCall(string type, string id, IDictionary serializedAdditionalRawData, FunctionCall function) : base(type, id, serializedAdditionalRawData) - { - Function = function; - } - - /// Initializes a new instance of for deserialization. - internal ChatCompletionsFunctionToolCall() - { - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.cs deleted file mode 100644 index d719101dfc61..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// The definition information for a chat completions function tool that can call a function in response to a tool call. - public partial class ChatCompletionsFunctionToolDefinition : ChatCompletionsToolDefinition - { - /// Initializes a new instance of . - /// The function definition details for the function tool. - /// is null. - public ChatCompletionsFunctionToolDefinition(FunctionDefinition function) - { - Argument.AssertNotNull(function, nameof(function)); - - Type = "function"; - Function = function; - } - - /// Initializes a new instance of . - /// The object type. - /// Keeps track of any properties unknown to the library. - /// The function definition details for the function tool. - internal ChatCompletionsFunctionToolDefinition(string type, IDictionary serializedAdditionalRawData, FunctionDefinition function) : base(type, serializedAdditionalRawData) - { - Function = function; - } - - /// The function definition details for the function tool. - public FunctionDefinition Function { get; } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs deleted file mode 100644 index 96cea7708042..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Inference -{ - public partial class ChatCompletionsNamedFunctionToolSelection : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - writer.WritePropertyName("function"u8); - writer.WriteObjectValue(Function, options); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - ChatCompletionsNamedFunctionToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement, options); - } - - internal static ChatCompletionsNamedFunctionToolSelection DeserializeChatCompletionsNamedFunctionToolSelection(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - ChatCompletionsFunctionToolSelection function = default; - string type = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("function"u8)) - { - function = ChatCompletionsFunctionToolSelection.DeserializeChatCompletionsFunctionToolSelection(property.Value, options); - continue; - } - if (property.NameEquals("type"u8)) - { - type = property.Value.GetString(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new ChatCompletionsNamedFunctionToolSelection(type, serializedAdditionalRawData, function); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support writing '{options.Format}' format."); - } - } - - ChatCompletionsNamedFunctionToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static new ChatCompletionsNamedFunctionToolSelection FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement); - } - - /// Convert into a . - internal override RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs deleted file mode 100644 index b6f3d48262b2..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// A tool selection of a specific, named function tool that will limit chat completions to using the named function. - public partial class ChatCompletionsNamedFunctionToolSelection : ChatCompletionsNamedToolSelection - { - /// Initializes a new instance of . - /// The function that should be called. - /// is null. - public ChatCompletionsNamedFunctionToolSelection(ChatCompletionsFunctionToolSelection function) - { - Argument.AssertNotNull(function, nameof(function)); - - Type = "function"; - Function = function; - } - - /// Initializes a new instance of . - /// The object type. - /// Keeps track of any properties unknown to the library. - /// The function that should be called. - internal ChatCompletionsNamedFunctionToolSelection(string type, IDictionary serializedAdditionalRawData, ChatCompletionsFunctionToolSelection function) : base(type, serializedAdditionalRawData) - { - Function = function; - } - - /// Initializes a new instance of for deserialization. - internal ChatCompletionsNamedFunctionToolSelection() - { - } - - /// The function that should be called. - public ChatCompletionsFunctionToolSelection Function { get; } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.Serialization.cs similarity index 58% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.Serialization.cs index 637a0ded9872..0a675eb3e901 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.Serialization.cs @@ -13,23 +13,23 @@ namespace Azure.AI.Inference { - public partial class ChatCompletionsFunctionToolDefinition : IUtf8JsonSerializable, IJsonModel + public partial class ChatCompletionsNamedToolChoice : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoice)} does not support writing '{format}' format."); } writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); writer.WritePropertyName("function"u8); writer.WriteObjectValue(Function, options); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -48,19 +48,19 @@ void IJsonModel.Write(Utf8JsonWriter writ writer.WriteEndObject(); } - ChatCompletionsFunctionToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ChatCompletionsNamedToolChoice IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoice)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement, options); + return DeserializeChatCompletionsNamedToolChoice(document.RootElement, options); } - internal static ChatCompletionsFunctionToolDefinition DeserializeChatCompletionsFunctionToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + internal static ChatCompletionsNamedToolChoice DeserializeChatCompletionsNamedToolChoice(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -68,20 +68,20 @@ internal static ChatCompletionsFunctionToolDefinition DeserializeChatCompletions { return null; } - FunctionDefinition function = default; - string type = default; + ChatCompletionsNamedToolChoiceType type = default; + ChatCompletionsNamedToolChoiceFunction function = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("function"u8)) + if (property.NameEquals("type"u8)) { - function = FunctionDefinition.DeserializeFunctionDefinition(property.Value, options); + type = new ChatCompletionsNamedToolChoiceType(property.Value.GetString()); continue; } - if (property.NameEquals("type"u8)) + if (property.NameEquals("function"u8)) { - type = property.Value.GetString(); + function = ChatCompletionsNamedToolChoiceFunction.DeserializeChatCompletionsNamedToolChoiceFunction(property.Value, options); continue; } if (options.Format != "W") @@ -90,50 +90,50 @@ internal static ChatCompletionsFunctionToolDefinition DeserializeChatCompletions } } serializedAdditionalRawData = rawDataDictionary; - return new ChatCompletionsFunctionToolDefinition(type, serializedAdditionalRawData, function); + return new ChatCompletionsNamedToolChoice(type, function, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoice)} does not support writing '{options.Format}' format."); } } - ChatCompletionsFunctionToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ChatCompletionsNamedToolChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement, options); + return DeserializeChatCompletionsNamedToolChoice(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoice)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new ChatCompletionsFunctionToolDefinition FromResponse(Response response) + internal static ChatCompletionsNamedToolChoice FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement); + return DeserializeChatCompletionsNamedToolChoice(document.RootElement); } /// Convert into a . - internal override RequestContent ToRequestContent() + internal virtual RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.cs new file mode 100644 index 000000000000..7c8d17876b52 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoice.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Inference +{ + /// A tool selection of a specific, named function tool that will limit chat completions to using the named function. + public partial class ChatCompletionsNamedToolChoice + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The function that should be called. + /// is null. + public ChatCompletionsNamedToolChoice(ChatCompletionsNamedToolChoiceFunction function) + { + Argument.AssertNotNull(function, nameof(function)); + + Function = function; + } + + /// Initializes a new instance of . + /// The type of the tool. Currently, only `function` is supported. + /// The function that should be called. + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsNamedToolChoice(ChatCompletionsNamedToolChoiceType type, ChatCompletionsNamedToolChoiceFunction function, IDictionary serializedAdditionalRawData) + { + Type = type; + Function = function; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ChatCompletionsNamedToolChoice() + { + } + + /// The type of the tool. Currently, only `function` is supported. + public ChatCompletionsNamedToolChoiceType Type { get; } = ChatCompletionsNamedToolChoiceType.Function; + + /// The function that should be called. + public ChatCompletionsNamedToolChoiceFunction Function { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.Serialization.cs similarity index 61% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.Serialization.cs index 027b88cab389..4481e25d2789 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.Serialization.cs @@ -13,16 +13,16 @@ namespace Azure.AI.Inference { - public partial class ChatCompletionsFunctionToolSelection : IUtf8JsonSerializable, IJsonModel + public partial class ChatCompletionsNamedToolChoiceFunction : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolSelection)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoiceFunction)} does not support writing '{format}' format."); } writer.WriteStartObject(); @@ -46,19 +46,19 @@ void IJsonModel.Write(Utf8JsonWriter write writer.WriteEndObject(); } - ChatCompletionsFunctionToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ChatCompletionsNamedToolChoiceFunction IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolSelection)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoiceFunction)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsFunctionToolSelection(document.RootElement, options); + return DeserializeChatCompletionsNamedToolChoiceFunction(document.RootElement, options); } - internal static ChatCompletionsFunctionToolSelection DeserializeChatCompletionsFunctionToolSelection(JsonElement element, ModelReaderWriterOptions options = null) + internal static ChatCompletionsNamedToolChoiceFunction DeserializeChatCompletionsNamedToolChoiceFunction(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -82,46 +82,46 @@ internal static ChatCompletionsFunctionToolSelection DeserializeChatCompletionsF } } serializedAdditionalRawData = rawDataDictionary; - return new ChatCompletionsFunctionToolSelection(name, serializedAdditionalRawData); + return new ChatCompletionsNamedToolChoiceFunction(name, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolSelection)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoiceFunction)} does not support writing '{options.Format}' format."); } } - ChatCompletionsFunctionToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ChatCompletionsNamedToolChoiceFunction IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsFunctionToolSelection(document.RootElement, options); + return DeserializeChatCompletionsNamedToolChoiceFunction(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolSelection)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolChoiceFunction)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static ChatCompletionsFunctionToolSelection FromResponse(Response response) + internal static ChatCompletionsNamedToolChoiceFunction FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeChatCompletionsFunctionToolSelection(document.RootElement); + return DeserializeChatCompletionsNamedToolChoiceFunction(document.RootElement); } /// Convert into a . diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.cs similarity index 84% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.cs index 9d40282d5d0d..961c1a6500cc 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolSelection.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceFunction.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Inference { /// A tool selection of a specific, named function tool that will limit chat completions to using the named function. - public partial class ChatCompletionsFunctionToolSelection + public partial class ChatCompletionsNamedToolChoiceFunction { /// /// Keeps track of any properties unknown to the library. @@ -45,27 +45,27 @@ public partial class ChatCompletionsFunctionToolSelection /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// The name of the function that should be called. /// is null. - public ChatCompletionsFunctionToolSelection(string name) + public ChatCompletionsNamedToolChoiceFunction(string name) { Argument.AssertNotNull(name, nameof(name)); Name = name; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The name of the function that should be called. /// Keeps track of any properties unknown to the library. - internal ChatCompletionsFunctionToolSelection(string name, IDictionary serializedAdditionalRawData) + internal ChatCompletionsNamedToolChoiceFunction(string name, IDictionary serializedAdditionalRawData) { Name = name; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal ChatCompletionsFunctionToolSelection() + /// Initializes a new instance of for deserialization. + internal ChatCompletionsNamedToolChoiceFunction() { } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceType.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceType.cs new file mode 100644 index 000000000000..930fad82bc73 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolChoiceType.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.Inference +{ + /// The ChatCompletionsNamedToolChoice_type. + public readonly partial struct ChatCompletionsNamedToolChoiceType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ChatCompletionsNamedToolChoiceType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FunctionValue = "function"; + + /// function. + public static ChatCompletionsNamedToolChoiceType Function { get; } = new ChatCompletionsNamedToolChoiceType(FunctionValue); + /// Determines if two values are the same. + public static bool operator ==(ChatCompletionsNamedToolChoiceType left, ChatCompletionsNamedToolChoiceType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ChatCompletionsNamedToolChoiceType left, ChatCompletionsNamedToolChoiceType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ChatCompletionsNamedToolChoiceType(string value) => new ChatCompletionsNamedToolChoiceType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ChatCompletionsNamedToolChoiceType other && Equals(other); + /// + public bool Equals(ChatCompletionsNamedToolChoiceType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs deleted file mode 100644 index 5b299b414e7c..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Inference -{ - [PersistableModelProxy(typeof(UnknownChatCompletionsNamedToolSelection))] - public partial class ChatCompletionsNamedToolSelection : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - ChatCompletionsNamedToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); - } - - internal static ChatCompletionsNamedToolSelection DeserializeChatCompletionsNamedToolSelection(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - if (element.TryGetProperty("type", out JsonElement discriminator)) - { - switch (discriminator.GetString()) - { - case "function": return ChatCompletionsNamedFunctionToolSelection.DeserializeChatCompletionsNamedFunctionToolSelection(element, options); - } - } - return UnknownChatCompletionsNamedToolSelection.DeserializeUnknownChatCompletionsNamedToolSelection(element, options); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support writing '{options.Format}' format."); - } - } - - ChatCompletionsNamedToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static ChatCompletionsNamedToolSelection FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeChatCompletionsNamedToolSelection(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs index 5a4882acb5f5..18f5fa013c07 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs @@ -89,9 +89,8 @@ public ChatCompletionsOptions(IEnumerable messages) /// /// A collection of textual sequences that will end completions generation. /// - /// The available tool definitions that the chat completions request can use, including caller-defined functions. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . + /// A list of tools the model may request to call. Currently, only functions are supported as a tool. The model + /// may response with a function call request and provide the input arguments in JSON format for that function. /// /// If specified, the model will configure which of the provided tools it can use for the chat completions response. /// @@ -175,9 +174,8 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// A collection of textual sequences that will end completions generation. public IList StopSequences { get; } /// - /// The available tool definitions that the chat completions request can use, including caller-defined functions. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . + /// A list of tools the model may request to call. Currently, only functions are supported as a tool. The model + /// may response with a function call request and provide the input arguments in JSON format for that function. /// public IList Tools { get; } /// diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.Serialization.cs index 6847d4c576e2..6caa22ef1c24 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.Serialization.cs @@ -7,12 +7,12 @@ using System; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.AI.Inference { - [PersistableModelProxy(typeof(UnknownChatCompletionsToolCall))] public partial class ChatCompletionsToolCall : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); @@ -26,10 +26,12 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade } writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); writer.WritePropertyName("id"u8); writer.WriteStringValue(Id); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -68,14 +70,35 @@ internal static ChatCompletionsToolCall DeserializeChatCompletionsToolCall(JsonE { return null; } - if (element.TryGetProperty("type", out JsonElement discriminator)) + string id = default; + ChatCompletionsToolCallType type = default; + FunctionCall function = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) { - switch (discriminator.GetString()) + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ChatCompletionsToolCallType(property.Value.GetString()); + continue; + } + if (property.NameEquals("function"u8)) + { + function = FunctionCall.DeserializeFunctionCall(property.Value, options); + continue; + } + if (options.Format != "W") { - case "function": return ChatCompletionsFunctionToolCall.DeserializeChatCompletionsFunctionToolCall(element, options); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } - return UnknownChatCompletionsToolCall.DeserializeUnknownChatCompletionsToolCall(element, options); + serializedAdditionalRawData = rawDataDictionary; + return new ChatCompletionsToolCall(id, type, function, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.cs index 5f1cc216e79d..bc9240a7e246 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCall.cs @@ -10,13 +10,8 @@ namespace Azure.AI.Inference { - /// - /// An abstract representation of a tool call that must be resolved in a subsequent request to perform the requested - /// chat completion. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - public abstract partial class ChatCompletionsToolCall + /// A function tool call requested by the AI model. + public partial class ChatCompletionsToolCall { /// /// Keeps track of any properties unknown to the library. @@ -48,26 +43,31 @@ public abstract partial class ChatCompletionsToolCall /// /// /// - private protected IDictionary _serializedAdditionalRawData; + private IDictionary _serializedAdditionalRawData; /// Initializes a new instance of . /// The ID of the tool call. - /// is null. - protected ChatCompletionsToolCall(string id) + /// The details of the function call requested by the AI model. + /// or is null. + public ChatCompletionsToolCall(string id, FunctionCall function) { Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(function, nameof(function)); Id = id; + Function = function; } /// Initializes a new instance of . - /// The object type. /// The ID of the tool call. + /// The type of tool call. Currently, only `function` is supported. + /// The details of the function call requested by the AI model. /// Keeps track of any properties unknown to the library. - internal ChatCompletionsToolCall(string type, string id, IDictionary serializedAdditionalRawData) + internal ChatCompletionsToolCall(string id, ChatCompletionsToolCallType type, FunctionCall function, IDictionary serializedAdditionalRawData) { - Type = type; Id = id; + Type = type; + Function = function; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -76,9 +76,12 @@ internal ChatCompletionsToolCall() { } - /// The object type. - internal string Type { get; set; } /// The ID of the tool call. public string Id { get; set; } + /// The type of tool call. Currently, only `function` is supported. + public ChatCompletionsToolCallType Type { get; } = ChatCompletionsToolCallType.Function; + + /// The details of the function call requested by the AI model. + public FunctionCall Function { get; set; } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCallType.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCallType.cs new file mode 100644 index 000000000000..660eae8b8078 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolCallType.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.Inference +{ + /// The ChatCompletionsToolCall_type. + public readonly partial struct ChatCompletionsToolCallType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ChatCompletionsToolCallType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FunctionValue = "function"; + + /// function. + public static ChatCompletionsToolCallType Function { get; } = new ChatCompletionsToolCallType(FunctionValue); + /// Determines if two values are the same. + public static bool operator ==(ChatCompletionsToolCallType left, ChatCompletionsToolCallType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ChatCompletionsToolCallType left, ChatCompletionsToolCallType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ChatCompletionsToolCallType(string value) => new ChatCompletionsToolCallType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ChatCompletionsToolCallType other && Equals(other); + /// + public bool Equals(ChatCompletionsToolCallType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolSelectionPreset.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolChoicePreset.cs similarity index 59% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolSelectionPreset.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolChoicePreset.cs index af2ed715c576..1c0a1a3118fd 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolSelectionPreset.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolChoicePreset.cs @@ -11,13 +11,13 @@ namespace Azure.AI.Inference { /// Represents a generic policy for how a chat completions tool may be selected. - public readonly partial struct ChatCompletionsToolSelectionPreset : IEquatable + public readonly partial struct ChatCompletionsToolChoicePreset : IEquatable { private readonly string _value; - /// Initializes a new instance of . + /// Initializes a new instance of . /// is null. - public ChatCompletionsToolSelectionPreset(string value) + public ChatCompletionsToolChoicePreset(string value) { _value = value ?? throw new ArgumentNullException(nameof(value)); } @@ -30,26 +30,26 @@ public ChatCompletionsToolSelectionPreset(string value) /// Specifies that the model may either use any of the tools provided in this chat completions request or /// instead return a standard chat completions response as if no tools were provided. /// - public static ChatCompletionsToolSelectionPreset Auto { get; } = new ChatCompletionsToolSelectionPreset(AutoValue); + public static ChatCompletionsToolChoicePreset Auto { get; } = new ChatCompletionsToolChoicePreset(AutoValue); /// /// Specifies that the model should not respond with a tool call and should instead provide a standard chat /// completions response. Response content may still be influenced by the provided tool definitions. /// - public static ChatCompletionsToolSelectionPreset None { get; } = new ChatCompletionsToolSelectionPreset(NoneValue); + public static ChatCompletionsToolChoicePreset None { get; } = new ChatCompletionsToolChoicePreset(NoneValue); /// Specifies that the model should respond with a call to one or more tools. - public static ChatCompletionsToolSelectionPreset Required { get; } = new ChatCompletionsToolSelectionPreset(RequiredValue); - /// Determines if two values are the same. - public static bool operator ==(ChatCompletionsToolSelectionPreset left, ChatCompletionsToolSelectionPreset right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(ChatCompletionsToolSelectionPreset left, ChatCompletionsToolSelectionPreset right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator ChatCompletionsToolSelectionPreset(string value) => new ChatCompletionsToolSelectionPreset(value); + public static ChatCompletionsToolChoicePreset Required { get; } = new ChatCompletionsToolChoicePreset(RequiredValue); + /// Determines if two values are the same. + public static bool operator ==(ChatCompletionsToolChoicePreset left, ChatCompletionsToolChoicePreset right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ChatCompletionsToolChoicePreset left, ChatCompletionsToolChoicePreset right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ChatCompletionsToolChoicePreset(string value) => new ChatCompletionsToolChoicePreset(value); /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is ChatCompletionsToolSelectionPreset other && Equals(other); + public override bool Equals(object obj) => obj is ChatCompletionsToolChoicePreset other && Equals(other); /// - public bool Equals(ChatCompletionsToolSelectionPreset other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + public bool Equals(ChatCompletionsToolChoicePreset other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.Serialization.cs index 134596576b09..e7563c808ef3 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.Serialization.cs @@ -7,12 +7,12 @@ using System; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; namespace Azure.AI.Inference { - [PersistableModelProxy(typeof(UnknownChatCompletionsToolDefinition))] public partial class ChatCompletionsToolDefinition : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); @@ -27,7 +27,9 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mode writer.WriteStartObject(); writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); + writer.WriteStringValue(Type.ToString()); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -66,14 +68,29 @@ internal static ChatCompletionsToolDefinition DeserializeChatCompletionsToolDefi { return null; } - if (element.TryGetProperty("type", out JsonElement discriminator)) + ChatCompletionsToolDefinitionType type = default; + FunctionDefinition function = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) { - switch (discriminator.GetString()) + if (property.NameEquals("type"u8)) { - case "function": return ChatCompletionsFunctionToolDefinition.DeserializeChatCompletionsFunctionToolDefinition(element, options); + type = new ChatCompletionsToolDefinitionType(property.Value.GetString()); + continue; + } + if (property.NameEquals("function"u8)) + { + function = FunctionDefinition.DeserializeFunctionDefinition(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } - return UnknownChatCompletionsToolDefinition.DeserializeUnknownChatCompletionsToolDefinition(element, options); + serializedAdditionalRawData = rawDataDictionary; + return new ChatCompletionsToolDefinition(type, function, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.cs index ac527ab55257..3ccfacb95646 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinition.cs @@ -10,12 +10,8 @@ namespace Azure.AI.Inference { - /// - /// An abstract representation of a tool that can be used by the model to improve a chat completions response. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - public abstract partial class ChatCompletionsToolDefinition + /// The definition of a chat completions tool that can call a function. + public partial class ChatCompletionsToolDefinition { /// /// Keeps track of any properties unknown to the library. @@ -47,23 +43,38 @@ public abstract partial class ChatCompletionsToolDefinition /// /// /// - private protected IDictionary _serializedAdditionalRawData; + private IDictionary _serializedAdditionalRawData; /// Initializes a new instance of . - protected ChatCompletionsToolDefinition() + /// The function definition details for the function tool. + /// is null. + public ChatCompletionsToolDefinition(FunctionDefinition function) { + Argument.AssertNotNull(function, nameof(function)); + + Function = function; } /// Initializes a new instance of . - /// The object type. + /// The type of the tool. Currently, only `function` is supported. + /// The function definition details for the function tool. /// Keeps track of any properties unknown to the library. - internal ChatCompletionsToolDefinition(string type, IDictionary serializedAdditionalRawData) + internal ChatCompletionsToolDefinition(ChatCompletionsToolDefinitionType type, FunctionDefinition function, IDictionary serializedAdditionalRawData) { Type = type; + Function = function; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// The object type. - internal string Type { get; set; } + /// Initializes a new instance of for deserialization. + internal ChatCompletionsToolDefinition() + { + } + + /// The type of the tool. Currently, only `function` is supported. + public ChatCompletionsToolDefinitionType Type { get; } = ChatCompletionsToolDefinitionType.Function; + + /// The function definition details for the function tool. + public FunctionDefinition Function { get; } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinitionType.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinitionType.cs new file mode 100644 index 000000000000..0204f4682b9d --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsToolDefinitionType.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.Inference +{ + /// The ChatCompletionsToolDefinition_type. + public readonly partial struct ChatCompletionsToolDefinitionType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ChatCompletionsToolDefinitionType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FunctionValue = "function"; + + /// function. + public static ChatCompletionsToolDefinitionType Function { get; } = new ChatCompletionsToolDefinitionType(FunctionValue); + /// Determines if two values are the same. + public static bool operator ==(ChatCompletionsToolDefinitionType left, ChatCompletionsToolDefinitionType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ChatCompletionsToolDefinitionType left, ChatCompletionsToolDefinitionType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ChatCompletionsToolDefinitionType(string value) => new ChatCompletionsToolDefinitionType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ChatCompletionsToolDefinitionType other && Equals(other); + /// + public bool Equals(ChatCompletionsToolDefinitionType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatRequestAssistantMessage.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatRequestAssistantMessage.cs index 55d8b7dac8ff..2adaf8ab6958 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatRequestAssistantMessage.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatRequestAssistantMessage.cs @@ -27,8 +27,6 @@ public ChatRequestAssistantMessage() /// /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat /// completions request to resolve as configured. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . /// internal ChatRequestAssistantMessage(ChatRole role, IDictionary serializedAdditionalRawData, string content, IList toolCalls) : base(role, serializedAdditionalRawData) { @@ -41,8 +39,6 @@ internal ChatRequestAssistantMessage(ChatRole role, IDictionary /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat /// completions request to resolve as configured. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . /// public IList ToolCalls { get; } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatResponseMessage.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatResponseMessage.cs index 1b4995b7ea07..6ba151e01adb 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatResponseMessage.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatResponseMessage.cs @@ -61,8 +61,6 @@ internal ChatResponseMessage(ChatRole role, string content) /// /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat /// completions request to resolve as configured. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . /// /// Keeps track of any properties unknown to the library. internal ChatResponseMessage(ChatRole role, string content, IReadOnlyList toolCalls, IDictionary serializedAdditionalRawData) @@ -85,8 +83,6 @@ internal ChatResponseMessage() /// /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat /// completions request to resolve as configured. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . /// public IReadOnlyList ToolCalls { get; } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml b/sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml new file mode 100644 index 000000000000..2f52491f2297 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml @@ -0,0 +1,217 @@ + + + + + +This sample shows how to call EmbedAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +EmbeddingsOptions embeddingsOptions = null; +Response response = await client.EmbedAsync(embeddingsOptions); +]]> +This sample shows how to call EmbedAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +EmbeddingsOptions embeddingsOptions = null; +Response response = await client.EmbedAsync(embeddingsOptions); +]]> + + + +This sample shows how to call Embed. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +EmbeddingsOptions embeddingsOptions = null; +Response response = client.Embed(embeddingsOptions); +]]> +This sample shows how to call Embed. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +EmbeddingsOptions embeddingsOptions = null; +Response response = client.Embed(embeddingsOptions); +]]> + + + +This sample shows how to call EmbedAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new object()); +Response response = await client.EmbedAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); +Console.WriteLine(result.GetProperty("model").ToString()); +]]> +This sample shows how to call EmbedAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new object()); +Response response = await client.EmbedAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); +Console.WriteLine(result.GetProperty("model").ToString()); +]]> + + + +This sample shows how to call Embed and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new object()); +Response response = client.Embed(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); +Console.WriteLine(result.GetProperty("model").ToString()); +]]> +This sample shows how to call Embed and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +using RequestContent content = RequestContent.Create(new object()); +Response response = client.Embed(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); +Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); +Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); +Console.WriteLine(result.GetProperty("model").ToString()); +]]> + + + +This sample shows how to call GetModelInfoAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = await client.GetModelInfoAsync(); +]]> +This sample shows how to call GetModelInfoAsync. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = await client.GetModelInfoAsync(); +]]> + + + +This sample shows how to call GetModelInfo. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = client.GetModelInfo(); +]]> +This sample shows how to call GetModelInfo. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = client.GetModelInfo(); +]]> + + + +This sample shows how to call GetModelInfoAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = await client.GetModelInfoAsync(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("model_name").ToString()); +Console.WriteLine(result.GetProperty("model_type").ToString()); +Console.WriteLine(result.GetProperty("model_provider_name").ToString()); +]]> +This sample shows how to call GetModelInfoAsync and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = await client.GetModelInfoAsync(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("model_name").ToString()); +Console.WriteLine(result.GetProperty("model_type").ToString()); +Console.WriteLine(result.GetProperty("model_provider_name").ToString()); +]]> + + + +This sample shows how to call GetModelInfo and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = client.GetModelInfo(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("model_name").ToString()); +Console.WriteLine(result.GetProperty("model_type").ToString()); +Console.WriteLine(result.GetProperty("model_provider_name").ToString()); +]]> +This sample shows how to call GetModelInfo and parse the result. +"); +AzureKeyCredential credential = new AzureKeyCredential(""); +EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + +Response response = client.GetModelInfo(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("model_name").ToString()); +Console.WriteLine(result.GetProperty("model_type").ToString()); +Console.WriteLine(result.GetProperty("model_provider_name").ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.Serialization.cs similarity index 53% rename from sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.Serialization.cs index c3c50bb2e9e9..8a543620fc51 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.Serialization.cs @@ -13,21 +13,21 @@ namespace Azure.AI.Inference { - internal partial class UnknownChatCompletionsNamedToolSelection : IUtf8JsonSerializable, IJsonModel + internal partial class EmbedRequest : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(EmbedRequest)} does not support writing '{format}' format."); } writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); + writer.WritePropertyName("embeddingsOptions"u8); + writer.WriteObjectValue(EmbeddingsOptions, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -46,19 +46,19 @@ void IJsonModel.Write(Utf8JsonWriter writer, writer.WriteEndObject(); } - ChatCompletionsNamedToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + EmbedRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(EmbedRequest)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); + return DeserializeEmbedRequest(document.RootElement, options); } - internal static UnknownChatCompletionsNamedToolSelection DeserializeUnknownChatCompletionsNamedToolSelection(JsonElement element, ModelReaderWriterOptions options = null) + internal static EmbedRequest DeserializeEmbedRequest(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -66,14 +66,14 @@ internal static UnknownChatCompletionsNamedToolSelection DeserializeUnknownChatC { return null; } - string type = "Unknown"; + EmbeddingsOptions embeddingsOptions = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("type"u8)) + if (property.NameEquals("embeddingsOptions"u8)) { - type = property.Value.GetString(); + embeddingsOptions = EmbeddingsOptions.DeserializeEmbeddingsOptions(property.Value, options); continue; } if (options.Format != "W") @@ -82,53 +82,53 @@ internal static UnknownChatCompletionsNamedToolSelection DeserializeUnknownChatC } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownChatCompletionsNamedToolSelection(type, serializedAdditionalRawData); + return new EmbedRequest(embeddingsOptions, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbedRequest)} does not support writing '{options.Format}' format."); } } - ChatCompletionsNamedToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + EmbedRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); + return DeserializeEmbedRequest(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbedRequest)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new UnknownChatCompletionsNamedToolSelection FromResponse(Response response) + internal static EmbedRequest FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeUnknownChatCompletionsNamedToolSelection(document.RootElement); + return DeserializeEmbedRequest(document.RootElement); } /// Convert into a . - internal override RequestContent ToRequestContent() + internal virtual RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.cs similarity index 58% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.cs index e4848e2f0528..4cb73d47f7cd 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsNamedToolSelection.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbedRequest.cs @@ -10,12 +10,8 @@ namespace Azure.AI.Inference { - /// - /// An abstract representation of an explicit, named tool selection to use for a chat completions request. - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - public abstract partial class ChatCompletionsNamedToolSelection + /// The EmbedRequest. + internal partial class EmbedRequest { /// /// Keeps track of any properties unknown to the library. @@ -47,23 +43,33 @@ public abstract partial class ChatCompletionsNamedToolSelection /// /// /// - private protected IDictionary _serializedAdditionalRawData; + private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - protected ChatCompletionsNamedToolSelection() + /// Initializes a new instance of . + /// + /// is null. + internal EmbedRequest(EmbeddingsOptions embeddingsOptions) { + Argument.AssertNotNull(embeddingsOptions, nameof(embeddingsOptions)); + + EmbeddingsOptions = embeddingsOptions; } - /// Initializes a new instance of . - /// The object type. + /// Initializes a new instance of . + /// /// Keeps track of any properties unknown to the library. - internal ChatCompletionsNamedToolSelection(string type, IDictionary serializedAdditionalRawData) + internal EmbedRequest(EmbeddingsOptions embeddingsOptions, IDictionary serializedAdditionalRawData) { - Type = type; + EmbeddingsOptions = embeddingsOptions; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// The object type. - internal string Type { get; set; } + /// Initializes a new instance of for deserialization. + internal EmbedRequest() + { + } + + /// Gets the embeddings options. + public EmbeddingsOptions EmbeddingsOptions { get; } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs new file mode 100644 index 000000000000..e3d5428bed52 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.Inference +{ + /// + /// The format of the embeddings result. + /// Returns a 422 error if the model doesn't support the value or parameter. + /// + public readonly partial struct EmbeddingEncodingFormat : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public EmbeddingEncodingFormat(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Base64Value = "base64"; + private const string BinaryValue = "binary"; + private const string FloatValue = "float"; + private const string Int8Value = "int8"; + private const string UbinaryValue = "ubinary"; + private const string Uint8Value = "uint8"; + + /// Base64. + public static EmbeddingEncodingFormat Base64 { get; } = new EmbeddingEncodingFormat(Base64Value); + /// Binary. + public static EmbeddingEncodingFormat Binary { get; } = new EmbeddingEncodingFormat(BinaryValue); + /// Floating point. + public static EmbeddingEncodingFormat Float { get; } = new EmbeddingEncodingFormat(FloatValue); + /// Signed 8-bit integer. + public static EmbeddingEncodingFormat Int8 { get; } = new EmbeddingEncodingFormat(Int8Value); + /// ubinary. + public static EmbeddingEncodingFormat Ubinary { get; } = new EmbeddingEncodingFormat(UbinaryValue); + /// Unsigned 8-bit integer. + public static EmbeddingEncodingFormat Uint8 { get; } = new EmbeddingEncodingFormat(Uint8Value); + /// Determines if two values are the same. + public static bool operator ==(EmbeddingEncodingFormat left, EmbeddingEncodingFormat right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(EmbeddingEncodingFormat left, EmbeddingEncodingFormat right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator EmbeddingEncodingFormat(string value) => new EmbeddingEncodingFormat(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is EmbeddingEncodingFormat other && Equals(other); + /// + public bool Equals(EmbeddingEncodingFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.cs new file mode 100644 index 000000000000..9e75eba6dc3c --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.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.Inference +{ + /// Represents the input types used for embedding search. + public readonly partial struct EmbeddingInputType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public EmbeddingInputType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TextValue = "text"; + private const string QueryValue = "query"; + private const string DocumentValue = "document"; + + /// Indicates the input is a general text input. + public static EmbeddingInputType Text { get; } = new EmbeddingInputType(TextValue); + /// Indicates the input represents a search query to find the most relevant documents in your vector database. + public static EmbeddingInputType Query { get; } = new EmbeddingInputType(QueryValue); + /// Indicates the input represents a document that is stored in a vector database. + public static EmbeddingInputType Document { get; } = new EmbeddingInputType(DocumentValue); + /// Determines if two values are the same. + public static bool operator ==(EmbeddingInputType left, EmbeddingInputType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(EmbeddingInputType left, EmbeddingInputType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator EmbeddingInputType(string value) => new EmbeddingInputType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is EmbeddingInputType other && Equals(other); + /// + public bool Equals(EmbeddingInputType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs similarity index 54% rename from sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs index 84f7e3fe34a6..56ace06d12cf 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs @@ -13,23 +13,30 @@ namespace Azure.AI.Inference { - internal partial class UnknownChatCompletionsToolCall : IUtf8JsonSerializable, IJsonModel + public partial class EmbeddingItem : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support writing '{format}' format."); } writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id); + writer.WritePropertyName("embedding"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Embedding); +#else + using (JsonDocument document = JsonDocument.Parse(Embedding)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -48,19 +55,19 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade writer.WriteEndObject(); } - ChatCompletionsToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + EmbeddingItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsToolCall(document.RootElement, options); + return DeserializeEmbeddingItem(document.RootElement, options); } - internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletionsToolCall(JsonElement element, ModelReaderWriterOptions options = null) + internal static EmbeddingItem DeserializeEmbeddingItem(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -68,20 +75,20 @@ internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletions { return null; } - string type = "Unknown"; - string id = default; + BinaryData embedding = default; + int index = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("type"u8)) + if (property.NameEquals("embedding"u8)) { - type = property.Value.GetString(); + embedding = BinaryData.FromString(property.Value.GetRawText()); continue; } - if (property.NameEquals("id"u8)) + if (property.NameEquals("index"u8)) { - id = property.Value.GetString(); + index = property.Value.GetInt32(); continue; } if (options.Format != "W") @@ -90,53 +97,53 @@ internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletions } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownChatCompletionsToolCall(type, id, serializedAdditionalRawData); + return new EmbeddingItem(embedding, index, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support writing '{options.Format}' format."); } } - ChatCompletionsToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + EmbeddingItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsToolCall(document.RootElement, options); + return DeserializeEmbeddingItem(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new UnknownChatCompletionsToolCall FromResponse(Response response) + internal static EmbeddingItem FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeUnknownChatCompletionsToolCall(document.RootElement); + return DeserializeEmbeddingItem(document.RootElement); } /// Convert into a . - internal override RequestContent ToRequestContent() + internal virtual RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs new file mode 100644 index 000000000000..676f0aba0bc7 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Inference +{ + /// Representation of a single embeddings relatedness comparison. + public partial class EmbeddingItem + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// + /// List of embedding values for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. Or a base64 encoded string of the embedding vector. + /// + /// Index of the prompt to which the EmbeddingItem corresponds. + /// is null. + internal EmbeddingItem(BinaryData embedding, int index) + { + Argument.AssertNotNull(embedding, nameof(embedding)); + + Embedding = embedding; + Index = index; + } + + /// Initializes a new instance of . + /// + /// List of embedding values for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. Or a base64 encoded string of the embedding vector. + /// + /// Index of the prompt to which the EmbeddingItem corresponds. + /// Keeps track of any properties unknown to the library. + internal EmbeddingItem(BinaryData embedding, int index, IDictionary serializedAdditionalRawData) + { + Embedding = embedding; + Index = index; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingItem() + { + } + + /// + /// List of embedding values for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. Or a base64 encoded string of the embedding vector. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// where T is of type + /// + /// + /// + /// 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 Embedding { get; } + /// Index of the prompt to which the EmbeddingItem corresponds. + public int Index { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs new file mode 100644 index 000000000000..b480784646e6 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs @@ -0,0 +1,383 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.Inference +{ + // Data plane generated client. + /// The Embeddings service client. + public partial class EmbeddingsClient + { + private const string AuthorizationHeader = "Authorization"; + private readonly AzureKeyCredential _keyCredential; + private const string AuthorizationApiKeyPrefix = "Bearer"; + private static readonly string[] AuthorizationScopes = new string[] { "https://ml.azure.com/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of EmbeddingsClient for mocking. + protected EmbeddingsClient() + { + } + + /// Initializes a new instance of EmbeddingsClient. + /// Service host. + /// A credential used to authenticate to an Azure Service. + /// or is null. + public EmbeddingsClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) + { + } + + /// Initializes a new instance of EmbeddingsClient. + /// Service host. + /// A credential used to authenticate to an Azure Service. + /// or is null. + public EmbeddingsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) + { + } + + /// Initializes a new instance of EmbeddingsClient. + /// Service host. + /// A credential used to authenticate to an Azure Service. + /// The options for configuring the client. + /// or is null. + public EmbeddingsClient(Uri endpoint, AzureKeyCredential credential, AzureAIInferenceClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new AzureAIInferenceClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _keyCredential = credential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader, AuthorizationApiKeyPrefix) }, new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + } + + /// Initializes a new instance of EmbeddingsClient. + /// Service host. + /// A credential used to authenticate to an Azure Service. + /// The options for configuring the client. + /// or is null. + public EmbeddingsClient(Uri endpoint, TokenCredential credential, AzureAIInferenceClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new AzureAIInferenceClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _tokenCredential = credential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + } + + /// + /// Return the embedding vectors for given text prompts. + /// The method makes a REST API call to the `/embeddings` route on the given endpoint. + /// + /// + /// + /// Controls what happens if extra parameters, undefined by the REST API, + /// are passed in the JSON request payload. + /// This sets the HTTP request header `extra-parameters`. + /// + /// The cancellation token to use. + /// is null. + /// + public virtual async Task> EmbedAsync(EmbeddingsOptions embeddingsOptions, ExtraParameters? extraParams = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(embeddingsOptions, nameof(embeddingsOptions)); + + EmbedRequest embedRequest = new EmbedRequest(embeddingsOptions, null); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await EmbedAsync(embedRequest.ToRequestContent(), extraParams?.ToString(), context).ConfigureAwait(false); + return Response.FromValue(EmbeddingsResult.FromResponse(response), response); + } + + /// + /// Return the embedding vectors for given text prompts. + /// The method makes a REST API call to the `/embeddings` route on the given endpoint. + /// + /// + /// + /// Controls what happens if extra parameters, undefined by the REST API, + /// are passed in the JSON request payload. + /// This sets the HTTP request header `extra-parameters`. + /// + /// The cancellation token to use. + /// is null. + /// + public virtual Response Embed(EmbeddingsOptions embeddingsOptions, ExtraParameters? extraParams = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(embeddingsOptions, nameof(embeddingsOptions)); + + EmbedRequest embedRequest = new EmbedRequest(embeddingsOptions, null); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = Embed(embedRequest.ToRequestContent(), extraParams?.ToString(), context); + return Response.FromValue(EmbeddingsResult.FromResponse(response), response); + } + + /// + /// [Protocol Method] Return the embedding vectors for given text prompts. + /// The method makes a REST API call to the `/embeddings` route on the given endpoint. + /// + /// + /// + /// 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. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// + /// Controls what happens if extra parameters, undefined by the REST API, + /// are passed in the JSON request payload. + /// This sets the HTTP request header `extra-parameters`. Allowed values: "error" | "drop" | "pass-through" + /// + /// 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 response returned from the service. + /// + public virtual async Task EmbedAsync(RequestContent content, string extraParams = null, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("EmbeddingsClient.Embed"); + scope.Start(); + try + { + using HttpMessage message = CreateEmbedRequest(content, extraParams, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Return the embedding vectors for given text prompts. + /// The method makes a REST API call to the `/embeddings` route on the given endpoint. + /// + /// + /// + /// 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. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// + /// Controls what happens if extra parameters, undefined by the REST API, + /// are passed in the JSON request payload. + /// This sets the HTTP request header `extra-parameters`. Allowed values: "error" | "drop" | "pass-through" + /// + /// 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 response returned from the service. + /// + public virtual Response Embed(RequestContent content, string extraParams = null, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("EmbeddingsClient.Embed"); + scope.Start(); + try + { + using HttpMessage message = CreateEmbedRequest(content, extraParams, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Returns information about the AI model. + /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. + /// + /// The cancellation token to use. + /// + public virtual async Task> GetModelInfoAsync(CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetModelInfoAsync(context).ConfigureAwait(false); + return Response.FromValue(ModelInfo.FromResponse(response), response); + } + + /// + /// Returns information about the AI model. + /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. + /// + /// The cancellation token to use. + /// + public virtual Response GetModelInfo(CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetModelInfo(context); + return Response.FromValue(ModelInfo.FromResponse(response), response); + } + + /// + /// [Protocol Method] Returns information about the AI model. + /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. + /// + /// + /// + /// 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. + /// + /// + /// + /// + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetModelInfoAsync(RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("EmbeddingsClient.GetModelInfo"); + scope.Start(); + try + { + using HttpMessage message = CreateGetModelInfoRequest(context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Returns information about the AI model. + /// The method makes a REST API call to the `/info` route on the given endpoint. + /// This method will only work when using Serverless API or Managed Compute endpoint. + /// It will not work for GitHub Models endpoint or Azure OpenAI endpoint. + /// + /// + /// + /// 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. + /// + /// + /// + /// + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetModelInfo(RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("EmbeddingsClient.GetModelInfo"); + scope.Start(); + try + { + using HttpMessage message = CreateGetModelInfoRequest(context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateEmbedRequest(RequestContent content, string extraParams, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/embeddings", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + if (extraParams != null) + { + request.Headers.Add("extra-parameters", extraParams); + } + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetModelInfoRequest(RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/info", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs new file mode 100644 index 000000000000..975c71f9d3da --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs @@ -0,0 +1,201 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.Inference +{ + public partial class EmbeddingsOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("input"u8); + writer.WriteStartArray(); + foreach (var item in Input) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(Dimensions)) + { + writer.WritePropertyName("dimensions"u8); + writer.WriteNumberValue(Dimensions.Value); + } + if (Optional.IsDefined(EncodingFormat)) + { + writer.WritePropertyName("encoding_format"u8); + writer.WriteStringValue(EncodingFormat.Value.ToString()); + } + if (Optional.IsDefined(InputType)) + { + writer.WritePropertyName("input_type"u8); + writer.WriteStringValue(InputType.Value.ToString()); + } + if (Optional.IsDefined(Model)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + } + foreach (var item in AdditionalProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + writer.WriteEndObject(); + } + + EmbeddingsOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddingsOptions(document.RootElement, options); + } + + internal static EmbeddingsOptions DeserializeEmbeddingsOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList input = default; + int? dimensions = default; + EmbeddingEncodingFormat? encodingFormat = default; + EmbeddingInputType? inputType = default; + string model = default; + IDictionary additionalProperties = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("input"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + input = array; + continue; + } + if (property.NameEquals("dimensions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + dimensions = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("encoding_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + encodingFormat = new EmbeddingEncodingFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("input_type"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inputType = new EmbeddingInputType(property.Value.GetString()); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + additionalProperties = additionalPropertiesDictionary; + return new EmbeddingsOptions( + input, + dimensions, + encodingFormat, + inputType, + model, + additionalProperties); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support writing '{options.Format}' format."); + } + } + + EmbeddingsOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddingsOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static EmbeddingsOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeEmbeddingsOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs new file mode 100644 index 000000000000..879babca6604 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs @@ -0,0 +1,118 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.Inference +{ + /// The configuration information for an embeddings request. + public partial class EmbeddingsOptions + { + /// Initializes a new instance of . + /// + /// Input text to embed, encoded as a string or array of tokens. + /// To embed multiple inputs in a single request, pass an array + /// of strings or array of token arrays. + /// + /// is null. + public EmbeddingsOptions(IEnumerable input) + { + Argument.AssertNotNull(input, nameof(input)); + + Input = input.ToList(); + AdditionalProperties = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// + /// Input text to embed, encoded as a string or array of tokens. + /// To embed multiple inputs in a single request, pass an array + /// of strings or array of token arrays. + /// + /// + /// Optional. The number of dimensions the resulting output embeddings should have. + /// Passing null causes the model to use its default value. + /// Returns a 422 error if the model doesn't support the value or parameter. + /// + /// Optional. The desired format for the returned embeddings. + /// + /// Optional. The type of the input. + /// Returns a 422 error if the model doesn't support the value or parameter. + /// + /// ID of the specific AI model to use, if more than one model is available on the endpoint. + /// Additional Properties. + internal EmbeddingsOptions(IList input, int? dimensions, EmbeddingEncodingFormat? encodingFormat, EmbeddingInputType? inputType, string model, IDictionary additionalProperties) + { + Input = input; + Dimensions = dimensions; + EncodingFormat = encodingFormat; + InputType = inputType; + Model = model; + AdditionalProperties = additionalProperties; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingsOptions() + { + } + + /// + /// Input text to embed, encoded as a string or array of tokens. + /// To embed multiple inputs in a single request, pass an array + /// of strings or array of token arrays. + /// + public IList Input { get; } + /// + /// Optional. The number of dimensions the resulting output embeddings should have. + /// Passing null causes the model to use its default value. + /// Returns a 422 error if the model doesn't support the value or parameter. + /// + public int? Dimensions { get; set; } + /// Optional. The desired format for the returned embeddings. + public EmbeddingEncodingFormat? EncodingFormat { get; set; } + /// + /// Optional. The type of the input. + /// Returns a 422 error if the model doesn't support the value or parameter. + /// + public EmbeddingInputType? InputType { get; set; } + /// ID of the specific AI model to use, if more than one model is available on the endpoint. + public string Model { get; set; } + /// + /// Additional Properties + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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 IDictionary AdditionalProperties { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs new file mode 100644 index 000000000000..ce69ed786690 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs @@ -0,0 +1,169 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.Inference +{ + public partial class EmbeddingsResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsResult)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage, options); + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + EmbeddingsResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsResult)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddingsResult(document.RootElement, options); + } + + internal static EmbeddingsResult DeserializeEmbeddingsResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + IReadOnlyList data = default; + EmbeddingsUsage usage = default; + string model = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("data"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(EmbeddingItem.DeserializeEmbeddingItem(item, options)); + } + data = array; + continue; + } + if (property.NameEquals("usage"u8)) + { + usage = EmbeddingsUsage.DeserializeEmbeddingsUsage(property.Value, options); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new EmbeddingsResult(id, data, usage, model, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(EmbeddingsResult)} does not support writing '{options.Format}' format."); + } + } + + EmbeddingsResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddingsResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(EmbeddingsResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static EmbeddingsResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeEmbeddingsResult(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs new file mode 100644 index 000000000000..c44b8e64397b --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.Inference +{ + /// + /// Representation of the response data from an embeddings request. + /// Embeddings measure the relatedness of text strings and are commonly used for search, clustering, + /// recommendations, and other similar scenarios. + /// + public partial class EmbeddingsResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Unique identifier for the embeddings result. + /// Embedding values for the prompts submitted in the request. + /// Usage counts for tokens input using the embeddings API. + /// The model ID used to generate this result. + /// , , or is null. + internal EmbeddingsResult(string id, IEnumerable data, EmbeddingsUsage usage, string model) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(data, nameof(data)); + Argument.AssertNotNull(usage, nameof(usage)); + Argument.AssertNotNull(model, nameof(model)); + + Id = id; + Data = data.ToList(); + Usage = usage; + Model = model; + } + + /// Initializes a new instance of . + /// Unique identifier for the embeddings result. + /// Embedding values for the prompts submitted in the request. + /// Usage counts for tokens input using the embeddings API. + /// The model ID used to generate this result. + /// Keeps track of any properties unknown to the library. + internal EmbeddingsResult(string id, IReadOnlyList data, EmbeddingsUsage usage, string model, IDictionary serializedAdditionalRawData) + { + Id = id; + Data = data; + Usage = usage; + Model = model; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingsResult() + { + } + + /// Unique identifier for the embeddings result. + public string Id { get; } + /// Embedding values for the prompts submitted in the request. + public IReadOnlyList Data { get; } + /// Usage counts for tokens input using the embeddings API. + public EmbeddingsUsage Usage { get; } + /// The model ID used to generate this result. + public string Model { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs similarity index 54% rename from sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs index 0fd79deb8261..5d5efa61a1cb 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs @@ -13,21 +13,23 @@ namespace Azure.AI.Inference { - internal partial class UnknownChatCompletionsToolDefinition : IUtf8JsonSerializable, IJsonModel + public partial class EmbeddingsUsage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support writing '{format}' format."); } writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); + writer.WritePropertyName("prompt_tokens"u8); + writer.WriteNumberValue(PromptTokens); + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -46,19 +48,19 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mode writer.WriteEndObject(); } - ChatCompletionsToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + EmbeddingsUsage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsToolDefinition(document.RootElement, options); + return DeserializeEmbeddingsUsage(document.RootElement, options); } - internal static UnknownChatCompletionsToolDefinition DeserializeUnknownChatCompletionsToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + internal static EmbeddingsUsage DeserializeEmbeddingsUsage(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -66,14 +68,20 @@ internal static UnknownChatCompletionsToolDefinition DeserializeUnknownChatCompl { return null; } - string type = "Unknown"; + int promptTokens = default; + int totalTokens = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("type"u8)) + if (property.NameEquals("prompt_tokens"u8)) { - type = property.Value.GetString(); + promptTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("total_tokens"u8)) + { + totalTokens = property.Value.GetInt32(); continue; } if (options.Format != "W") @@ -82,53 +90,53 @@ internal static UnknownChatCompletionsToolDefinition DeserializeUnknownChatCompl } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownChatCompletionsToolDefinition(type, serializedAdditionalRawData); + return new EmbeddingsUsage(promptTokens, totalTokens, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support writing '{options.Format}' format."); } } - ChatCompletionsToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + EmbeddingsUsage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsToolDefinition(document.RootElement, options); + return DeserializeEmbeddingsUsage(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new UnknownChatCompletionsToolDefinition FromResponse(Response response) + internal static EmbeddingsUsage FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeUnknownChatCompletionsToolDefinition(document.RootElement); + return DeserializeEmbeddingsUsage(document.RootElement); } /// Convert into a . - internal override RequestContent ToRequestContent() + internal virtual RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs new file mode 100644 index 000000000000..f0808a074012 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Inference +{ + /// Measurement of the amount of tokens used in this request and response. + public partial class EmbeddingsUsage + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Number of tokens in the request. + /// + /// Total number of tokens transacted in this request/response. Should equal the + /// number of tokens in the request. + /// + internal EmbeddingsUsage(int promptTokens, int totalTokens) + { + PromptTokens = promptTokens; + TotalTokens = totalTokens; + } + + /// Initializes a new instance of . + /// Number of tokens in the request. + /// + /// Total number of tokens transacted in this request/response. Should equal the + /// number of tokens in the request. + /// + /// Keeps track of any properties unknown to the library. + internal EmbeddingsUsage(int promptTokens, int totalTokens, IDictionary serializedAdditionalRawData) + { + PromptTokens = promptTokens; + TotalTokens = totalTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingsUsage() + { + } + + /// Number of tokens in the request. + public int PromptTokens { get; } + /// + /// Total number of tokens transacted in this request/response. Should equal the + /// number of tokens in the request. + /// + public int TotalTokens { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ModelType.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ModelType.cs index 960fae6ae43b..c9a683ad7562 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ModelType.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ModelType.cs @@ -27,20 +27,20 @@ public ModelType(string value) private const string TextGenerationValue = "text_generation"; private const string ImageEmbeddingsValue = "image_embeddings"; private const string AudioGenerationValue = "audio_generation"; - private const string ChatValue = "chat"; + private const string ChatCompletionValue = "chat_completion"; - /// Embeddings. + /// A model capable of generating embeddings from a text. public static ModelType Embeddings { get; } = new ModelType(EmbeddingsValue); - /// Image generation. + /// A model capable of generating images from an image and text description. public static ModelType ImageGeneration { get; } = new ModelType(ImageGenerationValue); - /// Text generation. + /// A text generation model. public static ModelType TextGeneration { get; } = new ModelType(TextGenerationValue); - /// Image embeddings. + /// A model capable of generating embeddings from an image. public static ModelType ImageEmbeddings { get; } = new ModelType(ImageEmbeddingsValue); - /// Audio generation. + /// A text-to-audio generative model. public static ModelType AudioGeneration { get; } = new ModelType(AudioGenerationValue); - /// Chat completions. - public static ModelType Chat { get; } = new ModelType(ChatValue); + /// A model capable of taking chat-formatted messages and generate responses. + public static ModelType ChatCompletion { get; } = new ModelType(ChatCompletionValue); /// Determines if two values are the same. public static bool operator ==(ModelType left, ModelType right) => left.Equals(right); /// Determines if two values are not the same. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.Serialization.cs index 906c73937e89..2fc2f77b2ebc 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.Serialization.cs @@ -79,7 +79,7 @@ internal static StreamingChatChoiceUpdate DeserializeStreamingChatChoiceUpdate(J } int index = default; CompletionsFinishReason? finishReason = default; - ChatResponseMessage delta = default; + StreamingChatResponseMessageUpdate delta = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -101,7 +101,7 @@ internal static StreamingChatChoiceUpdate DeserializeStreamingChatChoiceUpdate(J } if (property.NameEquals("delta"u8)) { - delta = ChatResponseMessage.DeserializeChatResponseMessage(property.Value, options); + delta = StreamingChatResponseMessageUpdate.DeserializeStreamingChatResponseMessageUpdate(property.Value, options); continue; } if (options.Format != "W") diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.cs index f29bb1b500e4..6de0a3b1fdd7 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatChoiceUpdate.cs @@ -55,7 +55,7 @@ public partial class StreamingChatChoiceUpdate /// The reason that this chat completions choice completed its generated. /// An update to the chat message for a given chat completions prompt. /// is null. - internal StreamingChatChoiceUpdate(int index, CompletionsFinishReason? finishReason, ChatResponseMessage delta) + internal StreamingChatChoiceUpdate(int index, CompletionsFinishReason? finishReason, StreamingChatResponseMessageUpdate delta) { Argument.AssertNotNull(delta, nameof(delta)); @@ -69,7 +69,7 @@ internal StreamingChatChoiceUpdate(int index, CompletionsFinishReason? finishRea /// The reason that this chat completions choice completed its generated. /// An update to the chat message for a given chat completions prompt. /// Keeps track of any properties unknown to the library. - internal StreamingChatChoiceUpdate(int index, CompletionsFinishReason? finishReason, ChatResponseMessage delta, IDictionary serializedAdditionalRawData) + internal StreamingChatChoiceUpdate(int index, CompletionsFinishReason? finishReason, StreamingChatResponseMessageUpdate delta, IDictionary serializedAdditionalRawData) { Index = index; FinishReason = finishReason; @@ -87,6 +87,6 @@ internal StreamingChatChoiceUpdate() /// The reason that this chat completions choice completed its generated. public CompletionsFinishReason? FinishReason { get; } /// An update to the chat message for a given chat completions prompt. - public ChatResponseMessage Delta { get; } + public StreamingChatResponseMessageUpdate Delta { get; } } } diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.Serialization.cs new file mode 100644 index 000000000000..cb0ff65ffaf1 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.Serialization.cs @@ -0,0 +1,178 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.Inference +{ + public partial class StreamingChatResponseMessageUpdate : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StreamingChatResponseMessageUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Role)) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.Value.ToString()); + } + if (Optional.IsDefined(Content)) + { + writer.WritePropertyName("content"u8); + writer.WriteStringValue(Content); + } + if (Optional.IsCollectionDefined(ToolCalls)) + { + writer.WritePropertyName("tool_calls"u8); + writer.WriteStartArray(); + foreach (var item in ToolCalls) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + StreamingChatResponseMessageUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StreamingChatResponseMessageUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStreamingChatResponseMessageUpdate(document.RootElement, options); + } + + internal static StreamingChatResponseMessageUpdate DeserializeStreamingChatResponseMessageUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ChatRole? role = default; + string content = default; + IReadOnlyList toolCalls = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + role = new ChatRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("tool_calls"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(StreamingChatResponseToolCallUpdate.DeserializeStreamingChatResponseToolCallUpdate(item, options)); + } + toolCalls = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new StreamingChatResponseMessageUpdate(role, content, toolCalls ?? new ChangeTrackingList(), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(StreamingChatResponseMessageUpdate)} does not support writing '{options.Format}' format."); + } + } + + StreamingChatResponseMessageUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeStreamingChatResponseMessageUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StreamingChatResponseMessageUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static StreamingChatResponseMessageUpdate FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeStreamingChatResponseMessageUpdate(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.cs new file mode 100644 index 000000000000..8aa8cea20212 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseMessageUpdate.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Inference +{ + /// A representation of a chat message update as received in a streaming response. + public partial class StreamingChatResponseMessageUpdate + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal StreamingChatResponseMessageUpdate() + { + ToolCalls = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The chat role associated with the message. If present, should always be 'assistant'. + /// The content of the message. + /// + /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat + /// completions request to resolve as configured. + /// + /// Keeps track of any properties unknown to the library. + internal StreamingChatResponseMessageUpdate(ChatRole? role, string content, IReadOnlyList toolCalls, IDictionary serializedAdditionalRawData) + { + Role = role; + Content = content; + ToolCalls = toolCalls; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The chat role associated with the message. If present, should always be 'assistant'. + public ChatRole? Role { get; } + /// The content of the message. + public string Content { get; } + /// + /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat + /// completions request to resolve as configured. + /// + public IReadOnlyList ToolCalls { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.Serialization.cs similarity index 58% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.Serialization.cs index 2ff06c84703f..fd8490dbf5c9 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.Serialization.cs @@ -13,25 +13,23 @@ namespace Azure.AI.Inference { - public partial class ChatCompletionsFunctionToolCall : IUtf8JsonSerializable, IJsonModel + public partial class StreamingChatResponseToolCallUpdate : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(StreamingChatResponseToolCallUpdate)} does not support writing '{format}' format."); } writer.WriteStartObject(); - writer.WritePropertyName("function"u8); - writer.WriteObjectValue(Function, options); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); writer.WritePropertyName("id"u8); writer.WriteStringValue(Id); + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -50,19 +48,19 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mo writer.WriteEndObject(); } - ChatCompletionsFunctionToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + StreamingChatResponseToolCallUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(StreamingChatResponseToolCallUpdate)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsFunctionToolCall(document.RootElement, options); + return DeserializeStreamingChatResponseToolCallUpdate(document.RootElement, options); } - internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFunctionToolCall(JsonElement element, ModelReaderWriterOptions options = null) + internal static StreamingChatResponseToolCallUpdate DeserializeStreamingChatResponseToolCallUpdate(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -70,26 +68,20 @@ internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFuncti { return null; } - FunctionCall function = default; - string type = default; string id = default; + FunctionCall function = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("function"u8)) - { - function = FunctionCall.DeserializeFunctionCall(property.Value, options); - continue; - } - if (property.NameEquals("type"u8)) + if (property.NameEquals("id"u8)) { - type = property.Value.GetString(); + id = property.Value.GetString(); continue; } - if (property.NameEquals("id"u8)) + if (property.NameEquals("function"u8)) { - id = property.Value.GetString(); + function = FunctionCall.DeserializeFunctionCall(property.Value, options); continue; } if (options.Format != "W") @@ -98,50 +90,50 @@ internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFuncti } } serializedAdditionalRawData = rawDataDictionary; - return new ChatCompletionsFunctionToolCall(type, id, serializedAdditionalRawData, function); + return new StreamingChatResponseToolCallUpdate(id, function, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(StreamingChatResponseToolCallUpdate)} does not support writing '{options.Format}' format."); } } - ChatCompletionsFunctionToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + StreamingChatResponseToolCallUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeChatCompletionsFunctionToolCall(document.RootElement, options); + return DeserializeStreamingChatResponseToolCallUpdate(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(StreamingChatResponseToolCallUpdate)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new ChatCompletionsFunctionToolCall FromResponse(Response response) + internal static StreamingChatResponseToolCallUpdate FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeChatCompletionsFunctionToolCall(document.RootElement); + return DeserializeStreamingChatResponseToolCallUpdate(document.RootElement); } /// Convert into a . - internal override RequestContent ToRequestContent() + internal virtual RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.cs b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.cs new file mode 100644 index 000000000000..213468dcfc3c --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/src/Generated/StreamingChatResponseToolCallUpdate.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Inference +{ + /// An update to the function tool call information requested by the AI model. + public partial class StreamingChatResponseToolCallUpdate + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted 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" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The ID of the tool call. + /// Updates to the function call requested by the AI model. + /// or is null. + internal StreamingChatResponseToolCallUpdate(string id, FunctionCall function) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(function, nameof(function)); + + Id = id; + Function = function; + } + + /// Initializes a new instance of . + /// The ID of the tool call. + /// Updates to the function call requested by the AI model. + /// Keeps track of any properties unknown to the library. + internal StreamingChatResponseToolCallUpdate(string id, FunctionCall function, IDictionary serializedAdditionalRawData) + { + Id = id; + Function = function; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal StreamingChatResponseToolCallUpdate() + { + } + + /// The ID of the tool call. + public string Id { get; } + /// Updates to the function call requested by the AI model. + public FunctionCall Function { get; } + } +} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.cs b/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.cs deleted file mode 100644 index 27162a1f09c6..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsNamedToolSelection.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// Unknown version of ChatCompletionsNamedToolSelection. - internal partial class UnknownChatCompletionsNamedToolSelection : ChatCompletionsNamedToolSelection - { - /// Initializes a new instance of . - /// The object type. - /// Keeps track of any properties unknown to the library. - internal UnknownChatCompletionsNamedToolSelection(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) - { - } - - /// Initializes a new instance of for deserialization. - internal UnknownChatCompletionsNamedToolSelection() - { - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.cs b/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.cs deleted file mode 100644 index 647a28b0af43..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolCall.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// Unknown version of ChatCompletionsToolCall. - internal partial class UnknownChatCompletionsToolCall : ChatCompletionsToolCall - { - /// Initializes a new instance of . - /// The object type. - /// The ID of the tool call. - /// Keeps track of any properties unknown to the library. - internal UnknownChatCompletionsToolCall(string type, string id, IDictionary serializedAdditionalRawData) : base(type, id, serializedAdditionalRawData) - { - } - - /// Initializes a new instance of for deserialization. - internal UnknownChatCompletionsToolCall() - { - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.cs b/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.cs deleted file mode 100644 index b33a226a4be9..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/UnknownChatCompletionsToolDefinition.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Inference -{ - /// Unknown version of ChatCompletionsToolDefinition. - internal partial class UnknownChatCompletionsToolDefinition : ChatCompletionsToolDefinition - { - /// Initializes a new instance of . - /// The object type. - /// Keeps track of any properties unknown to the library. - internal UnknownChatCompletionsToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) - { - } - - /// Initializes a new instance of for deserialization. - internal UnknownChatCompletionsToolDefinition() - { - } - } -} diff --git a/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs b/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs new file mode 100644 index 000000000000..1244fa042540 --- /dev/null +++ b/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs @@ -0,0 +1,255 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Azure.AI.Inference.Samples +{ + public partial class Samples_EmbeddingsClient + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_Embed_MaximumSetEmbeddings() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new object()); + Response response = client.Embed(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); + Console.WriteLine(result.GetProperty("model").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_Embed_MaximumSetEmbeddings_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new object()); + Response response = await client.EmbedAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); + Console.WriteLine(result.GetProperty("model").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_Embed_MaximumSetEmbeddings_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + EmbeddingsOptions embeddingsOptions = null; + Response response = client.Embed(embeddingsOptions); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_Embed_MaximumSetEmbeddings_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + EmbeddingsOptions embeddingsOptions = null; + Response response = await client.EmbedAsync(embeddingsOptions); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_Embed_MinimumSetEmbeddings() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new object()); + Response response = client.Embed(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); + Console.WriteLine(result.GetProperty("model").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_Embed_MinimumSetEmbeddings_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + using RequestContent content = RequestContent.Create(new object()); + Response response = await client.EmbedAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("embedding").ToString()); + Console.WriteLine(result.GetProperty("data")[0].GetProperty("index").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("prompt_tokens").ToString()); + Console.WriteLine(result.GetProperty("usage").GetProperty("total_tokens").ToString()); + Console.WriteLine(result.GetProperty("model").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_Embed_MinimumSetEmbeddings_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + EmbeddingsOptions embeddingsOptions = null; + Response response = client.Embed(embeddingsOptions); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_Embed_MinimumSetEmbeddings_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + EmbeddingsOptions embeddingsOptions = null; + Response response = await client.EmbedAsync(embeddingsOptions); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_GetModelInfo_MaximumSetModelInformation() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = client.GetModelInfo(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("model_name").ToString()); + Console.WriteLine(result.GetProperty("model_type").ToString()); + Console.WriteLine(result.GetProperty("model_provider_name").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_GetModelInfo_MaximumSetModelInformation_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = await client.GetModelInfoAsync(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("model_name").ToString()); + Console.WriteLine(result.GetProperty("model_type").ToString()); + Console.WriteLine(result.GetProperty("model_provider_name").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_GetModelInfo_MaximumSetModelInformation_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = client.GetModelInfo(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_GetModelInfo_MaximumSetModelInformation_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = await client.GetModelInfoAsync(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_GetModelInfo_MinimumSetModelInformation() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = client.GetModelInfo(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("model_name").ToString()); + Console.WriteLine(result.GetProperty("model_type").ToString()); + Console.WriteLine(result.GetProperty("model_provider_name").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_GetModelInfo_MinimumSetModelInformation_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = await client.GetModelInfoAsync(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("model_name").ToString()); + Console.WriteLine(result.GetProperty("model_type").ToString()); + Console.WriteLine(result.GetProperty("model_provider_name").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Client2_GetModelInfo_MinimumSetModelInformation_Convenience() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = client.GetModelInfo(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Client2_GetModelInfo_MinimumSetModelInformation_Convenience_Async() + { + Uri endpoint = new Uri(""); + AzureKeyCredential credential = new AzureKeyCredential(""); + EmbeddingsClient client = new EmbeddingsClient(endpoint, credential); + + Response response = await client.GetModelInfoAsync(); + } + } +} diff --git a/sdk/ai/Azure.AI.Inference/tsp-location.yaml b/sdk/ai/Azure.AI.Inference/tsp-location.yaml index cb0567d7c627..6478baff3705 100644 --- a/sdk/ai/Azure.AI.Inference/tsp-location.yaml +++ b/sdk/ai/Azure.AI.Inference/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/ai/ModelClient -repo: trangevi/azure-rest-api-specs -commit: 4039eb161a839f14dd1daa1ef01bc7a475fea5ff +commit: f0e7dcdaffbbe331e0810fda83e7d81a4c152f22 +repo: Azure/azure-rest-api-specs +additionalDirectories: