diff --git a/sdk/keyvault/Azure.Security.KeyVault.Administration/tsp-location.yaml b/sdk/keyvault/Azure.Security.KeyVault.Administration/tsp-location.yaml
index 1bca575d59ae..39d8d7dff629 100644
--- a/sdk/keyvault/Azure.Security.KeyVault.Administration/tsp-location.yaml
+++ b/sdk/keyvault/Azure.Security.KeyVault.Administration/tsp-location.yaml
@@ -1,9 +1,8 @@
directory: specification/keyvault/Security.KeyVault.Administration
-commit: b0a48bcbffead733affe03944ef09f5e8d12f8c8
+commit: 3e32fe20d37f48f3d0acd301e71b43586ed85348
repo: Azure/azure-rest-api-specs
-
-additionalDirectories:
-- specification/keyvault/Security.KeyVault.BackupRestore/
-- specification/keyvault/Security.KeyVault.Common/
-- specification/keyvault/Security.KeyVault.RBAC/
-- specification/keyvault/Security.KeyVault.Settings/
+additionalDirectories:
+- specification/keyvault/Security.KeyVault.BackupRestore
+- specification/keyvault/Security.KeyVault.Common
+- specification/keyvault/Security.KeyVault.RBAC
+- specification/keyvault/Security.KeyVault.Settings
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/Azure.AI.ChatProtocol.sln b/sdk/machinelearning/Azure.AI.ChatProtocol/Azure.AI.ChatProtocol.sln
new file mode 100644
index 000000000000..24a7e22f8cce
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/Azure.AI.ChatProtocol.sln
@@ -0,0 +1,56 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29709.97
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{ECC730C1-4AEA-420C-916A-66B19B79E4DC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.ChatProtocol", "src\Azure.AI.ChatProtocol.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.ChatProtocol.Tests", "tests\Azure.AI.ChatProtocol.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
+ EndGlobalSection
+EndGlobal
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/CHANGELOG.md b/sdk/machinelearning/Azure.AI.ChatProtocol/CHANGELOG.md
new file mode 100644
index 000000000000..8b33f0fedccc
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/CHANGELOG.md
@@ -0,0 +1,11 @@
+# Release History
+
+## 1.0.0-beta.1 (Unreleased)
+
+### Features Added
+
+### Breaking Changes
+
+### Bugs Fixed
+
+### Other Changes
\ No newline at end of file
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/Directory.Build.props b/sdk/machinelearning/Azure.AI.ChatProtocol/Directory.Build.props
new file mode 100644
index 000000000000..63bd836ad44b
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/Directory.Build.props
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/README.md b/sdk/machinelearning/Azure.AI.ChatProtocol/README.md
new file mode 100644
index 000000000000..88ac8d752019
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/README.md
@@ -0,0 +1,107 @@
+# Azure.AI.ChatProtocol client library for .NET
+
+Azure.AI.ChatProtocol is a managed service that helps developers get secret simply and securely.
+
+Use the client library for to:
+
+* [Get secret](https://docs.microsoft.com/azure)
+
+[Source code][source_root] | [Package (NuGet)][package] | [API reference documentation][reference_docs] | [Product documentation][azconfig_docs] | [Samples][source_samples]
+
+ [Source code](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/machinelearning/Azure.AI.ChatProtocol/src) | [Package (NuGet)](https://www.nuget.org/packages) | [API reference documentation](https://azure.github.io/azure-sdk-for-net) | [Product documentation](https://docs.microsoft.com/azure)
+
+## Getting started
+
+This section should include everything a developer needs to do to install and create their first client connection *very quickly*.
+
+### Install the package
+
+First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `dotnet add package package-name`, but should enable a developer to successfully install the package from NuGet, npm, or even cloning a GitHub repository.
+
+Install the client library for .NET with [NuGet](https://www.nuget.org/ ):
+
+```dotnetcli
+dotnet add package Azure.AI.ChatProtocol --prerelease
+```
+
+### Prerequisites
+
+Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB:
+
+> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) and [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API). In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`.
+
+### Authenticate the client
+
+If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating.
+
+For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object.
+
+### Service API versions
+
+The client library targets the latest service API version by default. A client instance accepts an optional service API version parameter from its options to specify which API version service to communicate.
+
+#### Select a service API version
+
+You have the flexibility to explicitly select a supported service API version when instantiating a client by configuring its associated options. This ensures that the client can communicate with services using the specified API version.
+
+For example,
+
+```C# Snippet:CreateClientForSpecificApiVersion
+Uri endpoint = new Uri("");
+DefaultAzureCredential credential = new DefaultAzureCredential();
+ClientOptions options = new ClientOptions(ClientOptions.ServiceVersion.)
+var client = new Client(endpoint, credential, options);
+```
+
+When selecting an API version, it's important to verify that there are no breaking changes compared to the latest API version. If there are significant differences, API calls may fail due to incompatibility.
+
+Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy.
+
+## Key concepts
+
+The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity.
+
+Include the *Thread safety* and *Additional concepts* sections below at the end of your *Key concepts* section. You may remove or add links depending on what your library makes use of:
+
+### Thread safety
+
+We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.
+
+### Additional concepts
+
+[Client options](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
+[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
+[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
+[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
+[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md) |
+[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#mocking) |
+[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
+
+
+## Examples
+
+You can familiarize yourself with different APIs using [Samples](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/machinelearning/Azure.AI.ChatProtocol/samples).
+
+## Troubleshooting
+
+Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery.
+
+Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API.
+
+If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code.
+
+## Next steps
+
+* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory.
+* If appropriate, point users to other packages that might be useful.
+* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for.
+
+## Contributing
+
+This is a template, but your SDK readme should include details on how to contribute code to the repo/package.
+
+
+[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization
+[style-guide-cloud]: https://aka.ms/azsdk/cloud-style-guide
+
+
\ No newline at end of file
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Azure.AI.ChatProtocol.csproj b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Azure.AI.ChatProtocol.csproj
new file mode 100644
index 000000000000..8146bc91e25a
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Azure.AI.ChatProtocol.csproj
@@ -0,0 +1,20 @@
+
+
+ This is the Azure.AI.ChatProtocol client library for developing .NET applications with rich experience.
+ Azure SDK Code Generation Azure.AI.ChatProtocol for Azure Data Plane
+ 1.0.0-beta.1
+ Azure.AI.ChatProtocol
+ $(RequiredTargetFrameworks)
+ true
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolClientBuilderExtensions.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolClientBuilderExtensions.cs
new file mode 100644
index 000000000000..ea7717bf6de6
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolClientBuilderExtensions.cs
@@ -0,0 +1,46 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using Azure;
+using Azure.AI.ChatProtocol;
+using Azure.Core.Extensions;
+
+namespace Microsoft.Extensions.Azure
+{
+ /// Extension methods to add to client builder.
+ public static partial class AIChatProtocolClientBuilderExtensions
+ {
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The to use.
+ /// A credential used to authenticate to an Azure Service.
+ public static IAzureClientBuilder AddChatProtocolClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential)
+ where TBuilder : IAzureClientFactoryBuilder
+ {
+ return builder.RegisterClientFactory((options) => new ChatProtocolClient(endpoint, credential, options));
+ }
+
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The to use.
+ public static IAzureClientBuilder AddChatProtocolClient(this TBuilder builder, Uri endpoint)
+ where TBuilder : IAzureClientFactoryBuilderWithCredential
+ {
+ return builder.RegisterClientFactory((options, cred) => new ChatProtocolClient(endpoint, cred, options));
+ }
+
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The configuration values.
+ public static IAzureClientBuilder AddChatProtocolClient(this TBuilder builder, TConfiguration configuration)
+ where TBuilder : IAzureClientFactoryBuilderWithConfiguration
+ {
+ return builder.RegisterClientFactory(configuration);
+ }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolModelFactory.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolModelFactory.cs
new file mode 100644
index 000000000000..d85f4af0e444
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/AIChatProtocolModelFactory.cs
@@ -0,0 +1,59 @@
+// 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.ChatProtocol
+{
+ /// Model factory for models.
+ public static partial class AIChatProtocolModelFactory
+ {
+ /// Initializes a new instance of .
+ /// The collection of generated completions.
+ /// A new instance for mocking.
+ public static ChatCompletion ChatCompletion(IEnumerable choices = null)
+ {
+ choices ??= new List();
+
+ return new ChatCompletion(choices?.ToList(), serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the of the chat choice, relative to the other choices in the same completion.
+ ///
+ /// The chat message for a given chat completion.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The reason this chat completion completed its generation.
+ /// A new instance for mocking.
+ public static ChatChoice ChatChoice(long index = default, ChatMessage message = null, BinaryData sessionState = null, IReadOnlyDictionary context = null, FinishReason finishReason = default)
+ {
+ context ??= new Dictionary();
+
+ return new ChatChoice(
+ index,
+ message,
+ sessionState,
+ context,
+ finishReason,
+ serializedAdditionalRawData: null);
+ }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Chat.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Chat.cs
new file mode 100644
index 000000000000..d47b23734fea
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Chat.cs
@@ -0,0 +1,381 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure.Core;
+using Azure.Core.Pipeline;
+
+namespace Azure.AI.ChatProtocol
+{
+ // Data plane generated sub-client.
+ /// The Chat sub-client.
+ public partial class Chat
+ {
+ private const string AuthorizationHeader = "api-key";
+ private readonly AzureKeyCredential _keyCredential;
+ private static readonly string[] AuthorizationScopes = Array.Empty();
+ private readonly TokenCredential _tokenCredential;
+ private readonly HttpPipeline _pipeline;
+ private readonly Uri _endpoint;
+
+ /// 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 Chat for mocking.
+ protected Chat()
+ {
+ }
+
+ /// Initializes a new instance of Chat.
+ /// The handler for diagnostic messaging in the client.
+ /// The HTTP pipeline for sending and receiving REST requests and responses.
+ /// The key credential to copy.
+ /// The token credential to copy.
+ /// The to use.
+ internal Chat(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, AzureKeyCredential keyCredential, TokenCredential tokenCredential, Uri endpoint)
+ {
+ ClientDiagnostics = clientDiagnostics;
+ _pipeline = pipeline;
+ _keyCredential = keyCredential;
+ _tokenCredential = tokenCredential;
+ _endpoint = endpoint;
+ }
+
+ /// Creates a new streaming chat completion.
+ /// The route where the endpoint exposes the chat operations.
+ /// The collection of context messages associated with this completion request.
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> CreateStreamingAsync(string operationRoute, IEnumerable messages, bool stream, BinaryData sessionState = null, IReadOnlyDictionary context = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ CreateStreamingRequest createStreamingRequest = new CreateStreamingRequest(messages.ToList(), stream, sessionState, context ?? new ChangeTrackingDictionary(), null);
+ RequestContext context0 = FromCancellationToken(cancellationToken);
+ Response response = await CreateStreamingAsync(operationRoute, createStreamingRequest.ToRequestContent(), context0).ConfigureAwait(false);
+ return Response.FromValue(ChatCompletionChunk.FromResponse(response), response);
+ }
+
+ /// Creates a new streaming chat completion.
+ /// The route where the endpoint exposes the chat operations.
+ /// The collection of context messages associated with this completion request.
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response CreateStreaming(string operationRoute, IEnumerable messages, bool stream, BinaryData sessionState = null, IReadOnlyDictionary context = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ CreateStreamingRequest createStreamingRequest = new CreateStreamingRequest(messages.ToList(), stream, sessionState, context ?? new ChangeTrackingDictionary(), null);
+ RequestContext context0 = FromCancellationToken(cancellationToken);
+ Response response = CreateStreaming(operationRoute, createStreamingRequest.ToRequestContent(), context0);
+ return Response.FromValue(ChatCompletionChunk.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new streaming chat completion.
+ ///
+ /// -
+ ///
+ /// 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 route where the endpoint exposes the chat operations.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task CreateStreamingAsync(string operationRoute, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Chat.CreateStreaming");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateStreamingRequest(operationRoute, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new streaming chat completion.
+ ///
+ /// -
+ ///
+ /// 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 route where the endpoint exposes the chat operations.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response CreateStreaming(string operationRoute, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Chat.CreateStreaming");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateStreamingRequest(operationRoute, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a new chat completion.
+ /// The route where the endpoint exposes the chat operations.
+ /// The collection of context messages associated with this completion request.
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> CreateAsync(string operationRoute, IEnumerable messages, bool stream, BinaryData sessionState = null, IReadOnlyDictionary context = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ CreateRequest createRequest = new CreateRequest(messages.ToList(), stream, sessionState, context ?? new ChangeTrackingDictionary(), null);
+ RequestContext context0 = FromCancellationToken(cancellationToken);
+ Response response = await CreateAsync(operationRoute, createRequest.ToRequestContent(), context0).ConfigureAwait(false);
+ return Response.FromValue(ChatCompletion.FromResponse(response), response);
+ }
+
+ /// Creates a new chat completion.
+ /// The route where the endpoint exposes the chat operations.
+ /// The collection of context messages associated with this completion request.
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response Create(string operationRoute, IEnumerable messages, bool stream, BinaryData sessionState = null, IReadOnlyDictionary context = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ CreateRequest createRequest = new CreateRequest(messages.ToList(), stream, sessionState, context ?? new ChangeTrackingDictionary(), null);
+ RequestContext context0 = FromCancellationToken(cancellationToken);
+ Response response = Create(operationRoute, createRequest.ToRequestContent(), context0);
+ return Response.FromValue(ChatCompletion.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new chat completion.
+ ///
+ /// -
+ ///
+ /// 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 route where the endpoint exposes the chat operations.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateAsync(string operationRoute, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Chat.Create");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateRequest(operationRoute, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new chat completion.
+ ///
+ /// -
+ ///
+ /// 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 route where the endpoint exposes the chat operations.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response Create(string operationRoute, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(operationRoute, nameof(operationRoute));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Chat.Create");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateRequest(operationRoute, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ internal HttpMessage CreateCreateStreamingRequest(string operationRoute, RequestContent content, 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("/", false);
+ uri.AppendPath(operationRoute, true);
+ request.Uri = uri;
+ request.Headers.Add("Accept", "application/json");
+ request.Headers.Add("Content-Type", "application/json");
+ request.Content = content;
+ return message;
+ }
+
+ internal HttpMessage CreateCreateRequest(string operationRoute, RequestContent content, 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("/", false);
+ uri.AppendPath(operationRoute, true);
+ request.Uri = uri;
+ request.Headers.Add("Accept", "application/json");
+ request.Headers.Add("Content-Type", "application/json");
+ request.Content = content;
+ return message;
+ }
+
+ private static RequestContext DefaultRequestContext = new RequestContext();
+ internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default)
+ {
+ 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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.Serialization.cs
new file mode 100644
index 000000000000..71dfd4257e07
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.Serialization.cs
@@ -0,0 +1,231 @@
+// 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.ChatProtocol
+{
+ public partial class ChatChoice : 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(ChatChoice)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("index"u8);
+ writer.WriteNumberValue(Index);
+ writer.WritePropertyName("message"u8);
+ writer.WriteObjectValue(Message, options);
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ if (Optional.IsCollectionDefined(Context))
+ {
+ writer.WritePropertyName("context"u8);
+ writer.WriteStartObject();
+ foreach (var item in Context)
+ {
+ writer.WritePropertyName(item.Key);
+ if (item.Value == null)
+ {
+ writer.WriteNullValue();
+ continue;
+ }
+#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
+ }
+ writer.WriteEndObject();
+ }
+ writer.WritePropertyName("finishReason"u8);
+ writer.WriteStringValue(FinishReason.ToString());
+ 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
+ }
+ }
+ }
+
+ ChatChoice 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(ChatChoice)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChatChoice(document.RootElement, options);
+ }
+
+ internal static ChatChoice DeserializeChatChoice(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ long index = default;
+ ChatMessage message = default;
+ BinaryData sessionState = default;
+ IReadOnlyDictionary context = default;
+ FinishReason finishReason = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("index"u8))
+ {
+ index = property.Value.GetInt64();
+ continue;
+ }
+ if (property.NameEquals("message"u8))
+ {
+ message = ChatMessage.DeserializeChatMessage(property.Value, options);
+ continue;
+ }
+ if (property.NameEquals("sessionState"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ sessionState = BinaryData.FromString(property.Value.GetRawText());
+ continue;
+ }
+ if (property.NameEquals("context"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ Dictionary dictionary = new Dictionary();
+ foreach (var property0 in property.Value.EnumerateObject())
+ {
+ if (property0.Value.ValueKind == JsonValueKind.Null)
+ {
+ dictionary.Add(property0.Name, null);
+ }
+ else
+ {
+ dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText()));
+ }
+ }
+ context = dictionary;
+ continue;
+ }
+ if (property.NameEquals("finishReason"u8))
+ {
+ finishReason = new FinishReason(property.Value.GetString());
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new ChatChoice(
+ index,
+ message,
+ sessionState,
+ context ?? new ChangeTrackingDictionary(),
+ finishReason,
+ 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(ChatChoice)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChatChoice 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 DeserializeChatChoice(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChatChoice)} 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 ChatChoice FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChatChoice(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.cs
new file mode 100644
index 000000000000..da67a0a5ea32
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatChoice.cs
@@ -0,0 +1,178 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ /// The representation of a single generated completion.
+ public partial class ChatChoice
+ {
+ ///
+ /// 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 index of the of the chat choice, relative to the other choices in the same completion.
+ ///
+ /// The chat message for a given chat completion.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// The reason this chat completion completed its generation.
+ /// is null.
+ internal ChatChoice(long index, ChatMessage message, FinishReason finishReason)
+ {
+ Argument.AssertNotNull(message, nameof(message));
+
+ Index = index;
+ Message = message;
+ Context = new ChangeTrackingDictionary();
+ FinishReason = finishReason;
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the of the chat choice, relative to the other choices in the same completion.
+ ///
+ /// The chat message for a given chat completion.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The reason this chat completion completed its generation.
+ /// Keeps track of any properties unknown to the library.
+ internal ChatChoice(long index, ChatMessage message, BinaryData sessionState, IReadOnlyDictionary context, FinishReason finishReason, IDictionary serializedAdditionalRawData)
+ {
+ Index = index;
+ Message = message;
+ SessionState = sessionState;
+ Context = context;
+ FinishReason = finishReason;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal ChatChoice()
+ {
+ }
+
+ /// The index of the of the chat choice, relative to the other choices in the same completion.
+ public long Index { get; }
+ ///
+ /// The chat message for a given chat completion.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ public ChatMessage Message { get; }
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; }
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// 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 IReadOnlyDictionary Context { get; }
+ /// The reason this chat completion completed its generation.
+ public FinishReason FinishReason { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.Serialization.cs
new file mode 100644
index 000000000000..4e13530c43b3
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.Serialization.cs
@@ -0,0 +1,152 @@
+// 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.ChatProtocol
+{
+ public partial class ChatCompletion : 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(ChatCompletion)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("choices"u8);
+ writer.WriteStartArray();
+ foreach (var item in Choices)
+ {
+ writer.WriteObjectValue(item, options);
+ }
+ writer.WriteEndArray();
+ if (options.Format != "W" && _serializedAdditionalRawData != null)
+ {
+ foreach (var item in _serializedAdditionalRawData)
+ {
+ writer.WritePropertyName(item.Key);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(item.Value);
+#else
+ using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ }
+ }
+
+ ChatCompletion 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(ChatCompletion)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChatCompletion(document.RootElement, options);
+ }
+
+ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ IReadOnlyList choices = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("choices"u8))
+ {
+ List array = new List();
+ foreach (var item in property.Value.EnumerateArray())
+ {
+ array.Add(ChatChoice.DeserializeChatChoice(item, options));
+ }
+ choices = array;
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new ChatCompletion(choices, 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(ChatCompletion)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChatCompletion 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 DeserializeChatCompletion(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChatCompletion)} 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 ChatCompletion FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChatCompletion(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.cs
new file mode 100644
index 000000000000..ca5a1a6cfeee
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletion.cs
@@ -0,0 +1,76 @@
+// 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.ChatProtocol
+{
+ /// Representation of the response to a chat completion request.
+ public partial class ChatCompletion
+ {
+ ///
+ /// 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 collection of generated completions.
+ /// is null.
+ internal ChatCompletion(IEnumerable choices)
+ {
+ Argument.AssertNotNull(choices, nameof(choices));
+
+ Choices = choices.ToList();
+ }
+
+ /// Initializes a new instance of .
+ /// The collection of generated completions.
+ /// Keeps track of any properties unknown to the library.
+ internal ChatCompletion(IReadOnlyList choices, IDictionary serializedAdditionalRawData)
+ {
+ Choices = choices;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal ChatCompletion()
+ {
+ }
+
+ /// The collection of generated completions.
+ public IReadOnlyList Choices { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.Serialization.cs
new file mode 100644
index 000000000000..1c085ff52545
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.Serialization.cs
@@ -0,0 +1,152 @@
+// 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.ChatProtocol
+{
+ internal partial class ChatCompletionChunk : 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(ChatCompletionChunk)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("choices"u8);
+ writer.WriteStartArray();
+ foreach (var item in Choices)
+ {
+ writer.WriteObjectValue(item, options);
+ }
+ writer.WriteEndArray();
+ if (options.Format != "W" && _serializedAdditionalRawData != null)
+ {
+ foreach (var item in _serializedAdditionalRawData)
+ {
+ writer.WritePropertyName(item.Key);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(item.Value);
+#else
+ using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ }
+ }
+
+ ChatCompletionChunk 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(ChatCompletionChunk)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChatCompletionChunk(document.RootElement, options);
+ }
+
+ internal static ChatCompletionChunk DeserializeChatCompletionChunk(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ IReadOnlyList choices = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("choices"u8))
+ {
+ List array = new List();
+ foreach (var item in property.Value.EnumerateArray())
+ {
+ array.Add(ChoiceDelta.DeserializeChoiceDelta(item, options));
+ }
+ choices = array;
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new ChatCompletionChunk(choices, 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(ChatCompletionChunk)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChatCompletionChunk 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 DeserializeChatCompletionChunk(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChatCompletionChunk)} 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 ChatCompletionChunk FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChatCompletionChunk(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.cs
new file mode 100644
index 000000000000..cafdec9a0eed
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatCompletionChunk.cs
@@ -0,0 +1,76 @@
+// 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.ChatProtocol
+{
+ /// A single response to a streaming completion request.
+ internal partial class ChatCompletionChunk
+ {
+ ///
+ /// 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 collection of choice deltas received in this chunk.
+ /// is null.
+ internal ChatCompletionChunk(IEnumerable choices)
+ {
+ Argument.AssertNotNull(choices, nameof(choices));
+
+ Choices = choices.ToList();
+ }
+
+ /// Initializes a new instance of .
+ /// The collection of choice deltas received in this chunk.
+ /// Keeps track of any properties unknown to the library.
+ internal ChatCompletionChunk(IReadOnlyList choices, IDictionary serializedAdditionalRawData)
+ {
+ Choices = choices;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal ChatCompletionChunk()
+ {
+ }
+
+ /// The collection of choice deltas received in this chunk.
+ public IReadOnlyList Choices { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.Serialization.cs
new file mode 100644
index 000000000000..18579326fef5
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.Serialization.cs
@@ -0,0 +1,147 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel.Primitives;
+using System.Text.Json;
+using Azure.Core;
+
+namespace Azure.AI.ChatProtocol
+{
+ [PersistableModelProxy(typeof(UnknownChatMessage))]
+ public partial class ChatMessage : 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(ChatMessage)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("kind"u8);
+ writer.WriteStringValue(Kind.ToString());
+ writer.WritePropertyName("role"u8);
+ writer.WriteStringValue(Role.ToString());
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ 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
+ }
+ }
+ }
+
+ ChatMessage 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(ChatMessage)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChatMessage(document.RootElement, options);
+ }
+
+ internal static ChatMessage DeserializeChatMessage(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ if (element.TryGetProperty("kind", out JsonElement discriminator))
+ {
+ switch (discriminator.GetString())
+ {
+ case "text": return TextChatMessage.DeserializeTextChatMessage(element, options);
+ }
+ }
+ return UnknownChatMessage.DeserializeUnknownChatMessage(element, options);
+ }
+
+ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options)
+ {
+ var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+
+ switch (format)
+ {
+ case "J":
+ return ModelReaderWriter.Write(this, options);
+ default:
+ throw new FormatException($"The model {nameof(ChatMessage)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChatMessage 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 DeserializeChatMessage(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChatMessage)} 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 ChatMessage FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChatMessage(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.cs
new file mode 100644
index 000000000000..e7a9d6fe080c
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessage.cs
@@ -0,0 +1,121 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ ///
+ /// A single, role-attributed message within a chat completion interaction.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ public abstract partial class ChatMessage
+ {
+ ///
+ /// 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 protected IDictionary _serializedAdditionalRawData;
+
+ /// Initializes a new instance of .
+ /// The role associated with the message.
+ protected ChatMessage(ChatRole role)
+ {
+ Role = role;
+ }
+
+ /// Initializes a new instance of .
+ /// The type of the message. If not specified, the message is assumed to be text.
+ /// The role associated with the message.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// Keeps track of any properties unknown to the library.
+ internal ChatMessage(MessageKind kind, ChatRole role, BinaryData sessionState, IDictionary serializedAdditionalRawData)
+ {
+ Kind = kind;
+ Role = role;
+ SessionState = sessionState;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal ChatMessage()
+ {
+ }
+
+ /// The type of the message. If not specified, the message is assumed to be text.
+ internal MessageKind Kind { get; set; }
+ /// The role associated with the message.
+ public ChatRole Role { get; set; }
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; set; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.Serialization.cs
new file mode 100644
index 000000000000..162d23af62fd
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.Serialization.cs
@@ -0,0 +1,150 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel.Primitives;
+using System.Text.Json;
+using Azure.Core;
+
+namespace Azure.AI.ChatProtocol
+{
+ [PersistableModelProxy(typeof(UnknownChatMessageDelta))]
+ internal partial class ChatMessageDelta : 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(ChatMessageDelta)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("kind"u8);
+ writer.WriteStringValue(Kind.ToString());
+ if (Optional.IsDefined(Role))
+ {
+ writer.WritePropertyName("role"u8);
+ writer.WriteStringValue(Role.Value.ToString());
+ }
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ 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
+ }
+ }
+ }
+
+ ChatMessageDelta 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(ChatMessageDelta)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChatMessageDelta(document.RootElement, options);
+ }
+
+ internal static ChatMessageDelta DeserializeChatMessageDelta(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ if (element.TryGetProperty("kind", out JsonElement discriminator))
+ {
+ switch (discriminator.GetString())
+ {
+ case "text": return TextChatMessageDelta.DeserializeTextChatMessageDelta(element, options);
+ }
+ }
+ return UnknownChatMessageDelta.DeserializeUnknownChatMessageDelta(element, options);
+ }
+
+ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options)
+ {
+ var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+
+ switch (format)
+ {
+ case "J":
+ return ModelReaderWriter.Write(this, options);
+ default:
+ throw new FormatException($"The model {nameof(ChatMessageDelta)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChatMessageDelta 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 DeserializeChatMessageDelta(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChatMessageDelta)} 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 ChatMessageDelta FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChatMessageDelta(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.cs
new file mode 100644
index 000000000000..3705d977c5e1
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatMessageDelta.cs
@@ -0,0 +1,114 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ ///
+ /// The representation of a delta message received in a streaming completion.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ internal abstract partial class ChatMessageDelta
+ {
+ ///
+ /// 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 protected IDictionary _serializedAdditionalRawData;
+
+ /// Initializes a new instance of .
+ protected ChatMessageDelta()
+ {
+ }
+
+ /// Initializes a new instance of .
+ /// The type of the message. If not specified, the message is assumed to be text.
+ /// The role associated with the message.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// Keeps track of any properties unknown to the library.
+ internal ChatMessageDelta(MessageKind kind, ChatRole? role, BinaryData sessionState, IDictionary serializedAdditionalRawData)
+ {
+ Kind = kind;
+ Role = role;
+ SessionState = sessionState;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// The type of the message. If not specified, the message is assumed to be text.
+ internal MessageKind Kind { get; set; }
+ /// The role associated with the message.
+ public ChatRole? Role { get; }
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClient.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClient.cs
new file mode 100644
index 000000000000..4ae7b64d3396
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClient.cs
@@ -0,0 +1,95 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Threading;
+using Azure.Core;
+using Azure.Core.Pipeline;
+
+namespace Azure.AI.ChatProtocol
+{
+ // Data plane generated client.
+ /// Azure APIs for the Azure Chat protocol.
+ public partial class ChatProtocolClient
+ {
+ private const string AuthorizationHeader = "api-key";
+ private readonly AzureKeyCredential _keyCredential;
+ private static readonly string[] AuthorizationScopes = Array.Empty();
+ private readonly TokenCredential _tokenCredential;
+ private readonly HttpPipeline _pipeline;
+ private readonly Uri _endpoint;
+
+ /// 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 ChatProtocolClient for mocking.
+ protected ChatProtocolClient()
+ {
+ }
+
+ /// Initializes a new instance of ChatProtocolClient.
+ /// The to use.
+ /// A credential used to authenticate to an Azure Service.
+ /// or is null.
+ public ChatProtocolClient(Uri endpoint, AzureKeyCredential credential) : this(endpoint, credential, new ChatProtocolClientOptions())
+ {
+ }
+
+ /// Initializes a new instance of ChatProtocolClient.
+ /// The to use.
+ /// A credential used to authenticate to an Azure Service.
+ /// or is null.
+ public ChatProtocolClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new ChatProtocolClientOptions())
+ {
+ }
+
+ /// Initializes a new instance of ChatProtocolClient.
+ /// The to use.
+ /// A credential used to authenticate to an Azure Service.
+ /// The options for configuring the client.
+ /// or is null.
+ public ChatProtocolClient(Uri endpoint, AzureKeyCredential credential, ChatProtocolClientOptions options)
+ {
+ Argument.AssertNotNull(endpoint, nameof(endpoint));
+ Argument.AssertNotNull(credential, nameof(credential));
+ options ??= new ChatProtocolClientOptions();
+
+ ClientDiagnostics = new ClientDiagnostics(options, true);
+ _keyCredential = credential;
+ _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier());
+ _endpoint = endpoint;
+ }
+
+ /// Initializes a new instance of ChatProtocolClient.
+ /// The to use.
+ /// A credential used to authenticate to an Azure Service.
+ /// The options for configuring the client.
+ /// or is null.
+ public ChatProtocolClient(Uri endpoint, TokenCredential credential, ChatProtocolClientOptions options)
+ {
+ Argument.AssertNotNull(endpoint, nameof(endpoint));
+ Argument.AssertNotNull(credential, nameof(credential));
+ options ??= new ChatProtocolClientOptions();
+
+ ClientDiagnostics = new ClientDiagnostics(options, true);
+ _tokenCredential = credential;
+ _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier());
+ _endpoint = endpoint;
+ }
+
+ private Chat _cachedChat;
+
+ /// Initializes a new instance of Chat.
+ public virtual Chat GetChatClient()
+ {
+ return Volatile.Read(ref _cachedChat) ?? Interlocked.CompareExchange(ref _cachedChat, new Chat(ClientDiagnostics, _pipeline, _keyCredential, _tokenCredential, _endpoint), null) ?? _cachedChat;
+ }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClientOptions.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClientOptions.cs
new file mode 100644
index 000000000000..94b8f8a4f4b8
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatProtocolClientOptions.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using Azure.Core;
+
+namespace Azure.AI.ChatProtocol
+{
+ /// Client options for ChatProtocolClient.
+ public partial class ChatProtocolClientOptions : ClientOptions
+ {
+ private const ServiceVersion LatestVersion = ServiceVersion.V2023_10_01_Preview;
+
+ /// The version of the service to use.
+ public enum ServiceVersion
+ {
+ /// Service version "2023-10-01-preview".
+ V2023_10_01_Preview = 1,
+ }
+
+ internal string Version { get; }
+
+ /// Initializes new instance of ChatProtocolClientOptions.
+ public ChatProtocolClientOptions(ServiceVersion version = LatestVersion)
+ {
+ Version = version switch
+ {
+ ServiceVersion.V2023_10_01_Preview => "2023-10-01-preview",
+ _ => throw new NotSupportedException()
+ };
+ }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatRole.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatRole.cs
new file mode 100644
index 000000000000..50c2381c14d8
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChatRole.cs
@@ -0,0 +1,54 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ComponentModel;
+
+namespace Azure.AI.ChatProtocol
+{
+ /// A representation of the intended purpose of a message.
+ public readonly partial struct ChatRole : IEquatable
+ {
+ private readonly string _value;
+
+ /// Initializes a new instance of .
+ /// is null.
+ public ChatRole(string value)
+ {
+ _value = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ private const string UserValue = "user";
+ private const string SystemValue = "system";
+ private const string AssistantValue = "assistant";
+
+ /// The role that provides input to the completion.
+ public static ChatRole User { get; } = new ChatRole(UserValue);
+ /// The role that instructs or configures the behavior of the assistant.
+ public static ChatRole System { get; } = new ChatRole(SystemValue);
+ /// The role that provides responses to the system-instructed, user-prompted input.
+ public static ChatRole Assistant { get; } = new ChatRole(AssistantValue);
+ /// Determines if two values are the same.
+ public static bool operator ==(ChatRole left, ChatRole right) => left.Equals(right);
+ /// Determines if two values are not the same.
+ public static bool operator !=(ChatRole left, ChatRole right) => !left.Equals(right);
+ /// Converts a to a .
+ public static implicit operator ChatRole(string value) => new ChatRole(value);
+
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool Equals(object obj) => obj is ChatRole other && Equals(other);
+ ///
+ public bool Equals(ChatRole 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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.Serialization.cs
new file mode 100644
index 000000000000..96205e7c7656
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.Serialization.cs
@@ -0,0 +1,238 @@
+// 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.ChatProtocol
+{
+ internal partial class ChoiceDelta : 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(ChoiceDelta)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("index"u8);
+ writer.WriteNumberValue(Index);
+ writer.WritePropertyName("delta"u8);
+ writer.WriteObjectValue(Delta, options);
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ if (Optional.IsCollectionDefined(Context))
+ {
+ writer.WritePropertyName("context"u8);
+ writer.WriteStartObject();
+ foreach (var item in Context)
+ {
+ writer.WritePropertyName(item.Key);
+ if (item.Value == null)
+ {
+ writer.WriteNullValue();
+ continue;
+ }
+#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
+ }
+ writer.WriteEndObject();
+ }
+ if (Optional.IsDefined(FinishReason))
+ {
+ writer.WritePropertyName("finishReason"u8);
+ writer.WriteStringValue(FinishReason.Value.ToString());
+ }
+ 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
+ }
+ }
+ }
+
+ ChoiceDelta 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(ChoiceDelta)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeChoiceDelta(document.RootElement, options);
+ }
+
+ internal static ChoiceDelta DeserializeChoiceDelta(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ long index = default;
+ ChatMessageDelta delta = default;
+ BinaryData sessionState = default;
+ IReadOnlyDictionary context = default;
+ FinishReason? finishReason = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("index"u8))
+ {
+ index = property.Value.GetInt64();
+ continue;
+ }
+ if (property.NameEquals("delta"u8))
+ {
+ delta = ChatMessageDelta.DeserializeChatMessageDelta(property.Value, options);
+ continue;
+ }
+ if (property.NameEquals("sessionState"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ sessionState = BinaryData.FromString(property.Value.GetRawText());
+ continue;
+ }
+ if (property.NameEquals("context"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ Dictionary dictionary = new Dictionary();
+ foreach (var property0 in property.Value.EnumerateObject())
+ {
+ if (property0.Value.ValueKind == JsonValueKind.Null)
+ {
+ dictionary.Add(property0.Name, null);
+ }
+ else
+ {
+ dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText()));
+ }
+ }
+ context = dictionary;
+ continue;
+ }
+ if (property.NameEquals("finishReason"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ finishReason = new FinishReason(property.Value.GetString());
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new ChoiceDelta(
+ index,
+ delta,
+ sessionState,
+ context ?? new ChangeTrackingDictionary(),
+ finishReason,
+ 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(ChoiceDelta)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ ChoiceDelta 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 DeserializeChoiceDelta(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(ChoiceDelta)} 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 ChoiceDelta FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeChoiceDelta(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.cs
new file mode 100644
index 000000000000..015dda5e7073
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/ChoiceDelta.cs
@@ -0,0 +1,176 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ /// The representation of an incremental choice received in a streaming completion.
+ internal partial class ChoiceDelta
+ {
+ ///
+ /// 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 index of the of the chat choice, relative to the other choices in the same completion.
+ ///
+ /// The partial message received for this choice.
+ /// 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 .
+ ///
+ /// is null.
+ internal ChoiceDelta(long index, ChatMessageDelta delta)
+ {
+ Argument.AssertNotNull(delta, nameof(delta));
+
+ Index = index;
+ Delta = delta;
+ Context = new ChangeTrackingDictionary();
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the of the chat choice, relative to the other choices in the same completion.
+ ///
+ /// The partial message received for this choice.
+ /// 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 .
+ ///
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// The reason this chat completion completed its generation.
+ /// Keeps track of any properties unknown to the library.
+ internal ChoiceDelta(long index, ChatMessageDelta delta, BinaryData sessionState, IReadOnlyDictionary context, FinishReason? finishReason, IDictionary serializedAdditionalRawData)
+ {
+ Index = index;
+ Delta = delta;
+ SessionState = sessionState;
+ Context = context;
+ FinishReason = finishReason;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal ChoiceDelta()
+ {
+ }
+
+ /// The index of the of the chat choice, relative to the other choices in the same completion.
+ public long Index { get; }
+ ///
+ /// The partial message received for this choice.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ public ChatMessageDelta Delta { get; }
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; }
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// 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 IReadOnlyDictionary Context { get; }
+ /// The reason this chat completion completed its generation.
+ public FinishReason? FinishReason { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.Serialization.cs
new file mode 100644
index 000000000000..65e9e972077c
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.Serialization.cs
@@ -0,0 +1,227 @@
+// 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.ChatProtocol
+{
+ internal partial class CreateRequest : 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(CreateRequest)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("messages"u8);
+ writer.WriteStartArray();
+ foreach (var item in Messages)
+ {
+ writer.WriteObjectValue(item, options);
+ }
+ writer.WriteEndArray();
+ writer.WritePropertyName("stream"u8);
+ writer.WriteBooleanValue(Stream);
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ if (Optional.IsCollectionDefined(Context))
+ {
+ writer.WritePropertyName("context"u8);
+ writer.WriteStartObject();
+ foreach (var item in Context)
+ {
+ writer.WritePropertyName(item.Key);
+ if (item.Value == null)
+ {
+ writer.WriteNullValue();
+ continue;
+ }
+#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
+ }
+ writer.WriteEndObject();
+ }
+ 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
+ }
+ }
+ }
+
+ CreateRequest 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(CreateRequest)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeCreateRequest(document.RootElement, options);
+ }
+
+ internal static CreateRequest DeserializeCreateRequest(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ IReadOnlyList messages = default;
+ bool stream = default;
+ BinaryData sessionState = default;
+ IReadOnlyDictionary context = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("messages"u8))
+ {
+ List array = new List();
+ foreach (var item in property.Value.EnumerateArray())
+ {
+ array.Add(ChatMessage.DeserializeChatMessage(item, options));
+ }
+ messages = array;
+ continue;
+ }
+ if (property.NameEquals("stream"u8))
+ {
+ stream = property.Value.GetBoolean();
+ continue;
+ }
+ if (property.NameEquals("sessionState"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ sessionState = BinaryData.FromString(property.Value.GetRawText());
+ continue;
+ }
+ if (property.NameEquals("context"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ Dictionary dictionary = new Dictionary();
+ foreach (var property0 in property.Value.EnumerateObject())
+ {
+ if (property0.Value.ValueKind == JsonValueKind.Null)
+ {
+ dictionary.Add(property0.Name, null);
+ }
+ else
+ {
+ dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText()));
+ }
+ }
+ context = dictionary;
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new CreateRequest(messages, stream, sessionState, context ?? new ChangeTrackingDictionary(), 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(CreateRequest)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ CreateRequest 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 DeserializeCreateRequest(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(CreateRequest)} 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 CreateRequest FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeCreateRequest(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.cs
new file mode 100644
index 000000000000..99df8caf782a
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateRequest.cs
@@ -0,0 +1,172 @@
+// 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.ChatProtocol
+{
+ /// The CreateRequest.
+ internal partial class CreateRequest
+ {
+ ///
+ /// 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 collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// is null.
+ internal CreateRequest(IEnumerable messages)
+ {
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ Messages = messages.ToList();
+ Context = new ChangeTrackingDictionary();
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// The collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// Keeps track of any properties unknown to the library.
+ internal CreateRequest(IReadOnlyList messages, bool stream, BinaryData sessionState, IReadOnlyDictionary context, IDictionary serializedAdditionalRawData)
+ {
+ Messages = messages;
+ Stream = stream;
+ SessionState = sessionState;
+ Context = context;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal CreateRequest()
+ {
+ }
+
+ ///
+ /// The collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ public IReadOnlyList Messages { get; }
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ public bool Stream { get; } = false;
+
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; }
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// 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 IReadOnlyDictionary Context { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.Serialization.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.Serialization.cs
new file mode 100644
index 000000000000..dfd23f79d86e
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.Serialization.cs
@@ -0,0 +1,227 @@
+// 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.ChatProtocol
+{
+ internal partial class CreateStreamingRequest : 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(CreateStreamingRequest)} does not support writing '{format}' format.");
+ }
+
+ writer.WritePropertyName("messages"u8);
+ writer.WriteStartArray();
+ foreach (var item in Messages)
+ {
+ writer.WriteObjectValue(item, options);
+ }
+ writer.WriteEndArray();
+ writer.WritePropertyName("stream"u8);
+ writer.WriteBooleanValue(Stream);
+ if (Optional.IsDefined(SessionState))
+ {
+ writer.WritePropertyName("sessionState"u8);
+#if NET6_0_OR_GREATER
+ writer.WriteRawValue(SessionState);
+#else
+ using (JsonDocument document = JsonDocument.Parse(SessionState, ModelSerializationExtensions.JsonDocumentOptions))
+ {
+ JsonSerializer.Serialize(writer, document.RootElement);
+ }
+#endif
+ }
+ if (Optional.IsCollectionDefined(Context))
+ {
+ writer.WritePropertyName("context"u8);
+ writer.WriteStartObject();
+ foreach (var item in Context)
+ {
+ writer.WritePropertyName(item.Key);
+ if (item.Value == null)
+ {
+ writer.WriteNullValue();
+ continue;
+ }
+#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
+ }
+ writer.WriteEndObject();
+ }
+ 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
+ }
+ }
+ }
+
+ CreateStreamingRequest 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(CreateStreamingRequest)} does not support reading '{format}' format.");
+ }
+
+ using JsonDocument document = JsonDocument.ParseValue(ref reader);
+ return DeserializeCreateStreamingRequest(document.RootElement, options);
+ }
+
+ internal static CreateStreamingRequest DeserializeCreateStreamingRequest(JsonElement element, ModelReaderWriterOptions options = null)
+ {
+ options ??= ModelSerializationExtensions.WireOptions;
+
+ if (element.ValueKind == JsonValueKind.Null)
+ {
+ return null;
+ }
+ IReadOnlyList messages = default;
+ bool stream = default;
+ BinaryData sessionState = default;
+ IReadOnlyDictionary context = default;
+ IDictionary serializedAdditionalRawData = default;
+ Dictionary rawDataDictionary = new Dictionary();
+ foreach (var property in element.EnumerateObject())
+ {
+ if (property.NameEquals("messages"u8))
+ {
+ List array = new List();
+ foreach (var item in property.Value.EnumerateArray())
+ {
+ array.Add(ChatMessage.DeserializeChatMessage(item, options));
+ }
+ messages = array;
+ continue;
+ }
+ if (property.NameEquals("stream"u8))
+ {
+ stream = property.Value.GetBoolean();
+ continue;
+ }
+ if (property.NameEquals("sessionState"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ sessionState = BinaryData.FromString(property.Value.GetRawText());
+ continue;
+ }
+ if (property.NameEquals("context"u8))
+ {
+ if (property.Value.ValueKind == JsonValueKind.Null)
+ {
+ continue;
+ }
+ Dictionary dictionary = new Dictionary();
+ foreach (var property0 in property.Value.EnumerateObject())
+ {
+ if (property0.Value.ValueKind == JsonValueKind.Null)
+ {
+ dictionary.Add(property0.Name, null);
+ }
+ else
+ {
+ dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText()));
+ }
+ }
+ context = dictionary;
+ continue;
+ }
+ if (options.Format != "W")
+ {
+ rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
+ }
+ }
+ serializedAdditionalRawData = rawDataDictionary;
+ return new CreateStreamingRequest(messages, stream, sessionState, context ?? new ChangeTrackingDictionary(), 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(CreateStreamingRequest)} does not support writing '{options.Format}' format.");
+ }
+ }
+
+ CreateStreamingRequest 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 DeserializeCreateStreamingRequest(document.RootElement, options);
+ }
+ default:
+ throw new FormatException($"The model {nameof(CreateStreamingRequest)} 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 CreateStreamingRequest FromResponse(Response response)
+ {
+ using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions);
+ return DeserializeCreateStreamingRequest(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/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.cs
new file mode 100644
index 000000000000..934df93a91f3
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/CreateStreamingRequest.cs
@@ -0,0 +1,172 @@
+// 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.ChatProtocol
+{
+ /// The CreateStreamingRequest.
+ internal partial class CreateStreamingRequest
+ {
+ ///
+ /// 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 collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// is null.
+ internal CreateStreamingRequest(IEnumerable messages)
+ {
+ Argument.AssertNotNull(messages, nameof(messages));
+
+ Messages = messages.ToList();
+ Context = new ChangeTrackingDictionary();
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// The collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// Keeps track of any properties unknown to the library.
+ internal CreateStreamingRequest(IReadOnlyList messages, bool stream, BinaryData sessionState, IReadOnlyDictionary context, IDictionary serializedAdditionalRawData)
+ {
+ Messages = messages;
+ Stream = stream;
+ SessionState = sessionState;
+ Context = context;
+ _serializedAdditionalRawData = serializedAdditionalRawData;
+ }
+
+ /// Initializes a new instance of for deserialization.
+ internal CreateStreamingRequest()
+ {
+ }
+
+ ///
+ /// The collection of context messages associated with this completion request.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ public IReadOnlyList Messages { get; }
+ /// Indicates whether the completion is a streaming or non-streaming completion.
+ public bool Stream { get; } = true;
+
+ ///
+ /// Field that allows the chat app to store and retrieve data, the structure of such data is dependant on the backend
+ /// being used. The client must send back the data in this field unchanged in subsequent requests, until the chat app
+ /// sends a new one. The data in this field can be used to implement stateful services, such as remembering previous
+ /// conversations or user preferences.
+ ///
+ /// To assign an object to 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 BinaryData SessionState { get; }
+ ///
+ /// Context allows the chat app to receive extra parameters from the client, such as temperature, functions, or
+ /// customer_info. These parameters are specific to the chat app and not understood by the generic clients.
+ ///
+ /// 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 IReadOnlyDictionary Context { get; }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Docs/Chat.xml b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Docs/Chat.xml
new file mode 100644
index 000000000000..afdc935d46b5
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Docs/Chat.xml
@@ -0,0 +1,93 @@
+
+
+
+
+
+This sample shows how to call CreateAsync.
+");
+AzureKeyCredential credential = new AzureKeyCredential("");
+Chat client = new ChatProtocolClient(endpoint, credential).GetChatClient();
+
+Response response = await client.CreateAsync("chat", new ChatMessage[]
+{
+ new TextChatMessage(ChatRole.User, "Tell me a joke")
+}, false);
+]]>
+
+
+
+This sample shows how to call Create.
+");
+AzureKeyCredential credential = new AzureKeyCredential("");
+Chat client = new ChatProtocolClient(endpoint, credential).GetChatClient();
+
+Response response = client.Create("chat", new ChatMessage[]
+{
+ new TextChatMessage(ChatRole.User, "Tell me a joke")
+}, false);
+]]>
+
+
+
+This sample shows how to call CreateAsync and parse the result.
+");
+AzureKeyCredential credential = new AzureKeyCredential("");
+Chat client = new ChatProtocolClient(endpoint, credential).GetChatClient();
+
+using RequestContent content = RequestContent.Create(new
+{
+ messages = new object[]
+ {
+ new
+ {
+ kind = "text",
+ content = "Tell me a joke",
+ role = "user",
+ }
+ },
+ stream = false,
+});
+Response response = await client.CreateAsync("chat", content);
+
+JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("index").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("message").GetProperty("kind").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("message").GetProperty("role").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("finishReason").ToString());
+]]>
+
+
+
+This sample shows how to call Create and parse the result.
+");
+AzureKeyCredential credential = new AzureKeyCredential("");
+Chat client = new ChatProtocolClient(endpoint, credential).GetChatClient();
+
+using RequestContent content = RequestContent.Create(new
+{
+ messages = new object[]
+ {
+ new
+ {
+ kind = "text",
+ content = "Tell me a joke",
+ role = "user",
+ }
+ },
+ stream = false,
+});
+Response response = client.Create("chat", content);
+
+JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("index").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("message").GetProperty("kind").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("message").GetProperty("role").ToString());
+Console.WriteLine(result.GetProperty("choices")[0].GetProperty("finishReason").ToString());
+]]>
+
+
+
\ No newline at end of file
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/FinishReason.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/FinishReason.cs
new file mode 100644
index 000000000000..924be349b066
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/FinishReason.cs
@@ -0,0 +1,51 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ComponentModel;
+
+namespace Azure.AI.ChatProtocol
+{
+ /// Representation of the reason why a chat session has finished processing.
+ public readonly partial struct FinishReason : IEquatable
+ {
+ private readonly string _value;
+
+ /// Initializes a new instance of .
+ /// is null.
+ public FinishReason(string value)
+ {
+ _value = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ private const string StoppedValue = "stop";
+ private const string TokenLimitReachedValue = "length";
+
+ /// Completion ended normally.
+ public static FinishReason Stopped { get; } = new FinishReason(StoppedValue);
+ /// The completion exhausted available tokens before generation could complete.
+ public static FinishReason TokenLimitReached { get; } = new FinishReason(TokenLimitReachedValue);
+ /// Determines if two values are the same.
+ public static bool operator ==(FinishReason left, FinishReason right) => left.Equals(right);
+ /// Determines if two values are not the same.
+ public static bool operator !=(FinishReason left, FinishReason right) => !left.Equals(right);
+ /// Converts a to a .
+ public static implicit operator FinishReason(string value) => new FinishReason(value);
+
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool Equals(object obj) => obj is FinishReason other && Equals(other);
+ ///
+ public bool Equals(FinishReason 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/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/Argument.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/Argument.cs
new file mode 100644
index 000000000000..21dc735023fa
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/Argument.cs
@@ -0,0 +1,129 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ internal static class Argument
+ {
+ public static void AssertNotNull(T value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ }
+
+ public static void AssertNotNull(T? value, string name)
+ where T : struct
+ {
+ if (!value.HasValue)
+ {
+ throw new ArgumentNullException(name);
+ }
+ }
+
+ public static void AssertNotNullOrEmpty(IEnumerable value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (value is ICollection collectionOfT && collectionOfT.Count == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ if (value is ICollection collection && collection.Count == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ using IEnumerator e = value.GetEnumerator();
+ if (!e.MoveNext())
+ {
+ throw new ArgumentException("Value cannot be an empty collection.", name);
+ }
+ }
+
+ public static void AssertNotNullOrEmpty(string value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (value.Length == 0)
+ {
+ throw new ArgumentException("Value cannot be an empty string.", name);
+ }
+ }
+
+ public static void AssertNotNullOrWhiteSpace(string value, string name)
+ {
+ if (value is null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name);
+ }
+ }
+
+ public static void AssertNotDefault(ref T value, string name)
+ where T : struct, IEquatable
+ {
+ if (value.Equals(default))
+ {
+ throw new ArgumentException("Value cannot be empty.", name);
+ }
+ }
+
+ public static void AssertInRange(T value, T minimum, T maximum, string name)
+ where T : notnull, IComparable
+ {
+ if (minimum.CompareTo(value) > 0)
+ {
+ throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed.");
+ }
+ if (maximum.CompareTo(value) < 0)
+ {
+ throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed.");
+ }
+ }
+
+ public static void AssertEnumDefined(Type enumType, object value, string name)
+ {
+ if (!Enum.IsDefined(enumType, value))
+ {
+ throw new ArgumentException($"Value not defined for {enumType.FullName}.", name);
+ }
+ }
+
+ public static T CheckNotNull(T value, string name)
+ where T : class
+ {
+ AssertNotNull(value, name);
+ return value;
+ }
+
+ public static string CheckNotNullOrEmpty(string value, string name)
+ {
+ AssertNotNullOrEmpty(value, name);
+ return value;
+ }
+
+ public static void AssertNull(T value, string name, string message = null)
+ {
+ if (value != null)
+ {
+ throw new ArgumentException(message ?? "Value must be null.", name);
+ }
+ }
+ }
+}
diff --git a/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/ChangeTrackingDictionary.cs b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/ChangeTrackingDictionary.cs
new file mode 100644
index 000000000000..6405707756aa
--- /dev/null
+++ b/sdk/machinelearning/Azure.AI.ChatProtocol/src/Generated/Internal/ChangeTrackingDictionary.cs
@@ -0,0 +1,167 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Azure.AI.ChatProtocol
+{
+ internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull
+ {
+ private IDictionary _innerDictionary;
+
+ public ChangeTrackingDictionary()
+ {
+ }
+
+ public ChangeTrackingDictionary(IDictionary dictionary)
+ {
+ if (dictionary == null)
+ {
+ return;
+ }
+ _innerDictionary = new Dictionary(dictionary);
+ }
+
+ public ChangeTrackingDictionary(IReadOnlyDictionary dictionary)
+ {
+ if (dictionary == null)
+ {
+ return;
+ }
+ _innerDictionary = new Dictionary();
+ foreach (var pair in dictionary)
+ {
+ _innerDictionary.Add(pair);
+ }
+ }
+
+ public bool IsUndefined => _innerDictionary == null;
+
+ public int Count => IsUndefined ? 0 : EnsureDictionary().Count;
+
+ public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly;
+
+ public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys;
+
+ public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values;
+
+ public TValue this[TKey key]
+ {
+ get
+ {
+ if (IsUndefined)
+ {
+ throw new KeyNotFoundException(nameof(key));
+ }
+ return EnsureDictionary()[key];
+ }
+ set
+ {
+ EnsureDictionary()[key] = value;
+ }
+ }
+
+ IEnumerable IReadOnlyDictionary.Keys => Keys;
+
+ IEnumerable IReadOnlyDictionary.Values => Values;
+
+ public IEnumerator> GetEnumerator()
+ {
+ if (IsUndefined)
+ {
+ IEnumerator> enumerateEmpty()
+ {
+ yield break;
+ }
+ return enumerateEmpty();
+ }
+ return EnsureDictionary().GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void Add(KeyValuePair item)
+ {
+ EnsureDictionary().Add(item);
+ }
+
+ public void Clear()
+ {
+ EnsureDictionary().Clear();
+ }
+
+ public bool Contains(KeyValuePair item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Contains(item);
+ }
+
+ public void CopyTo(KeyValuePair[] array, int index)
+ {
+ if (IsUndefined)
+ {
+ return;
+ }
+ EnsureDictionary().CopyTo(array, index);
+ }
+
+ public bool Remove(KeyValuePair item)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Remove(item);
+ }
+
+ public void Add(TKey key, TValue value)
+ {
+ EnsureDictionary().Add(key, value);
+ }
+
+ public bool ContainsKey(TKey key)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().ContainsKey(key);
+ }
+
+ public bool Remove(TKey key)
+ {
+ if (IsUndefined)
+ {
+ return false;
+ }
+ return EnsureDictionary().Remove(key);
+ }
+
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ if (IsUndefined)
+ {
+ value = default;
+ return false;
+ }
+ return EnsureDictionary().TryGetValue(key, out value);
+ }
+
+ public IDictionary EnsureDictionary()
+ {
+ return _innerDictionary ??= new Dictionary