From e333693af1569156ca4cde7fc837b70f911423f3 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Wed, 26 Mar 2025 17:18:24 +0000 Subject: [PATCH] CodeGen from PR 33514 in Azure/azure-rest-api-specs Merge 99e6b96d6522b49f634a2ade9562eadab0f2bc81 into e97f079559e24498564383a628277010f1ddeef7 --- .../AIInferenceClientBuilderExtensions.cs | 68 +----- .../src/Generated/AIInferenceModelFactory.cs | 95 ++++---- .../src/Generated/ChatCompletionsClient.cs | 220 ++++++++++++++++- ...ons.cs => ChatCompletionsClientOptions.cs} | 8 +- .../ChatCompletionsResponseFormat.cs | 2 +- ...sResponseFormatJsonSchema.Serialization.cs | 2 +- ...ChatCompletionsResponseFormatJsonSchema.cs | 2 +- ...ormatJsonSchemaDefinition.Serialization.cs | 2 +- ...tionsResponseFormatJsonSchemaDefinition.cs | 2 +- ...ssageAudioDataContentItem.Serialization.cs | 2 +- .../ChatMessageAudioDataContentItem.cs | 2 +- ...essageAudioUrlContentItem.Serialization.cs | 2 +- .../ChatMessageAudioUrlContentItem.cs | 2 +- .../src/Generated/ChatMessageContentItem.cs | 2 +- .../ChatMessageInputAudioUrl.Serialization.cs | 2 +- .../src/Generated/ChatMessageInputAudioUrl.cs | 2 +- ...on.cs => CompleteRequest.Serialization.cs} | 63 ++--- ...mpletionsOptions.cs => CompleteRequest.cs} | 105 ++++++-- .../src/Generated/Docs/EmbeddingsClient.xml | 101 -------- .../Generated/Docs/ImageEmbeddingsClient.xml | 101 -------- .../src/Generated/EmbeddingEncodingFormat.cs | 60 ----- .../src/Generated/EmbeddingInputType.cs | 54 ----- .../Generated/EmbeddingItem.Serialization.cs | 157 ------------ .../src/Generated/EmbeddingItem.cs | 128 ---------- .../src/Generated/EmbeddingsClient.cs | 228 ------------------ .../EmbeddingsOptions.Serialization.cs | 208 ---------------- .../src/Generated/EmbeddingsOptions.cs | 118 --------- .../EmbeddingsResult.Serialization.cs | 176 -------------- .../src/Generated/EmbeddingsResult.cs | 101 -------- .../EmbeddingsUsage.Serialization.cs | 150 ------------ .../src/Generated/EmbeddingsUsage.cs | 87 ------- .../ImageEmbeddingInput.Serialization.cs | 153 ------------ .../src/Generated/ImageEmbeddingInput.cs | 85 ------- .../src/Generated/ImageEmbeddingsClient.cs | 228 ------------------ .../ImageEmbeddingsOptions.Serialization.cs | 208 ---------------- .../src/Generated/ImageEmbeddingsOptions.cs | 123 ---------- .../Samples/Samples_EmbeddingsClient.cs | 126 ---------- .../Samples/Samples_ImageEmbeddingsClient.cs | 126 ---------- sdk/ai/Azure.AI.Inference/tsp-location.yaml | 3 +- 39 files changed, 402 insertions(+), 2902 deletions(-) rename sdk/ai/Azure.AI.Inference/src/Generated/{AzureAIInferenceClientOptions.cs => ChatCompletionsClientOptions.cs} (70%) rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsOptions.Serialization.cs => CompleteRequest.Serialization.cs} (82%) rename sdk/ai/Azure.AI.Inference/src/Generated/{ChatCompletionsOptions.cs => CompleteRequest.cs} (73%) delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/Docs/ImageEmbeddingsClient.xml delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsClient.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.Serialization.cs delete mode 100644 sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.cs delete mode 100644 sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs delete mode 100644 sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_ImageEmbeddingsClient.cs diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs index b164a88148d3..3348bd6a13c2 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceClientBuilderExtensions.cs @@ -12,89 +12,35 @@ 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)); - } - - /// 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. - /// Service host. - /// A credential used to authenticate to an Azure Service. - public static IAzureClientBuilder AddImageEmbeddingsClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) - where TBuilder : IAzureClientFactoryBuilder - { - return builder.RegisterClientFactory((options) => new ImageEmbeddingsClient(endpoint, credential, options)); - } - - /// Registers a instance. - /// The builder to register with. - /// Service host. - public static IAzureClientBuilder AddImageEmbeddingsClient(this TBuilder builder, Uri endpoint) - where TBuilder : IAzureClientFactoryBuilderWithCredential - { - return builder.RegisterClientFactory((options, cred) => new ImageEmbeddingsClient(endpoint, cred, options)); + return builder.RegisterClientFactory((options, cred) => new ChatCompletionsClient(endpoint, cred, options)); } /// Registers a instance. /// The builder to register with. /// The configuration values. - 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); - } - /// Registers a instance. - /// The builder to register with. - /// The configuration values. - public static IAzureClientBuilder AddImageEmbeddingsClient(this TBuilder builder, TConfiguration configuration) + public static IAzureClientBuilder AddChatCompletionsClient(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 8bd673de3aa2..c2fde0770668 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/AIInferenceModelFactory.cs @@ -38,6 +38,22 @@ public static ChatMessageTextContentItem ChatMessageTextContentItem(string text return new ChatMessageTextContentItem("text", serializedAdditionalRawData: null, text); } + /// Initializes a new instance of . + /// The details of the audio url. + /// A new instance for mocking. + public static ChatMessageAudioUrlContentItem ChatMessageAudioUrlContentItem(ChatMessageInputAudioUrl audioUrl = null) + { + return new ChatMessageAudioUrlContentItem("audio_url", serializedAdditionalRawData: null, audioUrl); + } + + /// Initializes a new instance of . + /// The details of the input audio data. + /// A new instance for mocking. + public static ChatMessageAudioDataContentItem ChatMessageAudioDataContentItem(ChatMessageInputAudio inputAudio = null) + { + return new ChatMessageAudioDataContentItem("input_audio", serializedAdditionalRawData: null, inputAudio); + } + /// Initializes a new instance of . /// The ID of the tool call. /// The type of tool call. Currently, only `function` is supported. @@ -57,6 +73,36 @@ public static ChatRequestToolMessage ChatRequestToolMessage(string content = nul return new ChatRequestToolMessage(ChatRole.Tool, serializedAdditionalRawData: null, content, toolCallId); } + /// Initializes a new instance of . + /// The definition of the required JSON schema in the response, and associated metadata. + /// A new instance for mocking. + public static ChatCompletionsResponseFormatJsonSchema ChatCompletionsResponseFormatJsonSchema(ChatCompletionsResponseFormatJsonSchemaDefinition jsonSchema = null) + { + return new ChatCompletionsResponseFormatJsonSchema("json_schema", serializedAdditionalRawData: null, jsonSchema); + } + + /// Initializes a new instance of . + /// A name that labels this JSON schema. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + /// + /// The definition of the JSON schema. See https://json-schema.org/overview/what-is-jsonschema. + /// Note that AI models usually only support a subset of the keywords defined by JSON schema. + /// Consult your AI model documentation to determine what is supported. + /// + /// A description of the response format, used by the AI model to determine how to generate responses in this format. + /// + /// If set to true, the service will error out if the provided JSON schema contains keywords + /// not supported by the AI model. An example of such keyword may be `maxLength` for JSON type `string`. + /// If false, and the provided JSON schema contains keywords not supported by the AI model, + /// the AI model will not error out. Instead it will ignore the unsupported keywords. + /// + /// A new instance for mocking. + public static ChatCompletionsResponseFormatJsonSchemaDefinition ChatCompletionsResponseFormatJsonSchemaDefinition(string name = null, IDictionary schema = null, string description = null, bool? strict = null) + { + schema ??= new Dictionary(); + + return new ChatCompletionsResponseFormatJsonSchemaDefinition(name, schema, description, strict, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The type of the tool. Currently, only `function` is supported. /// The function definition details for the function tool. @@ -120,55 +166,6 @@ 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 . - /// The input image encoded in base64 string as a data URL. Example: `data:image/{format};base64,{data}`. - /// - /// Optional. The text input to feed into the model (like DINO, CLIP). - /// Returns a 422 error if the model doesn't support the value or parameter. - /// - /// A new instance for mocking. - public static ImageEmbeddingInput ImageEmbeddingInput(string image = null, string text = null) - { - return new ImageEmbeddingInput(image, text, serializedAdditionalRawData: null); - } - /// Initializes a new instance of . /// A unique identifier associated with this chat completions response. /// diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs index 4bd774289ef0..aee3da5456c4 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClient.cs @@ -6,6 +6,8 @@ #nullable disable using System; +using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Azure.Core; @@ -41,7 +43,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 AzureAIInferenceClientOptions()) + public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new ChatCompletionsClientOptions()) { } @@ -49,7 +51,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 AzureAIInferenceClientOptions()) + public ChatCompletionsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new ChatCompletionsClientOptions()) { } @@ -58,11 +60,29 @@ protected ChatCompletionsClient() /// A credential used to authenticate to an Azure Service. /// The options for configuring the client. /// or is null. - public ChatCompletionsClient(Uri endpoint, TokenCredential credential, AzureAIInferenceClientOptions options) + public ChatCompletionsClient(Uri endpoint, AzureKeyCredential credential, ChatCompletionsClientOptions options) { Argument.AssertNotNull(endpoint, nameof(endpoint)); Argument.AssertNotNull(credential, nameof(credential)); - options ??= new AzureAIInferenceClientOptions(); + options ??= new ChatCompletionsClientOptions(); + + 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 ChatCompletionsClient. + /// Service host. + /// 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) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new ChatCompletionsClientOptions(); ClientDiagnostics = new ClientDiagnostics(options, true); _tokenCredential = credential; @@ -71,6 +91,198 @@ public ChatCompletionsClient(Uri endpoint, TokenCredential credential, AzureAIIn _apiVersion = options.Version; } + /// + /// Gets chat completions for the provided chat messages. + /// Completions support a wide variety of tasks and generate text that continues from or "completes" + /// provided prompt data. The method makes a REST API call to the `/chat/completions` route + /// on the given endpoint. + /// + /// + /// The collection of context messages associated with this chat completions request. + /// Typical usage begins with a chat message for the System role that provides instructions for + /// the behavior of the assistant, followed by alternating messages between the User and + /// Assistant roles. + /// + /// + /// A value that influences the probability of generated tokens appearing based on their cumulative + /// frequency in generated text. + /// Positive values will make tokens less likely to appear as their frequency increases and + /// decrease the likelihood of the model repeating the same statements verbatim. + /// Supported range is [-2, 2]. + /// + /// A value indicating whether chat completions should be streamed for this request. + /// + /// A value that influences the probability of generated tokens appearing based on their existing + /// presence in generated text. + /// Positive values will make tokens less likely to appear when they already exist and increase the + /// model's likelihood to output new topics. + /// Supported range is [-2, 2]. + /// + /// + /// The sampling temperature to use that controls the apparent creativity of generated completions. + /// Higher values will make output more random while lower values will make results more focused + /// and deterministic. + /// It is not recommended to modify temperature and top_p for the same completions request as the + /// interaction of these two settings is difficult to predict. + /// Supported range is [0, 1]. + /// + /// + /// An alternative to sampling with temperature called nucleus sampling. This value causes the + /// model to consider the results of tokens with the provided probability mass. As an example, a + /// value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be + /// considered. + /// It is not recommended to modify temperature and top_p for the same completions request as the + /// interaction of these two settings is difficult to predict. + /// Supported range is [0, 1]. + /// + /// The maximum number of tokens to generate. + /// + /// An object specifying the format that the model must output. + /// + /// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures the model will match your supplied JSON schema. + /// + /// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates is valid JSON. + /// + /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. + /// + /// A collection of textual sequences that will end completions generation. + /// + /// 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. + /// + /// If specified, the system will make a best effort to sample deterministically such that repeated requests with the + /// same seed and parameters should return the same result. Determinism is not guaranteed. + /// + /// ID of the specific AI model to use, if more than one model is available on the 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. + internal virtual async Task> CompleteAsync(IEnumerable messages, float? frequencyPenalty = null, bool? internalShouldStreamResponse = null, float? presencePenalty = null, float? temperature = null, float? nucleusSamplingFactor = null, int? maxTokens = null, ChatCompletionsResponseFormat responseFormat = null, IEnumerable stopSequences = null, IEnumerable tools = null, BinaryData toolChoice = null, long? seed = null, string model = null, ExtraParameters? extraParams = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(messages, nameof(messages)); + + CompleteRequest completeRequest = new CompleteRequest( + messages.ToList(), + frequencyPenalty, + internalShouldStreamResponse, + presencePenalty, + temperature, + nucleusSamplingFactor, + maxTokens, + responseFormat, + stopSequences?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), + tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), + toolChoice, + seed, + model, + null); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await CompleteAsync(completeRequest.ToRequestContent(), extraParams?.ToString(), context).ConfigureAwait(false); + return Response.FromValue(ChatCompletions.FromResponse(response), response); + } + + /// + /// Gets chat completions for the provided chat messages. + /// Completions support a wide variety of tasks and generate text that continues from or "completes" + /// provided prompt data. The method makes a REST API call to the `/chat/completions` route + /// on the given endpoint. + /// + /// + /// The collection of context messages associated with this chat completions request. + /// Typical usage begins with a chat message for the System role that provides instructions for + /// the behavior of the assistant, followed by alternating messages between the User and + /// Assistant roles. + /// + /// + /// A value that influences the probability of generated tokens appearing based on their cumulative + /// frequency in generated text. + /// Positive values will make tokens less likely to appear as their frequency increases and + /// decrease the likelihood of the model repeating the same statements verbatim. + /// Supported range is [-2, 2]. + /// + /// A value indicating whether chat completions should be streamed for this request. + /// + /// A value that influences the probability of generated tokens appearing based on their existing + /// presence in generated text. + /// Positive values will make tokens less likely to appear when they already exist and increase the + /// model's likelihood to output new topics. + /// Supported range is [-2, 2]. + /// + /// + /// The sampling temperature to use that controls the apparent creativity of generated completions. + /// Higher values will make output more random while lower values will make results more focused + /// and deterministic. + /// It is not recommended to modify temperature and top_p for the same completions request as the + /// interaction of these two settings is difficult to predict. + /// Supported range is [0, 1]. + /// + /// + /// An alternative to sampling with temperature called nucleus sampling. This value causes the + /// model to consider the results of tokens with the provided probability mass. As an example, a + /// value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be + /// considered. + /// It is not recommended to modify temperature and top_p for the same completions request as the + /// interaction of these two settings is difficult to predict. + /// Supported range is [0, 1]. + /// + /// The maximum number of tokens to generate. + /// + /// An object specifying the format that the model must output. + /// + /// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures the model will match your supplied JSON schema. + /// + /// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates is valid JSON. + /// + /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. + /// + /// A collection of textual sequences that will end completions generation. + /// + /// 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. + /// + /// If specified, the system will make a best effort to sample deterministically such that repeated requests with the + /// same seed and parameters should return the same result. Determinism is not guaranteed. + /// + /// ID of the specific AI model to use, if more than one model is available on the 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. + internal virtual Response Complete(IEnumerable messages, float? frequencyPenalty = null, bool? internalShouldStreamResponse = null, float? presencePenalty = null, float? temperature = null, float? nucleusSamplingFactor = null, int? maxTokens = null, ChatCompletionsResponseFormat responseFormat = null, IEnumerable stopSequences = null, IEnumerable tools = null, BinaryData toolChoice = null, long? seed = null, string model = null, ExtraParameters? extraParams = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(messages, nameof(messages)); + + CompleteRequest completeRequest = new CompleteRequest( + messages.ToList(), + frequencyPenalty, + internalShouldStreamResponse, + presencePenalty, + temperature, + nucleusSamplingFactor, + maxTokens, + responseFormat, + stopSequences?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), + tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), + toolChoice, + seed, + model, + null); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = Complete(completeRequest.ToRequestContent(), extraParams?.ToString(), context); + return Response.FromValue(ChatCompletions.FromResponse(response), response); + } + /// /// Returns information about the AI model. /// The method makes a REST API call to the `/info` route on the given endpoint. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs similarity index 70% rename from sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs index 46dcb4716cad..e68f1c4ec7fb 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/AzureAIInferenceClientOptions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsClientOptions.cs @@ -10,8 +10,8 @@ namespace Azure.AI.Inference { - /// Client options for Azure.AI.Inference library clients. - public partial class AzureAIInferenceClientOptions : ClientOptions + /// Client options for ChatCompletionsClient. + public partial class ChatCompletionsClientOptions : 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 AzureAIInferenceClientOptions. - public AzureAIInferenceClientOptions(ServiceVersion version = LatestVersion) + /// Initializes new instance of ChatCompletionsClientOptions. + public ChatCompletionsClientOptions(ServiceVersion version = LatestVersion) { Version = version switch { diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormat.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormat.cs index 0bb1aeceeb2a..4c0e48732ac6 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormat.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormat.cs @@ -15,7 +15,7 @@ namespace Azure.AI.Inference /// Note that to enable JSON mode, some AI models may also require you to instruct the model to produce JSON /// via a system or user message. /// 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 and . + /// The available derived classes include , and . /// public abstract partial class ChatCompletionsResponseFormat { diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.Serialization.cs index 27b9d9c6e41e..583f02f1bc1c 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference { - internal partial class ChatCompletionsResponseFormatJsonSchema : IUtf8JsonSerializable, IJsonModel + public partial class ChatCompletionsResponseFormatJsonSchema : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.cs index f6932d2b4955..58f1ede0d3b0 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchema.cs @@ -14,7 +14,7 @@ namespace Azure.AI.Inference /// A response format for Chat Completions that restricts responses to emitting valid JSON objects, with a /// JSON schema specified by the caller. /// - internal partial class ChatCompletionsResponseFormatJsonSchema : ChatCompletionsResponseFormat + public partial class ChatCompletionsResponseFormatJsonSchema : ChatCompletionsResponseFormat { /// Initializes a new instance of . /// The definition of the required JSON schema in the response, and associated metadata. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.Serialization.cs index 293b368904eb..e2ef56fe85e7 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference { - internal partial class ChatCompletionsResponseFormatJsonSchemaDefinition : IUtf8JsonSerializable, IJsonModel + public partial class ChatCompletionsResponseFormatJsonSchemaDefinition : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.cs index 749179704791..2f57877b44ae 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsResponseFormatJsonSchemaDefinition.cs @@ -14,7 +14,7 @@ namespace Azure.AI.Inference /// Defines the response format for chat completions as JSON with a given schema. /// The AI model will need to adhere to this schema when generating completions. /// - internal partial class ChatCompletionsResponseFormatJsonSchemaDefinition + public partial class ChatCompletionsResponseFormatJsonSchemaDefinition { /// /// Keeps track of any properties unknown to the library. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.Serialization.cs index 22cef9b1ea34..ea763c25ae97 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference { - internal partial class ChatMessageAudioDataContentItem : IUtf8JsonSerializable, IJsonModel + public partial class ChatMessageAudioDataContentItem : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.cs index 28f939ee09a9..de8ead7ebcce 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioDataContentItem.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Inference { /// A structured chat content item for audio content passed as base64 encoded data. - internal partial class ChatMessageAudioDataContentItem : ChatMessageContentItem + public partial class ChatMessageAudioDataContentItem : ChatMessageContentItem { /// Initializes a new instance of . /// The details of the input audio data. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.Serialization.cs index 62f4b2fe15ca..64c0debaa2e6 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference { - internal partial class ChatMessageAudioUrlContentItem : IUtf8JsonSerializable, IJsonModel + public partial class ChatMessageAudioUrlContentItem : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.cs index 36aa6cad1fe0..27b2c755180b 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageAudioUrlContentItem.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Inference { /// A structured chat content item for audio content passed as a url. - internal partial class ChatMessageAudioUrlContentItem : ChatMessageContentItem + public partial class ChatMessageAudioUrlContentItem : ChatMessageContentItem { /// Initializes a new instance of . /// The details of the audio url. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageContentItem.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageContentItem.cs index 3c1131052b9b..005c8f3090b9 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageContentItem.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageContentItem.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference /// /// An abstract representation of a structured content item within a chat message. /// 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 and . + /// The available derived classes include , , and . /// public abstract partial class ChatMessageContentItem { diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.Serialization.cs index d644daee2e96..0552bd96a5d9 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.Serialization.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Inference { - internal partial class ChatMessageInputAudioUrl : IUtf8JsonSerializable, IJsonModel + public partial class ChatMessageInputAudioUrl : IUtf8JsonSerializable, IJsonModel { void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.cs index 3d10e3b2eede..df89ba820d20 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/ChatMessageInputAudioUrl.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Inference { /// The details of the audio url. - internal partial class ChatMessageInputAudioUrl + public partial class ChatMessageInputAudioUrl { /// /// Keeps track of any properties unknown to the library. diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.Serialization.cs similarity index 82% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.Serialization.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.Serialization.cs index 3d353d1c67d8..5f529fd16cd5 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.Serialization.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.Serialization.cs @@ -13,25 +13,32 @@ namespace Azure.AI.Inference { - public partial class ChatCompletionsOptions : IUtf8JsonSerializable, IJsonModel + internal partial class CompleteRequest : 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) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } /// The JSON writer. /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(ChatCompletionsOptions)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(CompleteRequest)} does not support writing '{format}' format."); } writer.WritePropertyName("messages"u8); writer.WriteStartArray(); foreach (var item in Messages) { - writer.WriteObjectValue(item, options); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); if (Optional.IsDefined(FrequencyPenalty)) @@ -89,13 +96,13 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteEndArray(); } - if (Optional.IsDefined(InternalSuppressedToolChoice)) + if (Optional.IsDefined(ToolChoice)) { writer.WritePropertyName("tool_choice"u8); #if NET6_0_OR_GREATER - writer.WriteRawValue(InternalSuppressedToolChoice); + writer.WriteRawValue(ToolChoice); #else - using (JsonDocument document = JsonDocument.Parse(InternalSuppressedToolChoice, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(ToolChoice, ModelSerializationExtensions.JsonDocumentOptions)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -125,19 +132,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - ChatCompletionsOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + CompleteRequest 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(ChatCompletionsOptions)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(CompleteRequest)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeChatCompletionsOptions(document.RootElement, options); + return DeserializeCompleteRequest(document.RootElement, options); } - internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonElement element, ModelReaderWriterOptions options = null) + internal static CompleteRequest DeserializeCompleteRequest(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -145,7 +152,7 @@ internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonEle { return null; } - IList messages = default; + IReadOnlyList messages = default; float? frequencyPenalty = default; bool? stream = default; float? presencePenalty = default; @@ -153,12 +160,12 @@ internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonEle float? topP = default; int? maxTokens = default; ChatCompletionsResponseFormat responseFormat = default; - IList stop = default; - IList tools = default; + IReadOnlyList stop = default; + IReadOnlyList tools = default; BinaryData toolChoice = default; long? seed = default; string model = default; - IDictionary additionalProperties = default; + IReadOnlyDictionary additionalProperties = default; Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { @@ -289,7 +296,7 @@ internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonEle additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } additionalProperties = additionalPropertiesDictionary; - return new ChatCompletionsOptions( + return new CompleteRequest( messages, frequencyPenalty, stream, @@ -306,43 +313,43 @@ internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonEle additionalProperties); } - 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(ChatCompletionsOptions)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(CompleteRequest)} does not support writing '{options.Format}' format."); } } - ChatCompletionsOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + CompleteRequest 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeChatCompletionsOptions(document.RootElement, options); + return DeserializeCompleteRequest(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ChatCompletionsOptions)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(CompleteRequest)} 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 ChatCompletionsOptions FromResponse(Response response) + internal static CompleteRequest FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeChatCompletionsOptions(document.RootElement); + return DeserializeCompleteRequest(document.RootElement); } /// Convert into a . diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.cs similarity index 73% rename from sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs rename to sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.cs index 7bcda3441011..0dc749a8bf69 100644 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ChatCompletionsOptions.cs +++ b/sdk/ai/Azure.AI.Inference/src/Generated/CompleteRequest.cs @@ -11,14 +11,10 @@ namespace Azure.AI.Inference { - /// - /// The configuration information for a chat completions request. - /// Completions support a wide variety of tasks and generate text that continues from or "completes" - /// provided prompt data. - /// - public partial class ChatCompletionsOptions + /// The CompleteRequest. + internal partial class CompleteRequest { - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The collection of context messages associated with this chat completions request. /// Typical usage begins with a chat message for the System role that provides instructions for @@ -28,7 +24,7 @@ public partial class ChatCompletionsOptions /// The available derived classes include , , , and . /// /// is null. - public ChatCompletionsOptions(IEnumerable messages) + internal CompleteRequest(IEnumerable messages) { Argument.AssertNotNull(messages, nameof(messages)); @@ -38,7 +34,7 @@ public ChatCompletionsOptions(IEnumerable messages) AdditionalProperties = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The collection of context messages associated with this chat completions request. /// Typical usage begins with a chat message for the System role that provides instructions for @@ -89,21 +85,21 @@ public ChatCompletionsOptions(IEnumerable messages) /// /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. /// 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 and . + /// The available derived classes include , and . /// /// A collection of textual sequences that will end completions generation. /// /// 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. + /// If specified, the model will configure which of the provided tools it can use for the chat completions response. /// /// If specified, the system will make a best effort to sample deterministically such that repeated requests with the /// same seed and parameters should return the same result. Determinism is not guaranteed. /// /// ID of the specific AI model to use, if more than one model is available on the endpoint. /// Additional Properties. - internal ChatCompletionsOptions(IList messages, float? frequencyPenalty, bool? internalShouldStreamResponse, float? presencePenalty, float? temperature, float? nucleusSamplingFactor, int? maxTokens, ChatCompletionsResponseFormat responseFormat, IList stopSequences, IList tools, BinaryData internalSuppressedToolChoice, long? seed, string model, IDictionary additionalProperties) + internal CompleteRequest(IReadOnlyList messages, float? frequencyPenalty, bool? internalShouldStreamResponse, float? presencePenalty, float? temperature, float? nucleusSamplingFactor, int? maxTokens, ChatCompletionsResponseFormat responseFormat, IReadOnlyList stopSequences, IReadOnlyList tools, BinaryData toolChoice, long? seed, string model, IReadOnlyDictionary additionalProperties) { Messages = messages; FrequencyPenalty = frequencyPenalty; @@ -115,11 +111,26 @@ internal ChatCompletionsOptions(IList messages, float? frequ ResponseFormat = responseFormat; StopSequences = stopSequences; Tools = tools; - InternalSuppressedToolChoice = internalSuppressedToolChoice; + ToolChoice = toolChoice; Seed = seed; Model = model; AdditionalProperties = additionalProperties; } + + /// Initializes a new instance of for deserialization. + internal CompleteRequest() + { + } + + /// + /// The collection of context messages associated with this chat completions request. + /// Typical usage begins with a chat message for the System role that provides instructions for + /// the behavior of the assistant, followed by alternating messages between the User and + /// Assistant roles. + /// 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 , , , and . + /// + public IReadOnlyList Messages { get; } /// /// A value that influences the probability of generated tokens appearing based on their cumulative /// frequency in generated text. @@ -127,7 +138,9 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// decrease the likelihood of the model repeating the same statements verbatim. /// Supported range is [-2, 2]. /// - public float? FrequencyPenalty { get; set; } + public float? FrequencyPenalty { get; } + /// A value indicating whether chat completions should be streamed for this request. + public bool? InternalShouldStreamResponse { get; } /// /// A value that influences the probability of generated tokens appearing based on their existing /// presence in generated text. @@ -135,7 +148,7 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// model's likelihood to output new topics. /// Supported range is [-2, 2]. /// - public float? PresencePenalty { get; set; } + public float? PresencePenalty { get; } /// /// The sampling temperature to use that controls the apparent creativity of generated completions. /// Higher values will make output more random while lower values will make results more focused @@ -144,7 +157,7 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// interaction of these two settings is difficult to predict. /// Supported range is [0, 1]. /// - public float? Temperature { get; set; } + public float? Temperature { get; } /// /// An alternative to sampling with temperature called nucleus sampling. This value causes the /// model to consider the results of tokens with the provided probability mass. As an example, a @@ -154,9 +167,9 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// interaction of these two settings is difficult to predict. /// Supported range is [0, 1]. /// - public float? NucleusSamplingFactor { get; set; } + public float? NucleusSamplingFactor { get; } /// The maximum number of tokens to generate. - public int? MaxTokens { get; set; } + public int? MaxTokens { get; } /// /// An object specifying the format that the model must output. /// @@ -166,23 +179,65 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. /// 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 and . + /// The available derived classes include , and . /// - public ChatCompletionsResponseFormat ResponseFormat { get; set; } + public ChatCompletionsResponseFormat ResponseFormat { get; } /// A collection of textual sequences that will end completions generation. - public IList StopSequences { get; } + public IReadOnlyList StopSequences { get; } /// /// 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; } + public IReadOnlyList Tools { get; } + /// + /// If specified, the model will configure which of the provided tools it can use for the chat completions response. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// 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 ToolChoice { get; } /// /// If specified, the system will make a best effort to sample deterministically such that repeated requests with the /// same seed and parameters should return the same result. Determinism is not guaranteed. /// - public long? Seed { get; set; } + public long? Seed { get; } /// ID of the specific AI model to use, if more than one model is available on the endpoint. - public string Model { get; set; } + public string Model { get; } /// /// Additional Properties /// @@ -213,6 +268,6 @@ internal ChatCompletionsOptions(IList messages, float? frequ /// /// /// - public IDictionary AdditionalProperties { get; } + public IReadOnlyDictionary AdditionalProperties { 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 deleted file mode 100644 index 54f0260f0b6b..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/Docs/EmbeddingsClient.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - -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/Docs/ImageEmbeddingsClient.xml b/sdk/ai/Azure.AI.Inference/src/Generated/Docs/ImageEmbeddingsClient.xml deleted file mode 100644 index 280a6ad03aa7..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/Docs/ImageEmbeddingsClient.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - -This sample shows how to call GetModelInfoAsync. -"); -AzureKeyCredential credential = new AzureKeyCredential(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - -Response response = await client.GetModelInfoAsync(); -]]> -This sample shows how to call GetModelInfoAsync. -"); -AzureKeyCredential credential = new AzureKeyCredential(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - -Response response = await client.GetModelInfoAsync(); -]]> - - - -This sample shows how to call GetModelInfo. -"); -AzureKeyCredential credential = new AzureKeyCredential(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - -Response response = client.GetModelInfo(); -]]> -This sample shows how to call GetModelInfo. -"); -AzureKeyCredential credential = new AzureKeyCredential(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - -Response response = client.GetModelInfo(); -]]> - - - -This sample shows how to call GetModelInfoAsync and parse the result. -"); -AzureKeyCredential credential = new AzureKeyCredential(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(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(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(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(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(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(""); -ImageEmbeddingsClient client = new ImageEmbeddingsClient(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/EmbeddingEncodingFormat.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs deleted file mode 100644 index 968dfae30f12..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingEncodingFormat.cs +++ /dev/null @@ -1,60 +0,0 @@ -// 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 SingleValue = "float"; - private const string SByteValue = "int8"; - private const string UbinaryValue = "ubinary"; - private const string ByteValue = "uint8"; - - /// Base64. - public static EmbeddingEncodingFormat Base64 { get; } = new EmbeddingEncodingFormat(Base64Value); - /// Binary. - public static EmbeddingEncodingFormat Binary { get; } = new EmbeddingEncodingFormat(BinaryValue); - /// ubinary. - public static EmbeddingEncodingFormat Ubinary { get; } = new EmbeddingEncodingFormat(UbinaryValue); - /// 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 deleted file mode 100644 index 9e75eba6dc3c..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingInputType.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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/EmbeddingItem.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs deleted file mode 100644 index bedb417a16e3..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.Serialization.cs +++ /dev/null @@ -1,157 +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 EmbeddingItem : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(EmbeddingItem)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("embedding"u8); -#if NET6_0_OR_GREATER - writer.WriteRawValue(Embedding); -#else - using (JsonDocument document = JsonDocument.Parse(Embedding, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - writer.WritePropertyName("index"u8); - writer.WriteNumberValue(Index); - 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, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - EmbeddingItem 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(EmbeddingItem)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeEmbeddingItem(document.RootElement, options); - } - - internal static EmbeddingItem DeserializeEmbeddingItem(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - BinaryData embedding = default; - int index = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("embedding"u8)) - { - embedding = BinaryData.FromString(property.Value.GetRawText()); - continue; - } - if (property.NameEquals("index"u8)) - { - index = property.Value.GetInt32(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new EmbeddingItem(embedding, index, 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(EmbeddingItem)} does not support writing '{options.Format}' format."); - } - } - - EmbeddingItem 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeEmbeddingItem(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(EmbeddingItem)} 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 EmbeddingItem FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeEmbeddingItem(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/EmbeddingItem.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs deleted file mode 100644 index 676f0aba0bc7..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingItem.cs +++ /dev/null @@ -1,128 +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 -{ - /// 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 deleted file mode 100644 index 2b2f1bed6a53..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsClient.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -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, 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; - } - - /// - /// 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 deleted file mode 100644 index 85641804f737..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.Serialization.cs +++ /dev/null @@ -1,208 +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 EmbeddingsOptions : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(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.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, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - - 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, ModelSerializationExtensions.JsonDocumentOptions); - 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, ModelSerializationExtensions.JsonDocumentOptions); - 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 deleted file mode 100644 index 879babca6604..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsOptions.cs +++ /dev/null @@ -1,118 +0,0 @@ -// 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 deleted file mode 100644 index fbeae8c0a6ec..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.Serialization.cs +++ /dev/null @@ -1,176 +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 EmbeddingsResult : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(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.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, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - 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, ModelSerializationExtensions.JsonDocumentOptions); - 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, ModelSerializationExtensions.JsonDocumentOptions); - 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 deleted file mode 100644 index c44b8e64397b..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsResult.cs +++ /dev/null @@ -1,101 +0,0 @@ -// 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/EmbeddingsUsage.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs deleted file mode 100644 index 5315f328448a..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.Serialization.cs +++ /dev/null @@ -1,150 +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 EmbeddingsUsage : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support writing '{format}' format."); - } - - 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) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - EmbeddingsUsage 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(EmbeddingsUsage)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeEmbeddingsUsage(document.RootElement, options); - } - - internal static EmbeddingsUsage DeserializeEmbeddingsUsage(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - int promptTokens = default; - int totalTokens = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("prompt_tokens"u8)) - { - promptTokens = property.Value.GetInt32(); - continue; - } - if (property.NameEquals("total_tokens"u8)) - { - totalTokens = property.Value.GetInt32(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new EmbeddingsUsage(promptTokens, totalTokens, 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(EmbeddingsUsage)} does not support writing '{options.Format}' format."); - } - } - - EmbeddingsUsage 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeEmbeddingsUsage(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(EmbeddingsUsage)} 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 EmbeddingsUsage FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeEmbeddingsUsage(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/EmbeddingsUsage.cs b/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs deleted file mode 100644 index f0808a074012..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/EmbeddingsUsage.cs +++ /dev/null @@ -1,87 +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 -{ - /// 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/ImageEmbeddingInput.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.Serialization.cs deleted file mode 100644 index b9898e808b01..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.Serialization.cs +++ /dev/null @@ -1,153 +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 ImageEmbeddingInput : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ImageEmbeddingInput)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("image"u8); - writer.WriteStringValue(Image); - if (Optional.IsDefined(Text)) - { - writer.WritePropertyName("text"u8); - writer.WriteStringValue(Text); - } - 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, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - ImageEmbeddingInput 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(ImageEmbeddingInput)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeImageEmbeddingInput(document.RootElement, options); - } - - internal static ImageEmbeddingInput DeserializeImageEmbeddingInput(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string image = default; - string text = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("image"u8)) - { - image = property.Value.GetString(); - continue; - } - if (property.NameEquals("text"u8)) - { - text = property.Value.GetString(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new ImageEmbeddingInput(image, text, 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(ImageEmbeddingInput)} does not support writing '{options.Format}' format."); - } - } - - ImageEmbeddingInput 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeImageEmbeddingInput(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(ImageEmbeddingInput)} 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 ImageEmbeddingInput FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeImageEmbeddingInput(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/ImageEmbeddingInput.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.cs deleted file mode 100644 index 2ac62dd102f2..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingInput.cs +++ /dev/null @@ -1,85 +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 -{ - /// Represents an image with optional text. - public partial class ImageEmbeddingInput - { - /// - /// 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 input image encoded in base64 string as a data URL. Example: `data:image/{format};base64,{data}`. - /// is null. - public ImageEmbeddingInput(string image) - { - Argument.AssertNotNull(image, nameof(image)); - - Image = image; - } - - /// Initializes a new instance of . - /// The input image encoded in base64 string as a data URL. Example: `data:image/{format};base64,{data}`. - /// - /// Optional. The text input to feed into the model (like DINO, CLIP). - /// Returns a 422 error if the model doesn't support the value or parameter. - /// - /// Keeps track of any properties unknown to the library. - internal ImageEmbeddingInput(string image, string text, IDictionary serializedAdditionalRawData) - { - Image = image; - Text = text; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal ImageEmbeddingInput() - { - } - - /// The input image encoded in base64 string as a data URL. Example: `data:image/{format};base64,{data}`. - public string Image { get; } - /// - /// Optional. The text input to feed into the model (like DINO, CLIP). - /// Returns a 422 error if the model doesn't support the value or parameter. - /// - public string Text { get; set; } - } -} diff --git a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsClient.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsClient.cs deleted file mode 100644 index 9bf443cc4dcf..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsClient.cs +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.AI.Inference -{ - // Data plane generated client. - /// The ImageEmbeddings service client. - public partial class ImageEmbeddingsClient - { - 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 ImageEmbeddingsClient for mocking. - protected ImageEmbeddingsClient() - { - } - - /// Initializes a new instance of ImageEmbeddingsClient. - /// Service host. - /// A credential used to authenticate to an Azure Service. - /// or is null. - public ImageEmbeddingsClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) - { - } - - /// Initializes a new instance of ImageEmbeddingsClient. - /// Service host. - /// A credential used to authenticate to an Azure Service. - /// or is null. - public ImageEmbeddingsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new AzureAIInferenceClientOptions()) - { - } - - /// Initializes a new instance of ImageEmbeddingsClient. - /// Service host. - /// A credential used to authenticate to an Azure Service. - /// The options for configuring the client. - /// or is null. - public ImageEmbeddingsClient(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; - } - - /// - /// 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("ImageEmbeddingsClient.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("ImageEmbeddingsClient.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("/images/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/ImageEmbeddingsOptions.Serialization.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.Serialization.cs deleted file mode 100644 index 9c051c63fb5a..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.Serialization.cs +++ /dev/null @@ -1,208 +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 ImageEmbeddingsOptions : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ImageEmbeddingsOptions)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("input"u8); - writer.WriteStartArray(); - foreach (var item in Input) - { - writer.WriteObjectValue(item, options); - } - 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, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - - ImageEmbeddingsOptions 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(ImageEmbeddingsOptions)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeImageEmbeddingsOptions(document.RootElement, options); - } - - internal static ImageEmbeddingsOptions DeserializeImageEmbeddingsOptions(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(ImageEmbeddingInput.DeserializeImageEmbeddingInput(item, options)); - } - 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 ImageEmbeddingsOptions( - 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(ImageEmbeddingsOptions)} does not support writing '{options.Format}' format."); - } - } - - ImageEmbeddingsOptions 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeImageEmbeddingsOptions(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(ImageEmbeddingsOptions)} 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 ImageEmbeddingsOptions FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeImageEmbeddingsOptions(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/ImageEmbeddingsOptions.cs b/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.cs deleted file mode 100644 index e4e9a3b5b99f..000000000000 --- a/sdk/ai/Azure.AI.Inference/src/Generated/ImageEmbeddingsOptions.cs +++ /dev/null @@ -1,123 +0,0 @@ -// 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 image embeddings request. - public partial class ImageEmbeddingsOptions - { - /// Initializes a new instance of . - /// - /// Input image to embed. To embed multiple inputs in a single request, pass an array. - /// The input must not exceed the max input tokens for the model. - /// - /// is null. - public ImageEmbeddingsOptions(IEnumerable input) - { - Argument.AssertNotNull(input, nameof(input)); - - Input = input.ToList(); - AdditionalProperties = new ChangeTrackingDictionary(); - } - - /// Initializes a new instance of . - /// - /// Input image to embed. To embed multiple inputs in a single request, pass an array. - /// The input must not exceed the max input tokens for the model. - /// - /// - /// 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 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 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 ImageEmbeddingsOptions(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 ImageEmbeddingsOptions() - { - } - - /// - /// Input image to embed. To embed multiple inputs in a single request, pass an array. - /// The input must not exceed the max input tokens for the model. - /// - 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 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 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/tests/Generated/Samples/Samples_EmbeddingsClient.cs b/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.cs deleted file mode 100644 index a6f43d432014..000000000000 --- a/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_EmbeddingsClient.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.Text.Json; -using System.Threading.Tasks; -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_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/tests/Generated/Samples/Samples_ImageEmbeddingsClient.cs b/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_ImageEmbeddingsClient.cs deleted file mode 100644 index 7c068f00b89c..000000000000 --- a/sdk/ai/Azure.AI.Inference/tests/Generated/Samples/Samples_ImageEmbeddingsClient.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.Text.Json; -using System.Threading.Tasks; -using Azure.Identity; -using NUnit.Framework; - -namespace Azure.AI.Inference.Samples -{ - public partial class Samples_ImageEmbeddingsClient - { - [Test] - [Ignore("Only validating compilation of examples")] - public void Example_Client3_GetModelInfo_MaximumSetModelInformation() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(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_Client3_GetModelInfo_MaximumSetModelInformation_Async() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(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_Client3_GetModelInfo_MaximumSetModelInformation_Convenience() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - - Response response = client.GetModelInfo(); - } - - [Test] - [Ignore("Only validating compilation of examples")] - public async Task Example_Client3_GetModelInfo_MaximumSetModelInformation_Convenience_Async() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - - Response response = await client.GetModelInfoAsync(); - } - - [Test] - [Ignore("Only validating compilation of examples")] - public void Example_Client3_GetModelInfo_MinimumSetModelInformation() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(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_Client3_GetModelInfo_MinimumSetModelInformation_Async() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(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_Client3_GetModelInfo_MinimumSetModelInformation_Convenience() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(endpoint, credential); - - Response response = client.GetModelInfo(); - } - - [Test] - [Ignore("Only validating compilation of examples")] - public async Task Example_Client3_GetModelInfo_MinimumSetModelInformation_Convenience_Async() - { - Uri endpoint = new Uri(""); - AzureKeyCredential credential = new AzureKeyCredential(""); - ImageEmbeddingsClient client = new ImageEmbeddingsClient(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 89acd64c8262..bd2a231d9545 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 +commit: ea9c3aab94a092323ba9c9d2756106b531f8e499 repo: Azure/azure-rest-api-specs -commit: 317bc61a428bdbc6113f375f7c22b8575eff041f +additionalDirectories: