From df240910b04064e26d32a066ff683ed9fab1917b Mon Sep 17 00:00:00 2001 From: azure-sdk Date: Fri, 26 Jan 2024 10:51:07 +0000 Subject: [PATCH] Update SDK code me_po_6 --- .../AudioTranscription.Serialization.cs | 123 ++++- .../src/Generated/AudioTranscription.cs | 41 +- ...AudioTranscriptionOptions.Serialization.cs | 153 +++++- .../Generated/AudioTranscriptionOptions.cs | 37 +- ...AudioTranscriptionSegment.Serialization.cs | 122 ++++- .../Generated/AudioTranscriptionSegment.cs | 41 +- .../AudioTranslation.Serialization.cs | 123 ++++- .../src/Generated/AudioTranslation.cs | 41 +- .../AudioTranslationOptions.Serialization.cs | 147 +++++- .../src/Generated/AudioTranslationOptions.cs | 37 +- .../AudioTranslationSegment.Serialization.cs | 122 ++++- .../src/Generated/AudioTranslationSegment.cs | 41 +- ...tEnhancementConfiguration.Serialization.cs | 123 ++++- .../AzureChatEnhancementConfiguration.cs | 39 +- .../AzureChatEnhancements.Serialization.cs | 103 +++- .../src/Generated/AzureChatEnhancements.cs | 39 +- ...hatExtensionConfiguration.Serialization.cs | 104 +++- .../AzureChatExtensionConfiguration.cs | 39 +- ...tExtensionsMessageContext.Serialization.cs | 107 ++++- .../AzureChatExtensionsMessageContext.cs | 37 +- ...gEnhancementConfiguration.Serialization.cs | 109 ++++- ...reChatGroundingEnhancementConfiguration.cs | 49 ++ ...REnhancementConfiguration.Serialization.cs | 109 ++++- .../AzureChatOCREnhancementConfiguration.cs | 49 ++ ...hatExtensionConfiguration.Serialization.cs | 115 ++++- ...gnitiveSearchChatExtensionConfiguration.cs | 4 +- ...chChatExtensionParameters.Serialization.cs | 225 ++++++++- ...eCognitiveSearchChatExtensionParameters.cs | 37 +- ...hIndexFieldMappingOptions.Serialization.cs | 172 ++++++- ...CognitiveSearchIndexFieldMappingOptions.cs | 37 +- ...hatExtensionConfiguration.Serialization.cs | 115 ++++- ...AzureCosmosDBChatExtensionConfiguration.cs | 4 +- ...DBChatExtensionParameters.Serialization.cs | 183 ++++++- .../AzureCosmosDBChatExtensionParameters.cs | 37 +- ...smosDBFieldMappingOptions.Serialization.cs | 114 ++++- .../AzureCosmosDBFieldMappingOptions.cs | 41 +- ...AzureGroundingEnhancement.Serialization.cs | 105 +++- .../Generated/AzureGroundingEnhancement.cs | 41 +- ...nhancementCoordinatePoint.Serialization.cs | 103 +++- ...zureGroundingEnhancementCoordinatePoint.cs | 51 ++ ...eGroundingEnhancementLine.Serialization.cs | 107 ++++- .../AzureGroundingEnhancementLine.cs | 41 +- ...undingEnhancementLineSpan.Serialization.cs | 111 ++++- .../AzureGroundingEnhancementLineSpan.cs | 41 +- ...hatExtensionConfiguration.Serialization.cs | 115 ++++- ...LearningIndexChatExtensionConfiguration.cs | 4 +- ...exChatExtensionParameters.Serialization.cs | 173 ++++++- ...ineLearningIndexChatExtensionParameters.cs | 37 +- .../src/Generated/AzureOpenAIModelFactory.cs | 204 ++++++-- .../src/Generated/ChatChoice.Serialization.cs | 134 +++++- .../src/Generated/ChatChoice.cs | 44 +- .../ChatCompletions.Serialization.cs | 185 ++++++- .../src/Generated/ChatCompletions.cs | 41 +- ...mpletionsFunctionToolCall.Serialization.cs | 86 +++- .../ChatCompletionsFunctionToolCall.cs | 15 + ...onsFunctionToolDefinition.Serialization.cs | 115 ++++- .../ChatCompletionsFunctionToolDefinition.cs | 4 +- ...letionsJsonResponseFormat.Serialization.cs | 109 ++++- .../ChatCompletionsJsonResponseFormat.cs | 6 +- ...amedFunctionToolSelection.Serialization.cs | 144 ++++++ ...atCompletionsNamedFunctionToolSelection.cs | 45 ++ ...letionsNamedToolSelection.Serialization.cs | 127 +++++ .../ChatCompletionsNamedToolSelection.cs | 69 +++ .../ChatCompletionsOptions.Serialization.cs | 452 +++++++++++++++++- .../src/Generated/ChatCompletionsOptions.cs | 36 +- ...CompletionsResponseFormat.Serialization.cs | 101 +++- .../ChatCompletionsResponseFormat.cs | 39 +- ...letionsTextResponseFormat.Serialization.cs | 109 ++++- .../ChatCompletionsTextResponseFormat.cs | 6 +- .../ChatCompletionsToolCall.Serialization.cs | 77 ++- .../src/Generated/ChatCompletionsToolCall.cs | 42 +- ...CompletionsToolDefinition.Serialization.cs | 100 +++- .../ChatCompletionsToolDefinition.cs | 39 +- .../ChatFinishDetails.Serialization.cs | 92 +++- .../src/Generated/ChatFinishDetails.cs | 39 +- .../ChatMessageContentItem.Serialization.cs | 101 +++- .../src/Generated/ChatMessageContentItem.cs | 39 +- ...atMessageImageContentItem.Serialization.cs | 115 ++++- .../Generated/ChatMessageImageContentItem.cs | 9 +- .../ChatMessageImageUrl.Serialization.cs | 119 ++++- .../src/Generated/ChatMessageImageUrl.cs | 42 +- ...hatMessageTextContentItem.Serialization.cs | 115 ++++- .../Generated/ChatMessageTextContentItem.cs | 9 +- ...atRequestAssistantMessage.Serialization.cs | 151 +++++- .../Generated/ChatRequestAssistantMessage.cs | 9 +- ...hatRequestFunctionMessage.Serialization.cs | 126 ++++- .../Generated/ChatRequestFunctionMessage.cs | 9 +- .../ChatRequestMessage.Serialization.cs | 104 +++- .../src/Generated/ChatRequestMessage.cs | 39 +- .../ChatRequestSystemMessage.Serialization.cs | 121 ++++- .../src/Generated/ChatRequestSystemMessage.cs | 9 +- .../ChatRequestToolMessage.Serialization.cs | 126 ++++- .../src/Generated/ChatRequestToolMessage.cs | 9 +- .../ChatRequestUserMessage.Serialization.cs | 121 ++++- .../src/Generated/ChatRequestUserMessage.cs | 9 +- .../ChatResponseMessage.Serialization.cs | 128 ++++- .../src/Generated/ChatResponseMessage.cs | 42 +- .../src/Generated/Choice.Serialization.cs | 125 ++++- .../Azure.AI.OpenAI/src/Generated/Choice.cs | 42 +- .../Generated/Completions.Serialization.cs | 174 ++++++- .../src/Generated/Completions.cs | 41 +- ...etionsLogProbabilityModel.Serialization.cs | 147 +++++- .../CompletionsLogProbabilityModel.cs | 41 +- .../CompletionsOptions.Serialization.cs | 256 +++++++++- .../src/Generated/CompletionsOptions.cs | 36 +- .../CompletionsUsage.Serialization.cs | 105 +++- .../src/Generated/CompletionsUsage.cs | 53 ++ ...ntFilterBlocklistIdResult.Serialization.cs | 103 +++- .../ContentFilterBlocklistIdResult.cs | 49 ++ ...ilterCitedDetectionResult.Serialization.cs | 108 ++++- .../ContentFilterCitedDetectionResult.cs | 42 +- ...tentFilterDetectionResult.Serialization.cs | 103 +++- .../Generated/ContentFilterDetectionResult.cs | 51 ++ .../ContentFilterResult.Serialization.cs | 103 +++- .../src/Generated/ContentFilterResult.cs | 51 ++ ...terResultDetailsForPrompt.Serialization.cs | 142 +++++- .../ContentFilterResultDetailsForPrompt.cs | 37 +- ...entFilterResultsForChoice.Serialization.cs | 147 +++++- .../ContentFilterResultsForChoice.cs | 37 +- ...entFilterResultsForPrompt.Serialization.cs | 103 +++- .../ContentFilterResultsForPrompt.cs | 49 ++ ...hatExtensionConfiguration.Serialization.cs | 115 ++++- ...ElasticsearchChatExtensionConfiguration.cs | 4 +- ...chChatExtensionParameters.Serialization.cs | 191 +++++++- .../ElasticsearchChatExtensionParameters.cs | 37 +- ...hIndexFieldMappingOptions.Serialization.cs | 157 +++++- .../ElasticsearchIndexFieldMappingOptions.cs | 37 +- .../Generated/EmbeddingItem.Serialization.cs | 107 ++++- .../src/Generated/EmbeddingItem.cs | 51 ++ .../src/Generated/Embeddings.Serialization.cs | 107 ++++- .../src/Generated/Embeddings.cs | 41 +- .../EmbeddingsOptions.Serialization.cs | 126 ++++- .../src/Generated/EmbeddingsOptions.cs | 36 +- .../EmbeddingsUsage.Serialization.cs | 103 +++- .../src/Generated/EmbeddingsUsage.cs | 51 ++ .../Generated/FunctionCall.Serialization.cs | 86 +++- .../src/Generated/FunctionCall.cs | 54 +++ .../FunctionDefinition.Serialization.cs | 125 ++++- .../src/Generated/FunctionDefinition.cs | 37 +- .../Generated/FunctionName.Serialization.cs | 109 ++++- .../src/Generated/FunctionName.cs | 47 ++ .../ImageGenerationData.Serialization.cs | 112 ++++- .../src/Generated/ImageGenerationData.cs | 37 +- .../ImageGenerationOptions.Serialization.cs | 86 +++- .../src/Generated/ImageGenerationOptions.cs | 37 +- .../ImageGenerations.Serialization.cs | 84 +++- .../src/Generated/ImageGenerations.cs | 41 +- .../MaxTokensFinishDetails.Serialization.cs | 101 +++- .../src/Generated/MaxTokensFinishDetails.cs | 6 +- ...iKeyAuthenticationOptions.Serialization.cs | 115 ++++- .../OnYourDataApiKeyAuthenticationOptions.cs | 9 +- ...DataAuthenticationOptions.Serialization.cs | 104 +++- .../OnYourDataAuthenticationOptions.cs | 39 +- ...ringAuthenticationOptions.Serialization.cs | 115 ++++- ...taConnectionStringAuthenticationOptions.cs | 9 +- ...ntNameVectorizationSource.Serialization.cs | 115 ++++- ...urDataDeploymentNameVectorizationSource.cs | 9 +- ...dpointVectorizationSource.Serialization.cs | 121 ++++- .../OnYourDataEndpointVectorizationSource.cs | 9 +- ...eyIdAuthenticationOptions.Serialization.cs | 121 ++++- ...ourDataKeyAndKeyIdAuthenticationOptions.cs | 9 +- ...odelIdVectorizationSource.Serialization.cs | 115 ++++- .../OnYourDataModelIdVectorizationSource.cs | 9 +- ...tityAuthenticationOptions.Serialization.cs | 109 ++++- ...nedManagedIdentityAuthenticationOptions.cs | 6 +- ...tityAuthenticationOptions.Serialization.cs | 115 ++++- ...nedManagedIdentityAuthenticationOptions.cs | 9 +- ...urDataVectorizationSource.Serialization.cs | 102 +++- .../OnYourDataVectorizationSource.cs | 39 +- ...hatExtensionConfiguration.Serialization.cs | 115 ++++- .../PineconeChatExtensionConfiguration.cs | 4 +- ...neChatExtensionParameters.Serialization.cs | 177 ++++++- .../PineconeChatExtensionParameters.cs | 37 +- ...neconeFieldMappingOptions.Serialization.cs | 172 ++++++- .../Generated/PineconeFieldMappingOptions.cs | 37 +- .../StopFinishDetails.Serialization.cs | 103 +++- .../src/Generated/StopFinishDetails.cs | 9 +- ...hatExtensionConfiguration.Serialization.cs | 136 ++++++ .../UnknownAzureChatExtensionConfiguration.cs | 31 ++ ...letionsNamedToolSelection.Serialization.cs | 136 ++++++ ...nknownChatCompletionsNamedToolSelection.cs | 28 ++ ...CompletionsResponseFormat.Serialization.cs | 136 ++++++ .../UnknownChatCompletionsResponseFormat.cs | 28 ++ ...wnChatCompletionsToolCall.Serialization.cs | 103 +++- .../UnknownChatCompletionsToolCall.cs | 11 +- ...CompletionsToolDefinition.Serialization.cs | 136 ++++++ .../UnknownChatCompletionsToolDefinition.cs | 28 ++ .../UnknownChatFinishDetails.Serialization.cs | 101 +++- .../src/Generated/UnknownChatFinishDetails.cs | 11 +- ...ownChatMessageContentItem.Serialization.cs | 136 ++++++ .../UnknownChatMessageContentItem.cs | 28 ++ ...UnknownChatRequestMessage.Serialization.cs | 136 ++++++ .../Generated/UnknownChatRequestMessage.cs | 28 ++ ...DataAuthenticationOptions.Serialization.cs | 136 ++++++ .../UnknownOnYourDataAuthenticationOptions.cs | 28 ++ ...urDataVectorizationSource.Serialization.cs | 136 ++++++ .../UnknownOnYourDataVectorizationSource.cs | 28 ++ 197 files changed, 15379 insertions(+), 325 deletions(-) create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.Serialization.cs create mode 100644 sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.cs diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.Serialization.cs index 8d0357567a89f..00706a53cbe2e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,80 @@ namespace Azure.AI.OpenAI { - public partial class AudioTranscription + public partial class AudioTranscription : IUtf8JsonSerializable, IJsonModel { - internal static AudioTranscription DeserializeAudioTranscription(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranscription)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + if (Optional.IsDefined(InternalAudioTaskLabel)) + { + writer.WritePropertyName("task"u8); + writer.WriteStringValue(InternalAudioTaskLabel.Value.ToString()); + } + if (Optional.IsDefined(Language)) + { + writer.WritePropertyName("language"u8); + writer.WriteStringValue(Language); + } + if (Optional.IsDefined(Duration)) + { + writer.WritePropertyName("duration"u8); + writer.WriteNumberValue(Convert.ToDouble(Duration.Value.ToString("s\\.fff"))); + } + if (Optional.IsCollectionDefined(Segments)) + { + writer.WritePropertyName("segments"u8); + writer.WriteStartArray(); + foreach (var item in Segments) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AudioTranscription 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(AudioTranscription)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranscription(document.RootElement, options); + } + + internal static AudioTranscription DeserializeAudioTranscription(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -26,6 +97,8 @@ internal static AudioTranscription DeserializeAudioTranscription(JsonElement ele Optional language = default; Optional duration = default; Optional> segments = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -70,8 +143,52 @@ internal static AudioTranscription DeserializeAudioTranscription(JsonElement ele segments = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranscription(text, Optional.ToNullable(task), language.Value, Optional.ToNullable(duration), Optional.ToList(segments), 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(AudioTranscription)} does not support '{options.Format}' format."); } - return new AudioTranscription(text, Optional.ToNullable(task), language.Value, Optional.ToNullable(duration), Optional.ToList(segments)); + } + + AudioTranscription IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranscription(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranscription)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.cs index dd4e523bf8791..ab897d15c002e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscription.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI /// Result information for an operation that transcribed spoken audio into written text. public partial class AudioTranscription { + /// + /// 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 transcribed text for the provided audio data. /// is null. @@ -34,13 +66,20 @@ internal AudioTranscription(string text) /// /// The total duration of the audio processed to produce accompanying transcription information. /// A collection of information about the timing, probabilities, and other detail of each processed audio segment. - internal AudioTranscription(string text, AudioTaskLabel? internalAudioTaskLabel, string language, TimeSpan? duration, IReadOnlyList segments) + /// Keeps track of any properties unknown to the library. + internal AudioTranscription(string text, AudioTaskLabel? internalAudioTaskLabel, string language, TimeSpan? duration, IReadOnlyList segments, IDictionary serializedAdditionalRawData) { Text = text; InternalAudioTaskLabel = internalAudioTaskLabel; Language = language; Duration = duration; Segments = segments; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AudioTranscription() + { } /// The transcribed text for the provided audio data. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.Serialization.cs index 7c6678c5014f0..c15cdd7968772 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AudioTranscriptionOptions : IUtf8JsonSerializable + public partial class AudioTranscriptionOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranscriptionOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("file"u8); writer.WriteBase64StringValue(AudioData.ToArray(), "D"); @@ -47,7 +59,144 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("model"u8); writer.WriteStringValue(DeploymentName); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + AudioTranscriptionOptions 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(AudioTranscriptionOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranscriptionOptions(document.RootElement, options); + } + + internal static AudioTranscriptionOptions DeserializeAudioTranscriptionOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + BinaryData file = default; + Optional filename = default; + Optional responseFormat = default; + Optional language = default; + Optional prompt = default; + Optional temperature = default; + Optional model = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file"u8)) + { + file = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + responseFormat = new AudioTranscriptionFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("language"u8)) + { + language = property.Value.GetString(); + continue; + } + if (property.NameEquals("prompt"u8)) + { + prompt = property.Value.GetString(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranscriptionOptions(file, filename.Value, Optional.ToNullable(responseFormat), language.Value, prompt.Value, Optional.ToNullable(temperature), model.Value, 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(AudioTranscriptionOptions)} does not support '{options.Format}' format."); + } + } + + AudioTranscriptionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranscriptionOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranscriptionOptions)} does not support '{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 AudioTranscriptionOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAudioTranscriptionOptions(document.RootElement); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs index 19c603434d871..4cd8293400822 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// The configuration information for an audio transcription request. public partial class AudioTranscriptionOptions { + /// + /// 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 audio data to transcribe. This must be the binary content of a file in one of the supported media formats: @@ -35,7 +68,8 @@ public partial class AudioTranscriptionOptions /// If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit. /// /// The model to use for this transcription request. - internal AudioTranscriptionOptions(BinaryData audioData, string filename, AudioTranscriptionFormat? responseFormat, string language, string prompt, float? temperature, string deploymentName) + /// Keeps track of any properties unknown to the library. + internal AudioTranscriptionOptions(BinaryData audioData, string filename, AudioTranscriptionFormat? responseFormat, string language, string prompt, float? temperature, string deploymentName, IDictionary serializedAdditionalRawData) { AudioData = audioData; Filename = filename; @@ -44,6 +78,7 @@ internal AudioTranscriptionOptions(BinaryData audioData, string filename, AudioT Prompt = prompt; Temperature = temperature; DeploymentName = deploymentName; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The optional filename or descriptive identifier to associate with with the audio data. public string Filename { get; set; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.Serialization.cs index fc9f1a0115afe..a5df1b9d496b0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.Serialization.cs @@ -6,16 +6,86 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AudioTranscriptionSegment + public partial class AudioTranscriptionSegment : IUtf8JsonSerializable, IJsonModel { - internal static AudioTranscriptionSegment DeserializeAudioTranscriptionSegment(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranscriptionSegment)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteNumberValue(Id); + writer.WritePropertyName("start"u8); + writer.WriteNumberValue(Convert.ToDouble(Start.ToString("s\\.fff"))); + writer.WritePropertyName("end"u8); + writer.WriteNumberValue(Convert.ToDouble(End.ToString("s\\.fff"))); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature); + writer.WritePropertyName("avg_logprob"u8); + writer.WriteNumberValue(AverageLogProbability); + writer.WritePropertyName("compression_ratio"u8); + writer.WriteNumberValue(CompressionRatio); + writer.WritePropertyName("no_speech_prob"u8); + writer.WriteNumberValue(NoSpeechProbability); + writer.WritePropertyName("tokens"u8); + writer.WriteStartArray(); + foreach (var item in Tokens) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("seek"u8); + writer.WriteNumberValue(Seek); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AudioTranscriptionSegment 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(AudioTranscriptionSegment)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranscriptionSegment(document.RootElement, options); + } + + internal static AudioTranscriptionSegment DeserializeAudioTranscriptionSegment(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -30,6 +100,8 @@ internal static AudioTranscriptionSegment DeserializeAudioTranscriptionSegment(J float noSpeechProb = default; IReadOnlyList tokens = default; int seek = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -87,10 +159,46 @@ internal static AudioTranscriptionSegment DeserializeAudioTranscriptionSegment(J seek = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AudioTranscriptionSegment(id, start, end, text, temperature, avgLogprob, compressionRatio, noSpeechProb, tokens, seek); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranscriptionSegment(id, start, end, text, temperature, avgLogprob, compressionRatio, noSpeechProb, tokens, seek, 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(AudioTranscriptionSegment)} does not support '{options.Format}' format."); + } + } + + AudioTranscriptionSegment IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranscriptionSegment(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranscriptionSegment)} does not support '{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 AudioTranscriptionSegment FromResponse(Response response) @@ -98,5 +206,13 @@ internal static AudioTranscriptionSegment FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAudioTranscriptionSegment(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.cs index c52dfad27e043..a360076e1e93c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranscriptionSegment.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class AudioTranscriptionSegment { + /// + /// 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 0-based index of this segment within a transcription. /// The time at which this segment started relative to the beginning of the transcribed audio. @@ -71,7 +103,8 @@ internal AudioTranscriptionSegment(int id, TimeSpan start, TimeSpan end, string /// a later time than the segment's start, the segment's start may represent a significantly later time than the /// segment's associated seek position. /// - internal AudioTranscriptionSegment(int id, TimeSpan start, TimeSpan end, string text, float temperature, float averageLogProbability, float compressionRatio, float noSpeechProbability, IReadOnlyList tokens, int seek) + /// Keeps track of any properties unknown to the library. + internal AudioTranscriptionSegment(int id, TimeSpan start, TimeSpan end, string text, float temperature, float averageLogProbability, float compressionRatio, float noSpeechProbability, IReadOnlyList tokens, int seek, IDictionary serializedAdditionalRawData) { Id = id; Start = start; @@ -83,6 +116,12 @@ internal AudioTranscriptionSegment(int id, TimeSpan start, TimeSpan end, string NoSpeechProbability = noSpeechProbability; Tokens = tokens; Seek = seek; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AudioTranscriptionSegment() + { } /// The 0-based index of this segment within a transcription. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.Serialization.cs index 0e05e368f9c7c..e074621aa930d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,80 @@ namespace Azure.AI.OpenAI { - public partial class AudioTranslation + public partial class AudioTranslation : IUtf8JsonSerializable, IJsonModel { - internal static AudioTranslation DeserializeAudioTranslation(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranslation)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + if (Optional.IsDefined(InternalAudioTaskLabel)) + { + writer.WritePropertyName("task"u8); + writer.WriteStringValue(InternalAudioTaskLabel.Value.ToString()); + } + if (Optional.IsDefined(Language)) + { + writer.WritePropertyName("language"u8); + writer.WriteStringValue(Language); + } + if (Optional.IsDefined(Duration)) + { + writer.WritePropertyName("duration"u8); + writer.WriteNumberValue(Convert.ToDouble(Duration.Value.ToString("s\\.fff"))); + } + if (Optional.IsCollectionDefined(Segments)) + { + writer.WritePropertyName("segments"u8); + writer.WriteStartArray(); + foreach (var item in Segments) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AudioTranslation 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(AudioTranslation)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranslation(document.RootElement, options); + } + + internal static AudioTranslation DeserializeAudioTranslation(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -26,6 +97,8 @@ internal static AudioTranslation DeserializeAudioTranslation(JsonElement element Optional language = default; Optional duration = default; Optional> segments = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -70,8 +143,52 @@ internal static AudioTranslation DeserializeAudioTranslation(JsonElement element segments = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranslation(text, Optional.ToNullable(task), language.Value, Optional.ToNullable(duration), Optional.ToList(segments), 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(AudioTranslation)} does not support '{options.Format}' format."); } - return new AudioTranslation(text, Optional.ToNullable(task), language.Value, Optional.ToNullable(duration), Optional.ToList(segments)); + } + + AudioTranslation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranslation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranslation)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.cs index 78a40c4c9a648..8aaef60fcd209 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslation.cs @@ -14,6 +14,38 @@ namespace Azure.AI.OpenAI /// Result information for an operation that translated spoken audio into written text. public partial class AudioTranslation { + /// + /// 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 translated text for the provided audio data. /// is null. @@ -34,13 +66,20 @@ internal AudioTranslation(string text) /// /// The total duration of the audio processed to produce accompanying translation information. /// A collection of information about the timing, probabilities, and other detail of each processed audio segment. - internal AudioTranslation(string text, AudioTaskLabel? internalAudioTaskLabel, string language, TimeSpan? duration, IReadOnlyList segments) + /// Keeps track of any properties unknown to the library. + internal AudioTranslation(string text, AudioTaskLabel? internalAudioTaskLabel, string language, TimeSpan? duration, IReadOnlyList segments, IDictionary serializedAdditionalRawData) { Text = text; InternalAudioTaskLabel = internalAudioTaskLabel; Language = language; Duration = duration; Segments = segments; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AudioTranslation() + { } /// The translated text for the provided audio data. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.Serialization.cs index b64a30592eefb..ca8ab42e88c79 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AudioTranslationOptions : IUtf8JsonSerializable + public partial class AudioTranslationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranslationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("file"u8); writer.WriteBase64StringValue(AudioData.ToArray(), "D"); @@ -42,7 +54,138 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("model"u8); writer.WriteStringValue(DeploymentName); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + + AudioTranslationOptions 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(AudioTranslationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranslationOptions(document.RootElement, options); + } + + internal static AudioTranslationOptions DeserializeAudioTranslationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + BinaryData file = default; + Optional filename = default; + Optional responseFormat = default; + Optional prompt = default; + Optional temperature = default; + Optional model = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file"u8)) + { + file = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + responseFormat = new AudioTranslationFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("prompt"u8)) + { + prompt = property.Value.GetString(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranslationOptions(file, filename.Value, Optional.ToNullable(responseFormat), prompt.Value, Optional.ToNullable(temperature), model.Value, 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(AudioTranslationOptions)} does not support '{options.Format}' format."); + } + } + + AudioTranslationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranslationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranslationOptions)} does not support '{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 AudioTranslationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAudioTranslationOptions(document.RootElement); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs index d637e40801e0f..0b5d997807606 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// The configuration information for an audio translation request. public partial class AudioTranslationOptions { + /// + /// 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 audio data to translate. This must be the binary content of a file in one of the supported media formats: @@ -30,7 +63,8 @@ public partial class AudioTranslationOptions /// If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit. /// /// The model to use for this translation request. - internal AudioTranslationOptions(BinaryData audioData, string filename, AudioTranslationFormat? responseFormat, string prompt, float? temperature, string deploymentName) + /// Keeps track of any properties unknown to the library. + internal AudioTranslationOptions(BinaryData audioData, string filename, AudioTranslationFormat? responseFormat, string prompt, float? temperature, string deploymentName, IDictionary serializedAdditionalRawData) { AudioData = audioData; Filename = filename; @@ -38,6 +72,7 @@ internal AudioTranslationOptions(BinaryData audioData, string filename, AudioTra Prompt = prompt; Temperature = temperature; DeploymentName = deploymentName; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The optional filename or descriptive identifier to associate with with the audio data. public string Filename { get; set; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.Serialization.cs index ca50efcda205d..0b2b78602b9ae 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.Serialization.cs @@ -6,16 +6,86 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AudioTranslationSegment + public partial class AudioTranslationSegment : IUtf8JsonSerializable, IJsonModel { - internal static AudioTranslationSegment DeserializeAudioTranslationSegment(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AudioTranslationSegment)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteNumberValue(Id); + writer.WritePropertyName("start"u8); + writer.WriteNumberValue(Convert.ToDouble(Start.ToString("s\\.fff"))); + writer.WritePropertyName("end"u8); + writer.WriteNumberValue(Convert.ToDouble(End.ToString("s\\.fff"))); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature); + writer.WritePropertyName("avg_logprob"u8); + writer.WriteNumberValue(AverageLogProbability); + writer.WritePropertyName("compression_ratio"u8); + writer.WriteNumberValue(CompressionRatio); + writer.WritePropertyName("no_speech_prob"u8); + writer.WriteNumberValue(NoSpeechProbability); + writer.WritePropertyName("tokens"u8); + writer.WriteStartArray(); + foreach (var item in Tokens) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("seek"u8); + writer.WriteNumberValue(Seek); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AudioTranslationSegment 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(AudioTranslationSegment)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAudioTranslationSegment(document.RootElement, options); + } + + internal static AudioTranslationSegment DeserializeAudioTranslationSegment(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -30,6 +100,8 @@ internal static AudioTranslationSegment DeserializeAudioTranslationSegment(JsonE float noSpeechProb = default; IReadOnlyList tokens = default; int seek = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -87,10 +159,46 @@ internal static AudioTranslationSegment DeserializeAudioTranslationSegment(JsonE seek = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AudioTranslationSegment(id, start, end, text, temperature, avgLogprob, compressionRatio, noSpeechProb, tokens, seek); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AudioTranslationSegment(id, start, end, text, temperature, avgLogprob, compressionRatio, noSpeechProb, tokens, seek, 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(AudioTranslationSegment)} does not support '{options.Format}' format."); + } + } + + AudioTranslationSegment IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAudioTranslationSegment(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AudioTranslationSegment)} does not support '{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 AudioTranslationSegment FromResponse(Response response) @@ -98,5 +206,13 @@ internal static AudioTranslationSegment FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAudioTranslationSegment(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.cs index e1533bc9d6c85..7dc6569ac8ddd 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AudioTranslationSegment.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class AudioTranslationSegment { + /// + /// 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 0-based index of this segment within a translation. /// The time at which this segment started relative to the beginning of the translated audio. @@ -71,7 +103,8 @@ internal AudioTranslationSegment(int id, TimeSpan start, TimeSpan end, string te /// a later time than the segment's start, the segment's start may represent a significantly later time than the /// segment's associated seek position. /// - internal AudioTranslationSegment(int id, TimeSpan start, TimeSpan end, string text, float temperature, float averageLogProbability, float compressionRatio, float noSpeechProbability, IReadOnlyList tokens, int seek) + /// Keeps track of any properties unknown to the library. + internal AudioTranslationSegment(int id, TimeSpan start, TimeSpan end, string text, float temperature, float averageLogProbability, float compressionRatio, float noSpeechProbability, IReadOnlyList tokens, int seek, IDictionary serializedAdditionalRawData) { Id = id; Start = start; @@ -83,6 +116,12 @@ internal AudioTranslationSegment(int id, TimeSpan start, TimeSpan end, string te NoSpeechProbability = noSpeechProbability; Tokens = tokens; Seek = seek; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AudioTranslationSegment() + { } /// The 0-based index of this segment within a translation. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.Serialization.cs index 5d74fae94c675..dbeab48bd9acb 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureChatEnhancementConfiguration : IUtf8JsonSerializable + public partial class AzureChatEnhancementConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatEnhancementConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Grounding)) { @@ -25,9 +37,116 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("ocr"u8); writer.WriteObjectValue(Ocr); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureChatEnhancementConfiguration 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(AzureChatEnhancementConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatEnhancementConfiguration(document.RootElement, options); + } + + internal static AzureChatEnhancementConfiguration DeserializeAzureChatEnhancementConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional grounding = default; + Optional ocr = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("grounding"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + grounding = AzureChatGroundingEnhancementConfiguration.DeserializeAzureChatGroundingEnhancementConfiguration(property.Value); + continue; + } + if (property.NameEquals("ocr"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + ocr = AzureChatOCREnhancementConfiguration.DeserializeAzureChatOCREnhancementConfiguration(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureChatEnhancementConfiguration(grounding.Value, ocr.Value, 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(AzureChatEnhancementConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureChatEnhancementConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatEnhancementConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatEnhancementConfiguration)} does not support '{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 AzureChatEnhancementConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureChatEnhancementConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.cs index 2ccc151c9fe35..9abaf36c33a7c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancementConfiguration.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// A representation of the available Azure OpenAI enhancement configurations. public partial class AzureChatEnhancementConfiguration { + /// + /// 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 . public AzureChatEnhancementConfiguration() { @@ -18,10 +53,12 @@ public AzureChatEnhancementConfiguration() /// Initializes a new instance of . /// A representation of the available options for the Azure OpenAI grounding enhancement. /// A representation of the available options for the Azure OpenAI optical character recognition (OCR) enhancement. - internal AzureChatEnhancementConfiguration(AzureChatGroundingEnhancementConfiguration grounding, AzureChatOCREnhancementConfiguration ocr) + /// Keeps track of any properties unknown to the library. + internal AzureChatEnhancementConfiguration(AzureChatGroundingEnhancementConfiguration grounding, AzureChatOCREnhancementConfiguration ocr, IDictionary serializedAdditionalRawData) { Grounding = grounding; Ocr = ocr; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// A representation of the available options for the Azure OpenAI grounding enhancement. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.Serialization.cs index 3e2963a23e5aa..d482027612911 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureChatEnhancements + public partial class AzureChatEnhancements : IUtf8JsonSerializable, IJsonModel { - internal static AzureChatEnhancements DeserializeAzureChatEnhancements(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatEnhancements)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Grounding)) + { + writer.WritePropertyName("grounding"u8); + writer.WriteObjectValue(Grounding); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureChatEnhancements 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(AzureChatEnhancements)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatEnhancements(document.RootElement, options); + } + + internal static AzureChatEnhancements DeserializeAzureChatEnhancements(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } Optional grounding = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("grounding"u8)) @@ -31,10 +84,46 @@ internal static AzureChatEnhancements DeserializeAzureChatEnhancements(JsonEleme grounding = AzureGroundingEnhancement.DeserializeAzureGroundingEnhancement(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AzureChatEnhancements(grounding.Value); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureChatEnhancements(grounding.Value, 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(AzureChatEnhancements)} does not support '{options.Format}' format."); + } + } + + AzureChatEnhancements IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatEnhancements(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatEnhancements)} does not support '{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 AzureChatEnhancements FromResponse(Response response) @@ -42,5 +131,13 @@ internal static AzureChatEnhancements FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAzureChatEnhancements(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.cs index 4b1b681f4ba36..113d9a88ea0af 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatEnhancements.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -13,6 +16,38 @@ namespace Azure.AI.OpenAI /// public partial class AzureChatEnhancements { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . internal AzureChatEnhancements() { @@ -20,9 +55,11 @@ internal AzureChatEnhancements() /// Initializes a new instance of . /// The grounding enhancement that returns the bounding box of the objects detected in the image. - internal AzureChatEnhancements(AzureGroundingEnhancement grounding) + /// Keeps track of any properties unknown to the library. + internal AzureChatEnhancements(AzureGroundingEnhancement grounding, IDictionary serializedAdditionalRawData) { Grounding = grounding; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The grounding enhancement that returns the bounding box of the objects detected in the image. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.Serialization.cs index efcda12616138..fdcfb7acf360f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.Serialization.cs @@ -5,21 +5,121 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureChatExtensionConfiguration : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownAzureChatExtensionConfiguration))] + public partial class AzureChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureChatExtensionConfiguration 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(AzureChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatExtensionConfiguration(document.RootElement, options); + } + + internal static AzureChatExtensionConfiguration DeserializeAzureChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "AzureCognitiveSearch": return AzureCognitiveSearchChatExtensionConfiguration.DeserializeAzureCognitiveSearchChatExtensionConfiguration(element); + case "AzureMLIndex": return AzureMachineLearningIndexChatExtensionConfiguration.DeserializeAzureMachineLearningIndexChatExtensionConfiguration(element); + case "AzureCosmosDB": return AzureCosmosDBChatExtensionConfiguration.DeserializeAzureCosmosDBChatExtensionConfiguration(element); + case "Elasticsearch": return ElasticsearchChatExtensionConfiguration.DeserializeElasticsearchChatExtensionConfiguration(element); + case "Pinecone": return PineconeChatExtensionConfiguration.DeserializePineconeChatExtensionConfiguration(element); + } + } + return UnknownAzureChatExtensionConfiguration.DeserializeUnknownAzureChatExtensionConfiguration(element); + } + + 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(AzureChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatExtensionConfiguration)} does not support '{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 AzureChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.cs index 00b70e36df3fb..e93e7dfdc56dc 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionConfiguration.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -16,6 +19,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class AzureChatExtensionConfiguration { + /// + /// 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 AzureChatExtensionConfiguration() { @@ -26,9 +61,11 @@ protected AzureChatExtensionConfiguration() /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// - internal AzureChatExtensionConfiguration(AzureChatExtensionType type) + /// Keeps track of any properties unknown to the library. + internal AzureChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.Serialization.cs index 07f7f7a70e68f..6702a883d4b4f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.Serialization.cs @@ -5,6 +5,8 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -12,15 +14,70 @@ namespace Azure.AI.OpenAI { - public partial class AzureChatExtensionsMessageContext + public partial class AzureChatExtensionsMessageContext : IUtf8JsonSerializable, IJsonModel { - internal static AzureChatExtensionsMessageContext DeserializeAzureChatExtensionsMessageContext(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatExtensionsMessageContext)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsCollectionDefined(Messages)) + { + writer.WritePropertyName("messages"u8); + writer.WriteStartArray(); + foreach (var item in Messages) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureChatExtensionsMessageContext 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(AzureChatExtensionsMessageContext)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatExtensionsMessageContext(document.RootElement, options); + } + + internal static AzureChatExtensionsMessageContext DeserializeAzureChatExtensionsMessageContext(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } Optional> messages = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("messages"u8)) @@ -37,10 +94,46 @@ internal static AzureChatExtensionsMessageContext DeserializeAzureChatExtensions messages = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureChatExtensionsMessageContext(Optional.ToList(messages), 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(AzureChatExtensionsMessageContext)} does not support '{options.Format}' format."); + } + } + + AzureChatExtensionsMessageContext IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatExtensionsMessageContext(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatExtensionsMessageContext)} does not support '{options.Format}' format."); } - return new AzureChatExtensionsMessageContext(Optional.ToList(messages)); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static AzureChatExtensionsMessageContext FromResponse(Response response) @@ -48,5 +141,13 @@ internal static AzureChatExtensionsMessageContext FromResponse(Response response using var document = JsonDocument.Parse(response.Content); return DeserializeAzureChatExtensionsMessageContext(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.cs index 39535877a341a..a1a026d72e65a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatExtensionsMessageContext.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -17,6 +18,38 @@ namespace Azure.AI.OpenAI /// public partial class AzureChatExtensionsMessageContext { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . internal AzureChatExtensionsMessageContext() { @@ -30,9 +63,11 @@ internal AzureChatExtensionsMessageContext() /// course of generating a chat completions response that was augmented by capabilities from Azure OpenAI chat /// extensions. /// - internal AzureChatExtensionsMessageContext(IReadOnlyList messages) + /// Keeps track of any properties unknown to the library. + internal AzureChatExtensionsMessageContext(IReadOnlyList messages, IDictionary serializedAdditionalRawData) { Messages = messages; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.Serialization.cs index 3e6a5255e8907..074bd93c55a00 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureChatGroundingEnhancementConfiguration : IUtf8JsonSerializable + public partial class AzureChatGroundingEnhancementConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatGroundingEnhancementConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("enabled"u8); writer.WriteBooleanValue(Enabled); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureChatGroundingEnhancementConfiguration 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(AzureChatGroundingEnhancementConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatGroundingEnhancementConfiguration(document.RootElement, options); + } + + internal static AzureChatGroundingEnhancementConfiguration DeserializeAzureChatGroundingEnhancementConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool enabled = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("enabled"u8)) + { + enabled = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureChatGroundingEnhancementConfiguration(enabled, 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(AzureChatGroundingEnhancementConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureChatGroundingEnhancementConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatGroundingEnhancementConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatGroundingEnhancementConfiguration)} does not support '{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 AzureChatGroundingEnhancementConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureChatGroundingEnhancementConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.cs index d394300e5fea7..8e14c4e438d24 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatGroundingEnhancementConfiguration.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// A representation of the available options for the Azure OpenAI grounding enhancement. public partial class AzureChatGroundingEnhancementConfiguration { + /// + /// 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 . /// Specifies whether the enhancement is enabled. public AzureChatGroundingEnhancementConfiguration(bool enabled) @@ -17,6 +52,20 @@ public AzureChatGroundingEnhancementConfiguration(bool enabled) Enabled = enabled; } + /// Initializes a new instance of . + /// Specifies whether the enhancement is enabled. + /// Keeps track of any properties unknown to the library. + internal AzureChatGroundingEnhancementConfiguration(bool enabled, IDictionary serializedAdditionalRawData) + { + Enabled = enabled; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureChatGroundingEnhancementConfiguration() + { + } + /// Specifies whether the enhancement is enabled. public bool Enabled { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.Serialization.cs index d3ec2d4a2928c..22cd3a83f97e3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureChatOCREnhancementConfiguration : IUtf8JsonSerializable + public partial class AzureChatOCREnhancementConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatOCREnhancementConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("enabled"u8); writer.WriteBooleanValue(Enabled); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureChatOCREnhancementConfiguration 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(AzureChatOCREnhancementConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureChatOCREnhancementConfiguration(document.RootElement, options); + } + + internal static AzureChatOCREnhancementConfiguration DeserializeAzureChatOCREnhancementConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool enabled = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("enabled"u8)) + { + enabled = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureChatOCREnhancementConfiguration(enabled, 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(AzureChatOCREnhancementConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureChatOCREnhancementConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureChatOCREnhancementConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatOCREnhancementConfiguration)} does not support '{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 AzureChatOCREnhancementConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureChatOCREnhancementConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.cs index 98975b15ef970..6f3aee5baa5af 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureChatOCREnhancementConfiguration.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// A representation of the available options for the Azure OpenAI optical character recognition (OCR) enhancement. public partial class AzureChatOCREnhancementConfiguration { + /// + /// 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 . /// Specifies whether the enhancement is enabled. public AzureChatOCREnhancementConfiguration(bool enabled) @@ -17,6 +52,20 @@ public AzureChatOCREnhancementConfiguration(bool enabled) Enabled = enabled; } + /// Initializes a new instance of . + /// Specifies whether the enhancement is enabled. + /// Keeps track of any properties unknown to the library. + internal AzureChatOCREnhancementConfiguration(bool enabled, IDictionary serializedAdditionalRawData) + { + Enabled = enabled; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureChatOCREnhancementConfiguration() + { + } + /// Specifies whether the enhancement is enabled. public bool Enabled { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.Serialization.cs index a2dfd6dc2a164..1ed4b19a6d265 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureCognitiveSearchChatExtensionConfiguration : IUtf8JsonSerializable + public partial class AzureCognitiveSearchChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCognitiveSearchChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("parameters"u8); writer.WriteObjectValue(Parameters); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCognitiveSearchChatExtensionConfiguration 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(AzureCognitiveSearchChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCognitiveSearchChatExtensionConfiguration(document.RootElement, options); + } + + internal static AzureCognitiveSearchChatExtensionConfiguration DeserializeAzureCognitiveSearchChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AzureCognitiveSearchChatExtensionParameters parameters = default; + AzureChatExtensionType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("parameters"u8)) + { + parameters = AzureCognitiveSearchChatExtensionParameters.DeserializeAzureCognitiveSearchChatExtensionParameters(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCognitiveSearchChatExtensionConfiguration(type, serializedAdditionalRawData, parameters); + } + + 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(AzureCognitiveSearchChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureCognitiveSearchChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCognitiveSearchChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCognitiveSearchChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AzureCognitiveSearchChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCognitiveSearchChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.cs index 6aaac531f0d6e..956503b334f8f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionConfiguration.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -21,8 +22,9 @@ public partial class AzureCognitiveSearchChatExtensionConfiguration : AzureChatE /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// + /// Keeps track of any properties unknown to the library. /// The parameters to use when configuring Azure Cognitive Search. - internal AzureCognitiveSearchChatExtensionConfiguration(AzureChatExtensionType type, AzureCognitiveSearchChatExtensionParameters parameters) : base(type) + internal AzureCognitiveSearchChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData, AzureCognitiveSearchChatExtensionParameters parameters) : base(type, serializedAdditionalRawData) { Parameters = parameters; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.Serialization.cs index 76a1a8d9c335b..94848a3bd85a3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class AzureCognitiveSearchChatExtensionParameters : IUtf8JsonSerializable + internal partial class AzureCognitiveSearchChatExtensionParameters : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCognitiveSearchChatExtensionParameters)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Authentication)) { @@ -84,9 +96,218 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("embeddingDependency"u8); writer.WriteObjectValue(EmbeddingDependency); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCognitiveSearchChatExtensionParameters 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(AzureCognitiveSearchChatExtensionParameters)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCognitiveSearchChatExtensionParameters(document.RootElement, options); + } + + internal static AzureCognitiveSearchChatExtensionParameters DeserializeAzureCognitiveSearchChatExtensionParameters(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional authentication = default; + Optional topNDocuments = default; + Optional inScope = default; + Optional strictness = default; + Optional roleInformation = default; + Uri endpoint = default; + string indexName = default; + Optional key = default; + Optional fieldsMapping = default; + Optional queryType = default; + Optional semanticConfiguration = default; + Optional filter = default; + Optional embeddingEndpoint = default; + Optional embeddingKey = default; + Optional embeddingDependency = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("authentication"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("topNDocuments"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topNDocuments = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("inScope"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inScope = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("strictness"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strictness = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("roleInformation"u8)) + { + roleInformation = property.Value.GetString(); + continue; + } + if (property.NameEquals("endpoint"u8)) + { + endpoint = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("indexName"u8)) + { + indexName = property.Value.GetString(); + continue; + } + if (property.NameEquals("key"u8)) + { + key = property.Value.GetString(); + continue; + } + if (property.NameEquals("fieldsMapping"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fieldsMapping = AzureCognitiveSearchIndexFieldMappingOptions.DeserializeAzureCognitiveSearchIndexFieldMappingOptions(property.Value); + continue; + } + if (property.NameEquals("queryType"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + queryType = new AzureCognitiveSearchQueryType(property.Value.GetString()); + continue; + } + if (property.NameEquals("semanticConfiguration"u8)) + { + semanticConfiguration = property.Value.GetString(); + continue; + } + if (property.NameEquals("filter"u8)) + { + filter = property.Value.GetString(); + continue; + } + if (property.NameEquals("embeddingEndpoint"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + embeddingEndpoint = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("embeddingKey"u8)) + { + embeddingKey = property.Value.GetString(); + continue; + } + if (property.NameEquals("embeddingDependency"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + embeddingDependency = OnYourDataVectorizationSource.DeserializeOnYourDataVectorizationSource(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCognitiveSearchChatExtensionParameters(authentication.Value, Optional.ToNullable(topNDocuments), Optional.ToNullable(inScope), Optional.ToNullable(strictness), roleInformation.Value, endpoint, indexName, key.Value, fieldsMapping.Value, Optional.ToNullable(queryType), semanticConfiguration.Value, filter.Value, embeddingEndpoint.Value, embeddingKey.Value, embeddingDependency.Value, 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(AzureCognitiveSearchChatExtensionParameters)} does not support '{options.Format}' format."); + } + } + + AzureCognitiveSearchChatExtensionParameters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCognitiveSearchChatExtensionParameters(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCognitiveSearchChatExtensionParameters)} does not support '{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 AzureCognitiveSearchChatExtensionParameters FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCognitiveSearchChatExtensionParameters(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.cs index 68713a8ea8f6a..20e752cd96be4 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchChatExtensionParameters.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Parameters for Azure Cognitive Search when used as an Azure OpenAI chat extension. internal partial class AzureCognitiveSearchChatExtensionParameters { + /// + /// 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 authentication method to use when accessing the defined data source. @@ -35,7 +68,8 @@ internal partial class AzureCognitiveSearchChatExtensionParameters /// When using embeddings for search, specifies the resource endpoint URL from which embeddings should be retrieved. It should be in the format of format https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings?api-version={api-version}. /// When using embeddings, specifies the API key to use with the provided embeddings endpoint. /// The embedding dependency for vector search. - internal AzureCognitiveSearchChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, Uri searchEndpoint, string indexName, string key, AzureCognitiveSearchIndexFieldMappingOptions fieldMappingOptions, AzureCognitiveSearchQueryType? queryType, string semanticConfiguration, string filter, Uri embeddingEndpoint, string embeddingKey, OnYourDataVectorizationSource embeddingDependency) + /// Keeps track of any properties unknown to the library. + internal AzureCognitiveSearchChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, Uri searchEndpoint, string indexName, string key, AzureCognitiveSearchIndexFieldMappingOptions fieldMappingOptions, AzureCognitiveSearchQueryType? queryType, string semanticConfiguration, string filter, Uri embeddingEndpoint, string embeddingKey, OnYourDataVectorizationSource embeddingDependency, IDictionary serializedAdditionalRawData) { Authentication = authentication; DocumentCount = documentCount; @@ -52,6 +86,7 @@ internal AzureCognitiveSearchChatExtensionParameters(OnYourDataAuthenticationOpt EmbeddingEndpoint = embeddingEndpoint; EmbeddingKey = embeddingKey; EmbeddingDependency = embeddingDependency; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.Serialization.cs index 7ff17aad1f9d6..a9ebd966b93ac 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureCognitiveSearchIndexFieldMappingOptions : IUtf8JsonSerializable + public partial class AzureCognitiveSearchIndexFieldMappingOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCognitiveSearchIndexFieldMappingOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(TitleFieldName)) { @@ -65,9 +77,165 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCognitiveSearchIndexFieldMappingOptions 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(AzureCognitiveSearchIndexFieldMappingOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCognitiveSearchIndexFieldMappingOptions(document.RootElement, options); + } + + internal static AzureCognitiveSearchIndexFieldMappingOptions DeserializeAzureCognitiveSearchIndexFieldMappingOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional titleField = default; + Optional urlField = default; + Optional filepathField = default; + Optional> contentFields = default; + Optional contentFieldsSeparator = default; + Optional> vectorFields = default; + Optional> imageVectorFields = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("titleField"u8)) + { + titleField = property.Value.GetString(); + continue; + } + if (property.NameEquals("urlField"u8)) + { + urlField = property.Value.GetString(); + continue; + } + if (property.NameEquals("filepathField"u8)) + { + filepathField = property.Value.GetString(); + continue; + } + if (property.NameEquals("contentFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + contentFields = array; + continue; + } + if (property.NameEquals("contentFieldsSeparator"u8)) + { + contentFieldsSeparator = property.Value.GetString(); + continue; + } + if (property.NameEquals("vectorFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + vectorFields = array; + continue; + } + if (property.NameEquals("imageVectorFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + imageVectorFields = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCognitiveSearchIndexFieldMappingOptions(titleField.Value, urlField.Value, filepathField.Value, Optional.ToList(contentFields), contentFieldsSeparator.Value, Optional.ToList(vectorFields), Optional.ToList(imageVectorFields), 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(AzureCognitiveSearchIndexFieldMappingOptions)} does not support '{options.Format}' format."); + } + } + + AzureCognitiveSearchIndexFieldMappingOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCognitiveSearchIndexFieldMappingOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCognitiveSearchIndexFieldMappingOptions)} does not support '{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 AzureCognitiveSearchIndexFieldMappingOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCognitiveSearchIndexFieldMappingOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.cs index 3145681c4ae98..4813bf5ae917a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCognitiveSearchIndexFieldMappingOptions.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Optional settings to control how fields are processed when using a configured Azure Cognitive Search resource. public partial class AzureCognitiveSearchIndexFieldMappingOptions { + /// + /// 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 . public AzureCognitiveSearchIndexFieldMappingOptions() { @@ -29,7 +62,8 @@ public AzureCognitiveSearchIndexFieldMappingOptions() /// The separator pattern that content fields should use. /// The names of fields that represent vector data. /// The names of fields that represent image vector data. - internal AzureCognitiveSearchIndexFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames, IList imageVectorFieldNames) + /// Keeps track of any properties unknown to the library. + internal AzureCognitiveSearchIndexFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames, IList imageVectorFieldNames, IDictionary serializedAdditionalRawData) { TitleFieldName = titleFieldName; UrlFieldName = urlFieldName; @@ -38,6 +72,7 @@ internal AzureCognitiveSearchIndexFieldMappingOptions(string titleFieldName, str ContentFieldSeparator = contentFieldSeparator; VectorFieldNames = vectorFieldNames; ImageVectorFieldNames = imageVectorFieldNames; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The name of the index field to use as a title. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.Serialization.cs index 87d45f0ef5041..9af5c77aafbb3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureCosmosDBChatExtensionConfiguration : IUtf8JsonSerializable + public partial class AzureCosmosDBChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCosmosDBChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("parameters"u8); writer.WriteObjectValue(Parameters); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCosmosDBChatExtensionConfiguration 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(AzureCosmosDBChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCosmosDBChatExtensionConfiguration(document.RootElement, options); + } + + internal static AzureCosmosDBChatExtensionConfiguration DeserializeAzureCosmosDBChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AzureCosmosDBChatExtensionParameters parameters = default; + AzureChatExtensionType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("parameters"u8)) + { + parameters = AzureCosmosDBChatExtensionParameters.DeserializeAzureCosmosDBChatExtensionParameters(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCosmosDBChatExtensionConfiguration(type, serializedAdditionalRawData, parameters); + } + + 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(AzureCosmosDBChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureCosmosDBChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCosmosDBChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCosmosDBChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AzureCosmosDBChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCosmosDBChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.cs index 72bad8dd7f876..926298684fa5f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionConfiguration.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -21,8 +22,9 @@ public partial class AzureCosmosDBChatExtensionConfiguration : AzureChatExtensio /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// + /// Keeps track of any properties unknown to the library. /// The parameters to use when configuring Azure OpenAI CosmosDB chat extensions. - internal AzureCosmosDBChatExtensionConfiguration(AzureChatExtensionType type, AzureCosmosDBChatExtensionParameters parameters) : base(type) + internal AzureCosmosDBChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData, AzureCosmosDBChatExtensionParameters parameters) : base(type, serializedAdditionalRawData) { Parameters = parameters; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.Serialization.cs index cf725f13aa5aa..16cf0c74284fc 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class AzureCosmosDBChatExtensionParameters : IUtf8JsonSerializable + internal partial class AzureCosmosDBChatExtensionParameters : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCosmosDBChatExtensionParameters)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Authentication)) { @@ -53,9 +65,176 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("embeddingDependency"u8); writer.WriteObjectValue(EmbeddingDependency); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCosmosDBChatExtensionParameters 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(AzureCosmosDBChatExtensionParameters)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCosmosDBChatExtensionParameters(document.RootElement, options); + } + + internal static AzureCosmosDBChatExtensionParameters DeserializeAzureCosmosDBChatExtensionParameters(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional authentication = default; + Optional topNDocuments = default; + Optional inScope = default; + Optional strictness = default; + Optional roleInformation = default; + string databaseName = default; + string containerName = default; + string indexName = default; + AzureCosmosDBFieldMappingOptions fieldsMapping = default; + Optional embeddingDependency = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("authentication"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("topNDocuments"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topNDocuments = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("inScope"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inScope = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("strictness"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strictness = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("roleInformation"u8)) + { + roleInformation = property.Value.GetString(); + continue; + } + if (property.NameEquals("databaseName"u8)) + { + databaseName = property.Value.GetString(); + continue; + } + if (property.NameEquals("containerName"u8)) + { + containerName = property.Value.GetString(); + continue; + } + if (property.NameEquals("indexName"u8)) + { + indexName = property.Value.GetString(); + continue; + } + if (property.NameEquals("fieldsMapping"u8)) + { + fieldsMapping = AzureCosmosDBFieldMappingOptions.DeserializeAzureCosmosDBFieldMappingOptions(property.Value); + continue; + } + if (property.NameEquals("embeddingDependency"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + embeddingDependency = OnYourDataVectorizationSource.DeserializeOnYourDataVectorizationSource(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCosmosDBChatExtensionParameters(authentication.Value, Optional.ToNullable(topNDocuments), Optional.ToNullable(inScope), Optional.ToNullable(strictness), roleInformation.Value, databaseName, containerName, indexName, fieldsMapping, embeddingDependency.Value, 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(AzureCosmosDBChatExtensionParameters)} does not support '{options.Format}' format."); + } + } + + AzureCosmosDBChatExtensionParameters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCosmosDBChatExtensionParameters(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCosmosDBChatExtensionParameters)} does not support '{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 AzureCosmosDBChatExtensionParameters FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCosmosDBChatExtensionParameters(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.cs index bb0721b8bee1f..40b5b2e216c6b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBChatExtensionParameters.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -16,6 +17,38 @@ namespace Azure.AI.OpenAI /// internal partial class AzureCosmosDBChatExtensionParameters { + /// + /// 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 authentication method to use when accessing the defined data source. @@ -33,7 +66,8 @@ internal partial class AzureCosmosDBChatExtensionParameters /// The MongoDB vCore index name to use with Azure Cosmos DB. /// Customized field mapping behavior to use when interacting with the search index. /// The embedding dependency for vector search. - internal AzureCosmosDBChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string databaseName, string containerName, string indexName, AzureCosmosDBFieldMappingOptions fieldMappingOptions, OnYourDataVectorizationSource embeddingDependency) + /// Keeps track of any properties unknown to the library. + internal AzureCosmosDBChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string databaseName, string containerName, string indexName, AzureCosmosDBFieldMappingOptions fieldMappingOptions, OnYourDataVectorizationSource embeddingDependency, IDictionary serializedAdditionalRawData) { Authentication = authentication; DocumentCount = documentCount; @@ -45,6 +79,7 @@ internal AzureCosmosDBChatExtensionParameters(OnYourDataAuthenticationOptions au IndexName = indexName; FieldMappingOptions = fieldMappingOptions; EmbeddingDependency = embeddingDependency; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.Serialization.cs index 0905dda5fdadb..3beba15532c01 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureCosmosDBFieldMappingOptions : IUtf8JsonSerializable + public partial class AzureCosmosDBFieldMappingOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureCosmosDBFieldMappingOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("vectorFields"u8); writer.WriteStartArray(); @@ -22,9 +34,107 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(item); } writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureCosmosDBFieldMappingOptions 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(AzureCosmosDBFieldMappingOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureCosmosDBFieldMappingOptions(document.RootElement, options); + } + + internal static AzureCosmosDBFieldMappingOptions DeserializeAzureCosmosDBFieldMappingOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList vectorFields = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("vectorFields"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + vectorFields = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureCosmosDBFieldMappingOptions(vectorFields, 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(AzureCosmosDBFieldMappingOptions)} does not support '{options.Format}' format."); + } + } + + AzureCosmosDBFieldMappingOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureCosmosDBFieldMappingOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureCosmosDBFieldMappingOptions)} does not support '{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 AzureCosmosDBFieldMappingOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureCosmosDBFieldMappingOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.cs index e6804d45b4253..be0737add2920 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureCosmosDBFieldMappingOptions.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// Optional settings to control how fields are processed when using a configured Azure Cosmos DB resource. public partial class AzureCosmosDBFieldMappingOptions { + /// + /// 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 names of fields that represent vector data. /// is null. @@ -27,9 +59,16 @@ public AzureCosmosDBFieldMappingOptions(IEnumerable vectorFieldNames) /// Initializes a new instance of . /// The names of fields that represent vector data. - internal AzureCosmosDBFieldMappingOptions(IList vectorFieldNames) + /// Keeps track of any properties unknown to the library. + internal AzureCosmosDBFieldMappingOptions(IList vectorFieldNames, IDictionary serializedAdditionalRawData) { VectorFieldNames = vectorFieldNames; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureCosmosDBFieldMappingOptions() + { } /// The names of fields that represent vector data. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.Serialization.cs index 04143a2206ded..179535968db7b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.Serialization.cs @@ -5,21 +5,76 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureGroundingEnhancement + public partial class AzureGroundingEnhancement : IUtf8JsonSerializable, IJsonModel { - internal static AzureGroundingEnhancement DeserializeAzureGroundingEnhancement(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureGroundingEnhancement)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("lines"u8); + writer.WriteStartArray(); + foreach (var item in Lines) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureGroundingEnhancement 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(AzureGroundingEnhancement)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureGroundingEnhancement(document.RootElement, options); + } + + internal static AzureGroundingEnhancement DeserializeAzureGroundingEnhancement(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } IReadOnlyList lines = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("lines"u8)) @@ -32,10 +87,46 @@ internal static AzureGroundingEnhancement DeserializeAzureGroundingEnhancement(J lines = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AzureGroundingEnhancement(lines); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureGroundingEnhancement(lines, 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(AzureGroundingEnhancement)} does not support '{options.Format}' format."); + } + } + + AzureGroundingEnhancement IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureGroundingEnhancement(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureGroundingEnhancement)} does not support '{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 AzureGroundingEnhancement FromResponse(Response response) @@ -43,5 +134,13 @@ internal static AzureGroundingEnhancement FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAzureGroundingEnhancement(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.cs index dc0c1eaa163c9..18200cd457ee2 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancement.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// The grounding enhancement that returns the bounding box of the objects detected in the image. public partial class AzureGroundingEnhancement { + /// + /// 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 lines of text detected by the grounding enhancement. /// is null. @@ -27,9 +59,16 @@ internal AzureGroundingEnhancement(IEnumerable li /// Initializes a new instance of . /// The lines of text detected by the grounding enhancement. - internal AzureGroundingEnhancement(IReadOnlyList lines) + /// Keeps track of any properties unknown to the library. + internal AzureGroundingEnhancement(IReadOnlyList lines, IDictionary serializedAdditionalRawData) { Lines = lines; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureGroundingEnhancement() + { } /// The lines of text detected by the grounding enhancement. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.Serialization.cs index 0ca680e814813..3bc160fa9cefe 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureGroundingEnhancementCoordinatePoint + public partial class AzureGroundingEnhancementCoordinatePoint : IUtf8JsonSerializable, IJsonModel { - internal static AzureGroundingEnhancementCoordinatePoint DeserializeAzureGroundingEnhancementCoordinatePoint(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureGroundingEnhancementCoordinatePoint)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(Y); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureGroundingEnhancementCoordinatePoint 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(AzureGroundingEnhancementCoordinatePoint)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureGroundingEnhancementCoordinatePoint(document.RootElement, options); + } + + internal static AzureGroundingEnhancementCoordinatePoint DeserializeAzureGroundingEnhancementCoordinatePoint(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } float x = default; float y = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("x"u8)) @@ -32,10 +85,46 @@ internal static AzureGroundingEnhancementCoordinatePoint DeserializeAzureGroundi y = property.Value.GetSingle(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureGroundingEnhancementCoordinatePoint(x, y, 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(AzureGroundingEnhancementCoordinatePoint)} does not support '{options.Format}' format."); + } + } + + AzureGroundingEnhancementCoordinatePoint IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureGroundingEnhancementCoordinatePoint(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureGroundingEnhancementCoordinatePoint)} does not support '{options.Format}' format."); } - return new AzureGroundingEnhancementCoordinatePoint(x, y); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static AzureGroundingEnhancementCoordinatePoint FromResponse(Response response) @@ -43,5 +132,13 @@ internal static AzureGroundingEnhancementCoordinatePoint FromResponse(Response r using var document = JsonDocument.Parse(response.Content); return DeserializeAzureGroundingEnhancementCoordinatePoint(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.cs index 7c41bcd27a5a5..44b5c9dcbd187 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementCoordinatePoint.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// A representation of a single polygon point as used by the Azure grounding enhancement. public partial class AzureGroundingEnhancementCoordinatePoint { + /// + /// 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 x-coordinate (horizontal axis) of the point. /// The y-coordinate (vertical axis) of the point. @@ -19,6 +54,22 @@ internal AzureGroundingEnhancementCoordinatePoint(float x, float y) Y = y; } + /// Initializes a new instance of . + /// The x-coordinate (horizontal axis) of the point. + /// The y-coordinate (vertical axis) of the point. + /// Keeps track of any properties unknown to the library. + internal AzureGroundingEnhancementCoordinatePoint(float x, float y, IDictionary serializedAdditionalRawData) + { + X = x; + Y = y; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureGroundingEnhancementCoordinatePoint() + { + } + /// The x-coordinate (horizontal axis) of the point. public float X { get; } /// The y-coordinate (vertical axis) of the point. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.Serialization.cs index 8dd0e19e1266c..176689ab2e4da 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureGroundingEnhancementLine + public partial class AzureGroundingEnhancementLine : IUtf8JsonSerializable, IJsonModel { - internal static AzureGroundingEnhancementLine DeserializeAzureGroundingEnhancementLine(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureGroundingEnhancementLine)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("spans"u8); + writer.WriteStartArray(); + foreach (var item in Spans) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureGroundingEnhancementLine 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(AzureGroundingEnhancementLine)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureGroundingEnhancementLine(document.RootElement, options); + } + + internal static AzureGroundingEnhancementLine DeserializeAzureGroundingEnhancementLine(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string text = default; IReadOnlyList spans = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -38,10 +95,46 @@ internal static AzureGroundingEnhancementLine DeserializeAzureGroundingEnhanceme spans = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AzureGroundingEnhancementLine(text, spans); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureGroundingEnhancementLine(text, spans, 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(AzureGroundingEnhancementLine)} does not support '{options.Format}' format."); + } + } + + AzureGroundingEnhancementLine IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureGroundingEnhancementLine(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureGroundingEnhancementLine)} does not support '{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 AzureGroundingEnhancementLine FromResponse(Response response) @@ -49,5 +142,13 @@ internal static AzureGroundingEnhancementLine FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeAzureGroundingEnhancementLine(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.cs index 7e0467cd974de..338c2f55c72ff 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLine.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// A content line object consisting of an adjacent sequence of content elements, such as words and selection marks. public partial class AzureGroundingEnhancementLine { + /// + /// 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 text within the line. /// An array of spans that represent detected objects and its bounding box information. @@ -31,10 +63,17 @@ internal AzureGroundingEnhancementLine(string text, IEnumerable Initializes a new instance of . /// The text within the line. /// An array of spans that represent detected objects and its bounding box information. - internal AzureGroundingEnhancementLine(string text, IReadOnlyList spans) + /// Keeps track of any properties unknown to the library. + internal AzureGroundingEnhancementLine(string text, IReadOnlyList spans, IDictionary serializedAdditionalRawData) { Text = text; Spans = spans; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureGroundingEnhancementLine() + { } /// The text within the line. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.Serialization.cs index 32233c54e5d64..2b0d3f46a2304 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.Serialization.cs @@ -5,16 +5,75 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureGroundingEnhancementLineSpan + public partial class AzureGroundingEnhancementLineSpan : IUtf8JsonSerializable, IJsonModel { - internal static AzureGroundingEnhancementLineSpan DeserializeAzureGroundingEnhancementLineSpan(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureGroundingEnhancementLineSpan)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("offset"u8); + writer.WriteNumberValue(Offset); + writer.WritePropertyName("length"u8); + writer.WriteNumberValue(Length); + writer.WritePropertyName("polygon"u8); + writer.WriteStartArray(); + foreach (var item in Polygon) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureGroundingEnhancementLineSpan 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(AzureGroundingEnhancementLineSpan)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureGroundingEnhancementLineSpan(document.RootElement, options); + } + + internal static AzureGroundingEnhancementLineSpan DeserializeAzureGroundingEnhancementLineSpan(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +82,8 @@ internal static AzureGroundingEnhancementLineSpan DeserializeAzureGroundingEnhan int offset = default; int length = default; IReadOnlyList polygon = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -50,10 +111,46 @@ internal static AzureGroundingEnhancementLineSpan DeserializeAzureGroundingEnhan polygon = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new AzureGroundingEnhancementLineSpan(text, offset, length, polygon); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureGroundingEnhancementLineSpan(text, offset, length, polygon, 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(AzureGroundingEnhancementLineSpan)} does not support '{options.Format}' format."); + } + } + + AzureGroundingEnhancementLineSpan IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureGroundingEnhancementLineSpan(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureGroundingEnhancementLineSpan)} does not support '{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 AzureGroundingEnhancementLineSpan FromResponse(Response response) @@ -61,5 +158,13 @@ internal static AzureGroundingEnhancementLineSpan FromResponse(Response response using var document = JsonDocument.Parse(response.Content); return DeserializeAzureGroundingEnhancementLineSpan(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.cs index e365afda5df11..96286ae5efc3d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureGroundingEnhancementLineSpan.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// A span object that represents a detected object and its bounding box information. public partial class AzureGroundingEnhancementLineSpan { + /// + /// 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 text content of the span that represents the detected object. /// @@ -43,12 +75,19 @@ internal AzureGroundingEnhancementLineSpan(string text, int offset, int length, /// /// The length of the span in characters, measured in Unicode codepoints. /// An array of objects representing points in the polygon that encloses the detected object. - internal AzureGroundingEnhancementLineSpan(string text, int offset, int length, IReadOnlyList polygon) + /// Keeps track of any properties unknown to the library. + internal AzureGroundingEnhancementLineSpan(string text, int offset, int length, IReadOnlyList polygon, IDictionary serializedAdditionalRawData) { Text = text; Offset = offset; Length = length; Polygon = polygon; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AzureGroundingEnhancementLineSpan() + { } /// The text content of the span that represents the detected object. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.Serialization.cs index abf0b36484057..48c9c66c12c37 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class AzureMachineLearningIndexChatExtensionConfiguration : IUtf8JsonSerializable + public partial class AzureMachineLearningIndexChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureMachineLearningIndexChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("parameters"u8); writer.WriteObjectValue(Parameters); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureMachineLearningIndexChatExtensionConfiguration 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(AzureMachineLearningIndexChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureMachineLearningIndexChatExtensionConfiguration(document.RootElement, options); + } + + internal static AzureMachineLearningIndexChatExtensionConfiguration DeserializeAzureMachineLearningIndexChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AzureMachineLearningIndexChatExtensionParameters parameters = default; + AzureChatExtensionType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("parameters"u8)) + { + parameters = AzureMachineLearningIndexChatExtensionParameters.DeserializeAzureMachineLearningIndexChatExtensionParameters(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureMachineLearningIndexChatExtensionConfiguration(type, serializedAdditionalRawData, parameters); + } + + 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(AzureMachineLearningIndexChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureMachineLearningIndexChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureMachineLearningIndexChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureMachineLearningIndexChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AzureMachineLearningIndexChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureMachineLearningIndexChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.cs index 12eab5e8ed72b..ddd800d69e33e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionConfiguration.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -21,8 +22,9 @@ public partial class AzureMachineLearningIndexChatExtensionConfiguration : Azure /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// + /// Keeps track of any properties unknown to the library. /// The parameters for the Azure Machine Learning vector index chat extension. - internal AzureMachineLearningIndexChatExtensionConfiguration(AzureChatExtensionType type, AzureMachineLearningIndexChatExtensionParameters parameters) : base(type) + internal AzureMachineLearningIndexChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData, AzureMachineLearningIndexChatExtensionParameters parameters) : base(type, serializedAdditionalRawData) { Parameters = parameters; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.Serialization.cs index 671e6d3ba953a..d0e1b09ab5b23 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class AzureMachineLearningIndexChatExtensionParameters : IUtf8JsonSerializable + internal partial class AzureMachineLearningIndexChatExtensionParameters : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureMachineLearningIndexChatExtensionParameters)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Authentication)) { @@ -51,9 +63,166 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("filter"u8); writer.WriteStringValue(Filter); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + AzureMachineLearningIndexChatExtensionParameters 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(AzureMachineLearningIndexChatExtensionParameters)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAzureMachineLearningIndexChatExtensionParameters(document.RootElement, options); + } + + internal static AzureMachineLearningIndexChatExtensionParameters DeserializeAzureMachineLearningIndexChatExtensionParameters(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional authentication = default; + Optional topNDocuments = default; + Optional inScope = default; + Optional strictness = default; + Optional roleInformation = default; + string projectResourceId = default; + string name = default; + string version = default; + Optional filter = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("authentication"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("topNDocuments"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topNDocuments = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("inScope"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inScope = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("strictness"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strictness = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("roleInformation"u8)) + { + roleInformation = property.Value.GetString(); + continue; + } + if (property.NameEquals("projectResourceId"u8)) + { + projectResourceId = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("version"u8)) + { + version = property.Value.GetString(); + continue; + } + if (property.NameEquals("filter"u8)) + { + filter = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new AzureMachineLearningIndexChatExtensionParameters(authentication.Value, Optional.ToNullable(topNDocuments), Optional.ToNullable(inScope), Optional.ToNullable(strictness), roleInformation.Value, projectResourceId, name, version, filter.Value, 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(AzureMachineLearningIndexChatExtensionParameters)} does not support '{options.Format}' format."); + } + } + + AzureMachineLearningIndexChatExtensionParameters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAzureMachineLearningIndexChatExtensionParameters(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureMachineLearningIndexChatExtensionParameters)} does not support '{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 AzureMachineLearningIndexChatExtensionParameters FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeAzureMachineLearningIndexChatExtensionParameters(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.cs index 3b1210ea00b29..99f5d09a583a2 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureMachineLearningIndexChatExtensionParameters.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Parameters for the Azure Machine Learning vector index chat extension. internal partial class AzureMachineLearningIndexChatExtensionParameters { + /// + /// 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 authentication method to use when accessing the defined data source. @@ -29,7 +62,8 @@ internal partial class AzureMachineLearningIndexChatExtensionParameters /// The Azure Machine Learning vector index name. /// The version of the Azure Machine Learning vector index. /// Search filter. Only supported if the Azure Machine Learning vector index is of type AzureSearch. - internal AzureMachineLearningIndexChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string projectResourceId, string name, string version, string filter) + /// Keeps track of any properties unknown to the library. + internal AzureMachineLearningIndexChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string projectResourceId, string name, string version, string filter, IDictionary serializedAdditionalRawData) { Authentication = authentication; DocumentCount = documentCount; @@ -40,6 +74,7 @@ internal AzureMachineLearningIndexChatExtensionParameters(OnYourDataAuthenticati Name = name; Version = version; Filter = filter; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs index 58548ad79e586..ea5bc15cd5cae 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/AzureOpenAIModelFactory.cs @@ -37,7 +37,7 @@ public static AudioTranscriptionSegment AudioTranscriptionSegment(int id = defau { tokens ??= new List(); - return new AudioTranscriptionSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); + return new AudioTranscriptionSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -62,7 +62,7 @@ public static AudioTranslationSegment AudioTranslationSegment(int id = default, { tokens ??= new List(); - return new AudioTranslationSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek); + return new AudioTranslationSegment(id, start, end, text, temperature, averageLogProbability, compressionRatio, noSpeechProbability, tokens?.ToList(), seek, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -87,22 +87,16 @@ public static Completions Completions(string id = null, DateTimeOffset created = promptFilterResults ??= new List(); choices ??= new List(); - return new Completions(id, created, promptFilterResults?.ToList(), choices?.ToList(), usage); + return new Completions(id, created, promptFilterResults?.ToList(), choices?.ToList(), usage, serializedAdditionalRawData: null); } /// Initializes a new instance of . /// The index of this prompt in the set of prompt results. /// Content filtering results for this prompt. - /// is null. /// A new instance for mocking. public static ContentFilterResultsForPrompt ContentFilterResultsForPrompt(int promptIndex = default, ContentFilterResultDetailsForPrompt contentFilterResults = null) { - if (contentFilterResults == null) - { - throw new ArgumentNullException(nameof(contentFilterResults)); - } - - return new ContentFilterResultsForPrompt(promptIndex, contentFilterResults); + return new ContentFilterResultsForPrompt(promptIndex, contentFilterResults, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -139,7 +133,7 @@ public static ContentFilterResultDetailsForPrompt ContentFilterResultDetailsForP { customBlocklists ??= new List(); - return new ContentFilterResultDetailsForPrompt(sexual, violence, hate, selfHarm, profanity, customBlocklists?.ToList(), error, jailbreak); + return new ContentFilterResultDetailsForPrompt(sexual, violence, hate, selfHarm, profanity, customBlocklists?.ToList(), error, jailbreak, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -148,7 +142,7 @@ public static ContentFilterResultDetailsForPrompt ContentFilterResultDetailsForP /// A new instance for mocking. public static ContentFilterResult ContentFilterResult(ContentFilterSeverity severity = default, bool filtered = default) { - return new ContentFilterResult(severity, filtered); + return new ContentFilterResult(severity, filtered, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -157,22 +151,16 @@ public static ContentFilterResult ContentFilterResult(ContentFilterSeverity seve /// A new instance for mocking. public static ContentFilterDetectionResult ContentFilterDetectionResult(bool filtered = default, bool detected = default) { - return new ContentFilterDetectionResult(filtered, detected); + return new ContentFilterDetectionResult(filtered, detected, serializedAdditionalRawData: null); } /// Initializes a new instance of . /// The ID of the custom blocklist evaluated. /// A value indicating whether or not the content has been filtered. - /// is null. /// A new instance for mocking. public static ContentFilterBlocklistIdResult ContentFilterBlocklistIdResult(string id = null, bool filtered = default) { - if (id == null) - { - throw new ArgumentNullException(nameof(id)); - } - - return new ContentFilterBlocklistIdResult(id, filtered); + return new ContentFilterBlocklistIdResult(id, filtered, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -188,7 +176,7 @@ public static ContentFilterBlocklistIdResult ContentFilterBlocklistIdResult(stri /// A new instance for mocking. public static Choice Choice(string text = null, int index = default, ContentFilterResultsForChoice contentFilterResults = null, CompletionsLogProbabilityModel logProbabilityModel = null, CompletionsFinishReason? finishReason = null) { - return new Choice(text, index, contentFilterResults, logProbabilityModel, finishReason); + return new Choice(text, index, contentFilterResults, logProbabilityModel, finishReason, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -226,7 +214,7 @@ public static ContentFilterResultsForChoice ContentFilterResultsForChoice(Conten { customBlocklists ??= new List(); - return new ContentFilterResultsForChoice(sexual, violence, hate, selfHarm, profanity, customBlocklists?.ToList(), error, protectedMaterialText, protectedMaterialCode); + return new ContentFilterResultsForChoice(sexual, violence, hate, selfHarm, profanity, customBlocklists?.ToList(), error, protectedMaterialText, protectedMaterialCode, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -237,7 +225,7 @@ public static ContentFilterResultsForChoice ContentFilterResultsForChoice(Conten /// A new instance for mocking. public static ContentFilterCitedDetectionResult ContentFilterCitedDetectionResult(bool filtered = default, bool detected = default, Uri url = null, string license = null) { - return new ContentFilterCitedDetectionResult(filtered, detected, url, license); + return new ContentFilterCitedDetectionResult(filtered, detected, url, license, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -253,7 +241,7 @@ public static CompletionsLogProbabilityModel CompletionsLogProbabilityModel(IEnu topLogProbabilities ??= new List>(); textOffsets ??= new List(); - return new CompletionsLogProbabilityModel(tokens?.ToList(), tokenLogProbabilities?.ToList(), topLogProbabilities?.ToList(), textOffsets?.ToList()); + return new CompletionsLogProbabilityModel(tokens?.ToList(), tokenLogProbabilities?.ToList(), topLogProbabilities?.ToList(), textOffsets?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -263,7 +251,7 @@ public static CompletionsLogProbabilityModel CompletionsLogProbabilityModel(IEnu /// A new instance for mocking. public static CompletionsUsage CompletionsUsage(int completionTokens = default, int promptTokens = default, int totalTokens = default) { - return new CompletionsUsage(completionTokens, promptTokens, totalTokens); + return new CompletionsUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -292,7 +280,7 @@ public static ChatCompletions ChatCompletions(string id = null, DateTimeOffset c choices ??= new List(); promptFilterResults ??= new List(); - return new ChatCompletions(id, created, choices?.ToList(), promptFilterResults?.ToList(), systemFingerprint, usage); + return new ChatCompletions(id, created, choices?.ToList(), promptFilterResults?.ToList(), systemFingerprint, usage, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -315,7 +303,7 @@ public static ChatResponseMessage ChatResponseMessage(ChatRole role = default, s { toolCalls ??= new List(); - return new ChatResponseMessage(role, content, toolCalls?.ToList(), functionCall, azureExtensionsContext); + return new ChatResponseMessage(role, content, toolCalls?.ToList(), functionCall, azureExtensionsContext, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -330,7 +318,7 @@ public static AzureChatExtensionsMessageContext AzureChatExtensionsMessageContex { messages ??= new List(); - return new AzureChatExtensionsMessageContext(messages?.ToList()); + return new AzureChatExtensionsMessageContext(messages?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -338,7 +326,7 @@ public static AzureChatExtensionsMessageContext AzureChatExtensionsMessageContex /// A new instance for mocking. public static AzureChatEnhancements AzureChatEnhancements(AzureGroundingEnhancement grounding = null) { - return new AzureChatEnhancements(grounding); + return new AzureChatEnhancements(grounding, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -348,7 +336,7 @@ public static AzureGroundingEnhancement AzureGroundingEnhancement(IEnumerable(); - return new AzureGroundingEnhancement(lines?.ToList()); + return new AzureGroundingEnhancement(lines?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -359,7 +347,7 @@ public static AzureGroundingEnhancementLine AzureGroundingEnhancementLine(string { spans ??= new List(); - return new AzureGroundingEnhancementLine(text, spans?.ToList()); + return new AzureGroundingEnhancementLine(text, spans?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -375,7 +363,7 @@ public static AzureGroundingEnhancementLineSpan AzureGroundingEnhancementLineSpa { polygon ??= new List(); - return new AzureGroundingEnhancementLineSpan(text, offset, length, polygon?.ToList()); + return new AzureGroundingEnhancementLineSpan(text, offset, length, polygon?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -384,7 +372,7 @@ public static AzureGroundingEnhancementLineSpan AzureGroundingEnhancementLineSpa /// A new instance for mocking. public static AzureGroundingEnhancementCoordinatePoint AzureGroundingEnhancementCoordinatePoint(float x = default, float y = default) { - return new AzureGroundingEnhancementCoordinatePoint(x, y); + return new AzureGroundingEnhancementCoordinatePoint(x, y, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -397,7 +385,7 @@ public static AzureGroundingEnhancementCoordinatePoint AzureGroundingEnhancement /// A new instance for mocking. public static ImageGenerationData ImageGenerationData(Uri url = null, string base64Data = null, string revisedPrompt = null) { - return new ImageGenerationData(url, base64Data, revisedPrompt); + return new ImageGenerationData(url, base64Data, revisedPrompt, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -408,7 +396,7 @@ public static Embeddings Embeddings(IEnumerable data = null, Embe { data ??= new List(); - return new Embeddings(data?.ToList(), usage); + return new Embeddings(data?.ToList(), usage, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -420,7 +408,7 @@ public static Embeddings Embeddings(IEnumerable data = null, Embe /// A new instance for mocking. public static EmbeddingItem EmbeddingItem(ReadOnlyMemory embedding = default, int index = default) { - return new EmbeddingItem(embedding, index); + return new EmbeddingItem(embedding, index, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -429,7 +417,7 @@ public static EmbeddingItem EmbeddingItem(ReadOnlyMemory embedding = defa /// A new instance for mocking. public static EmbeddingsUsage EmbeddingsUsage(int promptTokens = default, int totalTokens = default) { - return new EmbeddingsUsage(promptTokens, totalTokens); + return new EmbeddingsUsage(promptTokens, totalTokens, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -437,7 +425,147 @@ public static EmbeddingsUsage EmbeddingsUsage(int promptTokens = default, int to /// A new instance for mocking. public static StopFinishDetails StopFinishDetails(string stop = null) { - return new StopFinishDetails("stop", stop); + return new StopFinishDetails("stop", serializedAdditionalRawData: null, stop); + } + + /// Initializes a new instance of . + /// The content of the message. + /// A new instance for mocking. + public static ChatMessageTextContentItem ChatMessageTextContentItem(string text = null) + { + return new ChatMessageTextContentItem("text", serializedAdditionalRawData: null, text); + } + + /// Initializes a new instance of . + /// An internet location, which must be accessible to the model,from which the image may be retrieved. + /// A new instance for mocking. + public static ChatMessageImageContentItem ChatMessageImageContentItem(ChatMessageImageUrl imageUrl = null) + { + return new ChatMessageImageContentItem("image_url", serializedAdditionalRawData: null, imageUrl); + } + + /// Initializes a new instance of . + /// The URL of the image. + /// + /// The evaluation quality setting to use, which controls relative prioritization of speed, token consumption, and + /// accuracy. + /// + /// A new instance for mocking. + public static ChatMessageImageUrl ChatMessageImageUrl(Uri url = null, ChatMessageImageDetailLevel? detail = null) + { + return new ChatMessageImageUrl(url, detail, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The contents of the system message. + /// An optional name for the participant. + /// A new instance for mocking. + public static ChatRequestSystemMessage ChatRequestSystemMessage(string content = null, string name = null) + { + return new ChatRequestSystemMessage(ChatRole.System, serializedAdditionalRawData: null, content, name); + } + + /// Initializes a new instance of . + /// The content of the message. + /// An optional name for the participant. + /// + /// The tool calls that must be resolved and have their outputs appended to subsequent input messages for the chat + /// completions request to resolve as configured. + /// + /// + /// The function call that must be resolved and have its output appended to subsequent input messages for the chat + /// completions request to resolve as configured. + /// + /// A new instance for mocking. + public static ChatRequestAssistantMessage ChatRequestAssistantMessage(string content = null, string name = null, IEnumerable toolCalls = null, FunctionCall functionCall = null) + { + toolCalls ??= new List(); + + return new ChatRequestAssistantMessage(ChatRole.Assistant, serializedAdditionalRawData: null, content, name, toolCalls?.ToList(), functionCall); + } + + /// Initializes a new instance of . + /// The content of the message. + /// The ID of the tool call resolved by the provided content. + /// A new instance for mocking. + public static ChatRequestToolMessage ChatRequestToolMessage(string content = null, string toolCallId = null) + { + return new ChatRequestToolMessage(ChatRole.Tool, serializedAdditionalRawData: null, content, toolCallId); + } + + /// Initializes a new instance of . + /// The name of the function that was called to produce output. + /// The output of the function as requested by the function call. + /// A new instance for mocking. + public static ChatRequestFunctionMessage ChatRequestFunctionMessage(string name = null, string content = null) + { + return new ChatRequestFunctionMessage(ChatRole.Function, serializedAdditionalRawData: null, name, content); + } + + /// Initializes a new instance of . + /// The function definition details for the function tool. + /// A new instance for mocking. + public static ChatCompletionsFunctionToolDefinition ChatCompletionsFunctionToolDefinition(FunctionDefinition function = null) + { + return new ChatCompletionsFunctionToolDefinition("function", serializedAdditionalRawData: null, function); + } + + /// Initializes a new instance of . + /// The API key to use for authentication. + /// A new instance for mocking. + public static OnYourDataApiKeyAuthenticationOptions OnYourDataApiKeyAuthenticationOptions(string key = null) + { + return new OnYourDataApiKeyAuthenticationOptions(OnYourDataAuthenticationType.ApiKey, serializedAdditionalRawData: null, key); + } + + /// Initializes a new instance of . + /// The connection string to use for authentication. + /// A new instance for mocking. + public static OnYourDataConnectionStringAuthenticationOptions OnYourDataConnectionStringAuthenticationOptions(string connectionString = null) + { + return new OnYourDataConnectionStringAuthenticationOptions(OnYourDataAuthenticationType.ConnectionString, serializedAdditionalRawData: null, connectionString); + } + + /// Initializes a new instance of . + /// The key to use for authentication. + /// The key ID to use for authentication. + /// A new instance for mocking. + public static OnYourDataKeyAndKeyIdAuthenticationOptions OnYourDataKeyAndKeyIdAuthenticationOptions(string key = null, string keyId = null) + { + return new OnYourDataKeyAndKeyIdAuthenticationOptions(OnYourDataAuthenticationType.KeyAndKeyId, serializedAdditionalRawData: null, key, keyId); + } + + /// Initializes a new instance of . + /// The resource ID of the user-assigned managed identity to use for authentication. + /// A new instance for mocking. + public static OnYourDataUserAssignedManagedIdentityAuthenticationOptions OnYourDataUserAssignedManagedIdentityAuthenticationOptions(string managedIdentityResourceId = null) + { + return new OnYourDataUserAssignedManagedIdentityAuthenticationOptions(OnYourDataAuthenticationType.UserAssignedManagedIdentity, serializedAdditionalRawData: null, managedIdentityResourceId); + } + + /// Initializes a new instance of . + /// Specifies the resource endpoint URL from which embeddings should be retrieved. It should be in the format of https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings. The api-version query parameter is not allowed. + /// Specifies the authentication options to use when retrieving embeddings from the specified endpoint. + /// A new instance for mocking. + public static OnYourDataEndpointVectorizationSource OnYourDataEndpointVectorizationSource(Uri endpoint = null, OnYourDataAuthenticationOptions authentication = null) + { + return new OnYourDataEndpointVectorizationSource(OnYourDataVectorizationSourceType.Endpoint, serializedAdditionalRawData: null, endpoint, authentication); + } + + /// Initializes a new instance of . + /// The embedding model deployment name within the same Azure OpenAI resource. This enables you to use vector search without Azure OpenAI api-key and without Azure OpenAI public network access. + /// A new instance for mocking. + public static OnYourDataDeploymentNameVectorizationSource OnYourDataDeploymentNameVectorizationSource(string deploymentName = null) + { + return new OnYourDataDeploymentNameVectorizationSource(OnYourDataVectorizationSourceType.DeploymentName, serializedAdditionalRawData: null, deploymentName); + } + + /// Initializes a new instance of . + /// The embedding model ID build inside the search service. Currently only supported by Elasticsearch®. + /// A new instance for mocking. + public static OnYourDataModelIdVectorizationSource OnYourDataModelIdVectorizationSource(string modelId = null) + { + return new OnYourDataModelIdVectorizationSource(OnYourDataVectorizationSourceType.ModelId, serializedAdditionalRawData: null, modelId); } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.Serialization.cs index 6cdde7b81ec20..4f5a00c8149b8 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.Serialization.cs @@ -5,16 +5,98 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatChoice + public partial class ChatChoice : IUtf8JsonSerializable, IJsonModel { - internal static ChatChoice DeserializeChatChoice(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatChoice)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Message)) + { + writer.WritePropertyName("message"u8); + writer.WriteObjectValue(Message); + } + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + if (FinishReason != null) + { + writer.WritePropertyName("finish_reason"u8); + writer.WriteStringValue(FinishReason.Value.ToString()); + } + else + { + writer.WriteNull("finish_reason"); + } + if (Optional.IsDefined(FinishDetails)) + { + writer.WritePropertyName("finish_details"u8); + writer.WriteObjectValue(FinishDetails); + } + if (Optional.IsDefined(InternalStreamingDeltaMessage)) + { + writer.WritePropertyName("delta"u8); + writer.WriteObjectValue(InternalStreamingDeltaMessage); + } + if (Optional.IsDefined(ContentFilterResults)) + { + writer.WritePropertyName("content_filter_results"u8); + writer.WriteObjectValue(ContentFilterResults); + } + if (Optional.IsDefined(Enhancements)) + { + writer.WritePropertyName("enhancements"u8); + writer.WriteObjectValue(Enhancements); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + 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 '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatChoice(document.RootElement, options); + } + + internal static ChatChoice DeserializeChatChoice(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -26,6 +108,8 @@ internal static ChatChoice DeserializeChatChoice(JsonElement element) Optional delta = default; Optional contentFilterResults = default; Optional enhancements = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("message"u8)) @@ -88,10 +172,46 @@ internal static ChatChoice DeserializeChatChoice(JsonElement element) enhancements = AzureChatEnhancements.DeserializeAzureChatEnhancements(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ChatChoice(message.Value, index, finishReason, finishDetails.Value, delta.Value, contentFilterResults.Value, enhancements.Value); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatChoice(message.Value, index, finishReason, finishDetails.Value, delta.Value, contentFilterResults.Value, enhancements.Value, 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 '{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); + return DeserializeChatChoice(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatChoice)} does not support '{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) @@ -99,5 +219,13 @@ internal static ChatChoice FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeChatChoice(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.cs index b65b2810a343e..f93d642a6c0a6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatChoice.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// 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 ordered index associated with this chat completions choice. /// The reason that this chat completions choice completed its generated. @@ -42,7 +77,8 @@ internal ChatChoice(int index, CompletionsFinishReason? finishReason) /// provided in the request. This supplementary information is only available when using Azure OpenAI and only when the /// request is configured to use enhancements. /// - internal ChatChoice(ChatResponseMessage message, int index, CompletionsFinishReason? finishReason, ChatFinishDetails finishDetails, ChatResponseMessage internalStreamingDeltaMessage, ContentFilterResultsForChoice contentFilterResults, AzureChatEnhancements enhancements) + /// Keeps track of any properties unknown to the library. + internal ChatChoice(ChatResponseMessage message, int index, CompletionsFinishReason? finishReason, ChatFinishDetails finishDetails, ChatResponseMessage internalStreamingDeltaMessage, ContentFilterResultsForChoice contentFilterResults, AzureChatEnhancements enhancements, IDictionary serializedAdditionalRawData) { Message = message; Index = index; @@ -51,6 +87,12 @@ internal ChatChoice(ChatResponseMessage message, int index, CompletionsFinishRea InternalStreamingDeltaMessage = internalStreamingDeltaMessage; ContentFilterResults = contentFilterResults; Enhancements = enhancements; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ChatChoice() + { } /// The chat message for a given chat completions prompt. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.Serialization.cs index 9aeba0e0a62da..f88542961a6ee 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.Serialization.cs @@ -5,13 +5,188 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletions + public partial class ChatCompletions : IUtf8JsonSerializable, IJsonModel { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("created"u8); + writer.WriteNumberValue(Created, "U"); + writer.WritePropertyName("choices"u8); + writer.WriteStartArray(); + foreach (var item in Choices) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (Optional.IsCollectionDefined(PromptFilterResults)) + { + writer.WritePropertyName("prompt_filter_results"u8); + writer.WriteStartArray(); + foreach (var item in PromptFilterResults) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(SystemFingerprint)) + { + writer.WritePropertyName("system_fingerprint"u8); + writer.WriteStringValue(SystemFingerprint); + } + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletions 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(ChatCompletions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletions(document.RootElement, options); + } + + internal static ChatCompletions DeserializeChatCompletions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + DateTimeOffset created = default; + IReadOnlyList choices = default; + Optional> promptFilterResults = default; + Optional systemFingerprint = default; + CompletionsUsage usage = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("created"u8)) + { + created = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("choices"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ChatChoice.DeserializeChatChoice(item)); + } + choices = array; + continue; + } + if (property.NameEquals("prompt_filter_results"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ContentFilterResultsForPrompt.DeserializeContentFilterResultsForPrompt(item)); + } + promptFilterResults = array; + continue; + } + if (property.NameEquals("system_fingerprint"u8)) + { + systemFingerprint = property.Value.GetString(); + continue; + } + if (property.NameEquals("usage"u8)) + { + usage = CompletionsUsage.DeserializeCompletionsUsage(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletions(id, created, choices, Optional.ToList(promptFilterResults), systemFingerprint.Value, usage, 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(ChatCompletions)} does not support '{options.Format}' format."); + } + } + + ChatCompletions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletions)} does not support '{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 ChatCompletions FromResponse(Response response) @@ -19,5 +194,13 @@ internal static ChatCompletions FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeChatCompletions(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.cs index c10911d414002..d0e3f5374d72a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletions.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class ChatCompletions { + /// + /// 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 . /// A unique identifier associated with this chat completions response. /// @@ -65,7 +97,8 @@ internal ChatCompletions(string id, DateTimeOffset created, IEnumerable /// Usage information for tokens processed and generated as part of this completions operation. - internal ChatCompletions(string id, DateTimeOffset created, IReadOnlyList choices, IReadOnlyList promptFilterResults, string systemFingerprint, CompletionsUsage usage) + /// Keeps track of any properties unknown to the library. + internal ChatCompletions(string id, DateTimeOffset created, IReadOnlyList choices, IReadOnlyList promptFilterResults, string systemFingerprint, CompletionsUsage usage, IDictionary serializedAdditionalRawData) { Id = id; Created = created; @@ -73,6 +106,12 @@ internal ChatCompletions(string id, DateTimeOffset created, IReadOnlyList Initializes a new instance of for deserialization. + internal ChatCompletions() + { } /// A unique identifier associated with this chat completions response. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs index a325cb588572f..b2da3c405af28 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.Serialization.cs @@ -5,16 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsFunctionToolCall : IUtf8JsonSerializable + public partial class ChatCompletionsFunctionToolCall : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("function"u8); writer.WriteObjectValue(Function); @@ -22,11 +33,40 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(Type); writer.WritePropertyName("id"u8); writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFunctionToolCall(JsonElement element) + ChatCompletionsFunctionToolCall 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(ChatCompletionsFunctionToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsFunctionToolCall(document.RootElement, options); + } + + internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFunctionToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -34,6 +74,8 @@ internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFuncti FunctionCall function = default; string type = default; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("function"u8)) @@ -51,10 +93,46 @@ internal static ChatCompletionsFunctionToolCall DeserializeChatCompletionsFuncti id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsFunctionToolCall(type, id, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support '{options.Format}' format."); } - return new ChatCompletionsFunctionToolCall(type, id, function); } + ChatCompletionsFunctionToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsFunctionToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolCall)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new ChatCompletionsFunctionToolCall FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.cs index 6ad6867f3a06a..36926d0008b9f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -16,5 +17,19 @@ namespace Azure.AI.OpenAI /// public partial class ChatCompletionsFunctionToolCall : ChatCompletionsToolCall { + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. + /// Keeps track of any properties unknown to the library. + /// The details of the function invocation requested by the tool call. + internal ChatCompletionsFunctionToolCall(string type, string id, IDictionary serializedAdditionalRawData, FunctionCall function) : base(type, id, serializedAdditionalRawData) + { + Function = function; + } + + /// Initializes a new instance of for deserialization. + internal ChatCompletionsFunctionToolCall() + { + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs index 80620fcf04701..2223152b4b675 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsFunctionToolDefinition : IUtf8JsonSerializable + public partial class ChatCompletionsFunctionToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("function"u8); writer.WriteObjectValue(Function); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatCompletionsFunctionToolDefinition 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(ChatCompletionsFunctionToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement, options); + } + + internal static ChatCompletionsFunctionToolDefinition DeserializeChatCompletionsFunctionToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + FunctionDefinition function = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + function = FunctionDefinition.DeserializeFunctionDefinition(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsFunctionToolDefinition(type, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsFunctionToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsFunctionToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatCompletionsFunctionToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsFunctionToolDefinition(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.cs index 72c3a39f55e65..6bea22d9d95da 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsFunctionToolDefinition.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,8 +27,9 @@ public ChatCompletionsFunctionToolDefinition(FunctionDefinition function) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The function definition details for the function tool. - internal ChatCompletionsFunctionToolDefinition(string type, FunctionDefinition function) : base(type) + internal ChatCompletionsFunctionToolDefinition(string type, IDictionary serializedAdditionalRawData, FunctionDefinition function) : base(type, serializedAdditionalRawData) { Function = function; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.Serialization.cs index 1e7c3eb533c85..0b294cce41af5 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class ChatCompletionsJsonResponseFormat : IUtf8JsonSerializable + internal partial class ChatCompletionsJsonResponseFormat : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsJsonResponseFormat)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatCompletionsJsonResponseFormat 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(ChatCompletionsJsonResponseFormat)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsJsonResponseFormat(document.RootElement, options); + } + + internal static ChatCompletionsJsonResponseFormat DeserializeChatCompletionsJsonResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsJsonResponseFormat(type, 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(ChatCompletionsJsonResponseFormat)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsJsonResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsJsonResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsJsonResponseFormat)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatCompletionsJsonResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsJsonResponseFormat(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.cs index 0ec1f9cd87f97..78638fb50332b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsJsonResponseFormat.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// A response format for Chat Completions that restricts responses to emitting valid JSON objects. @@ -18,7 +21,8 @@ public ChatCompletionsJsonResponseFormat() /// Initializes a new instance of . /// The discriminated type for the response format. - internal ChatCompletionsJsonResponseFormat(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsJsonResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs new file mode 100644 index 0000000000000..65951b6403ef0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.Serialization.cs @@ -0,0 +1,144 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class ChatCompletionsNamedFunctionToolSelection : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsNamedFunctionToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement, options); + } + + internal static ChatCompletionsNamedFunctionToolSelection DeserializeChatCompletionsNamedFunctionToolSelection(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsNamedFunctionToolSelection(type, serializedAdditionalRawData, name); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsNamedFunctionToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsNamedFunctionToolSelection)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatCompletionsNamedFunctionToolSelection FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsNamedFunctionToolSelection(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs new file mode 100644 index 0000000000000..4946847d0ad6b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedFunctionToolSelection.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + /// A tool selection of a specific, named function tool that will limit chat completions to using the named function. + internal partial class ChatCompletionsNamedFunctionToolSelection : ChatCompletionsNamedToolSelection + { + /// Initializes a new instance of . + /// The name of the function that should be called. + /// is null. + public ChatCompletionsNamedFunctionToolSelection(string name) + { + Argument.AssertNotNull(name, nameof(name)); + + Type = "function"; + Name = name; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + /// The name of the function that should be called. + internal ChatCompletionsNamedFunctionToolSelection(string type, IDictionary serializedAdditionalRawData, string name) : base(type, serializedAdditionalRawData) + { + Name = name; + } + + /// Initializes a new instance of for deserialization. + internal ChatCompletionsNamedFunctionToolSelection() + { + } + + /// The name of the function that should be called. + public string Name { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs new file mode 100644 index 0000000000000..dba62bf40a1ef --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.Serialization.cs @@ -0,0 +1,127 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + [PersistableModelProxy(typeof(UnknownChatCompletionsNamedToolSelection))] + internal partial class ChatCompletionsNamedToolSelection : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsNamedToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); + } + + internal static ChatCompletionsNamedToolSelection DeserializeChatCompletionsNamedToolSelection(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function": return ChatCompletionsNamedFunctionToolSelection.DeserializeChatCompletionsNamedFunctionToolSelection(element); + } + } + return UnknownChatCompletionsNamedToolSelection.DeserializeUnknownChatCompletionsNamedToolSelection(element); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsNamedToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsNamedToolSelection(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ChatCompletionsNamedToolSelection FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsNamedToolSelection(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.cs new file mode 100644 index 0000000000000..99119522d04af --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsNamedToolSelection.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// + /// An abstract representation of an explicit, named tool selection to use for a chat completions request. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include . + /// + internal abstract partial class ChatCompletionsNamedToolSelection + { + /// + /// 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 ChatCompletionsNamedToolSelection() + { + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsNamedToolSelection(string type, IDictionary serializedAdditionalRawData) + { + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The object type. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.Serialization.cs index bf1bbd6c36e64..f9d48e4f4286e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.Serialization.cs @@ -5,13 +5,463 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsOptions : IUtf8JsonSerializable + public partial class ChatCompletionsOptions : IUtf8JsonSerializable, IJsonModel { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsOptions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("messages"u8); + writer.WriteStartArray(); + foreach (var item in Messages) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + if (Optional.IsCollectionDefined(Functions)) + { + writer.WritePropertyName("functions"u8); + writer.WriteStartArray(); + foreach (var item in Functions) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(FunctionCall)) + { + writer.WritePropertyName("function_call"u8); + writer.WriteObjectValue(FunctionCall); + } + if (Optional.IsDefined(MaxTokens)) + { + writer.WritePropertyName("max_tokens"u8); + writer.WriteNumberValue(MaxTokens.Value); + } + if (Optional.IsDefined(Temperature)) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + if (Optional.IsDefined(NucleusSamplingFactor)) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(NucleusSamplingFactor.Value); + } + if (Optional.IsCollectionDefined(TokenSelectionBiases)) + { + writer.WritePropertyName("logit_bias"u8); + SerializeTokenSelectionBiases(writer); + } + if (Optional.IsDefined(User)) + { + writer.WritePropertyName("user"u8); + writer.WriteStringValue(User); + } + if (Optional.IsDefined(ChoiceCount)) + { + writer.WritePropertyName("n"u8); + writer.WriteNumberValue(ChoiceCount.Value); + } + if (Optional.IsCollectionDefined(StopSequences)) + { + writer.WritePropertyName("stop"u8); + writer.WriteStartArray(); + foreach (var item in StopSequences) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(PresencePenalty)) + { + writer.WritePropertyName("presence_penalty"u8); + writer.WriteNumberValue(PresencePenalty.Value); + } + if (Optional.IsDefined(FrequencyPenalty)) + { + writer.WritePropertyName("frequency_penalty"u8); + writer.WriteNumberValue(FrequencyPenalty.Value); + } + if (Optional.IsDefined(InternalShouldStreamResponse)) + { + writer.WritePropertyName("stream"u8); + writer.WriteBooleanValue(InternalShouldStreamResponse.Value); + } + if (Optional.IsDefined(DeploymentName)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(DeploymentName); + } + if (Optional.IsCollectionDefined(InternalAzureExtensionsDataSources)) + { + writer.WritePropertyName("dataSources"u8); + writer.WriteStartArray(); + foreach (var item in InternalAzureExtensionsDataSources) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(Enhancements)) + { + writer.WritePropertyName("enhancements"u8); + writer.WriteObjectValue(Enhancements); + } + if (Optional.IsDefined(Seed)) + { + writer.WritePropertyName("seed"u8); + writer.WriteNumberValue(Seed.Value); + } + if (Optional.IsDefined(ResponseFormat)) + { + writer.WritePropertyName("response_format"u8); + writer.WriteObjectValue(ResponseFormat); + } + if (Optional.IsCollectionDefined(Tools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(InternalSuppressedToolChoice)) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(InternalSuppressedToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(InternalSuppressedToolChoice)) + { + 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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsOptions 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(ChatCompletionsOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsOptions(document.RootElement, options); + } + + internal static ChatCompletionsOptions DeserializeChatCompletionsOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList messages = default; + Optional> functions = default; + Optional functionCall = default; + Optional maxTokens = default; + Optional temperature = default; + Optional topP = default; + Optional> logitBias = default; + Optional user = default; + Optional n = default; + Optional> stop = default; + Optional presencePenalty = default; + Optional frequencyPenalty = default; + Optional stream = default; + Optional model = default; + Optional> dataSources = default; + Optional enhancements = default; + Optional seed = default; + Optional responseFormat = default; + Optional> tools = default; + Optional toolChoice = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = 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(ChatRequestMessage.DeserializeChatRequestMessage(item)); + } + messages = array; + continue; + } + if (property.NameEquals("functions"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(FunctionDefinition.DeserializeFunctionDefinition(item)); + } + functions = array; + continue; + } + if (property.NameEquals("function_call"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + functionCall = FunctionDefinition.DeserializeFunctionDefinition(property.Value); + continue; + } + if (property.NameEquals("max_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maxTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("logit_bias"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetInt32()); + } + logitBias = dictionary; + continue; + } + if (property.NameEquals("user"u8)) + { + user = property.Value.GetString(); + continue; + } + if (property.NameEquals("n"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + n = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("stop"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + stop = array; + continue; + } + if (property.NameEquals("presence_penalty"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + presencePenalty = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("frequency_penalty"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + frequencyPenalty = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("stream"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + stream = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("dataSources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(AzureChatExtensionConfiguration.DeserializeAzureChatExtensionConfiguration(item)); + } + dataSources = array; + continue; + } + if (property.NameEquals("enhancements"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + enhancements = AzureChatEnhancementConfiguration.DeserializeAzureChatEnhancementConfiguration(property.Value); + continue; + } + if (property.NameEquals("seed"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + seed = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + responseFormat = ChatCompletionsResponseFormat.DeserializeChatCompletionsResponseFormat(property.Value); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ChatCompletionsToolDefinition.DeserializeChatCompletionsToolDefinition(item)); + } + tools = array; + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsOptions(messages, Optional.ToList(functions), functionCall.Value, Optional.ToNullable(maxTokens), Optional.ToNullable(temperature), Optional.ToNullable(topP), Optional.ToDictionary(logitBias), user.Value, Optional.ToNullable(n), Optional.ToList(stop), Optional.ToNullable(presencePenalty), Optional.ToNullable(frequencyPenalty), Optional.ToNullable(stream), model.Value, Optional.ToList(dataSources), enhancements.Value, Optional.ToNullable(seed), responseFormat.Value, Optional.ToList(tools), toolChoice.Value, 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(ChatCompletionsOptions)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsOptions)} does not support '{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 ChatCompletionsOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs index 670d5adec5881..3ec62e8011a14 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsOptions.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class ChatCompletionsOptions { + /// + /// 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 chat completions request. @@ -98,7 +130,8 @@ public partial class ChatCompletionsOptions /// An object specifying the format that the model must output. Used to enable JSON mode. /// The available tool definitions that the chat completions request can use, including caller-defined functions. /// If specified, the model will configure which of the provided tools it can use for the chat completions response. - internal ChatCompletionsOptions(IList messages, IList functions, FunctionDefinition functionCall, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary tokenSelectionBiases, string user, int? choiceCount, IList stopSequences, float? presencePenalty, float? frequencyPenalty, bool? internalShouldStreamResponse, string deploymentName, IList internalAzureExtensionsDataSources, AzureChatEnhancementConfiguration enhancements, long? seed, ChatCompletionsResponseFormat responseFormat, IList tools, BinaryData internalSuppressedToolChoice) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsOptions(IList messages, IList functions, FunctionDefinition functionCall, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary tokenSelectionBiases, string user, int? choiceCount, IList stopSequences, float? presencePenalty, float? frequencyPenalty, bool? internalShouldStreamResponse, string deploymentName, IList internalAzureExtensionsDataSources, AzureChatEnhancementConfiguration enhancements, long? seed, ChatCompletionsResponseFormat responseFormat, IList tools, BinaryData internalSuppressedToolChoice, IDictionary serializedAdditionalRawData) { Messages = messages; Functions = functions; @@ -120,6 +153,7 @@ internal ChatCompletionsOptions(IList messages, IList diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.Serialization.cs index bc5f7f72639ac..5785e8bf75155 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.Serialization.cs @@ -5,21 +5,118 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsResponseFormat : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownChatCompletionsResponseFormat))] + public partial class ChatCompletionsResponseFormat : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsResponseFormat)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatCompletionsResponseFormat 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(ChatCompletionsResponseFormat)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsResponseFormat(document.RootElement, options); + } + + internal static ChatCompletionsResponseFormat DeserializeChatCompletionsResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "text": return ChatCompletionsTextResponseFormat.DeserializeChatCompletionsTextResponseFormat(element); + case "json_object": return ChatCompletionsJsonResponseFormat.DeserializeChatCompletionsJsonResponseFormat(element); + } + } + return UnknownChatCompletionsResponseFormat.DeserializeUnknownChatCompletionsResponseFormat(element); + } + + 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(ChatCompletionsResponseFormat)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsResponseFormat)} does not support '{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 ChatCompletionsResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsResponseFormat(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.cs index 463d3ce49b0b1..04693b24c28fc 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsResponseFormat.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatCompletionsResponseFormat { + /// + /// 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 ChatCompletionsResponseFormat() { @@ -21,9 +56,11 @@ protected ChatCompletionsResponseFormat() /// Initializes a new instance of . /// The discriminated type for the response format. - internal ChatCompletionsResponseFormat(string type) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsResponseFormat(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The discriminated type for the response format. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.Serialization.cs index 65281166a0a23..7fb06a52cd7f8 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class ChatCompletionsTextResponseFormat : IUtf8JsonSerializable + internal partial class ChatCompletionsTextResponseFormat : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsTextResponseFormat)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatCompletionsTextResponseFormat 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(ChatCompletionsTextResponseFormat)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsTextResponseFormat(document.RootElement, options); + } + + internal static ChatCompletionsTextResponseFormat DeserializeChatCompletionsTextResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatCompletionsTextResponseFormat(type, 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(ChatCompletionsTextResponseFormat)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsTextResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsTextResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsTextResponseFormat)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatCompletionsTextResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsTextResponseFormat(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.cs index 8953cb5eb18c9..82044ed8f141d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsTextResponseFormat.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -21,7 +24,8 @@ public ChatCompletionsTextResponseFormat() /// Initializes a new instance of . /// The discriminated type for the response format. - internal ChatCompletionsTextResponseFormat(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsTextResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.Serialization.cs index 0c5239a93004b..e2c55b5a0263e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.Serialization.cs @@ -5,26 +5,66 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsToolCall : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownChatCompletionsToolCall))] + public partial class ChatCompletionsToolCall : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); writer.WritePropertyName("id"u8); writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static ChatCompletionsToolCall DeserializeChatCompletionsToolCall(JsonElement element) + ChatCompletionsToolCall 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(ChatCompletionsToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsToolCall(document.RootElement, options); + } + + internal static ChatCompletionsToolCall DeserializeChatCompletionsToolCall(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -39,6 +79,37 @@ internal static ChatCompletionsToolCall DeserializeChatCompletionsToolCall(JsonE return UnknownChatCompletionsToolCall.DeserializeUnknownChatCompletionsToolCall(element); } + 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(ChatCompletionsToolCall)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support '{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 ChatCompletionsToolCall FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.cs index 81d191b21e842..db06684436f2e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -18,6 +19,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatCompletionsToolCall { + /// + /// 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 ID of the tool call. /// is null. @@ -31,10 +64,17 @@ protected ChatCompletionsToolCall(string id) /// Initializes a new instance of . /// The object type. /// The ID of the tool call. - internal ChatCompletionsToolCall(string type, string id) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsToolCall(string type, string id, IDictionary serializedAdditionalRawData) { Type = type; Id = id; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ChatCompletionsToolCall() + { } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.Serialization.cs index 198fafc4c90c5..74cf6ac1495b6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.Serialization.cs @@ -5,21 +5,117 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatCompletionsToolDefinition : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownChatCompletionsToolDefinition))] + public partial class ChatCompletionsToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatCompletionsToolDefinition 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(ChatCompletionsToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatCompletionsToolDefinition(document.RootElement, options); + } + + internal static ChatCompletionsToolDefinition DeserializeChatCompletionsToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function": return ChatCompletionsFunctionToolDefinition.DeserializeChatCompletionsFunctionToolDefinition(element); + } + } + return UnknownChatCompletionsToolDefinition.DeserializeUnknownChatCompletionsToolDefinition(element); + } + + 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(ChatCompletionsToolDefinition)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatCompletionsToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support '{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 ChatCompletionsToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatCompletionsToolDefinition(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.cs index 83210b74dc4cc..712c79c1aeb93 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatCompletionsToolDefinition.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatCompletionsToolDefinition { + /// + /// 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 ChatCompletionsToolDefinition() { @@ -21,9 +56,11 @@ protected ChatCompletionsToolDefinition() /// Initializes a new instance of . /// The object type. - internal ChatCompletionsToolDefinition(string type) + /// Keeps track of any properties unknown to the library. + internal ChatCompletionsToolDefinition(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.Serialization.cs index 2c27d9166eff7..0c49712b3e391 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.Serialization.cs @@ -5,15 +5,64 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatFinishDetails + [PersistableModelProxy(typeof(UnknownChatFinishDetails))] + public partial class ChatFinishDetails : IUtf8JsonSerializable, IJsonModel { - internal static ChatFinishDetails DeserializeChatFinishDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatFinishDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatFinishDetails 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(ChatFinishDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatFinishDetails(document.RootElement, options); + } + + internal static ChatFinishDetails DeserializeChatFinishDetails(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +78,37 @@ internal static ChatFinishDetails DeserializeChatFinishDetails(JsonElement eleme return UnknownChatFinishDetails.DeserializeUnknownChatFinishDetails(element); } + 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(ChatFinishDetails)} does not support '{options.Format}' format."); + } + } + + ChatFinishDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatFinishDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatFinishDetails)} does not support '{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 ChatFinishDetails FromResponse(Response response) @@ -36,5 +116,13 @@ internal static ChatFinishDetails FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeChatFinishDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.cs index 687c457d06576..4a372d971fd56 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatFinishDetails.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatFinishDetails { + /// + /// 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 ChatFinishDetails() { @@ -21,9 +56,11 @@ protected ChatFinishDetails() /// Initializes a new instance of . /// The object type. - internal ChatFinishDetails(string type) + /// Keeps track of any properties unknown to the library. + internal ChatFinishDetails(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The object type. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.Serialization.cs index ce5857026552d..9cbd3555ea67b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.Serialization.cs @@ -5,21 +5,118 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatMessageContentItem : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownChatMessageContentItem))] + public partial class ChatMessageContentItem : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatMessageContentItem)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatMessageContentItem 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(ChatMessageContentItem)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatMessageContentItem(document.RootElement, options); + } + + internal static ChatMessageContentItem DeserializeChatMessageContentItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "text": return ChatMessageTextContentItem.DeserializeChatMessageTextContentItem(element); + case "image_url": return ChatMessageImageContentItem.DeserializeChatMessageImageContentItem(element); + } + } + return UnknownChatMessageContentItem.DeserializeUnknownChatMessageContentItem(element); + } + + 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(ChatMessageContentItem)} does not support '{options.Format}' format."); + } + } + + ChatMessageContentItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatMessageContentItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatMessageContentItem)} does not support '{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 ChatMessageContentItem FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatMessageContentItem(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.cs index 4f4e9684cfa3e..dbbe1ce846791 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageContentItem.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatMessageContentItem { + /// + /// 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 ChatMessageContentItem() { @@ -21,9 +56,11 @@ protected ChatMessageContentItem() /// Initializes a new instance of . /// The discriminated object type. - internal ChatMessageContentItem(string type) + /// Keeps track of any properties unknown to the library. + internal ChatMessageContentItem(string type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The discriminated object type. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.Serialization.cs index b6de633b438bd..322ceaba2f69b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatMessageImageContentItem : IUtf8JsonSerializable + public partial class ChatMessageImageContentItem : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatMessageImageContentItem)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("image_url"u8); writer.WriteObjectValue(ImageUrl); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatMessageImageContentItem 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(ChatMessageImageContentItem)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatMessageImageContentItem(document.RootElement, options); + } + + internal static ChatMessageImageContentItem DeserializeChatMessageImageContentItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ChatMessageImageUrl imageUrl = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("image_url"u8)) + { + imageUrl = ChatMessageImageUrl.DeserializeChatMessageImageUrl(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatMessageImageContentItem(type, serializedAdditionalRawData, imageUrl); + } + + 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(ChatMessageImageContentItem)} does not support '{options.Format}' format."); + } + } + + ChatMessageImageContentItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatMessageImageContentItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatMessageImageContentItem)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatMessageImageContentItem FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatMessageImageContentItem(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.cs index e419bc917c603..3dfdf32e48af1 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageContentItem.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ public ChatMessageImageContentItem(ChatMessageImageUrl imageUrl) /// Initializes a new instance of . /// The discriminated object type. + /// Keeps track of any properties unknown to the library. /// An internet location, which must be accessible to the model,from which the image may be retrieved. - internal ChatMessageImageContentItem(string type, ChatMessageImageUrl imageUrl) : base(type) + internal ChatMessageImageContentItem(string type, IDictionary serializedAdditionalRawData, ChatMessageImageUrl imageUrl) : base(type, serializedAdditionalRawData) { ImageUrl = imageUrl; } + /// Initializes a new instance of for deserialization. + internal ChatMessageImageContentItem() + { + } + /// An internet location, which must be accessible to the model,from which the image may be retrieved. public ChatMessageImageUrl ImageUrl { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.Serialization.cs index 8899287bd046b..a1efe1b097277 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatMessageImageUrl : IUtf8JsonSerializable + public partial class ChatMessageImageUrl : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatMessageImageUrl)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("url"u8); writer.WriteStringValue(Url.AbsoluteUri); @@ -22,9 +34,112 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("detail"u8); writer.WriteStringValue(Detail.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatMessageImageUrl 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(ChatMessageImageUrl)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatMessageImageUrl(document.RootElement, options); + } + + internal static ChatMessageImageUrl DeserializeChatMessageImageUrl(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Uri url = default; + Optional detail = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("url"u8)) + { + url = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("detail"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + detail = new ChatMessageImageDetailLevel(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatMessageImageUrl(url, Optional.ToNullable(detail), 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(ChatMessageImageUrl)} does not support '{options.Format}' format."); + } + } + + ChatMessageImageUrl IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatMessageImageUrl(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatMessageImageUrl)} does not support '{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 ChatMessageImageUrl FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatMessageImageUrl(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.cs index ea5fd330da845..05400d126d2fa 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageImageUrl.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// An internet location from which the model may retrieve an image. public partial class ChatMessageImageUrl { + /// + /// 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 URL of the image. /// is null. @@ -29,10 +62,17 @@ public ChatMessageImageUrl(Uri url) /// The evaluation quality setting to use, which controls relative prioritization of speed, token consumption, and /// accuracy. /// - internal ChatMessageImageUrl(Uri url, ChatMessageImageDetailLevel? detail) + /// Keeps track of any properties unknown to the library. + internal ChatMessageImageUrl(Uri url, ChatMessageImageDetailLevel? detail, IDictionary serializedAdditionalRawData) { Url = url; Detail = detail; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ChatMessageImageUrl() + { } /// The URL of the image. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.Serialization.cs index d2d87b6e9697b..10003d7c16b10 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatMessageTextContentItem : IUtf8JsonSerializable + public partial class ChatMessageTextContentItem : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatMessageTextContentItem)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("text"u8); writer.WriteStringValue(Text); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatMessageTextContentItem 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(ChatMessageTextContentItem)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatMessageTextContentItem(document.RootElement, options); + } + + internal static ChatMessageTextContentItem DeserializeChatMessageTextContentItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string text = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatMessageTextContentItem(type, serializedAdditionalRawData, text); + } + + 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(ChatMessageTextContentItem)} does not support '{options.Format}' format."); + } + } + + ChatMessageTextContentItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatMessageTextContentItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatMessageTextContentItem)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatMessageTextContentItem FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatMessageTextContentItem(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.cs index e06048921c3c1..7ac5cf534819b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatMessageTextContentItem.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ public ChatMessageTextContentItem(string text) /// Initializes a new instance of . /// The discriminated object type. + /// Keeps track of any properties unknown to the library. /// The content of the message. - internal ChatMessageTextContentItem(string type, string text) : base(type) + internal ChatMessageTextContentItem(string type, IDictionary serializedAdditionalRawData, string text) : base(type, serializedAdditionalRawData) { Text = text; } + /// Initializes a new instance of for deserialization. + internal ChatMessageTextContentItem() + { + } + /// The content of the message. public string Text { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.Serialization.cs index b1f11fa7d26f9..da30349b39f35 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestAssistantMessage : IUtf8JsonSerializable + public partial class ChatRequestAssistantMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestAssistantMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Content != null) { @@ -46,9 +58,144 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestAssistantMessage 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(ChatRequestAssistantMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestAssistantMessage(document.RootElement, options); + } + + internal static ChatRequestAssistantMessage DeserializeChatRequestAssistantMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string content = default; + Optional name = default; + Optional> toolCalls = default; + Optional functionCall = default; + ChatRole role = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + content = null; + continue; + } + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("tool_calls"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ChatCompletionsToolCall.DeserializeChatCompletionsToolCall(item)); + } + toolCalls = array; + continue; + } + if (property.NameEquals("function_call"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + functionCall = FunctionCall.DeserializeFunctionCall(property.Value); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatRequestAssistantMessage(role, serializedAdditionalRawData, content, name.Value, Optional.ToList(toolCalls), functionCall.Value); + } + + 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(ChatRequestAssistantMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestAssistantMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestAssistantMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestAssistantMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatRequestAssistantMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestAssistantMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.cs index f91ddc6a55054..8e1dbe14dc727 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestAssistantMessage.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -24,6 +25,7 @@ public ChatRequestAssistantMessage(string content) /// Initializes a new instance of . /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. /// The content of the message. /// An optional name for the participant. /// @@ -34,7 +36,7 @@ public ChatRequestAssistantMessage(string content) /// The function call that must be resolved and have its output appended to subsequent input messages for the chat /// completions request to resolve as configured. /// - internal ChatRequestAssistantMessage(ChatRole role, string content, string name, IList toolCalls, FunctionCall functionCall) : base(role) + internal ChatRequestAssistantMessage(ChatRole role, IDictionary serializedAdditionalRawData, string content, string name, IList toolCalls, FunctionCall functionCall) : base(role, serializedAdditionalRawData) { Content = content; Name = name; @@ -42,6 +44,11 @@ internal ChatRequestAssistantMessage(ChatRole role, string content, string name, FunctionCall = functionCall; } + /// Initializes a new instance of for deserialization. + internal ChatRequestAssistantMessage() + { + } + /// The content of the message. public string Content { get; } /// An optional name for the participant. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.Serialization.cs index b8b91055c16b4..eb69b3a92eaf0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestFunctionMessage : IUtf8JsonSerializable + public partial class ChatRequestFunctionMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestFunctionMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); @@ -28,9 +40,119 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestFunctionMessage 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(ChatRequestFunctionMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestFunctionMessage(document.RootElement, options); + } + + internal static ChatRequestFunctionMessage DeserializeChatRequestFunctionMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string content = default; + ChatRole role = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("content"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + content = null; + continue; + } + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatRequestFunctionMessage(role, serializedAdditionalRawData, name, content); + } + + 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(ChatRequestFunctionMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestFunctionMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestFunctionMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestFunctionMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatRequestFunctionMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestFunctionMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.cs index 47eb1335545cc..ed47da3cb366d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestFunctionMessage.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -28,14 +29,20 @@ public ChatRequestFunctionMessage(string name, string content) /// Initializes a new instance of . /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. /// The name of the function that was called to produce output. /// The output of the function as requested by the function call. - internal ChatRequestFunctionMessage(ChatRole role, string name, string content) : base(role) + internal ChatRequestFunctionMessage(ChatRole role, IDictionary serializedAdditionalRawData, string name, string content) : base(role, serializedAdditionalRawData) { Name = name; Content = content; } + /// Initializes a new instance of for deserialization. + internal ChatRequestFunctionMessage() + { + } + /// The name of the function that was called to produce output. public string Name { get; } /// The output of the function as requested by the function call. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.Serialization.cs index 84e67b71aae48..bb8c8857b2b5c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.Serialization.cs @@ -5,21 +5,121 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestMessage : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownChatRequestMessage))] + public partial class ChatRequestMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestMessage 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(ChatRequestMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestMessage(document.RootElement, options); + } + + internal static ChatRequestMessage DeserializeChatRequestMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("role", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "system": return ChatRequestSystemMessage.DeserializeChatRequestSystemMessage(element); + case "user": return ChatRequestUserMessage.DeserializeChatRequestUserMessage(element); + case "assistant": return ChatRequestAssistantMessage.DeserializeChatRequestAssistantMessage(element); + case "tool": return ChatRequestToolMessage.DeserializeChatRequestToolMessage(element); + case "function": return ChatRequestFunctionMessage.DeserializeChatRequestFunctionMessage(element); + } + } + return UnknownChatRequestMessage.DeserializeUnknownChatRequestMessage(element); + } + + 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(ChatRequestMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestMessage)} does not support '{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 ChatRequestMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.cs index ebfeee0467bd4..2736bc3da325b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestMessage.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class ChatRequestMessage { + /// + /// 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 ChatRequestMessage() { @@ -21,9 +56,11 @@ protected ChatRequestMessage() /// Initializes a new instance of . /// The chat role associated with this message. - internal ChatRequestMessage(ChatRole role) + /// Keeps track of any properties unknown to the library. + internal ChatRequestMessage(ChatRole role, IDictionary serializedAdditionalRawData) { Role = role; + _serializedAdditionalRawData = serializedAdditionalRawData; } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.Serialization.cs index bad98e7900f05..480cee80ed649 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestSystemMessage : IUtf8JsonSerializable + public partial class ChatRequestSystemMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestSystemMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("content"u8); writer.WriteStringValue(Content); @@ -24,9 +36,114 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestSystemMessage 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(ChatRequestSystemMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestSystemMessage(document.RootElement, options); + } + + internal static ChatRequestSystemMessage DeserializeChatRequestSystemMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string content = default; + Optional name = default; + ChatRole role = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatRequestSystemMessage(role, serializedAdditionalRawData, content, name.Value); + } + + 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(ChatRequestSystemMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestSystemMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestSystemMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestSystemMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatRequestSystemMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestSystemMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.cs index eb9f11f425b98..61400610e5430 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestSystemMessage.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -29,14 +30,20 @@ public ChatRequestSystemMessage(string content) /// Initializes a new instance of . /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. /// The contents of the system message. /// An optional name for the participant. - internal ChatRequestSystemMessage(ChatRole role, string content, string name) : base(role) + internal ChatRequestSystemMessage(ChatRole role, IDictionary serializedAdditionalRawData, string content, string name) : base(role, serializedAdditionalRawData) { Content = content; Name = name; } + /// Initializes a new instance of for deserialization. + internal ChatRequestSystemMessage() + { + } + /// The contents of the system message. public string Content { get; } /// An optional name for the participant. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.Serialization.cs index 9f48234f23829..a198459a9406c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestToolMessage : IUtf8JsonSerializable + public partial class ChatRequestToolMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestToolMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Content != null) { @@ -28,9 +40,119 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(ToolCallId); writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestToolMessage 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(ChatRequestToolMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestToolMessage(document.RootElement, options); + } + + internal static ChatRequestToolMessage DeserializeChatRequestToolMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string content = default; + string toolCallId = default; + ChatRole role = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + content = null; + continue; + } + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("tool_call_id"u8)) + { + toolCallId = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatRequestToolMessage(role, serializedAdditionalRawData, content, toolCallId); + } + + 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(ChatRequestToolMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestToolMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestToolMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestToolMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatRequestToolMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestToolMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.cs index 112b82372ae75..5eb06ca782434 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestToolMessage.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -28,14 +29,20 @@ public ChatRequestToolMessage(string content, string toolCallId) /// Initializes a new instance of . /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. /// The content of the message. /// The ID of the tool call resolved by the provided content. - internal ChatRequestToolMessage(ChatRole role, string content, string toolCallId) : base(role) + internal ChatRequestToolMessage(ChatRole role, IDictionary serializedAdditionalRawData, string content, string toolCallId) : base(role, serializedAdditionalRawData) { Content = content; ToolCallId = toolCallId; } + /// Initializes a new instance of for deserialization. + internal ChatRequestToolMessage() + { + } + /// The content of the message. public string Content { get; } /// The ID of the tool call resolved by the provided content. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.Serialization.cs index e58efb15df8df..139601f82c67d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ChatRequestUserMessage : IUtf8JsonSerializable + public partial class ChatRequestUserMessage : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestUserMessage)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("content"u8); SerializeContent(writer); @@ -24,9 +36,114 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ChatRequestUserMessage 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(ChatRequestUserMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatRequestUserMessage(document.RootElement, options); + } + + internal static ChatRequestUserMessage DeserializeChatRequestUserMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string content = default; + Optional name = default; + ChatRole role = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + content = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatRequestUserMessage(role, serializedAdditionalRawData, content, name.Value); + } + + 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(ChatRequestUserMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestUserMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatRequestUserMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestUserMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ChatRequestUserMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeChatRequestUserMessage(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.cs index e8988148dedc8..6ebd02e0b2ae3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatRequestUserMessage.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -15,13 +16,19 @@ public partial class ChatRequestUserMessage : ChatRequestMessage { /// Initializes a new instance of . /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. /// The contents of the user message, with available input types varying by selected model. /// An optional name for the participant. - internal ChatRequestUserMessage(ChatRole role, string content, string name) : base(role) + internal ChatRequestUserMessage(ChatRole role, IDictionary serializedAdditionalRawData, string content, string name) : base(role, serializedAdditionalRawData) { Content = content; Name = name; } + + /// Initializes a new instance of for deserialization. + internal ChatRequestUserMessage() + { + } /// An optional name for the participant. public string Name { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.Serialization.cs index 6f9ec90ba54de..7931024848756 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.Serialization.cs @@ -5,6 +5,8 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -12,10 +14,84 @@ namespace Azure.AI.OpenAI { - public partial class ChatResponseMessage + public partial class ChatResponseMessage : IUtf8JsonSerializable, IJsonModel { - internal static ChatResponseMessage DeserializeChatResponseMessage(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatResponseMessage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + if (Content != null) + { + writer.WritePropertyName("content"u8); + writer.WriteStringValue(Content); + } + else + { + writer.WriteNull("content"); + } + if (Optional.IsCollectionDefined(ToolCalls)) + { + writer.WritePropertyName("tool_calls"u8); + writer.WriteStartArray(); + foreach (var item in ToolCalls) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(FunctionCall)) + { + writer.WritePropertyName("function_call"u8); + writer.WriteObjectValue(FunctionCall); + } + if (Optional.IsDefined(AzureExtensionsContext)) + { + writer.WritePropertyName("context"u8); + writer.WriteObjectValue(AzureExtensionsContext); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatResponseMessage 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(ChatResponseMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatResponseMessage(document.RootElement, options); + } + + internal static ChatResponseMessage DeserializeChatResponseMessage(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -25,6 +101,8 @@ internal static ChatResponseMessage DeserializeChatResponseMessage(JsonElement e Optional> toolCalls = default; Optional functionCall = default; Optional context = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("role"u8)) @@ -74,10 +152,46 @@ internal static ChatResponseMessage DeserializeChatResponseMessage(JsonElement e context = AzureChatExtensionsMessageContext.DeserializeAzureChatExtensionsMessageContext(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ChatResponseMessage(role, content, Optional.ToList(toolCalls), functionCall.Value, context.Value, 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(ChatResponseMessage)} does not support '{options.Format}' format."); } - return new ChatResponseMessage(role, content, Optional.ToList(toolCalls), functionCall.Value, context.Value); } + ChatResponseMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatResponseMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatResponseMessage)} does not support '{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 ChatResponseMessage FromResponse(Response response) @@ -85,5 +199,13 @@ internal static ChatResponseMessage FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeChatResponseMessage(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.cs index 42f358779052f..be00f03903a3f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ChatResponseMessage.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// A representation of a chat message as received in a response. public partial class ChatResponseMessage { + /// + /// 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 chat role associated with the message. /// The content of the message. @@ -38,13 +71,20 @@ internal ChatResponseMessage(ChatRole role, string content) /// If Azure OpenAI chat extensions are configured, this array represents the incremental steps performed by those /// extensions while processing the chat completions request. /// - internal ChatResponseMessage(ChatRole role, string content, IReadOnlyList toolCalls, FunctionCall functionCall, AzureChatExtensionsMessageContext azureExtensionsContext) + /// Keeps track of any properties unknown to the library. + internal ChatResponseMessage(ChatRole role, string content, IReadOnlyList toolCalls, FunctionCall functionCall, AzureChatExtensionsMessageContext azureExtensionsContext, IDictionary serializedAdditionalRawData) { Role = role; Content = content; ToolCalls = toolCalls; FunctionCall = functionCall; AzureExtensionsContext = azureExtensionsContext; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ChatResponseMessage() + { } /// The chat role associated with the message. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.Serialization.cs index da21ee0750e01..d8ed144cbd736 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.Serialization.cs @@ -5,16 +5,89 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class Choice + public partial class Choice : IUtf8JsonSerializable, IJsonModel { - internal static Choice DeserializeChoice(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Choice)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + if (Optional.IsDefined(ContentFilterResults)) + { + writer.WritePropertyName("content_filter_results"u8); + writer.WriteObjectValue(ContentFilterResults); + } + if (LogProbabilityModel != null) + { + writer.WritePropertyName("logprobs"u8); + writer.WriteObjectValue(LogProbabilityModel); + } + else + { + writer.WriteNull("logprobs"); + } + if (FinishReason != null) + { + writer.WritePropertyName("finish_reason"u8); + writer.WriteStringValue(FinishReason.Value.ToString()); + } + else + { + writer.WriteNull("finish_reason"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + Choice 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(Choice)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChoice(document.RootElement, options); + } + + internal static Choice DeserializeChoice(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +97,8 @@ internal static Choice DeserializeChoice(JsonElement element) Optional contentFilterResults = default; CompletionsLogProbabilityModel logprobs = default; CompletionsFinishReason? finishReason = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("text"u8)) @@ -65,10 +140,46 @@ internal static Choice DeserializeChoice(JsonElement element) finishReason = new CompletionsFinishReason(property.Value.GetString()); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Choice(text, index, contentFilterResults.Value, logprobs, 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(Choice)} does not support '{options.Format}' format."); } - return new Choice(text, index, contentFilterResults.Value, logprobs, finishReason); } + Choice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChoice(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Choice)} does not support '{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 Choice FromResponse(Response response) @@ -76,5 +187,13 @@ internal static Choice FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeChoice(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.cs index 487703a48daab..35095691c8aae 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Choice.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -17,6 +18,38 @@ namespace Azure.AI.OpenAI /// public partial class Choice { + /// + /// 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 generated text for a given completions prompt. /// The ordered index associated with this completions choice. @@ -43,13 +76,20 @@ internal Choice(string text, int index, CompletionsLogProbabilityModel logProbab /// /// The log probabilities model for tokens associated with this completions choice. /// Reason for finishing. - internal Choice(string text, int index, ContentFilterResultsForChoice contentFilterResults, CompletionsLogProbabilityModel logProbabilityModel, CompletionsFinishReason? finishReason) + /// Keeps track of any properties unknown to the library. + internal Choice(string text, int index, ContentFilterResultsForChoice contentFilterResults, CompletionsLogProbabilityModel logProbabilityModel, CompletionsFinishReason? finishReason, IDictionary serializedAdditionalRawData) { Text = text; Index = index; ContentFilterResults = contentFilterResults; LogProbabilityModel = logProbabilityModel; FinishReason = finishReason; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Choice() + { } /// The generated text for a given completions prompt. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.Serialization.cs index 51a4e3e06ba6a..18d5c43fdd89e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.Serialization.cs @@ -5,13 +5,177 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class Completions + public partial class Completions : IUtf8JsonSerializable, IJsonModel { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Completions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("created"u8); + writer.WriteNumberValue(Created, "U"); + if (Optional.IsCollectionDefined(PromptFilterResults)) + { + writer.WritePropertyName("prompt_filter_results"u8); + writer.WriteStartArray(); + foreach (var item in PromptFilterResults) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + writer.WritePropertyName("choices"u8); + writer.WriteStartArray(); + foreach (var item in Choices) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + Completions 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(Completions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCompletions(document.RootElement, options); + } + + internal static Completions DeserializeCompletions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + DateTimeOffset created = default; + Optional> promptFilterResults = default; + IReadOnlyList choices = default; + CompletionsUsage usage = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("created"u8)) + { + created = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("prompt_filter_results"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ContentFilterResultsForPrompt.DeserializeContentFilterResultsForPrompt(item)); + } + promptFilterResults = array; + continue; + } + if (property.NameEquals("choices"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(Choice.DeserializeChoice(item)); + } + choices = array; + continue; + } + if (property.NameEquals("usage"u8)) + { + usage = CompletionsUsage.DeserializeCompletionsUsage(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Completions(id, created, Optional.ToList(promptFilterResults), choices, usage, 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(Completions)} does not support '{options.Format}' format."); + } + } + + Completions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCompletions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Completions)} does not support '{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 Completions FromResponse(Response response) @@ -19,5 +183,13 @@ internal static Completions FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeCompletions(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.cs index 622927bd03d21..7c8cae64ecae6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Completions.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class Completions { + /// + /// 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 . /// A unique identifier associated with this completions response. /// @@ -61,13 +93,20 @@ internal Completions(string id, DateTimeOffset created, IEnumerable choi /// Token limits and other settings may limit the number of choices generated. /// /// Usage information for tokens processed and generated as part of this completions operation. - internal Completions(string id, DateTimeOffset created, IReadOnlyList promptFilterResults, IReadOnlyList choices, CompletionsUsage usage) + /// Keeps track of any properties unknown to the library. + internal Completions(string id, DateTimeOffset created, IReadOnlyList promptFilterResults, IReadOnlyList choices, CompletionsUsage usage, IDictionary serializedAdditionalRawData) { Id = id; Created = created; PromptFilterResults = promptFilterResults; Choices = choices; Usage = usage; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Completions() + { } /// A unique identifier associated with this completions response. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.Serialization.cs index 8c946d892b3bc..846fd490ce939 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.Serialization.cs @@ -5,16 +5,111 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class CompletionsLogProbabilityModel + public partial class CompletionsLogProbabilityModel : IUtf8JsonSerializable, IJsonModel { - internal static CompletionsLogProbabilityModel DeserializeCompletionsLogProbabilityModel(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CompletionsLogProbabilityModel)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("tokens"u8); + writer.WriteStartArray(); + foreach (var item in Tokens) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("token_logprobs"u8); + writer.WriteStartArray(); + foreach (var item in TokenLogProbabilities) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteNumberValue(item.Value); + } + writer.WriteEndArray(); + writer.WritePropertyName("top_logprobs"u8); + writer.WriteStartArray(); + foreach (var item in TopLogProbabilities) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStartObject(); + foreach (var item0 in item) + { + writer.WritePropertyName(item0.Key); + if (item0.Value == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteNumberValue(item0.Value.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndArray(); + writer.WritePropertyName("text_offset"u8); + writer.WriteStartArray(); + foreach (var item in TextOffsets) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CompletionsLogProbabilityModel 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(CompletionsLogProbabilityModel)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCompletionsLogProbabilityModel(document.RootElement, options); + } + + internal static CompletionsLogProbabilityModel DeserializeCompletionsLogProbabilityModel(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +118,8 @@ internal static CompletionsLogProbabilityModel DeserializeCompletionsLogProbabil IReadOnlyList tokenLogprobs = default; IReadOnlyList> topLogprobs = default; IReadOnlyList textOffset = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("tokens"u8)) @@ -91,10 +188,46 @@ internal static CompletionsLogProbabilityModel DeserializeCompletionsLogProbabil textOffset = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new CompletionsLogProbabilityModel(tokens, tokenLogprobs, topLogprobs, textOffset); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CompletionsLogProbabilityModel(tokens, tokenLogprobs, topLogprobs, textOffset, 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(CompletionsLogProbabilityModel)} does not support '{options.Format}' format."); + } + } + + CompletionsLogProbabilityModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCompletionsLogProbabilityModel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CompletionsLogProbabilityModel)} does not support '{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 CompletionsLogProbabilityModel FromResponse(Response response) @@ -102,5 +235,13 @@ internal static CompletionsLogProbabilityModel FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeCompletionsLogProbabilityModel(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.cs index a08e256a405df..a0f591bdc303f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsLogProbabilityModel.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// Representation of a log probabilities model for a completions generation. public partial class CompletionsLogProbabilityModel { + /// + /// 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 textual forms of tokens evaluated in this probability model. /// A collection of log probability values for the tokens in this completions data. @@ -39,12 +71,19 @@ internal CompletionsLogProbabilityModel(IEnumerable tokens, IEnumerable< /// A collection of log probability values for the tokens in this completions data. /// A mapping of tokens to maximum log probability values in this completions data. /// The text offsets associated with tokens in this completions data. - internal CompletionsLogProbabilityModel(IReadOnlyList tokens, IReadOnlyList tokenLogProbabilities, IReadOnlyList> topLogProbabilities, IReadOnlyList textOffsets) + /// Keeps track of any properties unknown to the library. + internal CompletionsLogProbabilityModel(IReadOnlyList tokens, IReadOnlyList tokenLogProbabilities, IReadOnlyList> topLogProbabilities, IReadOnlyList textOffsets, IDictionary serializedAdditionalRawData) { Tokens = tokens; TokenLogProbabilities = tokenLogProbabilities; TopLogProbabilities = topLogProbabilities; TextOffsets = textOffsets; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CompletionsLogProbabilityModel() + { } /// The textual forms of tokens evaluated in this probability model. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.Serialization.cs index f34243d218338..c0742565cc8d5 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class CompletionsOptions : IUtf8JsonSerializable + public partial class CompletionsOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CompletionsOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("prompt"u8); writer.WriteStartArray(); @@ -97,9 +109,249 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("model"u8); writer.WriteStringValue(DeploymentName); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + CompletionsOptions 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(CompletionsOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCompletionsOptions(document.RootElement, options); + } + + internal static CompletionsOptions DeserializeCompletionsOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList prompt = default; + Optional maxTokens = default; + Optional temperature = default; + Optional topP = default; + Optional> logitBias = default; + Optional user = default; + Optional n = default; + Optional logprobs = default; + Optional echo = default; + Optional> stop = default; + Optional presencePenalty = default; + Optional frequencyPenalty = default; + Optional bestOf = default; + Optional stream = default; + Optional model = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("prompt"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + prompt = array; + continue; + } + if (property.NameEquals("max_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maxTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("logit_bias"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetInt32()); + } + logitBias = dictionary; + continue; + } + if (property.NameEquals("user"u8)) + { + user = property.Value.GetString(); + continue; + } + if (property.NameEquals("n"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + n = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("logprobs"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + logprobs = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("echo"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + echo = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("stop"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + stop = array; + continue; + } + if (property.NameEquals("presence_penalty"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + presencePenalty = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("frequency_penalty"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + frequencyPenalty = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("best_of"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + bestOf = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("stream"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + stream = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CompletionsOptions(prompt, Optional.ToNullable(maxTokens), Optional.ToNullable(temperature), Optional.ToNullable(topP), Optional.ToDictionary(logitBias), user.Value, Optional.ToNullable(n), Optional.ToNullable(logprobs), Optional.ToNullable(echo), Optional.ToList(stop), Optional.ToNullable(presencePenalty), Optional.ToNullable(frequencyPenalty), Optional.ToNullable(bestOf), Optional.ToNullable(stream), model.Value, 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(CompletionsOptions)} does not support '{options.Format}' format."); + } + } + + CompletionsOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCompletionsOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CompletionsOptions)} does not support '{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 CompletionsOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCompletionsOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.cs index 9fcac641677f7..3bc754a1ed113 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsOptions.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class CompletionsOptions { + /// + /// 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 prompts to generate completions from. /// The maximum number of tokens to generate. @@ -89,7 +121,8 @@ public partial class CompletionsOptions /// Not applicable to Azure OpenAI, where deployment information should be included in the Azure /// resource URI that's connected to. /// - internal CompletionsOptions(IList prompts, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary tokenSelectionBiases, string user, int? choicesPerPrompt, int? logProbabilityCount, bool? echo, IList stopSequences, float? presencePenalty, float? frequencyPenalty, int? generationSampleCount, bool? internalShouldStreamResponse, string deploymentName) + /// Keeps track of any properties unknown to the library. + internal CompletionsOptions(IList prompts, int? maxTokens, float? temperature, float? nucleusSamplingFactor, IDictionary tokenSelectionBiases, string user, int? choicesPerPrompt, int? logProbabilityCount, bool? echo, IList stopSequences, float? presencePenalty, float? frequencyPenalty, int? generationSampleCount, bool? internalShouldStreamResponse, string deploymentName, IDictionary serializedAdditionalRawData) { Prompts = prompts; MaxTokens = maxTokens; @@ -106,6 +139,7 @@ internal CompletionsOptions(IList prompts, int? maxTokens, float? temper GenerationSampleCount = generationSampleCount; InternalShouldStreamResponse = internalShouldStreamResponse; DeploymentName = deploymentName; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// /// An identifier for the caller or end user of the operation. This may be used for tracking diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.Serialization.cs index 271333b1e5664..a0599a2955467 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.Serialization.cs @@ -5,15 +5,68 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class CompletionsUsage + public partial class CompletionsUsage : IUtf8JsonSerializable, IJsonModel { - internal static CompletionsUsage DeserializeCompletionsUsage(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CompletionsUsage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("completion_tokens"u8); + writer.WriteNumberValue(CompletionTokens); + writer.WritePropertyName("prompt_tokens"u8); + writer.WriteNumberValue(PromptTokens); + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + CompletionsUsage 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(CompletionsUsage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCompletionsUsage(document.RootElement, options); + } + + internal static CompletionsUsage DeserializeCompletionsUsage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -21,6 +74,8 @@ internal static CompletionsUsage DeserializeCompletionsUsage(JsonElement element int completionTokens = default; int promptTokens = default; int totalTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("completion_tokens"u8)) @@ -38,10 +93,46 @@ internal static CompletionsUsage DeserializeCompletionsUsage(JsonElement element totalTokens = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new CompletionsUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(CompletionsUsage)} does not support '{options.Format}' format."); + } + } + + CompletionsUsage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeCompletionsUsage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CompletionsUsage)} does not support '{options.Format}' format."); } - return new CompletionsUsage(completionTokens, promptTokens, totalTokens); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static CompletionsUsage FromResponse(Response response) @@ -49,5 +140,13 @@ internal static CompletionsUsage FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeCompletionsUsage(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.cs index 6b90e3badaf34..34fec50f0b3a2 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/CompletionsUsage.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public partial class CompletionsUsage { + /// + /// 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 number of tokens generated across all completions emissions. /// The number of tokens in the provided prompts for the completions request. @@ -25,6 +60,24 @@ internal CompletionsUsage(int completionTokens, int promptTokens, int totalToken TotalTokens = totalTokens; } + /// Initializes a new instance of . + /// The number of tokens generated across all completions emissions. + /// The number of tokens in the provided prompts for the completions request. + /// The total number of tokens processed for the completions request and response. + /// Keeps track of any properties unknown to the library. + internal CompletionsUsage(int completionTokens, int promptTokens, int totalTokens, IDictionary serializedAdditionalRawData) + { + CompletionTokens = completionTokens; + PromptTokens = promptTokens; + TotalTokens = totalTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CompletionsUsage() + { + } + /// The number of tokens generated across all completions emissions. public int CompletionTokens { get; } /// The number of tokens in the provided prompts for the completions request. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.Serialization.cs index 5a2d0644f0928..faac262f1d7ba 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ContentFilterBlocklistIdResult + public partial class ContentFilterBlocklistIdResult : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterBlocklistIdResult DeserializeContentFilterBlocklistIdResult(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterBlocklistIdResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("filtered"u8); + writer.WriteBooleanValue(Filtered); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterBlocklistIdResult 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(ContentFilterBlocklistIdResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterBlocklistIdResult(document.RootElement, options); + } + + internal static ContentFilterBlocklistIdResult DeserializeContentFilterBlocklistIdResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string id = default; bool filtered = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -32,10 +85,46 @@ internal static ContentFilterBlocklistIdResult DeserializeContentFilterBlocklist filtered = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterBlocklistIdResult(id, filtered, 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(ContentFilterBlocklistIdResult)} does not support '{options.Format}' format."); + } + } + + ContentFilterBlocklistIdResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterBlocklistIdResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterBlocklistIdResult)} does not support '{options.Format}' format."); } - return new ContentFilterBlocklistIdResult(id, filtered); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ContentFilterBlocklistIdResult FromResponse(Response response) @@ -43,5 +132,13 @@ internal static ContentFilterBlocklistIdResult FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterBlocklistIdResult(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.cs index db58d4bd07706..63121ff9d11d6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterBlocklistIdResult.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Represents the outcome of an evaluation against a custom blocklist as performed by content filtering. public partial class ContentFilterBlocklistIdResult { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// The ID of the custom blocklist evaluated. /// A value indicating whether or not the content has been filtered. @@ -25,6 +58,22 @@ internal ContentFilterBlocklistIdResult(string id, bool filtered) Filtered = filtered; } + /// Initializes a new instance of . + /// The ID of the custom blocklist evaluated. + /// A value indicating whether or not the content has been filtered. + /// Keeps track of any properties unknown to the library. + internal ContentFilterBlocklistIdResult(string id, bool filtered, IDictionary serializedAdditionalRawData) + { + Id = id; + Filtered = filtered; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ContentFilterBlocklistIdResult() + { + } + /// The ID of the custom blocklist evaluated. public string Id { get; } /// A value indicating whether or not the content has been filtered. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.Serialization.cs index e757417f52e6a..4881ef3747aa5 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.Serialization.cs @@ -6,16 +6,72 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ContentFilterCitedDetectionResult + public partial class ContentFilterCitedDetectionResult : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterCitedDetectionResult DeserializeContentFilterCitedDetectionResult(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterCitedDetectionResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("filtered"u8); + writer.WriteBooleanValue(Filtered); + writer.WritePropertyName("detected"u8); + writer.WriteBooleanValue(Detected); + if (Optional.IsDefined(Url)) + { + writer.WritePropertyName("URL"u8); + writer.WriteStringValue(Url.AbsoluteUri); + } + writer.WritePropertyName("license"u8); + writer.WriteStringValue(License); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterCitedDetectionResult 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(ContentFilterCitedDetectionResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterCitedDetectionResult(document.RootElement, options); + } + + internal static ContentFilterCitedDetectionResult DeserializeContentFilterCitedDetectionResult(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -24,6 +80,8 @@ internal static ContentFilterCitedDetectionResult DeserializeContentFilterCitedD bool detected = default; Optional url = default; string license = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("filtered"u8)) @@ -50,10 +108,46 @@ internal static ContentFilterCitedDetectionResult DeserializeContentFilterCitedD license = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ContentFilterCitedDetectionResult(filtered, detected, url.Value, license); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterCitedDetectionResult(filtered, detected, url.Value, license, 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(ContentFilterCitedDetectionResult)} does not support '{options.Format}' format."); + } + } + + ContentFilterCitedDetectionResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterCitedDetectionResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterCitedDetectionResult)} does not support '{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 ContentFilterCitedDetectionResult FromResponse(Response response) @@ -61,5 +155,13 @@ internal static ContentFilterCitedDetectionResult FromResponse(Response response using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterCitedDetectionResult(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.cs index 8ef4e66477eab..c0557d1b8562a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterCitedDetectionResult.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Represents the outcome of a detection operation against protected resources as performed by content filtering. public partial class ContentFilterCitedDetectionResult { + /// + /// 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 . /// A value indicating whether or not the content has been filtered. /// A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. @@ -32,12 +65,19 @@ internal ContentFilterCitedDetectionResult(bool filtered, bool detected, string /// A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. /// The internet location associated with the detection. /// The license description associated with the detection. - internal ContentFilterCitedDetectionResult(bool filtered, bool detected, Uri url, string license) + /// Keeps track of any properties unknown to the library. + internal ContentFilterCitedDetectionResult(bool filtered, bool detected, Uri url, string license, IDictionary serializedAdditionalRawData) { Filtered = filtered; Detected = detected; Url = url; License = license; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ContentFilterCitedDetectionResult() + { } /// A value indicating whether or not the content has been filtered. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.Serialization.cs index 54a95ee79a585..6d5de67cb2d7e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ContentFilterDetectionResult + public partial class ContentFilterDetectionResult : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterDetectionResult DeserializeContentFilterDetectionResult(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterDetectionResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("filtered"u8); + writer.WriteBooleanValue(Filtered); + writer.WritePropertyName("detected"u8); + writer.WriteBooleanValue(Detected); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterDetectionResult 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(ContentFilterDetectionResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterDetectionResult(document.RootElement, options); + } + + internal static ContentFilterDetectionResult DeserializeContentFilterDetectionResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } bool filtered = default; bool detected = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("filtered"u8)) @@ -32,10 +85,46 @@ internal static ContentFilterDetectionResult DeserializeContentFilterDetectionRe detected = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterDetectionResult(filtered, detected, 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(ContentFilterDetectionResult)} does not support '{options.Format}' format."); + } + } + + ContentFilterDetectionResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterDetectionResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterDetectionResult)} does not support '{options.Format}' format."); } - return new ContentFilterDetectionResult(filtered, detected); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ContentFilterDetectionResult FromResponse(Response response) @@ -43,5 +132,13 @@ internal static ContentFilterDetectionResult FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterDetectionResult(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.cs index dc55d748a058d..eed9a9faac269 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterDetectionResult.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// Represents the outcome of a detection operation performed by content filtering. public partial class ContentFilterDetectionResult { + /// + /// 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 . /// A value indicating whether or not the content has been filtered. /// A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. @@ -19,6 +54,22 @@ internal ContentFilterDetectionResult(bool filtered, bool detected) Detected = detected; } + /// Initializes a new instance of . + /// A value indicating whether or not the content has been filtered. + /// A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. + /// Keeps track of any properties unknown to the library. + internal ContentFilterDetectionResult(bool filtered, bool detected, IDictionary serializedAdditionalRawData) + { + Filtered = filtered; + Detected = detected; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ContentFilterDetectionResult() + { + } + /// A value indicating whether or not the content has been filtered. public bool Filtered { get; } /// A value indicating whether detection occurred, irrespective of severity or whether the content was filtered. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.Serialization.cs index 428c78f4920c4..827b4b774083c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ContentFilterResult + public partial class ContentFilterResult : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterResult DeserializeContentFilterResult(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterResult)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("severity"u8); + writer.WriteStringValue(Severity.ToString()); + writer.WritePropertyName("filtered"u8); + writer.WriteBooleanValue(Filtered); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterResult 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(ContentFilterResult)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterResult(document.RootElement, options); + } + + internal static ContentFilterResult DeserializeContentFilterResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } ContentFilterSeverity severity = default; bool filtered = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("severity"u8)) @@ -32,10 +85,46 @@ internal static ContentFilterResult DeserializeContentFilterResult(JsonElement e filtered = property.Value.GetBoolean(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterResult(severity, filtered, 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(ContentFilterResult)} does not support '{options.Format}' format."); + } + } + + ContentFilterResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterResult)} does not support '{options.Format}' format."); } - return new ContentFilterResult(severity, filtered); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ContentFilterResult FromResponse(Response response) @@ -43,5 +132,13 @@ internal static ContentFilterResult FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterResult(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.cs index 2a2c1c154f761..3a5c47f9f985f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResult.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// Information about filtered content severity level and if it has been filtered or not. public partial class ContentFilterResult { + /// + /// 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 . /// Ratings for the intensity and risk level of filtered content. /// A value indicating whether or not the content has been filtered. @@ -19,6 +54,22 @@ internal ContentFilterResult(ContentFilterSeverity severity, bool filtered) Filtered = filtered; } + /// Initializes a new instance of . + /// Ratings for the intensity and risk level of filtered content. + /// A value indicating whether or not the content has been filtered. + /// Keeps track of any properties unknown to the library. + internal ContentFilterResult(ContentFilterSeverity severity, bool filtered, IDictionary serializedAdditionalRawData) + { + Severity = severity; + Filtered = filtered; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ContentFilterResult() + { + } + /// Ratings for the intensity and risk level of filtered content. public ContentFilterSeverity Severity { get; } /// A value indicating whether or not the content has been filtered. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.Serialization.cs index 98137570652d9..8f37b5bb4cdad 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.Serialization.cs @@ -5,6 +5,8 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -12,10 +14,98 @@ namespace Azure.AI.OpenAI { - public partial class ContentFilterResultDetailsForPrompt + public partial class ContentFilterResultDetailsForPrompt : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterResultDetailsForPrompt DeserializeContentFilterResultDetailsForPrompt(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterResultDetailsForPrompt)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Sexual)) + { + writer.WritePropertyName("sexual"u8); + writer.WriteObjectValue(Sexual); + } + if (Optional.IsDefined(Violence)) + { + writer.WritePropertyName("violence"u8); + writer.WriteObjectValue(Violence); + } + if (Optional.IsDefined(Hate)) + { + writer.WritePropertyName("hate"u8); + writer.WriteObjectValue(Hate); + } + if (Optional.IsDefined(SelfHarm)) + { + writer.WritePropertyName("self_harm"u8); + writer.WriteObjectValue(SelfHarm); + } + if (Optional.IsDefined(Profanity)) + { + writer.WritePropertyName("profanity"u8); + writer.WriteObjectValue(Profanity); + } + if (Optional.IsCollectionDefined(CustomBlocklists)) + { + writer.WritePropertyName("custom_blocklists"u8); + writer.WriteStartArray(); + foreach (var item in CustomBlocklists) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(Error)) + { + writer.WritePropertyName("error"u8); + JsonSerializer.Serialize(writer, Error); + } + if (Optional.IsDefined(Jailbreak)) + { + writer.WritePropertyName("jailbreak"u8); + writer.WriteObjectValue(Jailbreak); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterResultDetailsForPrompt 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(ContentFilterResultDetailsForPrompt)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterResultDetailsForPrompt(document.RootElement, options); + } + + internal static ContentFilterResultDetailsForPrompt DeserializeContentFilterResultDetailsForPrompt(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -28,6 +118,8 @@ internal static ContentFilterResultDetailsForPrompt DeserializeContentFilterResu Optional> customBlocklists = default; Optional error = default; Optional jailbreak = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("sexual"u8)) @@ -107,10 +199,46 @@ internal static ContentFilterResultDetailsForPrompt DeserializeContentFilterResu jailbreak = ContentFilterDetectionResult.DeserializeContentFilterDetectionResult(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ContentFilterResultDetailsForPrompt(sexual.Value, violence.Value, hate.Value, selfHarm.Value, profanity.Value, Optional.ToList(customBlocklists), error.Value, jailbreak.Value); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterResultDetailsForPrompt(sexual.Value, violence.Value, hate.Value, selfHarm.Value, profanity.Value, Optional.ToList(customBlocklists), error.Value, jailbreak.Value, 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(ContentFilterResultDetailsForPrompt)} does not support '{options.Format}' format."); + } + } + + ContentFilterResultDetailsForPrompt IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterResultDetailsForPrompt(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterResultDetailsForPrompt)} does not support '{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 ContentFilterResultDetailsForPrompt FromResponse(Response response) @@ -118,5 +246,13 @@ internal static ContentFilterResultDetailsForPrompt FromResponse(Response respon using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterResultDetailsForPrompt(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.cs index 12be1fc61d4ac..8ace266b1be58 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultDetailsForPrompt.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure; using Azure.Core; @@ -14,6 +15,38 @@ namespace Azure.AI.OpenAI /// Information about content filtering evaluated against input data to Azure OpenAI. public partial class ContentFilterResultDetailsForPrompt { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . internal ContentFilterResultDetailsForPrompt() { @@ -49,7 +82,8 @@ internal ContentFilterResultDetailsForPrompt() /// down or otherwise unable to complete the operation in time. /// /// Whether a jailbreak attempt was detected in the prompt. - internal ContentFilterResultDetailsForPrompt(ContentFilterResult sexual, ContentFilterResult violence, ContentFilterResult hate, ContentFilterResult selfHarm, ContentFilterDetectionResult profanity, IReadOnlyList customBlocklists, ResponseError error, ContentFilterDetectionResult jailbreak) + /// Keeps track of any properties unknown to the library. + internal ContentFilterResultDetailsForPrompt(ContentFilterResult sexual, ContentFilterResult violence, ContentFilterResult hate, ContentFilterResult selfHarm, ContentFilterDetectionResult profanity, IReadOnlyList customBlocklists, ResponseError error, ContentFilterDetectionResult jailbreak, IDictionary serializedAdditionalRawData) { Sexual = sexual; Violence = violence; @@ -59,6 +93,7 @@ internal ContentFilterResultDetailsForPrompt(ContentFilterResult sexual, Content CustomBlocklists = customBlocklists; Error = error; Jailbreak = jailbreak; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.Serialization.cs index 9347b7140e83e..881efbb57ffa0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.Serialization.cs @@ -5,6 +5,8 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -12,10 +14,103 @@ namespace Azure.AI.OpenAI { - public partial class ContentFilterResultsForChoice + public partial class ContentFilterResultsForChoice : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterResultsForChoice DeserializeContentFilterResultsForChoice(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterResultsForChoice)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Sexual)) + { + writer.WritePropertyName("sexual"u8); + writer.WriteObjectValue(Sexual); + } + if (Optional.IsDefined(Violence)) + { + writer.WritePropertyName("violence"u8); + writer.WriteObjectValue(Violence); + } + if (Optional.IsDefined(Hate)) + { + writer.WritePropertyName("hate"u8); + writer.WriteObjectValue(Hate); + } + if (Optional.IsDefined(SelfHarm)) + { + writer.WritePropertyName("self_harm"u8); + writer.WriteObjectValue(SelfHarm); + } + if (Optional.IsDefined(Profanity)) + { + writer.WritePropertyName("profanity"u8); + writer.WriteObjectValue(Profanity); + } + if (Optional.IsCollectionDefined(CustomBlocklists)) + { + writer.WritePropertyName("custom_blocklists"u8); + writer.WriteStartArray(); + foreach (var item in CustomBlocklists) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(Error)) + { + writer.WritePropertyName("error"u8); + JsonSerializer.Serialize(writer, Error); + } + if (Optional.IsDefined(ProtectedMaterialText)) + { + writer.WritePropertyName("protected_material_text"u8); + writer.WriteObjectValue(ProtectedMaterialText); + } + if (Optional.IsDefined(ProtectedMaterialCode)) + { + writer.WritePropertyName("protected_material_code"u8); + writer.WriteObjectValue(ProtectedMaterialCode); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterResultsForChoice 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(ContentFilterResultsForChoice)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterResultsForChoice(document.RootElement, options); + } + + internal static ContentFilterResultsForChoice DeserializeContentFilterResultsForChoice(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -29,6 +124,8 @@ internal static ContentFilterResultsForChoice DeserializeContentFilterResultsFor Optional error = default; Optional protectedMaterialText = default; Optional protectedMaterialCode = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("sexual"u8)) @@ -117,10 +214,46 @@ internal static ContentFilterResultsForChoice DeserializeContentFilterResultsFor protectedMaterialCode = ContentFilterCitedDetectionResult.DeserializeContentFilterCitedDetectionResult(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterResultsForChoice(sexual.Value, violence.Value, hate.Value, selfHarm.Value, profanity.Value, Optional.ToList(customBlocklists), error.Value, protectedMaterialText.Value, protectedMaterialCode.Value, 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(ContentFilterResultsForChoice)} does not support '{options.Format}' format."); } - return new ContentFilterResultsForChoice(sexual.Value, violence.Value, hate.Value, selfHarm.Value, profanity.Value, Optional.ToList(customBlocklists), error.Value, protectedMaterialText.Value, protectedMaterialCode.Value); } + ContentFilterResultsForChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterResultsForChoice(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterResultsForChoice)} does not support '{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 ContentFilterResultsForChoice FromResponse(Response response) @@ -128,5 +261,13 @@ internal static ContentFilterResultsForChoice FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterResultsForChoice(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.cs index 2ee21b68b8c66..6f2a677279132 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForChoice.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure; using Azure.Core; @@ -14,6 +15,38 @@ namespace Azure.AI.OpenAI /// Information about content filtering evaluated against generated model output. public partial class ContentFilterResultsForChoice { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . internal ContentFilterResultsForChoice() { @@ -50,7 +83,8 @@ internal ContentFilterResultsForChoice() /// /// Information about detection of protected text material. /// Information about detection of protected code material. - internal ContentFilterResultsForChoice(ContentFilterResult sexual, ContentFilterResult violence, ContentFilterResult hate, ContentFilterResult selfHarm, ContentFilterDetectionResult profanity, IReadOnlyList customBlocklists, ResponseError error, ContentFilterDetectionResult protectedMaterialText, ContentFilterCitedDetectionResult protectedMaterialCode) + /// Keeps track of any properties unknown to the library. + internal ContentFilterResultsForChoice(ContentFilterResult sexual, ContentFilterResult violence, ContentFilterResult hate, ContentFilterResult selfHarm, ContentFilterDetectionResult profanity, IReadOnlyList customBlocklists, ResponseError error, ContentFilterDetectionResult protectedMaterialText, ContentFilterCitedDetectionResult protectedMaterialCode, IDictionary serializedAdditionalRawData) { Sexual = sexual; Violence = violence; @@ -61,6 +95,7 @@ internal ContentFilterResultsForChoice(ContentFilterResult sexual, ContentFilter Error = error; ProtectedMaterialText = protectedMaterialText; ProtectedMaterialCode = protectedMaterialCode; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.Serialization.cs index 3302ccfac18fc..cc32c1eab358b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ContentFilterResultsForPrompt + public partial class ContentFilterResultsForPrompt : IUtf8JsonSerializable, IJsonModel { - internal static ContentFilterResultsForPrompt DeserializeContentFilterResultsForPrompt(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ContentFilterResultsForPrompt)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("prompt_index"u8); + writer.WriteNumberValue(PromptIndex); + writer.WritePropertyName("content_filter_results"u8); + writer.WriteObjectValue(ContentFilterResults); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ContentFilterResultsForPrompt 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(ContentFilterResultsForPrompt)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeContentFilterResultsForPrompt(document.RootElement, options); + } + + internal static ContentFilterResultsForPrompt DeserializeContentFilterResultsForPrompt(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } int promptIndex = default; ContentFilterResultDetailsForPrompt contentFilterResults = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("prompt_index"u8)) @@ -32,10 +85,46 @@ internal static ContentFilterResultsForPrompt DeserializeContentFilterResultsFor contentFilterResults = ContentFilterResultDetailsForPrompt.DeserializeContentFilterResultDetailsForPrompt(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ContentFilterResultsForPrompt(promptIndex, contentFilterResults, 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(ContentFilterResultsForPrompt)} does not support '{options.Format}' format."); + } + } + + ContentFilterResultsForPrompt IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeContentFilterResultsForPrompt(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ContentFilterResultsForPrompt)} does not support '{options.Format}' format."); } - return new ContentFilterResultsForPrompt(promptIndex, contentFilterResults); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static ContentFilterResultsForPrompt FromResponse(Response response) @@ -43,5 +132,13 @@ internal static ContentFilterResultsForPrompt FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeContentFilterResultsForPrompt(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.cs index 39c880a5bffe0..4cbcebace841a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ContentFilterResultsForPrompt.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Content filtering results for a single prompt in the request. public partial class ContentFilterResultsForPrompt { + /// + /// 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 this prompt in the set of prompt results. /// Content filtering results for this prompt. @@ -25,6 +58,22 @@ internal ContentFilterResultsForPrompt(int promptIndex, ContentFilterResultDetai ContentFilterResults = contentFilterResults; } + /// Initializes a new instance of . + /// The index of this prompt in the set of prompt results. + /// Content filtering results for this prompt. + /// Keeps track of any properties unknown to the library. + internal ContentFilterResultsForPrompt(int promptIndex, ContentFilterResultDetailsForPrompt contentFilterResults, IDictionary serializedAdditionalRawData) + { + PromptIndex = promptIndex; + ContentFilterResults = contentFilterResults; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ContentFilterResultsForPrompt() + { + } + /// The index of this prompt in the set of prompt results. public int PromptIndex { get; } /// Content filtering results for this prompt. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.Serialization.cs index 5ecc9588aa998..24ee84273b778 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ElasticsearchChatExtensionConfiguration : IUtf8JsonSerializable + public partial class ElasticsearchChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ElasticsearchChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("parameters"u8); writer.WriteObjectValue(Parameters); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ElasticsearchChatExtensionConfiguration 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(ElasticsearchChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeElasticsearchChatExtensionConfiguration(document.RootElement, options); + } + + internal static ElasticsearchChatExtensionConfiguration DeserializeElasticsearchChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ElasticsearchChatExtensionParameters parameters = default; + AzureChatExtensionType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("parameters"u8)) + { + parameters = ElasticsearchChatExtensionParameters.DeserializeElasticsearchChatExtensionParameters(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ElasticsearchChatExtensionConfiguration(type, serializedAdditionalRawData, parameters); + } + + 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(ElasticsearchChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + ElasticsearchChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeElasticsearchChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ElasticsearchChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ElasticsearchChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeElasticsearchChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.cs index af25452ff6766..9e40e385c77cf 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionConfiguration.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -21,8 +22,9 @@ public partial class ElasticsearchChatExtensionConfiguration : AzureChatExtensio /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// + /// Keeps track of any properties unknown to the library. /// The parameters to use when configuring Elasticsearch®. - internal ElasticsearchChatExtensionConfiguration(AzureChatExtensionType type, ElasticsearchChatExtensionParameters parameters) : base(type) + internal ElasticsearchChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData, ElasticsearchChatExtensionParameters parameters) : base(type, serializedAdditionalRawData) { Parameters = parameters; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.Serialization.cs index 061f10c646327..145398d33be1c 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class ElasticsearchChatExtensionParameters : IUtf8JsonSerializable + internal partial class ElasticsearchChatExtensionParameters : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ElasticsearchChatExtensionParameters)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Authentication)) { @@ -59,9 +71,184 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("embeddingDependency"u8); writer.WriteObjectValue(EmbeddingDependency); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ElasticsearchChatExtensionParameters 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(ElasticsearchChatExtensionParameters)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeElasticsearchChatExtensionParameters(document.RootElement, options); + } + + internal static ElasticsearchChatExtensionParameters DeserializeElasticsearchChatExtensionParameters(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional authentication = default; + Optional topNDocuments = default; + Optional inScope = default; + Optional strictness = default; + Optional roleInformation = default; + Uri endpoint = default; + string indexName = default; + Optional fieldsMapping = default; + Optional queryType = default; + Optional embeddingDependency = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("authentication"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("topNDocuments"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topNDocuments = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("inScope"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inScope = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("strictness"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strictness = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("roleInformation"u8)) + { + roleInformation = property.Value.GetString(); + continue; + } + if (property.NameEquals("endpoint"u8)) + { + endpoint = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("indexName"u8)) + { + indexName = property.Value.GetString(); + continue; + } + if (property.NameEquals("fieldsMapping"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fieldsMapping = ElasticsearchIndexFieldMappingOptions.DeserializeElasticsearchIndexFieldMappingOptions(property.Value); + continue; + } + if (property.NameEquals("queryType"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + queryType = new ElasticsearchQueryType(property.Value.GetString()); + continue; + } + if (property.NameEquals("embeddingDependency"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + embeddingDependency = OnYourDataVectorizationSource.DeserializeOnYourDataVectorizationSource(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ElasticsearchChatExtensionParameters(authentication.Value, Optional.ToNullable(topNDocuments), Optional.ToNullable(inScope), Optional.ToNullable(strictness), roleInformation.Value, endpoint, indexName, fieldsMapping.Value, Optional.ToNullable(queryType), embeddingDependency.Value, 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(ElasticsearchChatExtensionParameters)} does not support '{options.Format}' format."); + } + } + + ElasticsearchChatExtensionParameters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeElasticsearchChatExtensionParameters(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ElasticsearchChatExtensionParameters)} does not support '{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 ElasticsearchChatExtensionParameters FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeElasticsearchChatExtensionParameters(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.cs index 460dd6e85cb60..97de60e80ee50 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchChatExtensionParameters.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Parameters to use when configuring Elasticsearch® as an Azure OpenAI chat extension. internal partial class ElasticsearchChatExtensionParameters { + /// + /// 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 authentication method to use when accessing the defined data source. @@ -30,7 +63,8 @@ internal partial class ElasticsearchChatExtensionParameters /// The index field mapping options of Elasticsearch®. /// The query type of Elasticsearch®. /// The embedding dependency for vector search. - internal ElasticsearchChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, Uri endpoint, string indexName, ElasticsearchIndexFieldMappingOptions fieldMappingOptions, ElasticsearchQueryType? queryType, OnYourDataVectorizationSource embeddingDependency) + /// Keeps track of any properties unknown to the library. + internal ElasticsearchChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, Uri endpoint, string indexName, ElasticsearchIndexFieldMappingOptions fieldMappingOptions, ElasticsearchQueryType? queryType, OnYourDataVectorizationSource embeddingDependency, IDictionary serializedAdditionalRawData) { Authentication = authentication; DocumentCount = documentCount; @@ -42,6 +76,7 @@ internal ElasticsearchChatExtensionParameters(OnYourDataAuthenticationOptions au FieldMappingOptions = fieldMappingOptions; QueryType = queryType; EmbeddingDependency = embeddingDependency; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.Serialization.cs index 91a1afcca23ae..bf1a5ec0e47f8 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ElasticsearchIndexFieldMappingOptions : IUtf8JsonSerializable + public partial class ElasticsearchIndexFieldMappingOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ElasticsearchIndexFieldMappingOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(TitleFieldName)) { @@ -55,9 +67,150 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + ElasticsearchIndexFieldMappingOptions 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(ElasticsearchIndexFieldMappingOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeElasticsearchIndexFieldMappingOptions(document.RootElement, options); + } + + internal static ElasticsearchIndexFieldMappingOptions DeserializeElasticsearchIndexFieldMappingOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional titleField = default; + Optional urlField = default; + Optional filepathField = default; + Optional> contentFields = default; + Optional contentFieldsSeparator = default; + Optional> vectorFields = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("titleField"u8)) + { + titleField = property.Value.GetString(); + continue; + } + if (property.NameEquals("urlField"u8)) + { + urlField = property.Value.GetString(); + continue; + } + if (property.NameEquals("filepathField"u8)) + { + filepathField = property.Value.GetString(); + continue; + } + if (property.NameEquals("contentFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + contentFields = array; + continue; + } + if (property.NameEquals("contentFieldsSeparator"u8)) + { + contentFieldsSeparator = property.Value.GetString(); + continue; + } + if (property.NameEquals("vectorFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + vectorFields = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ElasticsearchIndexFieldMappingOptions(titleField.Value, urlField.Value, filepathField.Value, Optional.ToList(contentFields), contentFieldsSeparator.Value, Optional.ToList(vectorFields), 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(ElasticsearchIndexFieldMappingOptions)} does not support '{options.Format}' format."); + } + } + + ElasticsearchIndexFieldMappingOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeElasticsearchIndexFieldMappingOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ElasticsearchIndexFieldMappingOptions)} does not support '{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 ElasticsearchIndexFieldMappingOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeElasticsearchIndexFieldMappingOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.cs index b6cffc42adc25..7bc569ed4d126 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ElasticsearchIndexFieldMappingOptions.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Optional settings to control how fields are processed when using a configured Elasticsearch® resource. public partial class ElasticsearchIndexFieldMappingOptions { + /// + /// 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 . public ElasticsearchIndexFieldMappingOptions() { @@ -27,7 +60,8 @@ public ElasticsearchIndexFieldMappingOptions() /// The names of index fields that should be treated as content. /// The separator pattern that content fields should use. /// The names of fields that represent vector data. - internal ElasticsearchIndexFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames) + /// Keeps track of any properties unknown to the library. + internal ElasticsearchIndexFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames, IDictionary serializedAdditionalRawData) { TitleFieldName = titleFieldName; UrlFieldName = urlFieldName; @@ -35,6 +69,7 @@ internal ElasticsearchIndexFieldMappingOptions(string titleFieldName, string url ContentFieldNames = contentFieldNames; ContentFieldSeparator = contentFieldSeparator; VectorFieldNames = vectorFieldNames; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The name of the index field to use as a title. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.Serialization.cs index d0beb31615985..e84420b5ecd6f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.Serialization.cs @@ -6,21 +6,78 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class EmbeddingItem + public partial class EmbeddingItem : IUtf8JsonSerializable, IJsonModel { - internal static EmbeddingItem DeserializeEmbeddingItem(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("embedding"u8); + writer.WriteStartArray(); + foreach (var item in Embedding.Span) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + EmbeddingItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddingItem(document.RootElement, options); + } + + internal static EmbeddingItem DeserializeEmbeddingItem(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } ReadOnlyMemory embedding = default; int index = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("embedding"u8)) @@ -44,10 +101,46 @@ internal static EmbeddingItem DeserializeEmbeddingItem(JsonElement element) index = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new EmbeddingItem(embedding, index); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new EmbeddingItem(embedding, index, serializedAdditionalRawData); } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support '{options.Format}' format."); + } + } + + EmbeddingItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddingItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(EmbeddingItem)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static EmbeddingItem FromResponse(Response response) @@ -55,5 +148,13 @@ internal static EmbeddingItem FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeEmbeddingItem(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.cs index 928746b1982e8..ed26b5135972e 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingItem.cs @@ -6,12 +6,63 @@ #nullable disable using System; +using System.Collections.Generic; namespace Azure.AI.OpenAI { /// Representation of a single embeddings relatedness comparison. public partial class EmbeddingItem { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// + /// List of embeddings value for the input prompt. These represent a measurement of the + /// vector-based relatedness of the provided input. + /// + /// Index of the prompt to which the EmbeddingItem corresponds. + /// Keeps track of any properties unknown to the library. + internal EmbeddingItem(ReadOnlyMemory embedding, int index, IDictionary serializedAdditionalRawData) + { + Embedding = embedding; + Index = index; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingItem() + { + } /// Index of the prompt to which the EmbeddingItem corresponds. public int Index { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.Serialization.cs index 72d24abd17bc7..8a402e74a9bc3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.Serialization.cs @@ -5,22 +5,79 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class Embeddings + public partial class Embeddings : IUtf8JsonSerializable, IJsonModel { - internal static Embeddings DeserializeEmbeddings(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Embeddings)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("data"u8); + writer.WriteStartArray(); + foreach (var item in Data) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + Embeddings 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(Embeddings)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddings(document.RootElement, options); + } + + internal static Embeddings DeserializeEmbeddings(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } IReadOnlyList data = default; EmbeddingsUsage usage = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("data"u8)) @@ -38,10 +95,46 @@ internal static Embeddings DeserializeEmbeddings(JsonElement element) usage = EmbeddingsUsage.DeserializeEmbeddingsUsage(property.Value); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new Embeddings(data, usage); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new Embeddings(data, usage, 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(Embeddings)} does not support '{options.Format}' format."); + } + } + + Embeddings IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddings(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Embeddings)} does not support '{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 Embeddings FromResponse(Response response) @@ -49,5 +142,13 @@ internal static Embeddings FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeEmbeddings(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.cs index 000e50538298e..304b31d6a3a67 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/Embeddings.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class Embeddings { + /// + /// 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 . /// Embedding values for the prompts submitted in the request. /// Usage counts for tokens input using the embeddings API. @@ -35,10 +67,17 @@ internal Embeddings(IEnumerable data, EmbeddingsUsage usage) /// Initializes a new instance of . /// Embedding values for the prompts submitted in the request. /// Usage counts for tokens input using the embeddings API. - internal Embeddings(IReadOnlyList data, EmbeddingsUsage usage) + /// Keeps track of any properties unknown to the library. + internal Embeddings(IReadOnlyList data, EmbeddingsUsage usage, IDictionary serializedAdditionalRawData) { Data = data; Usage = usage; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Embeddings() + { } /// Embedding values for the prompts submitted in the request. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.Serialization.cs index b6023c36f1d36..f624a9b615b18 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class EmbeddingsOptions : IUtf8JsonSerializable + public partial class EmbeddingsOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(User)) { @@ -32,9 +44,119 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(item); } writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + EmbeddingsOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddingsOptions(document.RootElement, options); + } + + internal static EmbeddingsOptions DeserializeEmbeddingsOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional user = default; + Optional model = default; + IList input = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("user"u8)) + { + user = property.Value.GetString(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("input"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + input = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new EmbeddingsOptions(user.Value, model.Value, input, 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(EmbeddingsOptions)} does not support '{options.Format}' format."); + } + } + + EmbeddingsOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddingsOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(EmbeddingsOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static EmbeddingsOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeEmbeddingsOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.cs index 54877b9fcce7f..68c2db83f26b9 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsOptions.cs @@ -19,6 +19,38 @@ namespace Azure.AI.OpenAI /// public partial class EmbeddingsOptions { + /// + /// 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 . /// /// An identifier for the caller or end user of the operation. This may be used for tracking @@ -36,11 +68,13 @@ public partial class EmbeddingsOptions /// Unless you are embedding code, we suggest replacing newlines (\n) in your input with a single space, /// as we have observed inferior results when newlines are present. /// - internal EmbeddingsOptions(string user, string deploymentName, IList input) + /// Keeps track of any properties unknown to the library. + internal EmbeddingsOptions(string user, string deploymentName, IList input, IDictionary serializedAdditionalRawData) { User = user; DeploymentName = deploymentName; Input = input; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.Serialization.cs index 40d3da501788c..6b80e76ffa02f 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class EmbeddingsUsage + public partial class EmbeddingsUsage : IUtf8JsonSerializable, IJsonModel { - internal static EmbeddingsUsage DeserializeEmbeddingsUsage(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("prompt_tokens"u8); + writer.WriteNumberValue(PromptTokens); + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + EmbeddingsUsage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeEmbeddingsUsage(document.RootElement, options); + } + + internal static EmbeddingsUsage DeserializeEmbeddingsUsage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } int promptTokens = default; int totalTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("prompt_tokens"u8)) @@ -32,10 +85,46 @@ internal static EmbeddingsUsage DeserializeEmbeddingsUsage(JsonElement element) totalTokens = property.Value.GetInt32(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new EmbeddingsUsage(promptTokens, totalTokens, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support '{options.Format}' format."); + } + } + + EmbeddingsUsage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeEmbeddingsUsage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(EmbeddingsUsage)} does not support '{options.Format}' format."); } - return new EmbeddingsUsage(promptTokens, totalTokens); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static EmbeddingsUsage FromResponse(Response response) @@ -43,5 +132,13 @@ internal static EmbeddingsUsage FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeEmbeddingsUsage(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.cs index 7e32fc4486d8d..34b45d8059567 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/EmbeddingsUsage.cs @@ -5,11 +5,46 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// Measurement of the amount of tokens used in this request and response. public partial class EmbeddingsUsage { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// Number of tokens sent in the original request. /// Total number of tokens transacted in this request/response. @@ -19,6 +54,22 @@ internal EmbeddingsUsage(int promptTokens, int totalTokens) TotalTokens = totalTokens; } + /// Initializes a new instance of . + /// Number of tokens sent in the original request. + /// Total number of tokens transacted in this request/response. + /// Keeps track of any properties unknown to the library. + internal EmbeddingsUsage(int promptTokens, int totalTokens, IDictionary serializedAdditionalRawData) + { + PromptTokens = promptTokens; + TotalTokens = totalTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal EmbeddingsUsage() + { + } + /// Number of tokens sent in the original request. public int PromptTokens { get; } /// Total number of tokens transacted in this request/response. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs index 66e19e41a66da..bcb4960af66cc 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.Serialization.cs @@ -5,32 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class FunctionCall : IUtf8JsonSerializable + public partial class FunctionCall : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionCall)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); writer.WritePropertyName("arguments"u8); writer.WriteStringValue(Arguments); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static FunctionCall DeserializeFunctionCall(JsonElement element) + FunctionCall 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(FunctionCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFunctionCall(document.RootElement, options); + } + + internal static FunctionCall DeserializeFunctionCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string name = default; string arguments = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name"u8)) @@ -43,10 +85,46 @@ internal static FunctionCall DeserializeFunctionCall(JsonElement element) arguments = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FunctionCall(name, arguments, 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(FunctionCall)} does not support '{options.Format}' format."); } - return new FunctionCall(name, arguments); } + FunctionCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFunctionCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FunctionCall)} does not support '{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 FunctionCall FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs index 953ebefd2007e..68704ef0edc9d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionCall.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,59 @@ namespace Azure.AI.OpenAI /// The name and arguments of a function that should be called, as generated by the model. public partial class FunctionCall { + /// + /// 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 name of the function to call. + /// + /// The arguments to call the function with, as generated by the model in JSON format. + /// Note that the model does not always generate valid JSON, and may hallucinate parameters + /// not defined by your function schema. Validate the arguments in your code before calling + /// your function. + /// + /// Keeps track of any properties unknown to the library. + internal FunctionCall(string name, string arguments, IDictionary serializedAdditionalRawData) + { + Name = name; + Arguments = arguments; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FunctionCall() + { + } + /// The name of the function to call. public string Name { get; set; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs index ef78cab9e18f5..77397cbddd862 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class FunctionDefinition : IUtf8JsonSerializable + public partial class FunctionDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionDefinition)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); @@ -34,9 +46,118 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } #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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + FunctionDefinition 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(FunctionDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFunctionDefinition(document.RootElement, options); + } + + internal static FunctionDefinition DeserializeFunctionDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + Optional description = default; + Optional parameters = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("parameters"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + parameters = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FunctionDefinition(name, description.Value, parameters.Value, 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(FunctionDefinition)} does not support '{options.Format}' format."); + } + } + + FunctionDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFunctionDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FunctionDefinition)} does not support '{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 FunctionDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFunctionDefinition(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs index baf3db61f9fd8..92eb2d2860fd3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionDefinition.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// The definition of a caller-specified function that chat completions may invoke in response to matching user input. public partial class FunctionDefinition { + /// + /// 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 name of the function to be called. /// is null. @@ -30,11 +63,13 @@ public FunctionDefinition(string name) /// interpreting its parameters. /// /// The parameters the function accepts, described as a JSON Schema object. - internal FunctionDefinition(string name, string description, BinaryData parameters) + /// Keeps track of any properties unknown to the library. + internal FunctionDefinition(string name, string description, BinaryData parameters, IDictionary serializedAdditionalRawData) { Name = name; Description = description; Parameters = parameters; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// /// A description of what the function does. The model will use this description when selecting the function and diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.Serialization.cs index 6921e67a5bb10..18066c20c3e16 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class FunctionName : IUtf8JsonSerializable + internal partial class FunctionName : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FunctionName)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + FunctionName 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(FunctionName)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFunctionName(document.RootElement, options); + } + + internal static FunctionName DeserializeFunctionName(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new FunctionName(name, 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(FunctionName)} does not support '{options.Format}' format."); + } + } + + FunctionName IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeFunctionName(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FunctionName)} does not support '{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 FunctionName FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeFunctionName(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.cs index f09d4aeacb7c3..ed5c94755b4f5 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/FunctionName.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -16,6 +17,38 @@ namespace Azure.AI.OpenAI /// internal partial class FunctionName { + /// + /// 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 name of the function to call. /// is null. @@ -26,6 +59,20 @@ public FunctionName(string name) Name = name; } + /// Initializes a new instance of . + /// The name of the function to call. + /// Keeps track of any properties unknown to the library. + internal FunctionName(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FunctionName() + { + } + /// The name of the function to call. public string Name { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.Serialization.cs index 201292c438407..ba1fd35a8e26d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.Serialization.cs @@ -6,16 +6,76 @@ #nullable disable using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ImageGenerationData + public partial class ImageGenerationData : IUtf8JsonSerializable, IJsonModel { - internal static ImageGenerationData DeserializeImageGenerationData(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ImageGenerationData)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Url)) + { + writer.WritePropertyName("url"u8); + writer.WriteStringValue(Url.AbsoluteUri); + } + if (Optional.IsDefined(Base64Data)) + { + writer.WritePropertyName("b64_json"u8); + writer.WriteStringValue(Base64Data); + } + if (Optional.IsDefined(RevisedPrompt)) + { + writer.WritePropertyName("revised_prompt"u8); + writer.WriteStringValue(RevisedPrompt); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ImageGenerationData 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(ImageGenerationData)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeImageGenerationData(document.RootElement, options); + } + + internal static ImageGenerationData DeserializeImageGenerationData(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -23,6 +83,8 @@ internal static ImageGenerationData DeserializeImageGenerationData(JsonElement e Optional url = default; Optional b64Json = default; Optional revisedPrompt = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("url"u8)) @@ -44,10 +106,46 @@ internal static ImageGenerationData DeserializeImageGenerationData(JsonElement e revisedPrompt = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ImageGenerationData(url.Value, b64Json.Value, revisedPrompt.Value, 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(ImageGenerationData)} does not support '{options.Format}' format."); } - return new ImageGenerationData(url.Value, b64Json.Value, revisedPrompt.Value); } + ImageGenerationData IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeImageGenerationData(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ImageGenerationData)} does not support '{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 ImageGenerationData FromResponse(Response response) @@ -55,5 +153,13 @@ internal static ImageGenerationData FromResponse(Response response) using var document = JsonDocument.Parse(response.Content); return DeserializeImageGenerationData(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.cs index 032fa11e8b27c..9c576306380e7 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationData.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; namespace Azure.AI.OpenAI { @@ -15,6 +16,38 @@ namespace Azure.AI.OpenAI /// public partial class ImageGenerationData { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . internal ImageGenerationData() { @@ -27,11 +60,13 @@ internal ImageGenerationData() /// The final prompt used by the model to generate the image. /// Only provided with dall-3-models and only when revisions were made to the prompt. /// - internal ImageGenerationData(Uri url, string base64Data, string revisedPrompt) + /// Keeps track of any properties unknown to the library. + internal ImageGenerationData(Uri url, string base64Data, string revisedPrompt, IDictionary serializedAdditionalRawData) { Url = url; Base64Data = base64Data; RevisedPrompt = revisedPrompt; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The URL that provides temporary access to download the generated image. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs index 4d5ed71d2caf5..8e539281fb5a0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.Serialization.cs @@ -5,16 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class ImageGenerationOptions : IUtf8JsonSerializable + public partial class ImageGenerationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ImageGenerationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(DeploymentName)) { @@ -53,11 +64,40 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("user"u8); writer.WriteStringValue(User); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static ImageGenerationOptions DeserializeImageGenerationOptions(JsonElement element) + ImageGenerationOptions 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(ImageGenerationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeImageGenerationOptions(document.RootElement, options); + } + + internal static ImageGenerationOptions DeserializeImageGenerationOptions(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; @@ -70,6 +110,8 @@ internal static ImageGenerationOptions DeserializeImageGenerationOptions(JsonEle Optional quality = default; Optional style = default; Optional user = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("model"u8)) @@ -132,10 +174,46 @@ internal static ImageGenerationOptions DeserializeImageGenerationOptions(JsonEle user = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ImageGenerationOptions(model.Value, prompt, Optional.ToNullable(n), Optional.ToNullable(size), Optional.ToNullable(responseFormat), Optional.ToNullable(quality), Optional.ToNullable(style), user.Value); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ImageGenerationOptions(model.Value, prompt, Optional.ToNullable(n), Optional.ToNullable(size), Optional.ToNullable(responseFormat), Optional.ToNullable(quality), Optional.ToNullable(style), user.Value, 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(ImageGenerationOptions)} does not support '{options.Format}' format."); + } + } + + ImageGenerationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeImageGenerationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ImageGenerationOptions)} does not support '{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 ImageGenerationOptions FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs index 8d18c3730c713..c8be81978695a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Represents the request data used to generate images. public partial class ImageGenerationOptions { + /// + /// 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 . /// A description of the desired images. /// is null. @@ -49,7 +82,8 @@ public ImageGenerationOptions(string prompt) /// Only configurable with dall-e-3 models. /// /// A unique identifier representing your end-user, which can help to monitor and detect abuse. - internal ImageGenerationOptions(string deploymentName, string prompt, int? imageCount, ImageSize? size, ImageGenerationResponseFormat? responseFormat, ImageGenerationQuality? quality, ImageGenerationStyle? style, string user) + /// Keeps track of any properties unknown to the library. + internal ImageGenerationOptions(string deploymentName, string prompt, int? imageCount, ImageSize? size, ImageGenerationResponseFormat? responseFormat, ImageGenerationQuality? quality, ImageGenerationStyle? style, string user, IDictionary serializedAdditionalRawData) { DeploymentName = deploymentName; Prompt = prompt; @@ -59,6 +93,7 @@ internal ImageGenerationOptions(string deploymentName, string prompt, int? image Quality = quality; Style = style; User = user; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs index 6bf87f34cd241..c6f2aa73ceb54 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; using Azure; @@ -13,10 +14,18 @@ namespace Azure.AI.OpenAI { - public partial class ImageGenerations : IUtf8JsonSerializable + public partial class ImageGenerations : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ImageGenerations)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("created"u8); writer.WriteNumberValue(Created, "U"); @@ -27,17 +36,48 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteObjectValue(item); } writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } - internal static ImageGenerations DeserializeImageGenerations(JsonElement element) + ImageGenerations 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(ImageGenerations)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeImageGenerations(document.RootElement, options); + } + + internal static ImageGenerations DeserializeImageGenerations(JsonElement element, ModelReaderWriterOptions options = null) { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } DateTimeOffset created = default; IList data = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("created"u8)) @@ -55,10 +95,46 @@ internal static ImageGenerations DeserializeImageGenerations(JsonElement element data = array; continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } } - return new ImageGenerations(created, data); + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ImageGenerations(created, data, 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(ImageGenerations)} does not support '{options.Format}' format."); + } + } + + ImageGenerations IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeImageGenerations(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ImageGenerations)} does not support '{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 ImageGenerations FromResponse(Response response) diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs index 2018f87d16483..5fb5205408cec 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/ImageGenerations.cs @@ -15,6 +15,38 @@ namespace Azure.AI.OpenAI /// The result of a successful image generation operation. public partial class ImageGenerations { + /// + /// 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 . /// /// A timestamp representing when this operation was started. @@ -36,10 +68,17 @@ public ImageGenerations(DateTimeOffset created, IEnumerable /// Expressed in seconds since the Unix epoch of 1970-01-01T00:00:00+0000. /// /// The images generated by the operation. - internal ImageGenerations(DateTimeOffset created, IList data) + /// Keeps track of any properties unknown to the library. + internal ImageGenerations(DateTimeOffset created, IList data, IDictionary serializedAdditionalRawData) { Created = created; Data = data; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ImageGenerations() + { } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.Serialization.cs index c79e88c746645..ee0c706e64bde 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class MaxTokensFinishDetails + public partial class MaxTokensFinishDetails : IUtf8JsonSerializable, IJsonModel { - internal static MaxTokensFinishDetails DeserializeMaxTokensFinishDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MaxTokensFinishDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + MaxTokensFinishDetails 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(MaxTokensFinishDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMaxTokensFinishDetails(document.RootElement, options); + } + + internal static MaxTokensFinishDetails DeserializeMaxTokensFinishDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static MaxTokensFinishDetails DeserializeMaxTokensFinishDetails(JsonEle type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new MaxTokensFinishDetails(type, 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(MaxTokensFinishDetails)} does not support '{options.Format}' format."); + } + } + + MaxTokensFinishDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeMaxTokensFinishDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MaxTokensFinishDetails)} does not support '{options.Format}' format."); } - return new MaxTokensFinishDetails(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new MaxTokensFinishDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static MaxTokensFinishDetails DeserializeMaxTokensFinishDetails(JsonEle using var document = JsonDocument.Parse(response.Content); return DeserializeMaxTokensFinishDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.cs index e1925b4f7f154..d06be2b9ccaad 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/MaxTokensFinishDetails.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -21,7 +24,8 @@ internal MaxTokensFinishDetails() /// Initializes a new instance of . /// The object type. - internal MaxTokensFinishDetails(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal MaxTokensFinishDetails(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.Serialization.cs index 4b8c15d3f05d3..07aa28fba2996 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataApiKeyAuthenticationOptions : IUtf8JsonSerializable + public partial class OnYourDataApiKeyAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataApiKeyAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("key"u8); writer.WriteStringValue(Key); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataApiKeyAuthenticationOptions 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(OnYourDataApiKeyAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataApiKeyAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataApiKeyAuthenticationOptions DeserializeOnYourDataApiKeyAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string key = default; + OnYourDataAuthenticationType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("key"u8)) + { + key = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataApiKeyAuthenticationOptions(type, serializedAdditionalRawData, key); + } + + 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(OnYourDataApiKeyAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataApiKeyAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataApiKeyAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataApiKeyAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataApiKeyAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataApiKeyAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.cs index b392da63f7a24..8f9b6862a2f8b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataApiKeyAuthenticationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ public OnYourDataApiKeyAuthenticationOptions(string key) /// Initializes a new instance of . /// The authentication type. + /// Keeps track of any properties unknown to the library. /// The API key to use for authentication. - internal OnYourDataApiKeyAuthenticationOptions(OnYourDataAuthenticationType type, string key) : base(type) + internal OnYourDataApiKeyAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData, string key) : base(type, serializedAdditionalRawData) { Key = key; } + /// Initializes a new instance of for deserialization. + internal OnYourDataApiKeyAuthenticationOptions() + { + } + /// The API key to use for authentication. public string Key { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.Serialization.cs index 22dae03f3b7dd..0a01dd472de3a 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.Serialization.cs @@ -5,21 +5,121 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataAuthenticationOptions : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownOnYourDataAuthenticationOptions))] + public partial class OnYourDataAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataAuthenticationOptions 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(OnYourDataAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataAuthenticationOptions DeserializeOnYourDataAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "APIKey": return OnYourDataApiKeyAuthenticationOptions.DeserializeOnYourDataApiKeyAuthenticationOptions(element); + case "ConnectionString": return OnYourDataConnectionStringAuthenticationOptions.DeserializeOnYourDataConnectionStringAuthenticationOptions(element); + case "KeyAndKeyId": return OnYourDataKeyAndKeyIdAuthenticationOptions.DeserializeOnYourDataKeyAndKeyIdAuthenticationOptions(element); + case "SystemAssignedManagedIdentity": return OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.DeserializeOnYourDataSystemAssignedManagedIdentityAuthenticationOptions(element); + case "UserAssignedManagedIdentity": return OnYourDataUserAssignedManagedIdentityAuthenticationOptions.DeserializeOnYourDataUserAssignedManagedIdentityAuthenticationOptions(element); + } + } + return UnknownOnYourDataAuthenticationOptions.DeserializeUnknownOnYourDataAuthenticationOptions(element); + } + + 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(OnYourDataAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataAuthenticationOptions)} does not support '{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 OnYourDataAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.cs index 05bf2720c07c8..41c84b1b8c5a9 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataAuthenticationOptions.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class OnYourDataAuthenticationOptions { + /// + /// 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 OnYourDataAuthenticationOptions() { @@ -21,9 +56,11 @@ protected OnYourDataAuthenticationOptions() /// Initializes a new instance of . /// The authentication type. - internal OnYourDataAuthenticationOptions(OnYourDataAuthenticationType type) + /// Keeps track of any properties unknown to the library. + internal OnYourDataAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The authentication type. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.Serialization.cs index be7613eba96d3..4175b182a46a6 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataConnectionStringAuthenticationOptions : IUtf8JsonSerializable + public partial class OnYourDataConnectionStringAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataConnectionStringAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("connectionString"u8); writer.WriteStringValue(ConnectionString); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataConnectionStringAuthenticationOptions 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(OnYourDataConnectionStringAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataConnectionStringAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataConnectionStringAuthenticationOptions DeserializeOnYourDataConnectionStringAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string connectionString = default; + OnYourDataAuthenticationType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("connectionString"u8)) + { + connectionString = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataConnectionStringAuthenticationOptions(type, serializedAdditionalRawData, connectionString); + } + + 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(OnYourDataConnectionStringAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataConnectionStringAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataConnectionStringAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataConnectionStringAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataConnectionStringAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataConnectionStringAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.cs index 0dec1a98eccff..5ae1764ce69c1 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataConnectionStringAuthenticationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ public OnYourDataConnectionStringAuthenticationOptions(string connectionString) /// Initializes a new instance of . /// The authentication type. + /// Keeps track of any properties unknown to the library. /// The connection string to use for authentication. - internal OnYourDataConnectionStringAuthenticationOptions(OnYourDataAuthenticationType type, string connectionString) : base(type) + internal OnYourDataConnectionStringAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData, string connectionString) : base(type, serializedAdditionalRawData) { ConnectionString = connectionString; } + /// Initializes a new instance of for deserialization. + internal OnYourDataConnectionStringAuthenticationOptions() + { + } + /// The connection string to use for authentication. public string ConnectionString { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.Serialization.cs index 64b91985add09..fbbf95b45f855 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataDeploymentNameVectorizationSource : IUtf8JsonSerializable + public partial class OnYourDataDeploymentNameVectorizationSource : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataDeploymentNameVectorizationSource)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("deploymentName"u8); writer.WriteStringValue(DeploymentName); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataDeploymentNameVectorizationSource 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(OnYourDataDeploymentNameVectorizationSource)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataDeploymentNameVectorizationSource(document.RootElement, options); + } + + internal static OnYourDataDeploymentNameVectorizationSource DeserializeOnYourDataDeploymentNameVectorizationSource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string deploymentName = default; + OnYourDataVectorizationSourceType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("deploymentName"u8)) + { + deploymentName = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataVectorizationSourceType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataDeploymentNameVectorizationSource(type, serializedAdditionalRawData, deploymentName); + } + + 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(OnYourDataDeploymentNameVectorizationSource)} does not support '{options.Format}' format."); + } + } + + OnYourDataDeploymentNameVectorizationSource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataDeploymentNameVectorizationSource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataDeploymentNameVectorizationSource)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataDeploymentNameVectorizationSource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataDeploymentNameVectorizationSource(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.cs index 61b85c110649e..c0d776f9fe327 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataDeploymentNameVectorizationSource.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -29,12 +30,18 @@ public OnYourDataDeploymentNameVectorizationSource(string deploymentName) /// Initializes a new instance of . /// The type of vectorization source to use. + /// Keeps track of any properties unknown to the library. /// The embedding model deployment name within the same Azure OpenAI resource. This enables you to use vector search without Azure OpenAI api-key and without Azure OpenAI public network access. - internal OnYourDataDeploymentNameVectorizationSource(OnYourDataVectorizationSourceType type, string deploymentName) : base(type) + internal OnYourDataDeploymentNameVectorizationSource(OnYourDataVectorizationSourceType type, IDictionary serializedAdditionalRawData, string deploymentName) : base(type, serializedAdditionalRawData) { DeploymentName = deploymentName; } + /// Initializes a new instance of for deserialization. + internal OnYourDataDeploymentNameVectorizationSource() + { + } + /// The embedding model deployment name within the same Azure OpenAI resource. This enables you to use vector search without Azure OpenAI api-key and without Azure OpenAI public network access. public string DeploymentName { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.Serialization.cs index b4d65c06f121f..6669fadd339a0 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataEndpointVectorizationSource : IUtf8JsonSerializable + public partial class OnYourDataEndpointVectorizationSource : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataEndpointVectorizationSource)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("endpoint"u8); writer.WriteStringValue(Endpoint.AbsoluteUri); @@ -21,9 +33,114 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteObjectValue(Authentication); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataEndpointVectorizationSource 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(OnYourDataEndpointVectorizationSource)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataEndpointVectorizationSource(document.RootElement, options); + } + + internal static OnYourDataEndpointVectorizationSource DeserializeOnYourDataEndpointVectorizationSource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Uri endpoint = default; + OnYourDataAuthenticationOptions authentication = default; + OnYourDataVectorizationSourceType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("endpoint"u8)) + { + endpoint = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("authentication"u8)) + { + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataVectorizationSourceType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataEndpointVectorizationSource(type, serializedAdditionalRawData, endpoint, authentication); + } + + 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(OnYourDataEndpointVectorizationSource)} does not support '{options.Format}' format."); + } + } + + OnYourDataEndpointVectorizationSource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataEndpointVectorizationSource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataEndpointVectorizationSource)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataEndpointVectorizationSource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataEndpointVectorizationSource(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.cs index eb279089de144..77c4d8e550710 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataEndpointVectorizationSource.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -32,14 +33,20 @@ public OnYourDataEndpointVectorizationSource(Uri endpoint, OnYourDataAuthenticat /// Initializes a new instance of . /// The type of vectorization source to use. + /// Keeps track of any properties unknown to the library. /// Specifies the resource endpoint URL from which embeddings should be retrieved. It should be in the format of https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings. The api-version query parameter is not allowed. /// Specifies the authentication options to use when retrieving embeddings from the specified endpoint. - internal OnYourDataEndpointVectorizationSource(OnYourDataVectorizationSourceType type, Uri endpoint, OnYourDataAuthenticationOptions authentication) : base(type) + internal OnYourDataEndpointVectorizationSource(OnYourDataVectorizationSourceType type, IDictionary serializedAdditionalRawData, Uri endpoint, OnYourDataAuthenticationOptions authentication) : base(type, serializedAdditionalRawData) { Endpoint = endpoint; Authentication = authentication; } + /// Initializes a new instance of for deserialization. + internal OnYourDataEndpointVectorizationSource() + { + } + /// Specifies the resource endpoint URL from which embeddings should be retrieved. It should be in the format of https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/embeddings. The api-version query parameter is not allowed. public Uri Endpoint { get; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.Serialization.cs index 66c4cd6a57adc..43cf0c76f5c04 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataKeyAndKeyIdAuthenticationOptions : IUtf8JsonSerializable + public partial class OnYourDataKeyAndKeyIdAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataKeyAndKeyIdAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("key"u8); writer.WriteStringValue(Key); @@ -21,9 +33,114 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(KeyId); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataKeyAndKeyIdAuthenticationOptions 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(OnYourDataKeyAndKeyIdAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataKeyAndKeyIdAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataKeyAndKeyIdAuthenticationOptions DeserializeOnYourDataKeyAndKeyIdAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string key = default; + string keyId = default; + OnYourDataAuthenticationType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("key"u8)) + { + key = property.Value.GetString(); + continue; + } + if (property.NameEquals("keyId"u8)) + { + keyId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataKeyAndKeyIdAuthenticationOptions(type, serializedAdditionalRawData, key, keyId); + } + + 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(OnYourDataKeyAndKeyIdAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataKeyAndKeyIdAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataKeyAndKeyIdAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataKeyAndKeyIdAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataKeyAndKeyIdAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataKeyAndKeyIdAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.cs index 414781b34b2e9..7e9982640d586 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataKeyAndKeyIdAuthenticationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -29,14 +30,20 @@ public OnYourDataKeyAndKeyIdAuthenticationOptions(string key, string keyId) /// Initializes a new instance of . /// The authentication type. + /// Keeps track of any properties unknown to the library. /// The key to use for authentication. /// The key ID to use for authentication. - internal OnYourDataKeyAndKeyIdAuthenticationOptions(OnYourDataAuthenticationType type, string key, string keyId) : base(type) + internal OnYourDataKeyAndKeyIdAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData, string key, string keyId) : base(type, serializedAdditionalRawData) { Key = key; KeyId = keyId; } + /// Initializes a new instance of for deserialization. + internal OnYourDataKeyAndKeyIdAuthenticationOptions() + { + } + /// The key to use for authentication. public string Key { get; } /// The key ID to use for authentication. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.Serialization.cs index 6459341fb07ed..c45b74fa9fac5 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataModelIdVectorizationSource : IUtf8JsonSerializable + public partial class OnYourDataModelIdVectorizationSource : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataModelIdVectorizationSource)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("modelId"u8); writer.WriteStringValue(ModelId); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataModelIdVectorizationSource 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(OnYourDataModelIdVectorizationSource)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataModelIdVectorizationSource(document.RootElement, options); + } + + internal static OnYourDataModelIdVectorizationSource DeserializeOnYourDataModelIdVectorizationSource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string modelId = default; + OnYourDataVectorizationSourceType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("modelId"u8)) + { + modelId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataVectorizationSourceType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataModelIdVectorizationSource(type, serializedAdditionalRawData, modelId); + } + + 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(OnYourDataModelIdVectorizationSource)} does not support '{options.Format}' format."); + } + } + + OnYourDataModelIdVectorizationSource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataModelIdVectorizationSource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataModelIdVectorizationSource)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataModelIdVectorizationSource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataModelIdVectorizationSource(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.cs index 999922bf970d2..d0460467753f3 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataModelIdVectorizationSource.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -29,12 +30,18 @@ public OnYourDataModelIdVectorizationSource(string modelId) /// Initializes a new instance of . /// The type of vectorization source to use. + /// Keeps track of any properties unknown to the library. /// The embedding model ID build inside the search service. Currently only supported by Elasticsearch®. - internal OnYourDataModelIdVectorizationSource(OnYourDataVectorizationSourceType type, string modelId) : base(type) + internal OnYourDataModelIdVectorizationSource(OnYourDataVectorizationSourceType type, IDictionary serializedAdditionalRawData, string modelId) : base(type, serializedAdditionalRawData) { ModelId = modelId; } + /// Initializes a new instance of for deserialization. + internal OnYourDataModelIdVectorizationSource() + { + } + /// The embedding model ID build inside the search service. Currently only supported by Elasticsearch®. public string ModelId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.Serialization.cs index 4c0262a79247a..519efd5af17d7 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.Serialization.cs @@ -5,21 +5,126 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataSystemAssignedManagedIdentityAuthenticationOptions : IUtf8JsonSerializable + public partial class OnYourDataSystemAssignedManagedIdentityAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataSystemAssignedManagedIdentityAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataSystemAssignedManagedIdentityAuthenticationOptions 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(OnYourDataSystemAssignedManagedIdentityAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataSystemAssignedManagedIdentityAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataSystemAssignedManagedIdentityAuthenticationOptions DeserializeOnYourDataSystemAssignedManagedIdentityAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OnYourDataAuthenticationType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataSystemAssignedManagedIdentityAuthenticationOptions(type, 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(OnYourDataSystemAssignedManagedIdentityAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataSystemAssignedManagedIdentityAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataSystemAssignedManagedIdentityAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataSystemAssignedManagedIdentityAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataSystemAssignedManagedIdentityAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataSystemAssignedManagedIdentityAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.cs index a9295f3741aa0..734ef7b5d70ca 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataSystemAssignedManagedIdentityAuthenticationOptions.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// The authentication options for Azure OpenAI On Your Data when using a system-assigned managed identity. @@ -18,7 +21,8 @@ public OnYourDataSystemAssignedManagedIdentityAuthenticationOptions() /// Initializes a new instance of . /// The authentication type. - internal OnYourDataSystemAssignedManagedIdentityAuthenticationOptions(OnYourDataAuthenticationType type) : base(type) + /// Keeps track of any properties unknown to the library. + internal OnYourDataSystemAssignedManagedIdentityAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.Serialization.cs index 85e98ddd4d474..1dd8e2aa7592b 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataUserAssignedManagedIdentityAuthenticationOptions : IUtf8JsonSerializable + public partial class OnYourDataUserAssignedManagedIdentityAuthenticationOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataUserAssignedManagedIdentityAuthenticationOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("managedIdentityResourceId"u8); writer.WriteStringValue(ManagedIdentityResourceId); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataUserAssignedManagedIdentityAuthenticationOptions 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(OnYourDataUserAssignedManagedIdentityAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataUserAssignedManagedIdentityAuthenticationOptions(document.RootElement, options); + } + + internal static OnYourDataUserAssignedManagedIdentityAuthenticationOptions DeserializeOnYourDataUserAssignedManagedIdentityAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string managedIdentityResourceId = default; + OnYourDataAuthenticationType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("managedIdentityResourceId"u8)) + { + managedIdentityResourceId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new OnYourDataUserAssignedManagedIdentityAuthenticationOptions(type, serializedAdditionalRawData, managedIdentityResourceId); + } + + 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(OnYourDataUserAssignedManagedIdentityAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataUserAssignedManagedIdentityAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataUserAssignedManagedIdentityAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataUserAssignedManagedIdentityAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new OnYourDataUserAssignedManagedIdentityAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataUserAssignedManagedIdentityAuthenticationOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.cs index e82b2331ebb56..1b1eb23827a0d 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataUserAssignedManagedIdentityAuthenticationOptions.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ public OnYourDataUserAssignedManagedIdentityAuthenticationOptions(string managed /// Initializes a new instance of . /// The authentication type. + /// Keeps track of any properties unknown to the library. /// The resource ID of the user-assigned managed identity to use for authentication. - internal OnYourDataUserAssignedManagedIdentityAuthenticationOptions(OnYourDataAuthenticationType type, string managedIdentityResourceId) : base(type) + internal OnYourDataUserAssignedManagedIdentityAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData, string managedIdentityResourceId) : base(type, serializedAdditionalRawData) { ManagedIdentityResourceId = managedIdentityResourceId; } + /// Initializes a new instance of for deserialization. + internal OnYourDataUserAssignedManagedIdentityAuthenticationOptions() + { + } + /// The resource ID of the user-assigned managed identity to use for authentication. public string ManagedIdentityResourceId { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.Serialization.cs index 64d0559d58cf5..0e25642fe8669 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.Serialization.cs @@ -5,21 +5,119 @@ #nullable disable +using System; +using System.ClientModel.Primitives; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class OnYourDataVectorizationSource : IUtf8JsonSerializable + [PersistableModelProxy(typeof(UnknownOnYourDataVectorizationSource))] + public partial class OnYourDataVectorizationSource : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataVectorizationSource)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + OnYourDataVectorizationSource 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(OnYourDataVectorizationSource)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOnYourDataVectorizationSource(document.RootElement, options); + } + + internal static OnYourDataVectorizationSource DeserializeOnYourDataVectorizationSource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "Endpoint": return OnYourDataEndpointVectorizationSource.DeserializeOnYourDataEndpointVectorizationSource(element); + case "DeploymentName": return OnYourDataDeploymentNameVectorizationSource.DeserializeOnYourDataDeploymentNameVectorizationSource(element); + case "ModelId": return OnYourDataModelIdVectorizationSource.DeserializeOnYourDataModelIdVectorizationSource(element); + } + } + return UnknownOnYourDataVectorizationSource.DeserializeUnknownOnYourDataVectorizationSource(element); + } + + 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(OnYourDataVectorizationSource)} does not support '{options.Format}' format."); + } + } + + OnYourDataVectorizationSource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOnYourDataVectorizationSource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataVectorizationSource)} does not support '{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 OnYourDataVectorizationSource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeOnYourDataVectorizationSource(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.cs index 304a1875f46df..c0d6c2cb6bfe4 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/OnYourDataVectorizationSource.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// @@ -14,6 +17,38 @@ namespace Azure.AI.OpenAI /// public abstract partial class OnYourDataVectorizationSource { + /// + /// 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 OnYourDataVectorizationSource() { @@ -21,9 +56,11 @@ protected OnYourDataVectorizationSource() /// Initializes a new instance of . /// The type of vectorization source to use. - internal OnYourDataVectorizationSource(OnYourDataVectorizationSourceType type) + /// Keeps track of any properties unknown to the library. + internal OnYourDataVectorizationSource(OnYourDataVectorizationSourceType type, IDictionary serializedAdditionalRawData) { Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The type of vectorization source to use. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.Serialization.cs index daff9b85c4ba6..c737b8ad26baa 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.Serialization.cs @@ -5,23 +5,134 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class PineconeChatExtensionConfiguration : IUtf8JsonSerializable + public partial class PineconeChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PineconeChatExtensionConfiguration)} does not support '{format}' format."); + } + writer.WriteStartObject(); writer.WritePropertyName("parameters"u8); writer.WriteObjectValue(Parameters); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + PineconeChatExtensionConfiguration 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(PineconeChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePineconeChatExtensionConfiguration(document.RootElement, options); + } + + internal static PineconeChatExtensionConfiguration DeserializePineconeChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + PineconeChatExtensionParameters parameters = default; + AzureChatExtensionType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("parameters"u8)) + { + parameters = PineconeChatExtensionParameters.DeserializePineconeChatExtensionParameters(property.Value); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new PineconeChatExtensionConfiguration(type, serializedAdditionalRawData, parameters); + } + + 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(PineconeChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + PineconeChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializePineconeChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PineconeChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new PineconeChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializePineconeChatExtensionConfiguration(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal override RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.cs index c93d89950592c..5c00d8dc13db1 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionConfiguration.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -21,8 +22,9 @@ public partial class PineconeChatExtensionConfiguration : AzureChatExtensionConf /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. /// Azure chat extensions are only compatible with Azure OpenAI. /// + /// Keeps track of any properties unknown to the library. /// The parameters to use when configuring Azure OpenAI chat extensions. - internal PineconeChatExtensionConfiguration(AzureChatExtensionType type, PineconeChatExtensionParameters parameters) : base(type) + internal PineconeChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData, PineconeChatExtensionParameters parameters) : base(type, serializedAdditionalRawData) { Parameters = parameters; } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.Serialization.cs index 87a3ec1d3f65a..85ed64e9b5e58 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class PineconeChatExtensionParameters : IUtf8JsonSerializable + internal partial class PineconeChatExtensionParameters : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PineconeChatExtensionParameters)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(Authentication)) { @@ -51,9 +63,170 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("embeddingDependency"u8); writer.WriteObjectValue(EmbeddingDependency); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + PineconeChatExtensionParameters 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(PineconeChatExtensionParameters)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePineconeChatExtensionParameters(document.RootElement, options); + } + + internal static PineconeChatExtensionParameters DeserializePineconeChatExtensionParameters(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional authentication = default; + Optional topNDocuments = default; + Optional inScope = default; + Optional strictness = default; + Optional roleInformation = default; + string environment = default; + string indexName = default; + PineconeFieldMappingOptions fieldsMapping = default; + Optional embeddingDependency = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("authentication"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + authentication = OnYourDataAuthenticationOptions.DeserializeOnYourDataAuthenticationOptions(property.Value); + continue; + } + if (property.NameEquals("topNDocuments"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + topNDocuments = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("inScope"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inScope = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("strictness"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strictness = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("roleInformation"u8)) + { + roleInformation = property.Value.GetString(); + continue; + } + if (property.NameEquals("environment"u8)) + { + environment = property.Value.GetString(); + continue; + } + if (property.NameEquals("indexName"u8)) + { + indexName = property.Value.GetString(); + continue; + } + if (property.NameEquals("fieldsMapping"u8)) + { + fieldsMapping = PineconeFieldMappingOptions.DeserializePineconeFieldMappingOptions(property.Value); + continue; + } + if (property.NameEquals("embeddingDependency"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + embeddingDependency = OnYourDataVectorizationSource.DeserializeOnYourDataVectorizationSource(property.Value); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new PineconeChatExtensionParameters(authentication.Value, Optional.ToNullable(topNDocuments), Optional.ToNullable(inScope), Optional.ToNullable(strictness), roleInformation.Value, environment, indexName, fieldsMapping, embeddingDependency.Value, 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(PineconeChatExtensionParameters)} does not support '{options.Format}' format."); + } + } + + PineconeChatExtensionParameters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializePineconeChatExtensionParameters(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PineconeChatExtensionParameters)} does not support '{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 PineconeChatExtensionParameters FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializePineconeChatExtensionParameters(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.cs index 8947a5e89b601..b2712298d12e8 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeChatExtensionParameters.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Parameters for configuring Azure OpenAI Pinecone chat extensions. internal partial class PineconeChatExtensionParameters { + /// + /// 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 authentication method to use when accessing the defined data source. @@ -29,7 +62,8 @@ internal partial class PineconeChatExtensionParameters /// The name of the Pinecone database index. /// Customized field mapping behavior to use when interacting with the search index. /// The embedding dependency for vector search. - internal PineconeChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string environmentName, string indexName, PineconeFieldMappingOptions fieldMappingOptions, OnYourDataVectorizationSource embeddingDependency) + /// Keeps track of any properties unknown to the library. + internal PineconeChatExtensionParameters(OnYourDataAuthenticationOptions authentication, int? documentCount, bool? shouldRestrictResultScope, int? strictness, string roleInformation, string environmentName, string indexName, PineconeFieldMappingOptions fieldMappingOptions, OnYourDataVectorizationSource embeddingDependency, IDictionary serializedAdditionalRawData) { Authentication = authentication; DocumentCount = documentCount; @@ -40,6 +74,7 @@ internal PineconeChatExtensionParameters(OnYourDataAuthenticationOptions authent IndexName = indexName; FieldMappingOptions = fieldMappingOptions; EmbeddingDependency = embeddingDependency; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.Serialization.cs index e6f14d6d0dff9..880f2ff277f53 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.Serialization.cs @@ -5,15 +5,27 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; +using Azure; using Azure.Core; namespace Azure.AI.OpenAI { - public partial class PineconeFieldMappingOptions : IUtf8JsonSerializable + public partial class PineconeFieldMappingOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PineconeFieldMappingOptions)} does not support '{format}' format."); + } + writer.WriteStartObject(); if (Optional.IsDefined(TitleFieldName)) { @@ -65,9 +77,165 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } writer.WriteEndObject(); } + PineconeFieldMappingOptions 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(PineconeFieldMappingOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePineconeFieldMappingOptions(document.RootElement, options); + } + + internal static PineconeFieldMappingOptions DeserializePineconeFieldMappingOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional titleField = default; + Optional urlField = default; + Optional filepathField = default; + Optional> contentFields = default; + Optional contentFieldsSeparator = default; + Optional> vectorFields = default; + Optional> imageVectorFields = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("titleField"u8)) + { + titleField = property.Value.GetString(); + continue; + } + if (property.NameEquals("urlField"u8)) + { + urlField = property.Value.GetString(); + continue; + } + if (property.NameEquals("filepathField"u8)) + { + filepathField = property.Value.GetString(); + continue; + } + if (property.NameEquals("contentFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + contentFields = array; + continue; + } + if (property.NameEquals("contentFieldsSeparator"u8)) + { + contentFieldsSeparator = property.Value.GetString(); + continue; + } + if (property.NameEquals("vectorFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + vectorFields = array; + continue; + } + if (property.NameEquals("imageVectorFields"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + imageVectorFields = array; + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new PineconeFieldMappingOptions(titleField.Value, urlField.Value, filepathField.Value, Optional.ToList(contentFields), contentFieldsSeparator.Value, Optional.ToList(vectorFields), Optional.ToList(imageVectorFields), 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(PineconeFieldMappingOptions)} does not support '{options.Format}' format."); + } + } + + PineconeFieldMappingOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializePineconeFieldMappingOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PineconeFieldMappingOptions)} does not support '{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 PineconeFieldMappingOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializePineconeFieldMappingOptions(document.RootElement); + } + /// Convert into a Utf8JsonRequestContent. internal virtual RequestContent ToRequestContent() { diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.cs index daafcbe5597ed..b152182498949 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/PineconeFieldMappingOptions.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using Azure.Core; @@ -13,6 +14,38 @@ namespace Azure.AI.OpenAI /// Optional settings to control how fields are processed when using a configured Pinecone resource. public partial class PineconeFieldMappingOptions { + /// + /// 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 . public PineconeFieldMappingOptions() { @@ -29,7 +62,8 @@ public PineconeFieldMappingOptions() /// The separator pattern that content fields should use. /// The names of fields that represent vector data. /// The names of fields that represent image vector data. - internal PineconeFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames, IList imageVectorFieldNames) + /// Keeps track of any properties unknown to the library. + internal PineconeFieldMappingOptions(string titleFieldName, string urlFieldName, string filepathFieldName, IList contentFieldNames, string contentFieldSeparator, IList vectorFieldNames, IList imageVectorFieldNames, IDictionary serializedAdditionalRawData) { TitleFieldName = titleFieldName; UrlFieldName = urlFieldName; @@ -38,6 +72,7 @@ internal PineconeFieldMappingOptions(string titleFieldName, string urlFieldName, ContentFieldSeparator = contentFieldSeparator; VectorFieldNames = vectorFieldNames; ImageVectorFieldNames = imageVectorFieldNames; + _serializedAdditionalRawData = serializedAdditionalRawData; } /// The name of the index field to use as a title. diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.Serialization.cs index d603f610d8299..5096acd1deeef 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - public partial class StopFinishDetails + public partial class StopFinishDetails : IUtf8JsonSerializable, IJsonModel { - internal static StopFinishDetails DeserializeStopFinishDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StopFinishDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("stop"u8); + writer.WriteStringValue(Stop); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + StopFinishDetails 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(StopFinishDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStopFinishDetails(document.RootElement, options); + } + + internal static StopFinishDetails DeserializeStopFinishDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string stop = default; string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("stop"u8)) @@ -32,10 +85,46 @@ internal static StopFinishDetails DeserializeStopFinishDetails(JsonElement eleme type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new StopFinishDetails(type, serializedAdditionalRawData, stop); + } + + 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(StopFinishDetails)} does not support '{options.Format}' format."); + } + } + + StopFinishDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeStopFinishDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StopFinishDetails)} does not support '{options.Format}' format."); } - return new StopFinishDetails(type, stop); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new StopFinishDetails FromResponse(Response response) @@ -43,5 +132,13 @@ internal static StopFinishDetails DeserializeStopFinishDetails(JsonElement eleme using var document = JsonDocument.Parse(response.Content); return DeserializeStopFinishDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.cs index 8db58d867af42..37d414c47fef4 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/StopFinishDetails.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using Azure.Core; namespace Azure.AI.OpenAI @@ -26,12 +27,18 @@ internal StopFinishDetails(string stop) /// Initializes a new instance of . /// The object type. + /// Keeps track of any properties unknown to the library. /// The token sequence that the model terminated with. - internal StopFinishDetails(string type, string stop) : base(type) + internal StopFinishDetails(string type, IDictionary serializedAdditionalRawData, string stop) : base(type, serializedAdditionalRawData) { Stop = stop; } + /// Initializes a new instance of for deserialization. + internal StopFinishDetails() + { + } + /// The token sequence that the model terminated with. public string Stop { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.Serialization.cs new file mode 100644 index 0000000000000..5d046e59e360b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownAzureChatExtensionConfiguration : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AzureChatExtensionConfiguration)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AzureChatExtensionConfiguration 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(AzureChatExtensionConfiguration)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownAzureChatExtensionConfiguration(document.RootElement, options); + } + + internal static UnknownAzureChatExtensionConfiguration DeserializeUnknownAzureChatExtensionConfiguration(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AzureChatExtensionType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new AzureChatExtensionType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownAzureChatExtensionConfiguration(type, 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(AzureChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + AzureChatExtensionConfiguration IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownAzureChatExtensionConfiguration(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AzureChatExtensionConfiguration)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownAzureChatExtensionConfiguration FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownAzureChatExtensionConfiguration(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.cs new file mode 100644 index 0000000000000..c9f09702aa3ac --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownAzureChatExtensionConfiguration.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of AzureChatExtensionConfiguration. + internal partial class UnknownAzureChatExtensionConfiguration : AzureChatExtensionConfiguration + { + /// Initializes a new instance of . + /// + /// The label for the type of an Azure chat extension. This typically corresponds to a matching Azure resource. + /// Azure chat extensions are only compatible with Azure OpenAI. + /// + /// Keeps track of any properties unknown to the library. + internal UnknownAzureChatExtensionConfiguration(AzureChatExtensionType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownAzureChatExtensionConfiguration() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs new file mode 100644 index 0000000000000..8ef69b6c55e4a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownChatCompletionsNamedToolSelection : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsNamedToolSelection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatCompletionsNamedToolSelection(document.RootElement, options); + } + + internal static UnknownChatCompletionsNamedToolSelection DeserializeUnknownChatCompletionsNamedToolSelection(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatCompletionsNamedToolSelection(type, 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(ChatCompletionsNamedToolSelection)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsNamedToolSelection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatCompletionsNamedToolSelection(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsNamedToolSelection)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatCompletionsNamedToolSelection FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownChatCompletionsNamedToolSelection(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.cs new file mode 100644 index 0000000000000..f3a8852788547 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsNamedToolSelection.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of ChatCompletionsNamedToolSelection. + internal partial class UnknownChatCompletionsNamedToolSelection : ChatCompletionsNamedToolSelection + { + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal UnknownChatCompletionsNamedToolSelection(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatCompletionsNamedToolSelection() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.Serialization.cs new file mode 100644 index 0000000000000..5b29aedf19941 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownChatCompletionsResponseFormat : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsResponseFormat)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsResponseFormat 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(ChatCompletionsResponseFormat)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatCompletionsResponseFormat(document.RootElement, options); + } + + internal static UnknownChatCompletionsResponseFormat DeserializeUnknownChatCompletionsResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatCompletionsResponseFormat(type, 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(ChatCompletionsResponseFormat)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatCompletionsResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsResponseFormat)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatCompletionsResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownChatCompletionsResponseFormat(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.cs new file mode 100644 index 0000000000000..1b7ad649a682a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsResponseFormat.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of ChatCompletionsResponseFormat. + internal partial class UnknownChatCompletionsResponseFormat : ChatCompletionsResponseFormat + { + /// Initializes a new instance of . + /// The discriminated type for the response format. + /// Keeps track of any properties unknown to the library. + internal UnknownChatCompletionsResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatCompletionsResponseFormat() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs index 2517e268e79b9..5450a17c6a0e7 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.Serialization.cs @@ -5,21 +5,74 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class UnknownChatCompletionsToolCall + internal partial class UnknownChatCompletionsToolCall : IUtf8JsonSerializable, IJsonModel { - internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletionsToolCall(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsToolCall 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(ChatCompletionsToolCall)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatCompletionsToolCall(document.RootElement, options); + } + + internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletionsToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -32,10 +85,46 @@ internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletions id = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatCompletionsToolCall(type, id, 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(ChatCompletionsToolCall)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatCompletionsToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsToolCall)} does not support '{options.Format}' format."); } - return new UnknownChatCompletionsToolCall(type, id); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownChatCompletionsToolCall FromResponse(Response response) @@ -43,5 +132,13 @@ internal static UnknownChatCompletionsToolCall DeserializeUnknownChatCompletions using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownChatCompletionsToolCall(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.cs index b4c12448778ae..88be20fa05240 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolCall.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// Unknown version of ChatCompletionsToolCall. @@ -13,7 +16,13 @@ internal partial class UnknownChatCompletionsToolCall : ChatCompletionsToolCall /// Initializes a new instance of . /// The object type. /// The ID of the tool call. - internal UnknownChatCompletionsToolCall(string type, string id) : base(type, id) + /// Keeps track of any properties unknown to the library. + internal UnknownChatCompletionsToolCall(string type, string id, IDictionary serializedAdditionalRawData) : base(type, id, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatCompletionsToolCall() { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs new file mode 100644 index 0000000000000..f2b7117f88df5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownChatCompletionsToolDefinition : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatCompletionsToolDefinition 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(ChatCompletionsToolDefinition)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatCompletionsToolDefinition(document.RootElement, options); + } + + internal static UnknownChatCompletionsToolDefinition DeserializeUnknownChatCompletionsToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatCompletionsToolDefinition(type, 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(ChatCompletionsToolDefinition)} does not support '{options.Format}' format."); + } + } + + ChatCompletionsToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatCompletionsToolDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatCompletionsToolDefinition)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatCompletionsToolDefinition FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownChatCompletionsToolDefinition(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.cs new file mode 100644 index 0000000000000..5b671919dd476 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatCompletionsToolDefinition.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of ChatCompletionsToolDefinition. + internal partial class UnknownChatCompletionsToolDefinition : ChatCompletionsToolDefinition + { + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal UnknownChatCompletionsToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatCompletionsToolDefinition() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.Serialization.cs index 7ea220e2e93a4..66be262b056b9 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.Serialization.cs @@ -5,20 +5,71 @@ #nullable disable +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; using Azure; +using Azure.Core; namespace Azure.AI.OpenAI { - internal partial class UnknownChatFinishDetails + internal partial class UnknownChatFinishDetails : IUtf8JsonSerializable, IJsonModel { - internal static UnknownChatFinishDetails DeserializeUnknownChatFinishDetails(JsonElement element) + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatFinishDetails)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatFinishDetails 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(ChatFinishDetails)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatFinishDetails(document.RootElement, options); + } + + internal static UnknownChatFinishDetails DeserializeUnknownChatFinishDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + if (element.ValueKind == JsonValueKind.Null) { return null; } string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) @@ -26,10 +77,46 @@ internal static UnknownChatFinishDetails DeserializeUnknownChatFinishDetails(Jso type = property.Value.GetString(); continue; } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatFinishDetails(type, 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(ChatFinishDetails)} does not support '{options.Format}' format."); + } + } + + ChatFinishDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatFinishDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatFinishDetails)} does not support '{options.Format}' format."); } - return new UnknownChatFinishDetails(type); } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + /// Deserializes the model from a raw response. /// The response to deserialize the model from. internal static new UnknownChatFinishDetails FromResponse(Response response) @@ -37,5 +124,13 @@ internal static UnknownChatFinishDetails DeserializeUnknownChatFinishDetails(Jso using var document = JsonDocument.Parse(response.Content); return DeserializeUnknownChatFinishDetails(document.RootElement); } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.cs index 77721c62dda5b..0653163376a28 100644 --- a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatFinishDetails.cs @@ -5,6 +5,9 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace Azure.AI.OpenAI { /// Unknown version of ChatFinishDetails. @@ -12,7 +15,13 @@ internal partial class UnknownChatFinishDetails : ChatFinishDetails { /// Initializes a new instance of . /// The object type. - internal UnknownChatFinishDetails(string type) : base(type) + /// Keeps track of any properties unknown to the library. + internal UnknownChatFinishDetails(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatFinishDetails() { } } diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.Serialization.cs new file mode 100644 index 0000000000000..5a1614ad69ac0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownChatMessageContentItem : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatMessageContentItem)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatMessageContentItem 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(ChatMessageContentItem)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatMessageContentItem(document.RootElement, options); + } + + internal static UnknownChatMessageContentItem DeserializeUnknownChatMessageContentItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatMessageContentItem(type, 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(ChatMessageContentItem)} does not support '{options.Format}' format."); + } + } + + ChatMessageContentItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatMessageContentItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatMessageContentItem)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatMessageContentItem FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownChatMessageContentItem(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.cs new file mode 100644 index 0000000000000..7407e7520c345 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatMessageContentItem.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of ChatMessageContentItem. + internal partial class UnknownChatMessageContentItem : ChatMessageContentItem + { + /// Initializes a new instance of . + /// The discriminated object type. + /// Keeps track of any properties unknown to the library. + internal UnknownChatMessageContentItem(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatMessageContentItem() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.Serialization.cs new file mode 100644 index 0000000000000..0cfedebbebe70 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownChatRequestMessage : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatRequestMessage)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatRequestMessage 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(ChatRequestMessage)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownChatRequestMessage(document.RootElement, options); + } + + internal static UnknownChatRequestMessage DeserializeUnknownChatRequestMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ChatRole role = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new ChatRole(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownChatRequestMessage(role, 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(ChatRequestMessage)} does not support '{options.Format}' format."); + } + } + + ChatRequestMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownChatRequestMessage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatRequestMessage)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatRequestMessage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownChatRequestMessage(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.cs new file mode 100644 index 0000000000000..16ce3943613bb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownChatRequestMessage.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of ChatRequestMessage. + internal partial class UnknownChatRequestMessage : ChatRequestMessage + { + /// Initializes a new instance of . + /// The chat role associated with this message. + /// Keeps track of any properties unknown to the library. + internal UnknownChatRequestMessage(ChatRole role, IDictionary serializedAdditionalRawData) : base(role, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownChatRequestMessage() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.Serialization.cs new file mode 100644 index 0000000000000..c1705cb033243 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownOnYourDataAuthenticationOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataAuthenticationOptions)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + OnYourDataAuthenticationOptions 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(OnYourDataAuthenticationOptions)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownOnYourDataAuthenticationOptions(document.RootElement, options); + } + + internal static UnknownOnYourDataAuthenticationOptions DeserializeUnknownOnYourDataAuthenticationOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OnYourDataAuthenticationType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new OnYourDataAuthenticationType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownOnYourDataAuthenticationOptions(type, 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(OnYourDataAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + OnYourDataAuthenticationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownOnYourDataAuthenticationOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataAuthenticationOptions)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownOnYourDataAuthenticationOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownOnYourDataAuthenticationOptions(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.cs new file mode 100644 index 0000000000000..3d47c4f32f517 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataAuthenticationOptions.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of OnYourDataAuthenticationOptions. + internal partial class UnknownOnYourDataAuthenticationOptions : OnYourDataAuthenticationOptions + { + /// Initializes a new instance of . + /// The authentication type. + /// Keeps track of any properties unknown to the library. + internal UnknownOnYourDataAuthenticationOptions(OnYourDataAuthenticationType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownOnYourDataAuthenticationOptions() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.Serialization.cs new file mode 100644 index 0000000000000..e89bc613e2236 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.Serialization.cs @@ -0,0 +1,136 @@ +// 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; +using Azure.Core; + +namespace Azure.AI.OpenAI +{ + internal partial class UnknownOnYourDataVectorizationSource : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OnYourDataVectorizationSource)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + OnYourDataVectorizationSource 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(OnYourDataVectorizationSource)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUnknownOnYourDataVectorizationSource(document.RootElement, options); + } + + internal static UnknownOnYourDataVectorizationSource DeserializeUnknownOnYourDataVectorizationSource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + OnYourDataVectorizationSourceType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new OnYourDataVectorizationSourceType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new UnknownOnYourDataVectorizationSource(type, 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(OnYourDataVectorizationSource)} does not support '{options.Format}' format."); + } + } + + OnYourDataVectorizationSource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeUnknownOnYourDataVectorizationSource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OnYourDataVectorizationSource)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownOnYourDataVectorizationSource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownOnYourDataVectorizationSource(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.cs b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.cs new file mode 100644 index 0000000000000..2bf5702ab3fd7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI/src/Generated/UnknownOnYourDataVectorizationSource.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI +{ + /// Unknown version of OnYourDataVectorizationSource. + internal partial class UnknownOnYourDataVectorizationSource : OnYourDataVectorizationSource + { + /// Initializes a new instance of . + /// The type of vectorization source to use. + /// Keeps track of any properties unknown to the library. + internal UnknownOnYourDataVectorizationSource(OnYourDataVectorizationSourceType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownOnYourDataVectorizationSource() + { + } + } +}