diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/Configuration.json b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/Configuration.json new file mode 100644 index 000000000000..30deaa8da171 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/Configuration.json @@ -0,0 +1,12 @@ +{ + "package-name": "Azure.AI.Language.QuestionAnswering.Inference", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "model-namespace": false, + "license": { + "name": "MIT License", + "company": "Microsoft Corporation", + "link": "https://mit-license.org", + "header": "Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License.", + "description": "Copyright (c) Microsoft Corporation\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the “Software”), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE." + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/AnswersOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/AnswersOptions.cs index bce225e59ad2..26272b8ebab7 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/AnswersOptions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/AnswersOptions.cs @@ -1,8 +1,9 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System; using Azure.Core; +using Microsoft.TypeSpec.Generator.Customizations; namespace Azure.AI.Language.QuestionAnswering.Inference { @@ -16,7 +17,9 @@ public partial class AnswersOptions /// is null. internal AnswersOptions WithQuestion(string question) { - Question = Argument.CheckNotNullOrEmpty(question, nameof(question)); + Argument.AssertNotNullOrEmpty(question, nameof(question)); + + Question = question; return this; } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Azure.AI.Language.QuestionAnswering.Inference.csproj b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Azure.AI.Language.QuestionAnswering.Inference.csproj index 4d7fb4a29119..8eba955ab8aa 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Azure.AI.Language.QuestionAnswering.Inference.csproj +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Azure.AI.Language.QuestionAnswering.Inference.csproj @@ -6,18 +6,16 @@ Azure Inference $(RequiredTargetFrameworks) true - true Azure.AI.Language.QuestionAnswering.Inference Azure.AI.Language.QuestionAnswering.Inference $(NoWarn);AZC0034;AZC0012 - - - - + + + diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.cs deleted file mode 100644 index 1cc905357a6a..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Answer span object of QnA. - public partial class AnswerSpan - { - /// - /// 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 AnswerSpan() - { - } - - /// Initializes a new instance of . - /// Predicted text of answer span. - /// Predicted score of answer span, value ranges from 0 to 1. - /// The answer span offset from the start of answer. - /// The length of the answer span. - /// Keeps track of any properties unknown to the library. - internal AnswerSpan(string text, double? confidence, int? offset, int? length, IDictionary serializedAdditionalRawData) - { - Text = text; - Confidence = confidence; - Offset = offset; - Length = length; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Predicted text of answer span. - public string Text { get; } - /// Predicted score of answer span, value ranges from 0 to 1. - public double? Confidence { get; } - /// The answer span offset from the start of answer. - public int? Offset { get; } - /// The length of the answer span. - public int? Length { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.cs deleted file mode 100644 index 2eaef581fc89..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Represents the answer results. - public partial class AnswersFromTextResult - { - /// - /// 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 AnswersFromTextResult() - { - Answers = new ChangeTrackingList(); - } - - /// Initializes a new instance of . - /// Represents the answer results. - /// Keeps track of any properties unknown to the library. - internal AnswersFromTextResult(IReadOnlyList answers, IDictionary serializedAdditionalRawData) - { - Answers = answers; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Represents the answer results. - public IReadOnlyList Answers { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.cs deleted file mode 100644 index 6185001b9b76..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Represents List of Question Answers. - public partial class AnswersResult - { - /// - /// 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 AnswersResult() - { - Answers = new ChangeTrackingList(); - } - - /// Initializes a new instance of . - /// Represents Answer Result list. - /// Keeps track of any properties unknown to the library. - internal AnswersResult(IReadOnlyList answers, IDictionary serializedAdditionalRawData) - { - Answers = answers; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Represents Answer Result list. - public IReadOnlyList Answers { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Argument.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Argument.cs index eb4d6a4daa93..c26ac55d13d5 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Argument.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Argument.cs @@ -11,8 +11,10 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - internal static class Argument + internal static partial class Argument { + /// The value. + /// The name. public static void AssertNotNull(T value, string name) { if (value is null) @@ -21,8 +23,10 @@ public static void AssertNotNull(T value, string name) } } + /// The value. + /// The name. public static void AssertNotNull(T? value, string name) - where T : struct + where T : struct { if (!value.HasValue) { @@ -30,6 +34,8 @@ public static void AssertNotNull(T? value, string name) } } + /// The value. + /// The name. public static void AssertNotNullOrEmpty(IEnumerable value, string name) { if (value is null) @@ -51,6 +57,8 @@ public static void AssertNotNullOrEmpty(IEnumerable value, string name) } } + /// The value. + /// The name. public static void AssertNotNullOrEmpty(string value, string name) { if (value is null) @@ -62,68 +70,5 @@ public static void AssertNotNullOrEmpty(string value, string name) throw new ArgumentException("Value cannot be an empty string.", name); } } - - public static void AssertNotNullOrWhiteSpace(string value, string name) - { - if (value is null) - { - throw new ArgumentNullException(name); - } - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); - } - } - - public static void AssertNotDefault(ref T value, string name) - where T : struct, IEquatable - { - if (value.Equals(default)) - { - throw new ArgumentException("Value cannot be empty.", name); - } - } - - public static void AssertInRange(T value, T minimum, T maximum, string name) - where T : notnull, IComparable - { - if (minimum.CompareTo(value) > 0) - { - throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); - } - if (maximum.CompareTo(value) < 0) - { - throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); - } - } - - public static void AssertEnumDefined(Type enumType, object value, string name) - { - if (!Enum.IsDefined(enumType, value)) - { - throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); - } - } - - public static T CheckNotNull(T value, string name) - where T : class - { - AssertNotNull(value, name); - return value; - } - - public static string CheckNotNullOrEmpty(string value, string name) - { - AssertNotNullOrEmpty(value, name); - return value; - } - - public static void AssertNull(T value, string name, string message = null) - { - if (value != null) - { - throw new ArgumentException(message ?? "Value must be null.", name); - } - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CancellationTokenExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CancellationTokenExtensions.cs new file mode 100644 index 000000000000..dd3b7d7fa565 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CancellationTokenExtensions.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using Azure; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal static partial class CancellationTokenExtensions + { + public static RequestContext ToRequestContext(this CancellationToken cancellationToken) => cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingDictionary.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingDictionary.cs index 5ee6ec3515f4..1075bca7d919 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingDictionary.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -11,7 +11,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + internal partial class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary + where TKey : notnull { private IDictionary _innerDictionary; @@ -19,6 +20,7 @@ public ChangeTrackingDictionary() { } + /// The inner dictionary. public ChangeTrackingDictionary(IDictionary dictionary) { if (dictionary == null) @@ -28,6 +30,7 @@ public ChangeTrackingDictionary(IDictionary dictionary) _innerDictionary = new Dictionary(dictionary); } + /// The inner dictionary. public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) { if (dictionary == null) @@ -41,16 +44,22 @@ public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) } } + /// Gets the IsUndefined. public bool IsUndefined => _innerDictionary == null; + /// Gets the Count. public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + /// Gets the IsReadOnly. public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + /// Gets the Keys. public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + /// Gets the Values. public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + /// Gets or sets the value associated with the specified key. public TValue this[TKey key] { get @@ -67,8 +76,10 @@ public TValue this[TKey key] } } + /// Gets the Keys. IEnumerable IReadOnlyDictionary.Keys => Keys; + /// Gets the Values. IEnumerable IReadOnlyDictionary.Values => Values; public IEnumerator> GetEnumerator() @@ -89,6 +100,7 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } + /// The item to add. public void Add(KeyValuePair item) { EnsureDictionary().Add(item); @@ -99,6 +111,7 @@ public void Clear() EnsureDictionary().Clear(); } + /// The item to search for. public bool Contains(KeyValuePair item) { if (IsUndefined) @@ -108,6 +121,8 @@ public bool Contains(KeyValuePair item) return EnsureDictionary().Contains(item); } + /// The array to copy. + /// The index. public void CopyTo(KeyValuePair[] array, int index) { if (IsUndefined) @@ -117,6 +132,7 @@ public void CopyTo(KeyValuePair[] array, int index) EnsureDictionary().CopyTo(array, index); } + /// The item to remove. public bool Remove(KeyValuePair item) { if (IsUndefined) @@ -126,11 +142,14 @@ public bool Remove(KeyValuePair item) return EnsureDictionary().Remove(item); } + /// The key. + /// The value to add. public void Add(TKey key, TValue value) { EnsureDictionary().Add(key, value); } + /// The key to search for. public bool ContainsKey(TKey key) { if (IsUndefined) @@ -140,6 +159,7 @@ public bool ContainsKey(TKey key) return EnsureDictionary().ContainsKey(key); } + /// The key. public bool Remove(TKey key) { if (IsUndefined) @@ -149,6 +169,8 @@ public bool Remove(TKey key) return EnsureDictionary().Remove(key); } + /// The key to search for. + /// The value. public bool TryGetValue(TKey key, out TValue value) { if (IsUndefined) diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingList.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingList.cs index bfba88e33ce9..c0cf66a0cd98 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingList.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ChangeTrackingList.cs @@ -12,7 +12,7 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - internal class ChangeTrackingList : IList, IReadOnlyList + internal partial class ChangeTrackingList : IList, IReadOnlyList { private IList _innerList; @@ -20,6 +20,7 @@ public ChangeTrackingList() { } + /// The inner list. public ChangeTrackingList(IList innerList) { if (innerList != null) @@ -28,6 +29,7 @@ public ChangeTrackingList(IList innerList) } } + /// The inner list. public ChangeTrackingList(IReadOnlyList innerList) { if (innerList != null) @@ -36,12 +38,16 @@ public ChangeTrackingList(IReadOnlyList innerList) } } + /// Gets the IsUndefined. public bool IsUndefined => _innerList == null; + /// Gets the Count. public int Count => IsUndefined ? 0 : EnsureList().Count; + /// Gets the IsReadOnly. public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + /// Gets or sets the value associated with the specified key. public T this[int index] { get @@ -85,6 +91,7 @@ IEnumerator IEnumerable.GetEnumerator() return GetEnumerator(); } + /// The item to add. public void Add(T item) { EnsureList().Add(item); @@ -95,6 +102,7 @@ public void Clear() EnsureList().Clear(); } + /// The item. public bool Contains(T item) { if (IsUndefined) @@ -104,6 +112,8 @@ public bool Contains(T item) return EnsureList().Contains(item); } + /// The array to copy to. + /// The array index. public void CopyTo(T[] array, int arrayIndex) { if (IsUndefined) @@ -113,6 +123,7 @@ public void CopyTo(T[] array, int arrayIndex) EnsureList().CopyTo(array, arrayIndex); } + /// The item. public bool Remove(T item) { if (IsUndefined) @@ -122,6 +133,7 @@ public bool Remove(T item) return EnsureList().Remove(item); } + /// The item. public int IndexOf(T item) { if (IsUndefined) @@ -131,11 +143,14 @@ public int IndexOf(T item) return EnsureList().IndexOf(item); } + /// The inner list. + /// The item. public void Insert(int index, T item) { EnsureList().Insert(index, item); } + /// The inner list. public void RemoveAt(int index) { if (IsUndefined) diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ClientPipelineExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ClientPipelineExtensions.cs new file mode 100644 index 000000000000..df5dde075af8 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ClientPipelineExtensions.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal static partial class ClientPipelineExtensions + { + public static async ValueTask ProcessMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + await pipeline.SendAsync(message, userCancellationToken).ConfigureAwait(false); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static Response ProcessMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + pipeline.Send(message, userCancellationToken); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static async ValueTask> ProcessHeadAsBoolMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = await pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + + public static Response ProcessHeadAsBoolMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = pipeline.ProcessMessage(message, context); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenMemberAttribute.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenMemberAttribute.cs new file mode 100644 index 000000000000..72778edeb7e4 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenMemberAttribute.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.TypeSpec.Generator.Customizations +{ + [AttributeUsage((AttributeTargets.Property | AttributeTargets.Field))] + internal partial class CodeGenMemberAttribute : CodeGenTypeAttribute + { + /// The original name of the member. + public CodeGenMemberAttribute(string originalName) : base(originalName) + { + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSerializationAttribute.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSerializationAttribute.cs new file mode 100644 index 000000000000..dfcabf517497 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSerializationAttribute.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.TypeSpec.Generator.Customizations +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Struct), AllowMultiple = true, Inherited = true)] + internal partial class CodeGenSerializationAttribute : Attribute + { + /// The property name which these hooks apply to. + public CodeGenSerializationAttribute(string propertyName) + { + PropertyName = propertyName; + } + + /// The property name which these hooks apply to. + /// The serialization name of the property. + public CodeGenSerializationAttribute(string propertyName, string serializationName) + { + PropertyName = propertyName; + SerializationName = serializationName; + } + + /// Gets or sets the property name which these hooks should apply to. + public string PropertyName { get; } + + /// Gets or sets the serialization name of the property. + public string SerializationName { get; set; } + + /// + /// Gets or sets the method name to use when serializing the property value (property name excluded). + /// The signature of the serialization hook method must be or compatible with when invoking: private void SerializeHook(Utf8JsonWriter writer); + /// + public string SerializationValueHook { get; set; } + + /// + /// Gets or sets the method name to use when deserializing the property value from the JSON. + /// private static void DeserializationHook(JsonProperty property, ref TypeOfTheProperty propertyValue); // if the property is required + /// private static void DeserializationHook(JsonProperty property, ref Optional<TypeOfTheProperty> propertyValue); // if the property is optional + /// + public string DeserializationValueHook { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSuppressAttribute.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSuppressAttribute.cs new file mode 100644 index 000000000000..38d536e69173 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenSuppressAttribute.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.TypeSpec.Generator.Customizations +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct), AllowMultiple = true)] + internal partial class CodeGenSuppressAttribute : Attribute + { + /// The member to suppress. + /// The types of the parameters of the member. + public CodeGenSuppressAttribute(string member, params Type[] parameters) + { + Member = member; + Parameters = parameters; + } + + /// Gets the Member. + public string Member { get; } + + /// Gets the Parameters. + public Type[] Parameters { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenTypeAttribute.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenTypeAttribute.cs new file mode 100644 index 000000000000..f36b5f513173 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/CodeGenTypeAttribute.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Microsoft.TypeSpec.Generator.Customizations +{ + [AttributeUsage((AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct))] + internal partial class CodeGenTypeAttribute : Attribute + { + /// The original name of the type. + public CodeGenTypeAttribute(string originalName) + { + OriginalName = originalName; + } + + /// Gets the OriginalName. + public string OriginalName { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ErrorResult.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ErrorResult.cs new file mode 100644 index 000000000000..e185b7f18821 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ErrorResult.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal partial class ErrorResult : Response + { + private readonly Response _response; + private readonly RequestFailedException _exception; + + public ErrorResult(Response response, RequestFailedException exception) + { + _response = response; + _exception = exception; + } + + /// Gets the Value. + public override T Value => throw _exception; + + /// + public override Response GetRawResponse() + { + return _response; + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ModelSerializationExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ModelSerializationExtensions.cs index ac6aaf3fc452..d3caa601c582 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ModelSerializationExtensions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/ModelSerializationExtensions.cs @@ -11,18 +11,16 @@ using System.Diagnostics; using System.Globalization; using System.Text.Json; -using System.Xml; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - internal static class ModelSerializationExtensions + internal static partial class ModelSerializationExtensions { - internal static readonly JsonDocumentOptions JsonDocumentOptions = new JsonDocumentOptions { MaxDepth = 256 }; internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); - internal static readonly ModelReaderWriterOptions WireV3Options = new ModelReaderWriterOptions("W|v3"); - internal static readonly ModelReaderWriterOptions JsonV3Options = new ModelReaderWriterOptions("J|v3"); - internal static readonly BinaryData SentinelValue = BinaryData.FromBytes("\"__EMPTY__\""u8.ToArray()); + internal static readonly JsonDocumentOptions JsonDocumentOptions = new JsonDocumentOptions + { + MaxDepth = 256 + }; public static object GetObject(this JsonElement element) { @@ -48,14 +46,14 @@ public static object GetObject(this JsonElement element) case JsonValueKind.Null: return null; case JsonValueKind.Object: - var dictionary = new Dictionary(); + Dictionary dictionary = new Dictionary(); foreach (var jsonProperty in element.EnumerateObject()) { dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); } return dictionary; case JsonValueKind.Array: - var list = new List(); + List list = new List(); foreach (var item in element.EnumerateArray()) { list.Add(item.GetObject()); @@ -93,7 +91,7 @@ public static char GetChar(this JsonElement element) { if (element.ValueKind == JsonValueKind.String) { - var text = element.GetString(); + string text = element.GetString(); if (text == null || text.Length != 1) { throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); @@ -107,14 +105,14 @@ public static char GetChar(this JsonElement element) } [Conditional("DEBUG")] - public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + public static void ThrowNonNullablePropertyIsNull(this JsonProperty @property) { - throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + throw new JsonException($"A property '{@property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); } public static string GetRequiredString(this JsonElement element) { - var value = element.GetString(); + string value = element.GetString(); if (value == null) { throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); @@ -181,9 +179,6 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, T value, Mode case IJsonModel jsonModel: jsonModel.Write(writer, options ?? WireOptions); break; - case IUtf8JsonSerializable serializable: - serializable.Write(writer); - break; case byte[] bytes: writer.WriteBase64StringValue(bytes); break; @@ -259,151 +254,5 @@ public static void WriteObjectValue(this Utf8JsonWriter writer, object value, Mo { writer.WriteObjectValue(value, options); } - - internal static bool IsSentinelValue(BinaryData value) - { - ReadOnlySpan sentinelSpan = SentinelValue.ToMemory().Span; - ReadOnlySpan valueSpan = value.ToMemory().Span; - return sentinelSpan.SequenceEqual(valueSpan); - } - - internal static class TypeFormatters - { - private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; - public const string DefaultNumberFormat = "G"; - - public static string ToString(bool value) => value ? "true" : "false"; - - public static string ToString(DateTime value, string format) => value.Kind switch - { - DateTimeKind.Utc => ToString((DateTimeOffset)value, format), - _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Azure SDK requires it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") - }; - - public static string ToString(DateTimeOffset value, string format) => format switch - { - "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), - "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), - "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), - "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), - "R" => value.ToString("r", CultureInfo.InvariantCulture), - _ => value.ToString(format, CultureInfo.InvariantCulture) - }; - - public static string ToString(TimeSpan value, string format) => format switch - { - "P" => XmlConvert.ToString(value), - _ => value.ToString(format, CultureInfo.InvariantCulture) - }; - - public static string ToString(byte[] value, string format) => format switch - { - "U" => ToBase64UrlString(value), - "D" => Convert.ToBase64String(value), - _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) - }; - - public static string ToBase64UrlString(byte[] value) - { - int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; - int size = checked(numWholeOrPartialInputBlocks * 4); - char[] output = new char[size]; - - int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); - - int i = 0; - for (; i < numBase64Chars; i++) - { - char ch = output[i]; - if (ch == '+') - { - output[i] = '-'; - } - else - { - if (ch == '/') - { - output[i] = '_'; - } - else - { - if (ch == '=') - { - break; - } - } - } - } - - return new string(output, 0, i); - } - - public static byte[] FromBase64UrlString(string value) - { - int paddingCharsToAdd = (value.Length % 4) switch - { - 0 => 0, - 2 => 2, - 3 => 1, - _ => throw new InvalidOperationException("Malformed input") - }; - char[] output = new char[(value.Length + paddingCharsToAdd)]; - int i = 0; - for (; i < value.Length; i++) - { - char ch = value[i]; - if (ch == '-') - { - output[i] = '+'; - } - else - { - if (ch == '_') - { - output[i] = '/'; - } - else - { - output[i] = ch; - } - } - } - - for (; i < output.Length; i++) - { - output[i] = '='; - } - - return Convert.FromBase64CharArray(output, 0, output.Length); - } - - public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch - { - "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), - _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) - }; - - public static TimeSpan ParseTimeSpan(string value, string format) => format switch - { - "P" => XmlConvert.ToTimeSpan(value), - _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) - }; - - public static string ConvertToString(object value, string format = null) => value switch - { - null => "null", - string s => s, - bool b => ToString(b), - int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), - byte[] b0 when format != null => ToString(b0, format), - IEnumerable s0 => string.Join(",", s0), - DateTimeOffset dateTime when format != null => ToString(dateTime, format), - TimeSpan timeSpan when format != null => ToString(timeSpan, format), - TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), - Guid guid => guid.ToString(), - BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), - _ => value.ToString() - }; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Optional.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Optional.cs index 6a4028d0f8c0..0ae0c76b8db6 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Optional.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Optional.cs @@ -10,7 +10,7 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - internal static class Optional + internal static partial class Optional { public static bool IsCollectionDefined(IEnumerable collection) { @@ -28,7 +28,7 @@ public static bool IsCollectionDefined(IReadOnlyDictionary(T? value) - where T : struct + where T : struct { return value.HasValue; } @@ -38,14 +38,14 @@ public static bool IsDefined(object value) return value != null; } - public static bool IsDefined(JsonElement value) + public static bool IsDefined(string value) { - return value.ValueKind != JsonValueKind.Undefined; + return value != null; } - public static bool IsDefined(string value) + public static bool IsDefined(JsonElement value) { - return value != null; + return value.ValueKind != JsonValueKind.Undefined; } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RawRequestUriBuilderExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RawRequestUriBuilderExtensions.cs new file mode 100644 index 000000000000..f04741966b9d --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RawRequestUriBuilderExtensions.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal static partial class RawRequestUriBuilderExtensions + { + public static void AppendQueryDelimited(this RawRequestUriBuilder builder, string name, IEnumerable value, string delimiter, SerializationFormat format = SerializationFormat.Default, bool escape = true) + { + delimiter ??= ","; + IEnumerable stringValues = value.Select(v => TypeFormatters.ConvertToString(v, format)); + builder.AppendQuery(name, string.Join(delimiter, stringValues), escape); + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RequestContextExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RequestContextExtensions.cs new file mode 100644 index 000000000000..fdb24c3b111e --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/RequestContextExtensions.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using Azure; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal static partial class RequestContextExtensions + { + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + public static ValueTuple Parse(this RequestContext context) + { + if (context == null) + { + return (CancellationToken.None, ErrorOptions.Default); + } + return (context.CancellationToken, context.ErrorOptions); + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/SerializationFormat.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/SerializationFormat.cs new file mode 100644 index 000000000000..188a54570a8f --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/SerializationFormat.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal enum SerializationFormat + { + /// The default serialization format. + Default = 0, + /// The RFC1123 date time format. + DateTime_RFC1123 = 1, + /// The RFC3339 date time format. + DateTime_RFC3339 = 2, + /// The RFC7231 date time format. + DateTime_RFC7231 = 3, + /// The ISO8601 date time format. + DateTime_ISO8601 = 4, + /// The Unix date time format. + DateTime_Unix = 5, + /// The ISO8601 date format. + Date_ISO8601 = 6, + /// The ISO8601 duration format. + Duration_ISO8601 = 7, + /// The constant duration format. + Duration_Constant = 8, + /// The seconds duration format. + Duration_Seconds = 9, + /// The seconds duration format with float precision. + Duration_Seconds_Float = 10, + /// The seconds duration format with double precision. + Duration_Seconds_Double = 11, + /// The milliseconds duration format. + Duration_Milliseconds = 12, + /// The milliseconds duration format with float precision. + Duration_Milliseconds_Float = 13, + /// The milliseconds duration format with double precision. + Duration_Milliseconds_Double = 14, + /// The ISO8601 time format. + Time_ISO8601 = 15, + /// The Base64Url bytes format. + Bytes_Base64Url = 16, + /// The Base64 bytes format. + Bytes_Base64 = 17 + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/TypeFormatters.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/TypeFormatters.cs new file mode 100644 index 000000000000..1af2b8eb4024 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/TypeFormatters.cs @@ -0,0 +1,180 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal static partial class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Generated clients require it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => System.Xml.XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked (value.Length + 2) / 3; + int size = checked (numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => System.Xml.XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ToFormatSpecifier(SerializationFormat format) => format switch + { + SerializationFormat.DateTime_RFC1123 => "R", + SerializationFormat.DateTime_RFC3339 => "O", + SerializationFormat.DateTime_RFC7231 => "R", + SerializationFormat.DateTime_ISO8601 => "O", + SerializationFormat.Date_ISO8601 => "D", + SerializationFormat.DateTime_Unix => "U", + SerializationFormat.Bytes_Base64Url => "U", + SerializationFormat.Bytes_Base64 => "D", + SerializationFormat.Duration_ISO8601 => "P", + SerializationFormat.Duration_Constant => "c", + SerializationFormat.Duration_Seconds => "%s", + SerializationFormat.Duration_Seconds_Float => "s\\.FFF", + SerializationFormat.Duration_Seconds_Double => "s\\.FFFFFF", + SerializationFormat.Time_ISO8601 => "T", + _ => null + }; + + public static string ConvertToString(object value, SerializationFormat format = SerializationFormat.Default) + { + string formatSpecifier = ToFormatSpecifier(format); + + return value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when formatSpecifier != null => ToString(b0, formatSpecifier), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when formatSpecifier != null => ToString(dateTime, formatSpecifier), + TimeSpan timeSpan when format == SerializationFormat.Duration_Seconds => Convert.ToInt32(timeSpan.TotalSeconds).ToString(CultureInfo.InvariantCulture), + TimeSpan timeSpan0 when format == SerializationFormat.Duration_Seconds_Float || format == SerializationFormat.Duration_Seconds_Double => timeSpan0.TotalSeconds.ToString(CultureInfo.InvariantCulture), + TimeSpan timeSpan1 when format == SerializationFormat.Duration_Milliseconds => Convert.ToInt32(timeSpan1.TotalMilliseconds).ToString(CultureInfo.InvariantCulture), + TimeSpan timeSpan2 when format == SerializationFormat.Duration_Milliseconds_Float || format == SerializationFormat.Duration_Milliseconds_Double => timeSpan2.TotalMilliseconds.ToString(CultureInfo.InvariantCulture), + TimeSpan timeSpan3 when formatSpecifier != null => ToString(timeSpan3, formatSpecifier), + TimeSpan timeSpan4 => System.Xml.XmlConvert.ToString(timeSpan4), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Utf8JsonRequestContent.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Utf8JsonRequestContent.cs index ff84e4d80a64..7e9f57236bf1 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Utf8JsonRequestContent.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Internal/Utf8JsonRequestContent.cs @@ -13,7 +13,7 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - internal class Utf8JsonRequestContent : RequestContent + internal partial class Utf8JsonRequestContent : RequestContent { private readonly MemoryStream _stream; private readonly RequestContent _content; @@ -25,20 +25,26 @@ public Utf8JsonRequestContent() JsonWriter = new Utf8JsonWriter(_stream); } + /// Gets the JsonWriter. public Utf8JsonWriter JsonWriter { get; } + /// The stream containing the data to be written. + /// The cancellation token to use. public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) { await JsonWriter.FlushAsync().ConfigureAwait(false); await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); } + /// The stream containing the data to be written. + /// The cancellation token to use. public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) { JsonWriter.Flush(); _content.WriteTo(stream, cancellationToken); } + /// public override bool TryComputeLength(out long length) { length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.cs deleted file mode 100644 index 75fa330f0a47..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Context object with previous QnA's information. - public partial class KnowledgeBaseAnswerContext - { - /// - /// 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 . - /// Previous turn top answer result QnA ID. - public KnowledgeBaseAnswerContext(int previousQnaId) - { - PreviousQnaId = previousQnaId; - } - - /// Initializes a new instance of . - /// Previous turn top answer result QnA ID. - /// Previous user query. - /// Keeps track of any properties unknown to the library. - internal KnowledgeBaseAnswerContext(int previousQnaId, string previousQuestion, IDictionary serializedAdditionalRawData) - { - PreviousQnaId = previousQnaId; - PreviousQuestion = previousQuestion; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal KnowledgeBaseAnswerContext() - { - } - - /// Previous turn top answer result QnA ID. - public int PreviousQnaId { get; } - /// Previous user query. - public string PreviousQuestion { get; set; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.cs deleted file mode 100644 index 7a8749c97fd6..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Dialog associated with Answer. - public partial class KnowledgeBaseAnswerDialog - { - /// - /// 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 KnowledgeBaseAnswerDialog() - { - Prompts = new ChangeTrackingList(); - } - - /// Initializes a new instance of . - /// - /// To mark if a prompt is relevant only with a previous question or not. If true, - /// do not include this QnA as search result for queries without context; - /// otherwise, if false, ignores context and includes this QnA in search result. - /// - /// List of prompts associated with the answer. - /// Keeps track of any properties unknown to the library. - internal KnowledgeBaseAnswerDialog(bool? isContextOnly, IReadOnlyList prompts, IDictionary serializedAdditionalRawData) - { - IsContextOnly = isContextOnly; - Prompts = prompts; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// - /// To mark if a prompt is relevant only with a previous question or not. If true, - /// do not include this QnA as search result for queries without context; - /// otherwise, if false, ignores context and includes this QnA in search result. - /// - public bool? IsContextOnly { get; } - /// List of prompts associated with the answer. - public IReadOnlyList Prompts { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.cs deleted file mode 100644 index c725dd835b3b..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Prompt for an answer. - public partial class KnowledgeBaseAnswerPrompt - { - /// - /// 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 KnowledgeBaseAnswerPrompt() - { - } - - /// Initializes a new instance of . - /// Index of the prompt - used in ordering of the prompts. - /// QnA ID corresponding to the prompt. - /// Text displayed to represent a follow up question prompt. - /// Keeps track of any properties unknown to the library. - internal KnowledgeBaseAnswerPrompt(int? displayOrder, int? id, string displayText, IDictionary serializedAdditionalRawData) - { - DisplayOrder = displayOrder; - Id = id; - DisplayText = displayText; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Index of the prompt - used in ordering of the prompts. - public int? DisplayOrder { get; } - /// QnA ID corresponding to the prompt. - public int? Id { get; } - /// Text displayed to represent a follow up question prompt. - public string DisplayText { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceClientBuilderExtensions.cs similarity index 61% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientExtensions.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceClientBuilderExtensions.cs index f1b75d021d65..990409865768 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientExtensions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceClientBuilderExtensions.cs @@ -13,35 +13,35 @@ namespace Microsoft.Extensions.Azure { - /// Extension methods to add to client builder. - public static partial class QuestionAnsweringClientExtensions + /// Extension methods to add clients to . + public static partial class LanguageQuestionAnsweringInferenceClientBuilderExtensions { - /// Registers a instance. + /// Registers a client with the specified . /// The builder to register with. - /// Supported Cognitive Services endpoint (e.g., https://<resource-name>.api.cognitiveservices.azure.com). - /// A credential used to authenticate to an Azure Service. + /// + /// public static IAzureClientBuilder AddQuestionAnsweringClient(this TBuilder builder, Uri endpoint, AzureKeyCredential credential) - where TBuilder : IAzureClientFactoryBuilder + where TBuilder : IAzureClientFactoryBuilder { - return builder.RegisterClientFactory((options) => new QuestionAnsweringClient(endpoint, credential, options)); + return builder.RegisterClientFactory(options => new QuestionAnsweringClient(endpoint, credential, options)); } - /// Registers a instance. + /// Registers a client with the specified . /// The builder to register with. - /// Supported Cognitive Services endpoint (e.g., https://<resource-name>.api.cognitiveservices.azure.com). + /// public static IAzureClientBuilder AddQuestionAnsweringClient(this TBuilder builder, Uri endpoint) - where TBuilder : IAzureClientFactoryBuilderWithCredential + where TBuilder : IAzureClientFactoryBuilderWithCredential { - return builder.RegisterClientFactory((options, cred) => new QuestionAnsweringClient(endpoint, cred, options)); + return builder.RegisterClientFactory((options, credential) => new QuestionAnsweringClient(endpoint, credential, options)); } - /// Registers a instance. + /// Registers a client with the specified . /// The builder to register with. - /// The configuration values. + /// The configuration to use for the client. [RequiresUnreferencedCode("Requires unreferenced code until we opt into EnableConfigurationBindingGenerator.")] [RequiresDynamicCode("Requires unreferenced code until we opt into EnableConfigurationBindingGenerator.")] public static IAzureClientBuilder AddQuestionAnsweringClient(this TBuilder builder, TConfiguration configuration) - where TBuilder : IAzureClientFactoryBuilderWithConfiguration + where TBuilder : IAzureClientFactoryBuilderWithConfiguration { return builder.RegisterClientFactory(configuration); } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceModelFactory.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceModelFactory.cs new file mode 100644 index 000000000000..992906ab98cc --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LanguageQuestionAnsweringInferenceModelFactory.cs @@ -0,0 +1,273 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// A factory class for creating instances of the models for mocking. + public static partial class LanguageQuestionAnsweringInferenceModelFactory + { + /// Parameters to query a knowledge base. + /// + /// Exact QnA ID to fetch from the knowledge base, this field takes priority over + /// question. + /// + /// User question to query against the knowledge base. + /// Max number of answers to be returned for the question. + /// Unique identifier for the user. + /// Minimum threshold score for answers, value ranges from 0 to 1. + /// Context object with previous QnA's information. + /// Type of ranker to be used. + /// Filter QnAs based on given metadata list and knowledge base sources. + /// To configure Answer span prediction feature. + /// (Optional) Flag to enable Query over Unstructured Sources. + /// To fine tune query results. + /// A new instance for mocking. + public static AnswersOptions AnswersOptions(int? qnaId = default, string question = default, int? top = default, string userId = default, double? confidenceThreshold = default, KnowledgeBaseAnswerContext answerContext = default, RankerKind? rankerKind = default, QueryFilters filters = default, ShortAnswerOptions shortAnswerOptions = default, bool? includeUnstructuredSources = default, QueryPreferences queryPreferences = default) + { + return new AnswersOptions( + qnaId, + question, + top, + userId, + confidenceThreshold, + answerContext, + rankerKind, + filters, + shortAnswerOptions, + includeUnstructuredSources, + queryPreferences, + additionalBinaryDataProperties: null); + } + + /// Context object with previous QnA's information. + /// Previous turn top answer result QnA ID. + /// Previous user query. + /// A new instance for mocking. + public static KnowledgeBaseAnswerContext KnowledgeBaseAnswerContext(int previousQnaId = default, string previousQuestion = default) + { + return new KnowledgeBaseAnswerContext(previousQnaId, previousQuestion, additionalBinaryDataProperties: null); + } + + /// filters over knowledge base. + /// Find QnAs that are associated with the given list of metadata. + /// + /// Find QnAs that are associated with any of the given list of sources in + /// knowledge base. + /// + /// Logical operation used to join metadata filter with source filter. + /// A new instance for mocking. + public static QueryFilters QueryFilters(MetadataFilter metadataFilter = default, IEnumerable sourceFilter = default, LogicalOperationKind? logicalOperation = default) + { + sourceFilter ??= new ChangeTrackingList(); + + return new QueryFilters(metadataFilter, sourceFilter.ToList(), logicalOperation, additionalBinaryDataProperties: null); + } + + /// Find QnAs that are associated with the given list of metadata. + /// Dictionary of string. + /// Operation used to join metadata filters. + /// A new instance for mocking. + public static MetadataFilter MetadataFilter(IEnumerable metadataRecords = default, LogicalOperationKind? logicalOperation = default) + { + metadataRecords ??= new ChangeTrackingList(); + + return new MetadataFilter(metadataRecords.ToList(), logicalOperation, additionalBinaryDataProperties: null); + } + + /// Object to provide the key value pair for each metadata. + /// Metadata Key from Metadata dictionary used in the QnA. + /// Metadata Value from Metadata dictionary used in the QnA. + /// A new instance for mocking. + public static MetadataRecord MetadataRecord(string key = default, string value = default) + { + return new MetadataRecord(key, value, additionalBinaryDataProperties: null); + } + + /// To configure Answer span prediction feature. + /// Enable or disable Answer Span prediction. + /// + /// Minimum threshold score required to include an answer span, value ranges from 0 + /// to 1. + /// + /// Number of Top answers to be considered for span prediction from 1 to 10. + /// A new instance for mocking. + public static ShortAnswerOptions ShortAnswerOptions(bool isEnabled = default, double? confidenceThreshold = default, int? top = default) + { + return new ShortAnswerOptions(isEnabled, confidenceThreshold, top, additionalBinaryDataProperties: null); + } + + /// Additional properties to fine tune query results. + /// To specify what scoring algorithm is preferred. + /// Policy for controling exact query match behavior. + /// A new instance for mocking. + public static QueryPreferences QueryPreferences(Scorer? scorer = default, MatchingPolicy matchingPolicy = default) + { + return new QueryPreferences(scorer, matchingPolicy, additionalBinaryDataProperties: null); + } + + /// + /// Specify parameters for query matching + /// Please note this is the abstract base class. The derived classes available for instantiation are: . + /// + /// Kind of matching policy to be applied. + /// A new instance for mocking. + public static MatchingPolicy MatchingPolicy(string kind = default) + { + return new UnknownMatchingPolicy(new MatchingPolicyKind(kind), additionalBinaryDataProperties: null); + } + + /// Represents fields for Prebuilt query matching. Prebuilt weights will be used for giving preference to question and answer columns when quering AI search. + /// List of fields to filter during query. For ex if only "questions" is used then query will be filtered on that column. + /// Disabling full match on query. Enabling this will give preference to qna pairs that have exact match. + /// A new instance for mocking. + public static PrebuiltQueryMatchingPolicy PrebuiltQueryMatchingPolicy(IEnumerable fields = default, bool? isFullMatchingDisabled = default) + { + fields ??= new ChangeTrackingList(); + + return new PrebuiltQueryMatchingPolicy(MatchingPolicyKind.Prebuilt, additionalBinaryDataProperties: null, fields.ToList(), isFullMatchingDisabled); + } + + /// Represents List of Question Answers. + /// Represents Answer Result list. + /// A new instance for mocking. + public static AnswersResult AnswersResult(IEnumerable answers = default) + { + answers ??= new ChangeTrackingList(); + + return new AnswersResult(answers.ToList(), additionalBinaryDataProperties: null); + } + + /// Represents knowledge base answer. + /// List of questions associated with the answer. + /// Answer text. + /// Answer confidence score, value ranges from 0 to 1. + /// ID of the QnA result. + /// Source of QnA result. + /// + /// Metadata associated with the answer, useful to categorize or filter question + /// answers. + /// + /// Dialog associated with Answer. + /// Answer span object of QnA with respect to user's question. + /// A new instance for mocking. + public static KnowledgeBaseAnswer KnowledgeBaseAnswer(IEnumerable questions = default, string answer = default, double? confidence = default, int? qnaId = default, string source = default, IDictionary metadata = default, KnowledgeBaseAnswerDialog dialog = default, AnswerSpan shortAnswer = default) + { + questions ??= new ChangeTrackingList(); + metadata ??= new ChangeTrackingDictionary(); + + return new KnowledgeBaseAnswer( + questions.ToList(), + answer, + confidence, + qnaId, + source, + metadata, + dialog, + shortAnswer, + additionalBinaryDataProperties: null); + } + + /// Dialog associated with Answer. + /// + /// To mark if a prompt is relevant only with a previous question or not. If true, + /// do not include this QnA as search result for queries without context; + /// otherwise, if false, ignores context and includes this QnA in search result. + /// + /// List of prompts associated with the answer. + /// A new instance for mocking. + public static KnowledgeBaseAnswerDialog KnowledgeBaseAnswerDialog(bool? isContextOnly = default, IEnumerable prompts = default) + { + prompts ??= new ChangeTrackingList(); + + return new KnowledgeBaseAnswerDialog(isContextOnly, prompts.ToList(), additionalBinaryDataProperties: null); + } + + /// Prompt for an answer. + /// Index of the prompt - used in ordering of the prompts. + /// QnA ID corresponding to the prompt. + /// Text displayed to represent a follow up question prompt. + /// A new instance for mocking. + public static KnowledgeBaseAnswerPrompt KnowledgeBaseAnswerPrompt(int? displayOrder = default, int? id = default, string displayText = default) + { + return new KnowledgeBaseAnswerPrompt(displayOrder, id, displayText, additionalBinaryDataProperties: null); + } + + /// Answer span object of QnA. + /// Predicted text of answer span. + /// Predicted score of answer span, value ranges from 0 to 1. + /// The answer span offset from the start of answer. + /// The length of the answer span. + /// A new instance for mocking. + public static AnswerSpan AnswerSpan(string text = default, double? confidence = default, int? offset = default, int? length = default) + { + return new AnswerSpan(text, confidence, offset, length, additionalBinaryDataProperties: null); + } + + /// The question and text record parameters to answer. + /// User question to query against the given text records. + /// Text records to be searched for given question. + /// + /// Language of the text records. This is BCP-47 representation of a language. For + /// example, use "en" for English; "es" for Spanish etc. If not set, use "en" for + /// English as default. + /// + /// + /// Specifies the method used to interpret string offsets. Defaults to Text + /// Elements (Graphemes) according to Unicode v8.0.0. For additional information + /// see https://aka.ms/text-analytics-offsets. + /// + /// A new instance for mocking. + public static AnswersFromTextOptions AnswersFromTextOptions(string question = default, IEnumerable textDocuments = default, string language = default, StringIndexType? stringIndexType = default) + { + textDocuments ??= new ChangeTrackingList(); + + return new AnswersFromTextOptions(question, textDocuments.ToList(), language, stringIndexType, additionalBinaryDataProperties: null); + } + + /// Represent input text record to be queried. + /// Unique identifier for the text record. + /// Text contents of the record. + /// A new instance for mocking. + public static TextDocument TextDocument(string id = default, string text = default) + { + return new TextDocument(id, text, additionalBinaryDataProperties: null); + } + + /// Represents the answer results. + /// Represents the answer results. + /// A new instance for mocking. + public static AnswersFromTextResult AnswersFromTextResult(IEnumerable answers = default) + { + answers ??= new ChangeTrackingList(); + + return new AnswersFromTextResult(answers.ToList(), additionalBinaryDataProperties: null); + } + + /// Represents answer result. + /// Answer. + /// answer confidence score, value ranges from 0 to 1. + /// record ID. + /// Answer span object with respect to user's question. + /// The sentence offset from the start of the document. + /// The length of the sentence. + /// A new instance for mocking. + public static TextAnswer TextAnswer(string answer = default, double? confidence = default, string id = default, AnswerSpan shortAnswer = default, int? offset = default, int? length = default) + { + return new TextAnswer( + answer, + confidence, + id, + shortAnswer, + offset, + length, + additionalBinaryDataProperties: null); + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.Serialization.cs deleted file mode 100644 index aa2c40832425..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.Serialization.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - [PersistableModelProxy(typeof(UnknownMatchingPolicy))] - public partial class MatchingPolicy : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("kind"u8); - writer.WriteStringValue(Kind.ToString()); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - MatchingPolicy 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(MatchingPolicy)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeMatchingPolicy(document.RootElement, options); - } - - internal static MatchingPolicy DeserializeMatchingPolicy(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - if (element.TryGetProperty("kind", out JsonElement discriminator)) - { - switch (discriminator.GetString()) - { - case "Prebuilt": return PrebuiltQueryMatchingPolicy.DeserializePrebuiltQueryMatchingPolicy(element, options); - } - } - return UnknownMatchingPolicy.DeserializeUnknownMatchingPolicy(element, options); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); - default: - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{options.Format}' format."); - } - } - - MatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMatchingPolicy(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static MatchingPolicy FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMatchingPolicy(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.cs deleted file mode 100644 index 54a2da2df381..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicy.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// - /// Specify parameters for query matching - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - public abstract partial class MatchingPolicy - { - /// - /// 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 MatchingPolicy() - { - } - - /// Initializes a new instance of . - /// Kind of matching policy to be applied. - /// Keeps track of any properties unknown to the library. - internal MatchingPolicy(MatchingPolicyKind kind, IDictionary serializedAdditionalRawData) - { - Kind = kind; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Kind of matching policy to be applied. - internal MatchingPolicyKind Kind { get; set; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.cs deleted file mode 100644 index 7bdc65fbe86c..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.cs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Find QnAs that are associated with the given list of metadata. - public partial class MetadataFilter - { - /// - /// 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 MetadataFilter() - { - MetadataRecords = new ChangeTrackingList(); - } - - /// Initializes a new instance of . - /// Dictionary of string. - /// Operation used to join metadata filters. - /// Keeps track of any properties unknown to the library. - internal MetadataFilter(IList metadataRecords, LogicalOperationKind? logicalOperation, IDictionary serializedAdditionalRawData) - { - MetadataRecords = metadataRecords; - LogicalOperation = logicalOperation; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Dictionary of string. - public IList MetadataRecords { get; } - /// Operation used to join metadata filters. - public LogicalOperationKind? LogicalOperation { get; set; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.Serialization.cs deleted file mode 100644 index 9c89211e779e..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.Serialization.cs +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - public partial class MetadataRecord : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(MetadataRecord)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("key"u8); - writer.WriteStringValue(Key); - writer.WritePropertyName("value"u8); - writer.WriteStringValue(Value); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - MetadataRecord 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(MetadataRecord)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeMetadataRecord(document.RootElement, options); - } - - internal static MetadataRecord DeserializeMetadataRecord(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string key = default; - string value = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("key"u8)) - { - key = property.Value.GetString(); - continue; - } - if (property.NameEquals("value"u8)) - { - value = property.Value.GetString(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new MetadataRecord(key, 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, AzureAILanguageQuestionAnsweringInferenceContext.Default); - default: - throw new FormatException($"The model {nameof(MetadataRecord)} does not support writing '{options.Format}' format."); - } - } - - MetadataRecord IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMetadataRecord(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(MetadataRecord)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static MetadataRecord FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMetadataRecord(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.cs deleted file mode 100644 index a18211804d9b..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataRecord.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Object to provide the key value pair for each metadata. - public partial class MetadataRecord - { - /// - /// 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 . - /// Metadata Key from Metadata dictionary used in the QnA. - /// Metadata Value from Metadata dictionary used in the QnA. - /// or is null. - public MetadataRecord(string key, string value) - { - Argument.AssertNotNull(key, nameof(key)); - Argument.AssertNotNull(value, nameof(value)); - - Key = key; - Value = value; - } - - /// Initializes a new instance of . - /// Metadata Key from Metadata dictionary used in the QnA. - /// Metadata Value from Metadata dictionary used in the QnA. - /// Keeps track of any properties unknown to the library. - internal MetadataRecord(string key, string value, IDictionary serializedAdditionalRawData) - { - Key = key; - Value = value; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal MetadataRecord() - { - } - - /// Metadata Key from Metadata dictionary used in the QnA. - public string Key { get; } - /// Metadata Value from Metadata dictionary used in the QnA. - public string Value { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.Serialization.cs similarity index 53% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.Serialization.cs index 573b848ff600..828f091deaa4 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswerSpan.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class AnswerSpan : IUtf8JsonSerializable, IJsonModel + /// Answer span object of QnA. + public partial class AnswerSpan : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOption /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswerSpan)} does not support writing '{format}' format."); } - if (Optional.IsDefined(Text)) { writer.WritePropertyName("text"u8); @@ -54,15 +53,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("length"u8); writer.WriteNumberValue(Length.Value); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -71,79 +70,85 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AnswerSpan IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + AnswerSpan IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual AnswerSpan JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswerSpan)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeAnswerSpan(document.RootElement, options); } - internal static AnswerSpan DeserializeAnswerSpan(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static AnswerSpan DeserializeAnswerSpan(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } string text = default; - double? confidenceScore = default; + double? confidence = default; int? offset = default; int? length = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("text"u8)) + if (prop.NameEquals("text"u8)) { - text = property.Value.GetString(); + text = prop.Value.GetString(); continue; } - if (property.NameEquals("confidenceScore"u8)) + if (prop.NameEquals("confidenceScore"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - confidenceScore = property.Value.GetDouble(); + confidence = prop.Value.GetDouble(); continue; } - if (property.NameEquals("offset"u8)) + if (prop.NameEquals("offset"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - offset = property.Value.GetInt32(); + offset = prop.Value.GetInt32(); continue; } - if (property.NameEquals("length"u8)) + if (prop.NameEquals("length"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - length = property.Value.GetInt32(); + length = prop.Value.GetInt32(); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new AnswerSpan(text, confidenceScore, offset, length, serializedAdditionalRawData); + return new AnswerSpan(text, confidence, offset, length, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -153,15 +158,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) } } - AnswerSpan IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + AnswerSpan IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual AnswerSpan PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeAnswerSpan(document.RootElement, options); } default: @@ -169,22 +179,7 @@ AnswerSpan IPersistableModel.Create(BinaryData data, ModelReaderWrit } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static AnswerSpan FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAnswerSpan(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.cs new file mode 100644 index 000000000000..fae27578d90e --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswerSpan.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Answer span object of QnA. + public partial class AnswerSpan + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + internal AnswerSpan() + { + } + + /// Initializes a new instance of . + /// Predicted text of answer span. + /// Predicted score of answer span, value ranges from 0 to 1. + /// The answer span offset from the start of answer. + /// The length of the answer span. + /// Keeps track of any properties unknown to the library. + internal AnswerSpan(string text, double? confidence, int? offset, int? length, IDictionary additionalBinaryDataProperties) + { + Text = text; + Confidence = confidence; + Offset = offset; + Length = length; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Predicted text of answer span. + public string Text { get; } + + /// Predicted score of answer span, value ranges from 0 to 1. + public double? Confidence { get; } + + /// The answer span offset from the start of answer. + public int? Offset { get; } + + /// The length of the answer span. + public int? Length { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.Serialization.cs similarity index 50% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.Serialization.cs index 83d047f300f0..b2c334d239e0 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.Serialization.cs @@ -13,10 +13,16 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class AnswersFromTextOptions : IUtf8JsonSerializable, IJsonModel + /// The question and text record parameters to answer. + public partial class AnswersFromTextOptions : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + /// Initializes a new instance of for deserialization. + internal AnswersFromTextOptions() + { + } + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,17 +34,16 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReader /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersFromTextOptions)} does not support writing '{format}' format."); } - writer.WritePropertyName("question"u8); writer.WriteStringValue(Question); writer.WritePropertyName("records"u8); writer.WriteStartArray(); - foreach (var item in TextDocuments) + foreach (TextDocument item in TextDocuments) { writer.WriteObjectValue(item, options); } @@ -53,15 +58,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("stringIndexType"u8); writer.WriteStringValue(StringIndexType.Value.ToString()); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -70,76 +75,82 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AnswersFromTextOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + AnswersFromTextOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual AnswersFromTextOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersFromTextOptions)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeAnswersFromTextOptions(document.RootElement, options); } - internal static AnswersFromTextOptions DeserializeAnswersFromTextOptions(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static AnswersFromTextOptions DeserializeAnswersFromTextOptions(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } string question = default; - IList records = default; + IList textDocuments = default; string language = default; StringIndexType? stringIndexType = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("question"u8)) + if (prop.NameEquals("question"u8)) { - question = property.Value.GetString(); + question = prop.Value.GetString(); continue; } - if (property.NameEquals("records"u8)) + if (prop.NameEquals("records"u8)) { List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(TextDocument.DeserializeTextDocument(item, options)); } - records = array; + textDocuments = array; continue; } - if (property.NameEquals("language"u8)) + if (prop.NameEquals("language"u8)) { - language = property.Value.GetString(); + language = prop.Value.GetString(); continue; } - if (property.NameEquals("stringIndexType"u8)) + if (prop.NameEquals("stringIndexType"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - stringIndexType = new StringIndexType(property.Value.GetString()); + stringIndexType = new StringIndexType(prop.Value.GetString()); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new AnswersFromTextOptions(question, records, language, stringIndexType, serializedAdditionalRawData); + return new AnswersFromTextOptions(question, textDocuments, language, stringIndexType, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -149,15 +160,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpti } } - AnswersFromTextOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + AnswersFromTextOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual AnswersFromTextOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeAnswersFromTextOptions(document.RootElement, options); } default: @@ -165,21 +181,18 @@ AnswersFromTextOptions IPersistableModel.Create(BinaryDa } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static AnswersFromTextOptions FromResponse(Response response) + /// The to serialize into . + public static implicit operator RequestContent(AnswersFromTextOptions answersFromTextOptions) { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAnswersFromTextOptions(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + if (answersFromTextOptions == null) + { + return null; + } + Utf8JsonRequestContent content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(answersFromTextOptions, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.cs similarity index 61% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.cs index fd39c9a19088..95a1f3d1ed37 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextOptions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextOptions.cs @@ -14,37 +14,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference /// The question and text record parameters to answer. public partial class AnswersFromTextOptions { - /// - /// 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; + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; /// Initializes a new instance of . /// User question to query against the given text records. @@ -72,25 +43,22 @@ public AnswersFromTextOptions(string question, IEnumerable textDoc /// Elements (Graphemes) according to Unicode v8.0.0. For additional information /// see https://aka.ms/text-analytics-offsets. /// - /// Keeps track of any properties unknown to the library. - internal AnswersFromTextOptions(string question, IList textDocuments, string language, StringIndexType? stringIndexType, IDictionary serializedAdditionalRawData) + /// Keeps track of any properties unknown to the library. + internal AnswersFromTextOptions(string question, IList textDocuments, string language, StringIndexType? stringIndexType, IDictionary additionalBinaryDataProperties) { Question = question; TextDocuments = textDocuments; Language = language; StringIndexType = stringIndexType; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal AnswersFromTextOptions() - { + _additionalBinaryDataProperties = additionalBinaryDataProperties; } /// User question to query against the given text records. public string Question { get; } + /// Text records to be searched for given question. public IList TextDocuments { get; } + /// /// Language of the text records. This is BCP-47 representation of a language. For /// example, use "en" for English; "es" for Spanish etc. If not set, use "en" for diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.Serialization.cs similarity index 51% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.Serialization.cs index 70b3ea4dcf84..25af33669ded 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersFromTextResult.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.Serialization.cs @@ -9,14 +9,15 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; +using Azure; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class AnswersFromTextResult : IUtf8JsonSerializable, IJsonModel + /// Represents the answer results. + public partial class AnswersFromTextResult : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,31 +29,30 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderW /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersFromTextResult)} does not support writing '{format}' format."); } - if (Optional.IsCollectionDefined(Answers)) { writer.WritePropertyName("answers"u8); writer.WriteStartArray(); - foreach (var item in Answers) + foreach (TextAnswer item in Answers) { writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -61,39 +61,43 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AnswersFromTextResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + AnswersFromTextResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual AnswersFromTextResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersFromTextResult)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeAnswersFromTextResult(document.RootElement, options); } - internal static AnswersFromTextResult DeserializeAnswersFromTextResult(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static AnswersFromTextResult DeserializeAnswersFromTextResult(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } - IReadOnlyList answers = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IList answers = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("answers"u8)) + if (prop.NameEquals("answers"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(TextAnswer.DeserializeTextAnswer(item, options)); } @@ -102,17 +106,19 @@ internal static AnswersFromTextResult DeserializeAnswersFromTextResult(JsonEleme } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new AnswersFromTextResult(answers ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new AnswersFromTextResult(answers ?? new ChangeTrackingList(), additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -122,15 +128,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptio } } - AnswersFromTextResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + AnswersFromTextResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual AnswersFromTextResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeAnswersFromTextResult(document.RootElement, options); } default: @@ -138,22 +149,14 @@ AnswersFromTextResult IPersistableModel.Create(BinaryData } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static AnswersFromTextResult FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAnswersFromTextResult(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() + /// The to deserialize the from. + public static explicit operator AnswersFromTextResult(Response response) { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; + using JsonDocument document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAnswersFromTextResult(document.RootElement, ModelSerializationExtensions.WireOptions); } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.cs new file mode 100644 index 000000000000..bcda9e09f79c --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersFromTextResult.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Represents the answer results. + public partial class AnswersFromTextResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + internal AnswersFromTextResult() + { + Answers = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// Represents the answer results. + /// Keeps track of any properties unknown to the library. + internal AnswersFromTextResult(IList answers, IDictionary additionalBinaryDataProperties) + { + Answers = answers; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Represents the answer results. + public IList Answers { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.Serialization.cs similarity index 54% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.Serialization.cs index b2452df28185..8b829c43b30f 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.Serialization.cs @@ -13,10 +13,11 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class AnswersOptions : IUtf8JsonSerializable, IJsonModel + /// Parameters to query a knowledge base. + public partial class AnswersOptions : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +29,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersOptions)} does not support writing '{format}' format."); } - if (Optional.IsDefined(QnaId)) { writer.WritePropertyName("qnaId"u8); @@ -44,10 +44,10 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("question"u8); writer.WriteStringValue(Question); } - if (Optional.IsDefined(Size)) + if (Optional.IsDefined(Top)) { writer.WritePropertyName("top"u8); - writer.WriteNumberValue(Size.Value); + writer.WriteNumberValue(Top.Value); } if (Optional.IsDefined(UserId)) { @@ -89,15 +89,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("queryPreferences"u8); writer.WriteObjectValue(QueryPreferences, options); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -106,22 +106,27 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AnswersOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + AnswersOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual AnswersOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersOptions)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeAnswersOptions(document.RootElement, options); } - internal static AnswersOptions DeserializeAnswersOptions(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static AnswersOptions DeserializeAnswersOptions(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; @@ -130,133 +135,134 @@ internal static AnswersOptions DeserializeAnswersOptions(JsonElement element, Mo string question = default; int? top = default; string userId = default; - double? confidenceScoreThreshold = default; - KnowledgeBaseAnswerContext context = default; - RankerKind? rankerType = default; + double? confidenceThreshold = default; + KnowledgeBaseAnswerContext answerContext = default; + RankerKind? rankerKind = default; QueryFilters filters = default; - ShortAnswerOptions answerSpanRequest = default; + ShortAnswerOptions shortAnswerOptions = default; bool? includeUnstructuredSources = default; QueryPreferences queryPreferences = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("qnaId"u8)) + if (prop.NameEquals("qnaId"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - qnaId = property.Value.GetInt32(); + qnaId = prop.Value.GetInt32(); continue; } - if (property.NameEquals("question"u8)) + if (prop.NameEquals("question"u8)) { - question = property.Value.GetString(); + question = prop.Value.GetString(); continue; } - if (property.NameEquals("top"u8)) + if (prop.NameEquals("top"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - top = property.Value.GetInt32(); + top = prop.Value.GetInt32(); continue; } - if (property.NameEquals("userId"u8)) + if (prop.NameEquals("userId"u8)) { - userId = property.Value.GetString(); + userId = prop.Value.GetString(); continue; } - if (property.NameEquals("confidenceScoreThreshold"u8)) + if (prop.NameEquals("confidenceScoreThreshold"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - confidenceScoreThreshold = property.Value.GetDouble(); + confidenceThreshold = prop.Value.GetDouble(); continue; } - if (property.NameEquals("context"u8)) + if (prop.NameEquals("context"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - context = KnowledgeBaseAnswerContext.DeserializeKnowledgeBaseAnswerContext(property.Value, options); + answerContext = KnowledgeBaseAnswerContext.DeserializeKnowledgeBaseAnswerContext(prop.Value, options); continue; } - if (property.NameEquals("rankerType"u8)) + if (prop.NameEquals("rankerType"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - rankerType = new RankerKind(property.Value.GetString()); + rankerKind = new RankerKind(prop.Value.GetString()); continue; } - if (property.NameEquals("filters"u8)) + if (prop.NameEquals("filters"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - filters = QueryFilters.DeserializeQueryFilters(property.Value, options); + filters = QueryFilters.DeserializeQueryFilters(prop.Value, options); continue; } - if (property.NameEquals("answerSpanRequest"u8)) + if (prop.NameEquals("answerSpanRequest"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - answerSpanRequest = ShortAnswerOptions.DeserializeShortAnswerOptions(property.Value, options); + shortAnswerOptions = ShortAnswerOptions.DeserializeShortAnswerOptions(prop.Value, options); continue; } - if (property.NameEquals("includeUnstructuredSources"u8)) + if (prop.NameEquals("includeUnstructuredSources"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - includeUnstructuredSources = property.Value.GetBoolean(); + includeUnstructuredSources = prop.Value.GetBoolean(); continue; } - if (property.NameEquals("queryPreferences"u8)) + if (prop.NameEquals("queryPreferences"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - queryPreferences = QueryPreferences.DeserializeQueryPreferences(property.Value, options); + queryPreferences = QueryPreferences.DeserializeQueryPreferences(prop.Value, options); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; return new AnswersOptions( qnaId, question, top, userId, - confidenceScoreThreshold, - context, - rankerType, + confidenceThreshold, + answerContext, + rankerKind, filters, - answerSpanRequest, + shortAnswerOptions, includeUnstructuredSources, queryPreferences, - serializedAdditionalRawData); + additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -266,15 +272,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opti } } - AnswersOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + AnswersOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual AnswersOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeAnswersOptions(document.RootElement, options); } default: @@ -282,21 +293,18 @@ AnswersOptions IPersistableModel.Create(BinaryData data, ModelRe } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static AnswersOptions FromResponse(Response response) + /// The to serialize into . + public static implicit operator RequestContent(AnswersOptions answersOptions) { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAnswersOptions(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + if (answersOptions == null) + { + return null; + } + Utf8JsonRequestContent content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(answersOptions, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.cs similarity index 64% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.cs index 1040587b9d7c..af5d17b82594 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersOptions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersOptions.cs @@ -13,37 +13,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference /// Parameters to query a knowledge base. public partial class AnswersOptions { - /// - /// 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; + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; /// Initializes a new instance of . public AnswersOptions() @@ -56,7 +27,7 @@ public AnswersOptions() /// question. /// /// User question to query against the knowledge base. - /// Max number of answers to be returned for the question. + /// Max number of answers to be returned for the question. /// Unique identifier for the user. /// Minimum threshold score for answers, value ranges from 0 to 1. /// Context object with previous QnA's information. @@ -65,12 +36,12 @@ public AnswersOptions() /// To configure Answer span prediction feature. /// (Optional) Flag to enable Query over Unstructured Sources. /// To fine tune query results. - /// Keeps track of any properties unknown to the library. - internal AnswersOptions(int? qnaId, string question, int? size, string userId, double? confidenceThreshold, KnowledgeBaseAnswerContext answerContext, RankerKind? rankerKind, QueryFilters filters, ShortAnswerOptions shortAnswerOptions, bool? includeUnstructuredSources, QueryPreferences queryPreferences, IDictionary serializedAdditionalRawData) + /// Keeps track of any properties unknown to the library. + internal AnswersOptions(int? qnaId, string question, int? top, string userId, double? confidenceThreshold, KnowledgeBaseAnswerContext answerContext, RankerKind? rankerKind, QueryFilters filters, ShortAnswerOptions shortAnswerOptions, bool? includeUnstructuredSources, QueryPreferences queryPreferences, IDictionary additionalBinaryDataProperties) { QnaId = qnaId; Question = question; - Size = size; + Top = top; UserId = userId; ConfidenceThreshold = confidenceThreshold; AnswerContext = answerContext; @@ -79,7 +50,7 @@ internal AnswersOptions(int? qnaId, string question, int? size, string userId, d ShortAnswerOptions = shortAnswerOptions; IncludeUnstructuredSources = includeUnstructuredSources; QueryPreferences = queryPreferences; - _serializedAdditionalRawData = serializedAdditionalRawData; + _additionalBinaryDataProperties = additionalBinaryDataProperties; } /// @@ -87,22 +58,34 @@ internal AnswersOptions(int? qnaId, string question, int? size, string userId, d /// question. /// public int? QnaId { get; set; } + /// User question to query against the knowledge base. public string Question { get; set; } + + /// Max number of answers to be returned for the question. + public int? Top { get; set; } + /// Unique identifier for the user. public string UserId { get; set; } + /// Minimum threshold score for answers, value ranges from 0 to 1. public double? ConfidenceThreshold { get; set; } + /// Context object with previous QnA's information. public KnowledgeBaseAnswerContext AnswerContext { get; set; } + /// Type of ranker to be used. public RankerKind? RankerKind { get; set; } + /// Filter QnAs based on given metadata list and knowledge base sources. public QueryFilters Filters { get; set; } + /// To configure Answer span prediction feature. public ShortAnswerOptions ShortAnswerOptions { get; set; } + /// (Optional) Flag to enable Query over Unstructured Sources. public bool? IncludeUnstructuredSources { get; set; } + /// To fine tune query results. public QueryPreferences QueryPreferences { get; set; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.Serialization.cs similarity index 50% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.Serialization.cs index 9044d4ad2749..fa264ccf5101 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/AnswersResult.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.Serialization.cs @@ -9,14 +9,15 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; +using Azure; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class AnswersResult : IUtf8JsonSerializable, IJsonModel + /// Represents List of Question Answers. + public partial class AnswersResult : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,31 +29,30 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpt /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersResult)} does not support writing '{format}' format."); } - if (Optional.IsCollectionDefined(Answers)) { writer.WritePropertyName("answers"u8); writer.WriteStartArray(); - foreach (var item in Answers) + foreach (KnowledgeBaseAnswer item in Answers) { writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -61,39 +61,43 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AnswersResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + AnswersResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual AnswersResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(AnswersResult)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeAnswersResult(document.RootElement, options); } - internal static AnswersResult DeserializeAnswersResult(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static AnswersResult DeserializeAnswersResult(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } - IReadOnlyList answers = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IList answers = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("answers"u8)) + if (prop.NameEquals("answers"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(KnowledgeBaseAnswer.DeserializeKnowledgeBaseAnswer(item, options)); } @@ -102,17 +106,19 @@ internal static AnswersResult DeserializeAnswersResult(JsonElement element, Mode } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new AnswersResult(answers ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new AnswersResult(answers ?? new ChangeTrackingList(), additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -122,15 +128,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions optio } } - AnswersResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + AnswersResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual AnswersResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeAnswersResult(document.RootElement, options); } default: @@ -138,22 +149,14 @@ AnswersResult IPersistableModel.Create(BinaryData data, ModelRead } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static AnswersResult FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAnswersResult(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() + /// The to deserialize the from. + public static explicit operator AnswersResult(Response response) { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; + using JsonDocument document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAnswersResult(document.RootElement, ModelSerializationExtensions.WireOptions); } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.cs new file mode 100644 index 000000000000..bb6539df4e0c --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AnswersResult.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Represents List of Question Answers. + public partial class AnswersResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + internal AnswersResult() + { + Answers = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// Represents Answer Result list. + /// Keeps track of any properties unknown to the library. + internal AnswersResult(IList answers, IDictionary additionalBinaryDataProperties) + { + Answers = answers; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Represents Answer Result list. + public IList Answers { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AzureAILanguageQuestionAnsweringInferenceContext.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AzureAILanguageQuestionAnsweringInferenceContext.cs index 09edc46d8010..3b44eb3774ce 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AzureAILanguageQuestionAnsweringInferenceContext.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/AzureAILanguageQuestionAnsweringInferenceContext.cs @@ -11,7 +11,7 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { /// /// Context class which will be filled in by the System.ClientModel.SourceGeneration. - /// For more information see 'https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/docs/ModelReaderWriterContext.md' + /// For more information /// [ModelReaderWriterBuildable(typeof(AnswersFromTextOptions))] [ModelReaderWriterBuildable(typeof(AnswersFromTextResult))] diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.Serialization.cs similarity index 53% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.Serialization.cs index 0d63be89bb10..5d9167245f2a 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class KnowledgeBaseAnswer : IUtf8JsonSerializable, IJsonModel + /// Represents knowledge base answer. + public partial class KnowledgeBaseAnswer : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,18 +28,22 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswer)} does not support writing '{format}' format."); } - if (Optional.IsCollectionDefined(Questions)) { writer.WritePropertyName("questions"u8); writer.WriteStartArray(); - foreach (var item in Questions) + foreach (string item in Questions) { + if (item == null) + { + writer.WriteNullValue(); + continue; + } writer.WriteStringValue(item); } writer.WriteEndArray(); @@ -71,6 +75,11 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit foreach (var item in Metadata) { writer.WritePropertyName(item.Key); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } writer.WriteStringValue(item.Value); } writer.WriteEndObject(); @@ -85,15 +94,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("answerSpan"u8); writer.WriteObjectValue(ShortAnswer, options); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -102,134 +111,154 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - KnowledgeBaseAnswer IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + KnowledgeBaseAnswer IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswer JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswer)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeKnowledgeBaseAnswer(document.RootElement, options); } - internal static KnowledgeBaseAnswer DeserializeKnowledgeBaseAnswer(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static KnowledgeBaseAnswer DeserializeKnowledgeBaseAnswer(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } - IReadOnlyList questions = default; + IList questions = default; string answer = default; - double? confidenceScore = default; - int? id = default; + double? confidence = default; + int? qnaId = default; string source = default; - IReadOnlyDictionary metadata = default; + IDictionary metadata = default; KnowledgeBaseAnswerDialog dialog = default; - AnswerSpan answerSpan = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + AnswerSpan shortAnswer = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("questions"u8)) + if (prop.NameEquals("questions"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { - array.Add(item.GetString()); + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString()); + } } questions = array; continue; } - if (property.NameEquals("answer"u8)) + if (prop.NameEquals("answer"u8)) { - answer = property.Value.GetString(); + answer = prop.Value.GetString(); continue; } - if (property.NameEquals("confidenceScore"u8)) + if (prop.NameEquals("confidenceScore"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - confidenceScore = property.Value.GetDouble(); + confidence = prop.Value.GetDouble(); continue; } - if (property.NameEquals("id"u8)) + if (prop.NameEquals("id"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - id = property.Value.GetInt32(); + qnaId = prop.Value.GetInt32(); continue; } - if (property.NameEquals("source"u8)) + if (prop.NameEquals("source"u8)) { - source = property.Value.GetString(); + source = prop.Value.GetString(); continue; } - if (property.NameEquals("metadata"u8)) + if (prop.NameEquals("metadata"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } Dictionary dictionary = new Dictionary(); - foreach (var property0 in property.Value.EnumerateObject()) + foreach (var prop0 in prop.Value.EnumerateObject()) { - dictionary.Add(property0.Name, property0.Value.GetString()); + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } } metadata = dictionary; continue; } - if (property.NameEquals("dialog"u8)) + if (prop.NameEquals("dialog"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - dialog = KnowledgeBaseAnswerDialog.DeserializeKnowledgeBaseAnswerDialog(property.Value, options); + dialog = KnowledgeBaseAnswerDialog.DeserializeKnowledgeBaseAnswerDialog(prop.Value, options); continue; } - if (property.NameEquals("answerSpan"u8)) + if (prop.NameEquals("answerSpan"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - answerSpan = AnswerSpan.DeserializeAnswerSpan(property.Value, options); + shortAnswer = AnswerSpan.DeserializeAnswerSpan(prop.Value, options); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; return new KnowledgeBaseAnswer( questions ?? new ChangeTrackingList(), answer, - confidenceScore, - id, + confidence, + qnaId, source, metadata ?? new ChangeTrackingDictionary(), dialog, - answerSpan, - serializedAdditionalRawData); + shortAnswer, + additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -239,15 +268,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions } } - KnowledgeBaseAnswer IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + KnowledgeBaseAnswer IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswer PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeKnowledgeBaseAnswer(document.RootElement, options); } default: @@ -255,22 +289,7 @@ KnowledgeBaseAnswer IPersistableModel.Create(BinaryData dat } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static KnowledgeBaseAnswer FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeKnowledgeBaseAnswer(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.cs similarity index 57% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.cs index abbf0e479e0f..c3ca5b284aab 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswer.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswer.cs @@ -13,37 +13,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference /// Represents knowledge base answer. public partial class KnowledgeBaseAnswer { - /// - /// 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; + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; /// Initializes a new instance of . internal KnowledgeBaseAnswer() @@ -64,8 +35,8 @@ internal KnowledgeBaseAnswer() /// /// Dialog associated with Answer. /// Answer span object of QnA with respect to user's question. - /// Keeps track of any properties unknown to the library. - internal KnowledgeBaseAnswer(IReadOnlyList questions, string answer, double? confidence, int? qnaId, string source, IReadOnlyDictionary metadata, KnowledgeBaseAnswerDialog dialog, AnswerSpan shortAnswer, IDictionary serializedAdditionalRawData) + /// Keeps track of any properties unknown to the library. + internal KnowledgeBaseAnswer(IList questions, string answer, double? confidence, int? qnaId, string source, IDictionary metadata, KnowledgeBaseAnswerDialog dialog, AnswerSpan shortAnswer, IDictionary additionalBinaryDataProperties) { Questions = questions; Answer = answer; @@ -75,26 +46,33 @@ internal KnowledgeBaseAnswer(IReadOnlyList questions, string answer, dou Metadata = metadata; Dialog = dialog; ShortAnswer = shortAnswer; - _serializedAdditionalRawData = serializedAdditionalRawData; + _additionalBinaryDataProperties = additionalBinaryDataProperties; } /// List of questions associated with the answer. - public IReadOnlyList Questions { get; } + public IList Questions { get; } + /// Answer text. public string Answer { get; } + /// Answer confidence score, value ranges from 0 to 1. public double? Confidence { get; } + /// ID of the QnA result. public int? QnaId { get; } + /// Source of QnA result. public string Source { get; } + /// /// Metadata associated with the answer, useful to categorize or filter question /// answers. /// - public IReadOnlyDictionary Metadata { get; } + public IDictionary Metadata { get; } + /// Dialog associated with Answer. public KnowledgeBaseAnswerDialog Dialog { get; } + /// Answer span object of QnA with respect to user's question. public AnswerSpan ShortAnswer { get; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.Serialization.cs similarity index 51% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.Serialization.cs index 660f71a0bd57..3c994b7ff092 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerContext.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.Serialization.cs @@ -9,14 +9,19 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class KnowledgeBaseAnswerContext : IUtf8JsonSerializable, IJsonModel + /// Context object with previous QnA's information. + public partial class KnowledgeBaseAnswerContext : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + /// Initializes a new instance of for deserialization. + internal KnowledgeBaseAnswerContext() + { + } + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +33,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRe /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerContext)} does not support writing '{format}' format."); } - writer.WritePropertyName("previousQnaId"u8); writer.WriteNumberValue(PreviousQnaId); if (Optional.IsDefined(PreviousQuestion)) @@ -41,15 +45,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("previousUserQuery"u8); writer.WriteStringValue(PreviousQuestion); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -58,55 +62,61 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - KnowledgeBaseAnswerContext IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + KnowledgeBaseAnswerContext IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerContext JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerContext)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeKnowledgeBaseAnswerContext(document.RootElement, options); } - internal static KnowledgeBaseAnswerContext DeserializeKnowledgeBaseAnswerContext(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static KnowledgeBaseAnswerContext DeserializeKnowledgeBaseAnswerContext(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } int previousQnaId = default; - string previousUserQuery = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + string previousQuestion = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("previousQnaId"u8)) + if (prop.NameEquals("previousQnaId"u8)) { - previousQnaId = property.Value.GetInt32(); + previousQnaId = prop.Value.GetInt32(); continue; } - if (property.NameEquals("previousUserQuery"u8)) + if (prop.NameEquals("previousUserQuery"u8)) { - previousUserQuery = property.Value.GetString(); + previousQuestion = prop.Value.GetString(); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new KnowledgeBaseAnswerContext(previousQnaId, previousUserQuery, serializedAdditionalRawData); + return new KnowledgeBaseAnswerContext(previousQnaId, previousQuestion, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -116,15 +126,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriter } } - KnowledgeBaseAnswerContext IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + KnowledgeBaseAnswerContext IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerContext PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeKnowledgeBaseAnswerContext(document.RootElement, options); } default: @@ -132,22 +147,7 @@ KnowledgeBaseAnswerContext IPersistableModel.Create( } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static KnowledgeBaseAnswerContext FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeKnowledgeBaseAnswerContext(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.cs new file mode 100644 index 000000000000..c833145f3033 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerContext.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Context object with previous QnA's information. + public partial class KnowledgeBaseAnswerContext + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Previous turn top answer result QnA ID. + public KnowledgeBaseAnswerContext(int previousQnaId) + { + PreviousQnaId = previousQnaId; + } + + /// Initializes a new instance of . + /// Previous turn top answer result QnA ID. + /// Previous user query. + /// Keeps track of any properties unknown to the library. + internal KnowledgeBaseAnswerContext(int previousQnaId, string previousQuestion, IDictionary additionalBinaryDataProperties) + { + PreviousQnaId = previousQnaId; + PreviousQuestion = previousQuestion; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Previous turn top answer result QnA ID. + public int PreviousQnaId { get; } + + /// Previous user query. + public string PreviousQuestion { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.Serialization.cs similarity index 55% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.Serialization.cs index c763ba12cab2..68f85ff2af47 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerDialog.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class KnowledgeBaseAnswerDialog : IUtf8JsonSerializable, IJsonModel + /// Dialog associated with Answer. + public partial class KnowledgeBaseAnswerDialog : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRea /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerDialog)} does not support writing '{format}' format."); } - if (Optional.IsDefined(IsContextOnly)) { writer.WritePropertyName("isContextOnly"u8); @@ -43,21 +42,21 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WritePropertyName("prompts"u8); writer.WriteStartArray(); - foreach (var item in Prompts) + foreach (KnowledgeBaseAnswerPrompt item in Prompts) { writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -66,49 +65,53 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - KnowledgeBaseAnswerDialog IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + KnowledgeBaseAnswerDialog IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerDialog JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerDialog)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeKnowledgeBaseAnswerDialog(document.RootElement, options); } - internal static KnowledgeBaseAnswerDialog DeserializeKnowledgeBaseAnswerDialog(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static KnowledgeBaseAnswerDialog DeserializeKnowledgeBaseAnswerDialog(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } bool? isContextOnly = default; - IReadOnlyList prompts = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IList prompts = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("isContextOnly"u8)) + if (prop.NameEquals("isContextOnly"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - isContextOnly = property.Value.GetBoolean(); + isContextOnly = prop.Value.GetBoolean(); continue; } - if (property.NameEquals("prompts"u8)) + if (prop.NameEquals("prompts"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(KnowledgeBaseAnswerPrompt.DeserializeKnowledgeBaseAnswerPrompt(item, options)); } @@ -117,17 +120,19 @@ internal static KnowledgeBaseAnswerDialog DeserializeKnowledgeBaseAnswerDialog(J } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new KnowledgeBaseAnswerDialog(isContextOnly, prompts ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new KnowledgeBaseAnswerDialog(isContextOnly, prompts ?? new ChangeTrackingList(), additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -137,15 +142,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO } } - KnowledgeBaseAnswerDialog IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + KnowledgeBaseAnswerDialog IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerDialog PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeKnowledgeBaseAnswerDialog(document.RootElement, options); } default: @@ -153,22 +163,7 @@ KnowledgeBaseAnswerDialog IPersistableModel.Create(Bi } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static KnowledgeBaseAnswerDialog FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeKnowledgeBaseAnswerDialog(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.cs new file mode 100644 index 000000000000..377295b32286 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerDialog.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Dialog associated with Answer. + public partial class KnowledgeBaseAnswerDialog + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + internal KnowledgeBaseAnswerDialog() + { + Prompts = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// + /// To mark if a prompt is relevant only with a previous question or not. If true, + /// do not include this QnA as search result for queries without context; + /// otherwise, if false, ignores context and includes this QnA in search result. + /// + /// List of prompts associated with the answer. + /// Keeps track of any properties unknown to the library. + internal KnowledgeBaseAnswerDialog(bool? isContextOnly, IList prompts, IDictionary additionalBinaryDataProperties) + { + IsContextOnly = isContextOnly; + Prompts = prompts; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// + /// To mark if a prompt is relevant only with a previous question or not. If true, + /// do not include this QnA as search result for queries without context; + /// otherwise, if false, ignores context and includes this QnA in search result. + /// + public bool? IsContextOnly { get; } + + /// List of prompts associated with the answer. + public IList Prompts { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.Serialization.cs similarity index 53% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.Serialization.cs index c7dd3ad84755..4f9880e30ff4 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/KnowledgeBaseAnswerPrompt.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class KnowledgeBaseAnswerPrompt : IUtf8JsonSerializable, IJsonModel + /// Prompt for an answer. + public partial class KnowledgeBaseAnswerPrompt : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRea /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerPrompt)} does not support writing '{format}' format."); } - if (Optional.IsDefined(DisplayOrder)) { writer.WritePropertyName("displayOrder"u8); @@ -49,15 +48,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("displayText"u8); writer.WriteStringValue(DisplayText); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -66,69 +65,75 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - KnowledgeBaseAnswerPrompt IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + KnowledgeBaseAnswerPrompt IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerPrompt JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(KnowledgeBaseAnswerPrompt)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeKnowledgeBaseAnswerPrompt(document.RootElement, options); } - internal static KnowledgeBaseAnswerPrompt DeserializeKnowledgeBaseAnswerPrompt(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static KnowledgeBaseAnswerPrompt DeserializeKnowledgeBaseAnswerPrompt(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } int? displayOrder = default; - int? qnaId = default; + int? id = default; string displayText = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("displayOrder"u8)) + if (prop.NameEquals("displayOrder"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - displayOrder = property.Value.GetInt32(); + displayOrder = prop.Value.GetInt32(); continue; } - if (property.NameEquals("qnaId"u8)) + if (prop.NameEquals("qnaId"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - qnaId = property.Value.GetInt32(); + id = prop.Value.GetInt32(); continue; } - if (property.NameEquals("displayText"u8)) + if (prop.NameEquals("displayText"u8)) { - displayText = property.Value.GetString(); + displayText = prop.Value.GetString(); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new KnowledgeBaseAnswerPrompt(displayOrder, qnaId, displayText, serializedAdditionalRawData); + return new KnowledgeBaseAnswerPrompt(displayOrder, id, displayText, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -138,15 +143,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterO } } - KnowledgeBaseAnswerPrompt IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + KnowledgeBaseAnswerPrompt IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual KnowledgeBaseAnswerPrompt PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeKnowledgeBaseAnswerPrompt(document.RootElement, options); } default: @@ -154,22 +164,7 @@ KnowledgeBaseAnswerPrompt IPersistableModel.Create(Bi } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static KnowledgeBaseAnswerPrompt FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeKnowledgeBaseAnswerPrompt(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.cs new file mode 100644 index 000000000000..1df3420c5bd7 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/KnowledgeBaseAnswerPrompt.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Prompt for an answer. + public partial class KnowledgeBaseAnswerPrompt + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + internal KnowledgeBaseAnswerPrompt() + { + } + + /// Initializes a new instance of . + /// Index of the prompt - used in ordering of the prompts. + /// QnA ID corresponding to the prompt. + /// Text displayed to represent a follow up question prompt. + /// Keeps track of any properties unknown to the library. + internal KnowledgeBaseAnswerPrompt(int? displayOrder, int? id, string displayText, IDictionary additionalBinaryDataProperties) + { + DisplayOrder = displayOrder; + Id = id; + DisplayText = displayText; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Index of the prompt - used in ordering of the prompts. + public int? DisplayOrder { get; } + + /// QnA ID corresponding to the prompt. + public int? Id { get; } + + /// Text displayed to represent a follow up question prompt. + public string DisplayText { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LogicalOperationKind.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/LogicalOperationKind.cs similarity index 67% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LogicalOperationKind.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/LogicalOperationKind.cs index a7af3d99b6e1..159216ec14ff 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/LogicalOperationKind.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/LogicalOperationKind.cs @@ -14,38 +14,57 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public readonly partial struct LogicalOperationKind : IEquatable { private readonly string _value; + /// 'AND' for using corresponding logical operation. + private const string ANDValue = "AND"; + /// Set 'OR' for using corresponding logical operation. + private const string ORValue = "OR"; /// Initializes a new instance of . + /// The value. /// is null. public LogicalOperationKind(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string ANDValue = "AND"; - private const string ORValue = "OR"; + _value = value; + } /// 'AND' for using corresponding logical operation. public static LogicalOperationKind AND { get; } = new LogicalOperationKind(ANDValue); + /// Set 'OR' for using corresponding logical operation. public static LogicalOperationKind OR { get; } = new LogicalOperationKind(ORValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(LogicalOperationKind left, LogicalOperationKind right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(LogicalOperationKind left, LogicalOperationKind right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator LogicalOperationKind(string value) => new LogicalOperationKind(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator LogicalOperationKind?(string value) => value == null ? null : new LogicalOperationKind(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is LogicalOperationKind other && Equals(other); - /// + + /// public bool Equals(LogicalOperationKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.Serialization.cs new file mode 100644 index 000000000000..37108bc0402d --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.Serialization.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// + /// Specify parameters for query matching + /// Please note this is the abstract base class. The derived classes available for instantiation are: . + /// + [PersistableModelProxy(typeof(UnknownMatchingPolicy))] + public abstract partial class MatchingPolicy : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal MatchingPolicy() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{format}' format."); + } + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(Kind.ToString()); + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + 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 + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + MatchingPolicy IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual MatchingPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMatchingPolicy(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static MatchingPolicy DeserializeMatchingPolicy(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("kind"u8, out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "Prebuilt": + return PrebuiltQueryMatchingPolicy.DeserializePrebuiltQueryMatchingPolicy(element, options); + } + } + return UnknownMatchingPolicy.DeserializeUnknownMatchingPolicy(element, options); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); + default: + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + MatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual MatchingPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) + { + return DeserializeMatchingPolicy(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.cs new file mode 100644 index 000000000000..2ab75bf7f19c --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicy.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// + /// Specify parameters for query matching + /// Please note this is the abstract base class. The derived classes available for instantiation are: . + /// + public abstract partial class MatchingPolicy + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Kind of matching policy to be applied. + private protected MatchingPolicy(MatchingPolicyKind kind) + { + Kind = kind; + } + + /// Initializes a new instance of . + /// Kind of matching policy to be applied. + /// Keeps track of any properties unknown to the library. + internal MatchingPolicy(MatchingPolicyKind kind, IDictionary additionalBinaryDataProperties) + { + Kind = kind; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Kind of matching policy to be applied. + internal MatchingPolicyKind Kind { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyFieldsType.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyFieldsType.cs similarity index 68% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyFieldsType.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyFieldsType.cs index 2d0e9c185e68..8efbc82552d1 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyFieldsType.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyFieldsType.cs @@ -14,38 +14,57 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public readonly partial struct MatchingPolicyFieldsType : IEquatable { private readonly string _value; + /// Include 'Questions' field. + private const string QuestionsValue = "Questions"; + /// Include 'Answer' field. + private const string AnswerValue = "Answer"; /// Initializes a new instance of . + /// The value. /// is null. public MatchingPolicyFieldsType(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string QuestionsValue = "Questions"; - private const string AnswerValue = "Answer"; + _value = value; + } /// Include 'Questions' field. public static MatchingPolicyFieldsType Questions { get; } = new MatchingPolicyFieldsType(QuestionsValue); + /// Include 'Answer' field. public static MatchingPolicyFieldsType Answer { get; } = new MatchingPolicyFieldsType(AnswerValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(MatchingPolicyFieldsType left, MatchingPolicyFieldsType right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(MatchingPolicyFieldsType left, MatchingPolicyFieldsType right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator MatchingPolicyFieldsType(string value) => new MatchingPolicyFieldsType(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator MatchingPolicyFieldsType?(string value) => value == null ? null : new MatchingPolicyFieldsType(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is MatchingPolicyFieldsType other && Equals(other); - /// + + /// public bool Equals(MatchingPolicyFieldsType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyKind.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyKind.cs similarity index 65% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyKind.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyKind.cs index fc61bac8ba82..730916b8b51c 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MatchingPolicyKind.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MatchingPolicyKind.cs @@ -14,35 +14,52 @@ namespace Azure.AI.Language.QuestionAnswering.Inference internal readonly partial struct MatchingPolicyKind : IEquatable { private readonly string _value; + /// Prebuilt weights will be used for giving preference to question and answer columns when quering AI search. + private const string PrebuiltValue = "Prebuilt"; /// Initializes a new instance of . + /// The value. /// is null. public MatchingPolicyKind(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string PrebuiltValue = "Prebuilt"; + _value = value; + } /// Prebuilt weights will be used for giving preference to question and answer columns when quering AI search. public static MatchingPolicyKind Prebuilt { get; } = new MatchingPolicyKind(PrebuiltValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(MatchingPolicyKind left, MatchingPolicyKind right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(MatchingPolicyKind left, MatchingPolicyKind right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator MatchingPolicyKind(string value) => new MatchingPolicyKind(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator MatchingPolicyKind?(string value) => value == null ? null : new MatchingPolicyKind(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is MatchingPolicyKind other && Equals(other); - /// + + /// public bool Equals(MatchingPolicyKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.Serialization.cs similarity index 52% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.Serialization.cs index 6845c038d9fb..379997eeee1f 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/MetadataFilter.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class MetadataFilter : IUtf8JsonSerializable, IJsonModel + /// Find QnAs that are associated with the given list of metadata. + public partial class MetadataFilter : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,17 +28,16 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(MetadataFilter)} does not support writing '{format}' format."); } - if (Optional.IsCollectionDefined(MetadataRecords)) { writer.WritePropertyName("metadata"u8); writer.WriteStartArray(); - foreach (var item in MetadataRecords) + foreach (MetadataRecord item in MetadataRecords) { writer.WriteObjectValue(item, options); } @@ -49,15 +48,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("logicalOperation"u8); writer.WriteStringValue(LogicalOperation.Value.ToString()); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -66,68 +65,74 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - MetadataFilter IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + MetadataFilter IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual MetadataFilter JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(MetadataFilter)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeMetadataFilter(document.RootElement, options); } - internal static MetadataFilter DeserializeMetadataFilter(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static MetadataFilter DeserializeMetadataFilter(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } - IList metadata = default; + IList metadataRecords = default; LogicalOperationKind? logicalOperation = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("metadata"u8)) + if (prop.NameEquals("metadata"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(MetadataRecord.DeserializeMetadataRecord(item, options)); } - metadata = array; + metadataRecords = array; continue; } - if (property.NameEquals("logicalOperation"u8)) + if (prop.NameEquals("logicalOperation"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - logicalOperation = new LogicalOperationKind(property.Value.GetString()); + logicalOperation = new LogicalOperationKind(prop.Value.GetString()); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new MetadataFilter(metadata ?? new ChangeTrackingList(), logicalOperation, serializedAdditionalRawData); + return new MetadataFilter(metadataRecords ?? new ChangeTrackingList(), logicalOperation, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -137,15 +142,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions opti } } - MetadataFilter IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + MetadataFilter IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual MetadataFilter PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeMetadataFilter(document.RootElement, options); } default: @@ -153,22 +163,7 @@ MetadataFilter IPersistableModel.Create(BinaryData data, ModelRe } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static MetadataFilter FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMetadataFilter(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.cs new file mode 100644 index 000000000000..2e95bb0d5756 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataFilter.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Find QnAs that are associated with the given list of metadata. + public partial class MetadataFilter + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public MetadataFilter() + { + MetadataRecords = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// Dictionary of string. + /// Operation used to join metadata filters. + /// Keeps track of any properties unknown to the library. + internal MetadataFilter(IList metadataRecords, LogicalOperationKind? logicalOperation, IDictionary additionalBinaryDataProperties) + { + MetadataRecords = metadataRecords; + LogicalOperation = logicalOperation; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Dictionary of string. + public IList MetadataRecords { get; } + + /// Operation used to join metadata filters. + public LogicalOperationKind? LogicalOperation { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.Serialization.cs new file mode 100644 index 000000000000..8f41e4aee2c7 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Object to provide the key value pair for each metadata. + public partial class MetadataRecord : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal MetadataRecord() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MetadataRecord)} does not support writing '{format}' format."); + } + writer.WritePropertyName("key"u8); + writer.WriteStringValue(Key); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Value); + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + 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 + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + MetadataRecord IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual MetadataRecord JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MetadataRecord)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMetadataRecord(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static MetadataRecord DeserializeMetadataRecord(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string key = default; + string value = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("key"u8)) + { + key = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("value"u8)) + { + value = prop.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new MetadataRecord(key, value, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); + default: + throw new FormatException($"The model {nameof(MetadataRecord)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + MetadataRecord IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual MetadataRecord PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) + { + return DeserializeMetadataRecord(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MetadataRecord)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.cs new file mode 100644 index 000000000000..6db6946b0ff5 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/MetadataRecord.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Object to provide the key value pair for each metadata. + public partial class MetadataRecord + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Metadata Key from Metadata dictionary used in the QnA. + /// Metadata Value from Metadata dictionary used in the QnA. + /// or is null. + public MetadataRecord(string key, string value) + { + Argument.AssertNotNull(key, nameof(key)); + Argument.AssertNotNull(value, nameof(value)); + + Key = key; + Value = value; + } + + /// Initializes a new instance of . + /// Metadata Key from Metadata dictionary used in the QnA. + /// Metadata Value from Metadata dictionary used in the QnA. + /// Keeps track of any properties unknown to the library. + internal MetadataRecord(string key, string value, IDictionary additionalBinaryDataProperties) + { + Key = key; + Value = value; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Metadata Key from Metadata dictionary used in the QnA. + public string Key { get; } + + /// Metadata Value from Metadata dictionary used in the QnA. + public string Value { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.Serialization.cs similarity index 52% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.Serialization.cs index b5f7dc9efeb4..ed5051378c29 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class PrebuiltQueryMatchingPolicy : IUtf8JsonSerializable, IJsonModel + /// Represents fields for Prebuilt query matching. Prebuilt weights will be used for giving preference to question and answer columns when quering AI search. + public partial class PrebuiltQueryMatchingPolicy : MatchingPolicy, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,18 +28,17 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelR /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(PrebuiltQueryMatchingPolicy)} does not support writing '{format}' format."); } - base.JsonModelWriteCore(writer, options); if (Optional.IsCollectionDefined(Fields)) { writer.WritePropertyName("fields"u8); writer.WriteStartArray(); - foreach (var item in Fields) + foreach (MatchingPolicyFieldsType item in Fields) { writer.WriteStringValue(item.ToString()); } @@ -52,74 +51,80 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri } } - PrebuiltQueryMatchingPolicy IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + PrebuiltQueryMatchingPolicy IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (PrebuiltQueryMatchingPolicy)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override MatchingPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(PrebuiltQueryMatchingPolicy)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializePrebuiltQueryMatchingPolicy(document.RootElement, options); } - internal static PrebuiltQueryMatchingPolicy DeserializePrebuiltQueryMatchingPolicy(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static PrebuiltQueryMatchingPolicy DeserializePrebuiltQueryMatchingPolicy(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } - IList fields = default; - bool? disableFullMatch = default; MatchingPolicyKind kind = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + IList fields = default; + bool? isFullMatchingDisabled = default; + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("fields"u8)) + if (prop.NameEquals("kind"u8)) + { + kind = new MatchingPolicyKind(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("fields"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { array.Add(new MatchingPolicyFieldsType(item.GetString())); } fields = array; continue; } - if (property.NameEquals("disableFullMatch"u8)) + if (prop.NameEquals("disableFullMatch"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - disableFullMatch = property.Value.GetBoolean(); - continue; - } - if (property.NameEquals("kind"u8)) - { - kind = new MatchingPolicyKind(property.Value.GetString()); + isFullMatchingDisabled = prop.Value.GetBoolean(); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new PrebuiltQueryMatchingPolicy(kind, serializedAdditionalRawData, fields ?? new ChangeTrackingList(), disableFullMatch); + return new PrebuiltQueryMatchingPolicy(kind, additionalBinaryDataProperties, fields ?? new ChangeTrackingList(), isFullMatchingDisabled); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -129,15 +134,20 @@ BinaryData IPersistableModel.Write(ModelReaderWrite } } - PrebuiltQueryMatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + PrebuiltQueryMatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (PrebuiltQueryMatchingPolicy)PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected override MatchingPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializePrebuiltQueryMatchingPolicy(document.RootElement, options); } default: @@ -145,22 +155,7 @@ PrebuiltQueryMatchingPolicy IPersistableModel.Creat } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static new PrebuiltQueryMatchingPolicy FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializePrebuiltQueryMatchingPolicy(document.RootElement); - } - - /// Convert into a . - internal override RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.cs similarity index 82% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.cs index 8e0a53db1423..27635d69e375 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/PrebuiltQueryMatchingPolicy.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/PrebuiltQueryMatchingPolicy.cs @@ -14,18 +14,17 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public partial class PrebuiltQueryMatchingPolicy : MatchingPolicy { /// Initializes a new instance of . - public PrebuiltQueryMatchingPolicy() + public PrebuiltQueryMatchingPolicy() : base(MatchingPolicyKind.Prebuilt) { - Kind = MatchingPolicyKind.Prebuilt; Fields = new ChangeTrackingList(); } /// Initializes a new instance of . /// Kind of matching policy to be applied. - /// Keeps track of any properties unknown to the library. + /// Keeps track of any properties unknown to the library. /// List of fields to filter during query. For ex if only "questions" is used then query will be filtered on that column. /// Disabling full match on query. Enabling this will give preference to qna pairs that have exact match. - internal PrebuiltQueryMatchingPolicy(MatchingPolicyKind kind, IDictionary serializedAdditionalRawData, IList fields, bool? isFullMatchingDisabled) : base(kind, serializedAdditionalRawData) + internal PrebuiltQueryMatchingPolicy(MatchingPolicyKind kind, IDictionary additionalBinaryDataProperties, IList fields, bool? isFullMatchingDisabled) : base(kind, additionalBinaryDataProperties) { Fields = fields; IsFullMatchingDisabled = isFullMatchingDisabled; @@ -33,6 +32,7 @@ internal PrebuiltQueryMatchingPolicy(MatchingPolicyKind kind, IDictionary List of fields to filter during query. For ex if only "questions" is used then query will be filtered on that column. public IList Fields { get; } + /// Disabling full match on query. Enabling this will give preference to qna pairs that have exact match. public bool? IsFullMatchingDisabled { get; set; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.Serialization.cs similarity index 52% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.Serialization.cs index c54373c2f258..e3bb64b76ead 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class QueryFilters : IUtf8JsonSerializable, IJsonModel + /// filters over knowledge base. + public partial class QueryFilters : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(QueryFilters)} does not support writing '{format}' format."); } - if (Optional.IsDefined(MetadataFilter)) { writer.WritePropertyName("metadataFilter"u8); @@ -43,8 +42,13 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WritePropertyName("sourceFilter"u8); writer.WriteStartArray(); - foreach (var item in SourceFilter) + foreach (string item in SourceFilter) { + if (item == null) + { + writer.WriteNullValue(); + continue; + } writer.WriteStringValue(item); } writer.WriteEndArray(); @@ -54,15 +58,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("logicalOperation"u8); writer.WriteStringValue(LogicalOperation.Value.ToString()); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -71,22 +75,27 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - QueryFilters IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + QueryFilters IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual QueryFilters JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(QueryFilters)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeQueryFilters(document.RootElement, options); } - internal static QueryFilters DeserializeQueryFilters(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static QueryFilters DeserializeQueryFilters(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; @@ -94,55 +103,63 @@ internal static QueryFilters DeserializeQueryFilters(JsonElement element, ModelR MetadataFilter metadataFilter = default; IList sourceFilter = default; LogicalOperationKind? logicalOperation = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("metadataFilter"u8)) + if (prop.NameEquals("metadataFilter"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - metadataFilter = MetadataFilter.DeserializeMetadataFilter(property.Value, options); + metadataFilter = MetadataFilter.DeserializeMetadataFilter(prop.Value, options); continue; } - if (property.NameEquals("sourceFilter"u8)) + if (prop.NameEquals("sourceFilter"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + foreach (var item in prop.Value.EnumerateArray()) { - array.Add(item.GetString()); + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString()); + } } sourceFilter = array; continue; } - if (property.NameEquals("logicalOperation"u8)) + if (prop.NameEquals("logicalOperation"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - logicalOperation = new LogicalOperationKind(property.Value.GetString()); + logicalOperation = new LogicalOperationKind(prop.Value.GetString()); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new QueryFilters(metadataFilter, sourceFilter ?? new ChangeTrackingList(), logicalOperation, serializedAdditionalRawData); + return new QueryFilters(metadataFilter, sourceFilter ?? new ChangeTrackingList(), logicalOperation, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -152,15 +169,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions option } } - QueryFilters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + QueryFilters IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual QueryFilters PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeQueryFilters(document.RootElement, options); } default: @@ -168,22 +190,7 @@ QueryFilters IPersistableModel.Create(BinaryData data, ModelReader } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static QueryFilters FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeQueryFilters(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.cs similarity index 53% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.cs index 19c3ccb64a87..431ca303dbf8 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryFilters.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryFilters.cs @@ -13,37 +13,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference /// filters over knowledge base. public partial class QueryFilters { - /// - /// 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; + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; /// Initializes a new instance of . public QueryFilters() @@ -58,22 +29,24 @@ public QueryFilters() /// knowledge base. /// /// Logical operation used to join metadata filter with source filter. - /// Keeps track of any properties unknown to the library. - internal QueryFilters(MetadataFilter metadataFilter, IList sourceFilter, LogicalOperationKind? logicalOperation, IDictionary serializedAdditionalRawData) + /// Keeps track of any properties unknown to the library. + internal QueryFilters(MetadataFilter metadataFilter, IList sourceFilter, LogicalOperationKind? logicalOperation, IDictionary additionalBinaryDataProperties) { MetadataFilter = metadataFilter; SourceFilter = sourceFilter; LogicalOperation = logicalOperation; - _serializedAdditionalRawData = serializedAdditionalRawData; + _additionalBinaryDataProperties = additionalBinaryDataProperties; } /// Find QnAs that are associated with the given list of metadata. public MetadataFilter MetadataFilter { get; set; } + /// /// Find QnAs that are associated with any of the given list of sources in /// knowledge base. /// public IList SourceFilter { get; } + /// Logical operation used to join metadata filter with source filter. public LogicalOperationKind? LogicalOperation { get; set; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.Serialization.cs similarity index 52% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.Serialization.cs index b7e49f86b254..854512ac2d80 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class QueryPreferences : IUtf8JsonSerializable, IJsonModel + /// Additional properties to fine tune query results. + public partial class QueryPreferences : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(QueryPreferences)} does not support writing '{format}' format."); } - if (Optional.IsDefined(Scorer)) { writer.WritePropertyName("scorer"u8); @@ -44,15 +43,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("matchingPolicy"u8); writer.WriteObjectValue(MatchingPolicy, options); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -61,63 +60,69 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - QueryPreferences IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + QueryPreferences IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual QueryPreferences JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(QueryPreferences)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeQueryPreferences(document.RootElement, options); } - internal static QueryPreferences DeserializeQueryPreferences(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static QueryPreferences DeserializeQueryPreferences(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } Scorer? scorer = default; MatchingPolicy matchingPolicy = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("scorer"u8)) + if (prop.NameEquals("scorer"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - scorer = new Scorer(property.Value.GetString()); + scorer = new Scorer(prop.Value.GetString()); continue; } - if (property.NameEquals("matchingPolicy"u8)) + if (prop.NameEquals("matchingPolicy"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - matchingPolicy = MatchingPolicy.DeserializeMatchingPolicy(property.Value, options); + matchingPolicy = MatchingPolicy.DeserializeMatchingPolicy(prop.Value, options); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; - return new QueryPreferences(scorer, matchingPolicy, serializedAdditionalRawData); + return new QueryPreferences(scorer, matchingPolicy, additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -127,15 +132,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions op } } - QueryPreferences IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + QueryPreferences IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual QueryPreferences PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeQueryPreferences(document.RootElement, options); } default: @@ -143,22 +153,7 @@ QueryPreferences IPersistableModel.Create(BinaryData data, Mod } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static QueryPreferences FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeQueryPreferences(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.cs new file mode 100644 index 000000000000..c8f1de0fc018 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/QueryPreferences.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Additional properties to fine tune query results. + public partial class QueryPreferences + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public QueryPreferences() + { + } + + /// Initializes a new instance of . + /// To specify what scoring algorithm is preferred. + /// Policy for controling exact query match behavior. + /// Keeps track of any properties unknown to the library. + internal QueryPreferences(Scorer? scorer, MatchingPolicy matchingPolicy, IDictionary additionalBinaryDataProperties) + { + Scorer = scorer; + MatchingPolicy = matchingPolicy; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// To specify what scoring algorithm is preferred. + public Scorer? Scorer { get; set; } + + /// Policy for controling exact query match behavior. + public MatchingPolicy MatchingPolicy { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/RankerKind.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/RankerKind.cs similarity index 67% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/RankerKind.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/RankerKind.cs index 94f3bf021035..9b1989e6aa48 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/RankerKind.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/RankerKind.cs @@ -14,38 +14,57 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public readonly partial struct RankerKind : IEquatable { private readonly string _value; + /// Question only ranker. + private const string QuestionOnlyValue = "QuestionOnly"; + /// Default ranker. + private const string DefaultValue = "Default"; /// Initializes a new instance of . + /// The value. /// is null. public RankerKind(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string QuestionOnlyValue = "QuestionOnly"; - private const string DefaultValue = "Default"; + _value = value; + } /// Question only ranker. public static RankerKind QuestionOnly { get; } = new RankerKind(QuestionOnlyValue); + /// Default ranker. public static RankerKind Default { get; } = new RankerKind(DefaultValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(RankerKind left, RankerKind right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(RankerKind left, RankerKind right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator RankerKind(string value) => new RankerKind(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator RankerKind?(string value) => value == null ? null : new RankerKind(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is RankerKind other && Equals(other); - /// + + /// public bool Equals(RankerKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Scorer.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/Scorer.cs similarity index 65% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Scorer.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/Scorer.cs index 027d9b9f0457..f8e9e4430ba9 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Scorer.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/Scorer.cs @@ -14,41 +14,62 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public readonly partial struct Scorer : IEquatable { private readonly string _value; + /// Set this value for scoring based on classic algorithms like wordnet, tfidf, ngram etc. + private const string ClassicValue = "Classic"; + /// Set this value for scoring based on transformer based models. + private const string TransformerValue = "Transformer"; + /// Set this scorer to use AI search semantic based ranking. Semantic ranking should be configured for this to be used. + private const string SemanticValue = "Semantic"; /// Initializes a new instance of . + /// The value. /// is null. public Scorer(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string ClassicValue = "Classic"; - private const string TransformerValue = "Transformer"; - private const string SemanticValue = "Semantic"; + _value = value; + } /// Set this value for scoring based on classic algorithms like wordnet, tfidf, ngram etc. public static Scorer Classic { get; } = new Scorer(ClassicValue); + /// Set this value for scoring based on transformer based models. public static Scorer Transformer { get; } = new Scorer(TransformerValue); + /// Set this scorer to use AI search semantic based ranking. Semantic ranking should be configured for this to be used. public static Scorer Semantic { get; } = new Scorer(SemanticValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(Scorer left, Scorer right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(Scorer left, Scorer right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator Scorer(string value) => new Scorer(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator Scorer?(string value) => value == null ? null : new Scorer(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is Scorer other && Equals(other); - /// + + /// public bool Equals(Scorer other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.Serialization.cs new file mode 100644 index 000000000000..eb8cf44fbcd8 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.Serialization.cs @@ -0,0 +1,172 @@ +// 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; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// To configure Answer span prediction feature. + public partial class ShortAnswerOptions : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal ShortAnswerOptions() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support writing '{format}' format."); + } + writer.WritePropertyName("enable"u8); + writer.WriteBooleanValue(IsEnabled); + if (Optional.IsDefined(ConfidenceThreshold)) + { + writer.WritePropertyName("confidenceScoreThreshold"u8); + writer.WriteNumberValue(ConfidenceThreshold.Value); + } + if (Optional.IsDefined(Top)) + { + writer.WritePropertyName("topAnswersWithSpan"u8); + writer.WriteNumberValue(Top.Value); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + 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 + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + ShortAnswerOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual ShortAnswerOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeShortAnswerOptions(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static ShortAnswerOptions DeserializeShortAnswerOptions(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool isEnabled = default; + double? confidenceThreshold = default; + int? top = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("enable"u8)) + { + isEnabled = prop.Value.GetBoolean(); + continue; + } + if (prop.NameEquals("confidenceScoreThreshold"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + confidenceThreshold = prop.Value.GetDouble(); + continue; + } + if (prop.NameEquals("topAnswersWithSpan"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + top = prop.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new ShortAnswerOptions(isEnabled, confidenceThreshold, top, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); + default: + throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + ShortAnswerOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual ShortAnswerOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) + { + return DeserializeShortAnswerOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.cs new file mode 100644 index 000000000000..d38bf24b6887 --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/ShortAnswerOptions.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// To configure Answer span prediction feature. + public partial class ShortAnswerOptions + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Enable or disable Answer Span prediction. + public ShortAnswerOptions(bool isEnabled) + { + IsEnabled = isEnabled; + } + + /// Initializes a new instance of . + /// Enable or disable Answer Span prediction. + /// + /// Minimum threshold score required to include an answer span, value ranges from 0 + /// to 1. + /// + /// Number of Top answers to be considered for span prediction from 1 to 10. + /// Keeps track of any properties unknown to the library. + internal ShortAnswerOptions(bool isEnabled, double? confidenceThreshold, int? top, IDictionary additionalBinaryDataProperties) + { + IsEnabled = isEnabled; + ConfidenceThreshold = confidenceThreshold; + Top = top; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Enable or disable Answer Span prediction. + public bool IsEnabled { get; } + + /// + /// Minimum threshold score required to include an answer span, value ranges from 0 + /// to 1. + /// + public double? ConfidenceThreshold { get; set; } + + /// Number of Top answers to be considered for span prediction from 1 to 10. + public int? Top { get; set; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/StringIndexType.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/StringIndexType.cs similarity index 64% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/StringIndexType.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/StringIndexType.cs index 00124ace03f2..e7b6163ac750 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/StringIndexType.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/StringIndexType.cs @@ -18,17 +18,35 @@ namespace Azure.AI.Language.QuestionAnswering.Inference public readonly partial struct StringIndexType : IEquatable { private readonly string _value; + /// + /// Returned offset and length values will correspond to TextElements (Graphemes + /// and Grapheme clusters) confirming to the Unicode 8.0.0 standard. Use this + /// option if your application is written in .Net Framework or .Net Core and you + /// will be using StringInfo. + /// + private const string TextElementsV8Value = "TextElements_v8"; + /// + /// Returned offset and length values will correspond to Unicode code points. Use + /// this option if your application is written in a language that support Unicode, + /// for example Python. + /// + private const string UnicodeCodePointValue = "UnicodeCodePoint"; + /// + /// Returned offset and length values will correspond to UTF-16 code units. Use + /// this option if your application is written in a language that support Unicode, + /// for example Java, JavaScript. + /// + private const string Utf16CodeUnitValue = "Utf16CodeUnit"; /// Initializes a new instance of . + /// The value. /// is null. public StringIndexType(string value) { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } + Argument.AssertNotNull(value, nameof(value)); - private const string TextElementsV8Value = "TextElements_v8"; - private const string UnicodeCodePointValue = "UnicodeCodePoint"; - private const string Utf16CodeUnitValue = "Utf16CodeUnit"; + _value = value; + } /// /// Returned offset and length values will correspond to TextElements (Graphemes @@ -37,35 +55,51 @@ public StringIndexType(string value) /// will be using StringInfo. /// public static StringIndexType TextElementsV8 { get; } = new StringIndexType(TextElementsV8Value); + /// /// Returned offset and length values will correspond to Unicode code points. Use /// this option if your application is written in a language that support Unicode, /// for example Python. /// public static StringIndexType UnicodeCodePoint { get; } = new StringIndexType(UnicodeCodePointValue); + /// /// Returned offset and length values will correspond to UTF-16 code units. Use /// this option if your application is written in a language that support Unicode, /// for example Java, JavaScript. /// public static StringIndexType Utf16CodeUnit { get; } = new StringIndexType(Utf16CodeUnitValue); + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. public static bool operator ==(StringIndexType left, StringIndexType right) => left.Equals(right); + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. public static bool operator !=(StringIndexType left, StringIndexType right) => !left.Equals(right); - /// Converts a to a . + + /// Converts a string to a . + /// The value. public static implicit operator StringIndexType(string value) => new StringIndexType(value); - /// + /// Converts a string to a . + /// The value. + public static implicit operator StringIndexType?(string value) => value == null ? null : new StringIndexType(value); + + /// [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) => obj is StringIndexType other && Equals(other); - /// + + /// public bool Equals(StringIndexType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - /// + /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// + + /// public override string ToString() => _value; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.Serialization.cs similarity index 54% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.Serialization.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.Serialization.cs index 5400c62136da..1398fd973375 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.Serialization.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.Serialization.cs @@ -9,14 +9,14 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.AI.Language.QuestionAnswering.Inference { - public partial class TextAnswer : IUtf8JsonSerializable, IJsonModel + /// Represents answer result. + public partial class TextAnswer : IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - + /// The JSON writer. + /// The client options for reading and writing models. void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); @@ -28,12 +28,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOption /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(TextAnswer)} does not support writing '{format}' format."); } - if (Optional.IsDefined(Answer)) { writer.WritePropertyName("answer"u8); @@ -64,15 +63,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("length"u8); writer.WriteNumberValue(Length.Value); } - if (options.Format != "W" && _serializedAdditionalRawData != null) + if (options.Format != "W" && _additionalBinaryDataProperties != null) { - foreach (var item in _serializedAdditionalRawData) + foreach (var item in _additionalBinaryDataProperties) { writer.WritePropertyName(item.Key); #if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); + writer.WriteRawValue(item.Value); #else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + using (JsonDocument document = JsonDocument.Parse(item.Value)) { JsonSerializer.Serialize(writer, document.RootElement); } @@ -81,102 +80,108 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - TextAnswer IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + /// The JSON reader. + /// The client options for reading and writing models. + TextAnswer IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual TextAnswer JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { throw new FormatException($"The model {nameof(TextAnswer)} does not support reading '{format}' format."); } - using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeTextAnswer(document.RootElement, options); } - internal static TextAnswer DeserializeTextAnswer(JsonElement element, ModelReaderWriterOptions options = null) + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static TextAnswer DeserializeTextAnswer(JsonElement element, ModelReaderWriterOptions options) { - options ??= ModelSerializationExtensions.WireOptions; - if (element.ValueKind == JsonValueKind.Null) { return null; } string answer = default; - double? confidenceScore = default; + double? confidence = default; string id = default; - AnswerSpan answerSpan = default; + AnswerSpan shortAnswer = default; int? offset = default; int? length = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) { - if (property.NameEquals("answer"u8)) + if (prop.NameEquals("answer"u8)) { - answer = property.Value.GetString(); + answer = prop.Value.GetString(); continue; } - if (property.NameEquals("confidenceScore"u8)) + if (prop.NameEquals("confidenceScore"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - confidenceScore = property.Value.GetDouble(); + confidence = prop.Value.GetDouble(); continue; } - if (property.NameEquals("id"u8)) + if (prop.NameEquals("id"u8)) { - id = property.Value.GetString(); + id = prop.Value.GetString(); continue; } - if (property.NameEquals("answerSpan"u8)) + if (prop.NameEquals("answerSpan"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - answerSpan = AnswerSpan.DeserializeAnswerSpan(property.Value, options); + shortAnswer = AnswerSpan.DeserializeAnswerSpan(prop.Value, options); continue; } - if (property.NameEquals("offset"u8)) + if (prop.NameEquals("offset"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - offset = property.Value.GetInt32(); + offset = prop.Value.GetInt32(); continue; } - if (property.NameEquals("length"u8)) + if (prop.NameEquals("length"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + if (prop.Value.ValueKind == JsonValueKind.Null) { continue; } - length = property.Value.GetInt32(); + length = prop.Value.GetInt32(); continue; } if (options.Format != "W") { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); } } - serializedAdditionalRawData = rawDataDictionary; return new TextAnswer( answer, - confidenceScore, + confidence, id, - answerSpan, + shortAnswer, offset, length, - serializedAdditionalRawData); + additionalBinaryDataProperties); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": @@ -186,15 +191,20 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) } } - TextAnswer IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + /// The data to parse. + /// The client options for reading and writing models. + TextAnswer IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + /// The data to parse. + /// The client options for reading and writing models. + protected virtual TextAnswer PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); return DeserializeTextAnswer(document.RootElement, options); } default: @@ -202,22 +212,7 @@ TextAnswer IPersistableModel.Create(BinaryData data, ModelReaderWrit } } + /// The client options for reading and writing models. string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static TextAnswer FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeTextAnswer(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.cs similarity index 55% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.cs index 1e0a3d06d338..bcb2f9a87038 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextAnswer.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextAnswer.cs @@ -13,37 +13,8 @@ namespace Azure.AI.Language.QuestionAnswering.Inference /// Represents answer result. public partial class TextAnswer { - /// - /// 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; + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; /// Initializes a new instance of . internal TextAnswer() @@ -57,8 +28,8 @@ internal TextAnswer() /// Answer span object with respect to user's question. /// The sentence offset from the start of the document. /// The length of the sentence. - /// Keeps track of any properties unknown to the library. - internal TextAnswer(string answer, double? confidence, string id, AnswerSpan shortAnswer, int? offset, int? length, IDictionary serializedAdditionalRawData) + /// Keeps track of any properties unknown to the library. + internal TextAnswer(string answer, double? confidence, string id, AnswerSpan shortAnswer, int? offset, int? length, IDictionary additionalBinaryDataProperties) { Answer = answer; Confidence = confidence; @@ -66,19 +37,24 @@ internal TextAnswer(string answer, double? confidence, string id, AnswerSpan sho ShortAnswer = shortAnswer; Offset = offset; Length = length; - _serializedAdditionalRawData = serializedAdditionalRawData; + _additionalBinaryDataProperties = additionalBinaryDataProperties; } /// Answer. public string Answer { get; } + /// answer confidence score, value ranges from 0 to 1. public double? Confidence { get; } + /// record ID. public string Id { get; } + /// Answer span object with respect to user's question. public AnswerSpan ShortAnswer { get; } + /// The sentence offset from the start of the document. public int? Offset { get; } + /// The length of the sentence. public int? Length { get; } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.Serialization.cs new file mode 100644 index 000000000000..838145d0193e --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Represent input text record to be queried. + public partial class TextDocument : IJsonModel + { + /// Initializes a new instance of for deserialization. + internal TextDocument() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TextDocument)} does not support writing '{format}' format."); + } + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + 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 + } + } + } + + /// The JSON reader. + /// The client options for reading and writing models. + TextDocument IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual TextDocument JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TextDocument)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTextDocument(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static TextDocument DeserializeTextDocument(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string text = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + id = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("text"u8)) + { + text = prop.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new TextDocument(id, text, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); + default: + throw new FormatException($"The model {nameof(TextDocument)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + TextDocument IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual TextDocument PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) + { + return DeserializeTextDocument(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TextDocument)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.cs new file mode 100644 index 000000000000..b95ff4a0fa5c --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/TextDocument.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// Represent input text record to be queried. + public partial class TextDocument + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// Unique identifier for the text record. + /// Text contents of the record. + /// or is null. + public TextDocument(string id, string text) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(text, nameof(text)); + + Id = id; + Text = text; + } + + /// Initializes a new instance of . + /// Unique identifier for the text record. + /// Text contents of the record. + /// Keeps track of any properties unknown to the library. + internal TextDocument(string id, string text, IDictionary additionalBinaryDataProperties) + { + Id = id; + Text = text; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Unique identifier for the text record. + public string Id { get; } + + /// Text contents of the record. + public string Text { get; } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.Serialization.cs new file mode 100644 index 000000000000..e116927e17ba --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.Serialization.cs @@ -0,0 +1,125 @@ +// 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; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + internal partial class UnknownMatchingPolicy : MatchingPolicy, IJsonModel + { + /// Initializes a new instance of for deserialization. + internal UnknownMatchingPolicy() + { + } + + /// The JSON writer. + /// The client options for reading and writing models. + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + } + + /// The JSON reader. + /// The client options for reading and writing models. + MatchingPolicy IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override MatchingPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMatchingPolicy(document.RootElement, options); + } + + /// The JSON element to deserialize. + /// The client options for reading and writing models. + internal static UnknownMatchingPolicy DeserializeUnknownMatchingPolicy(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MatchingPolicyKind kind = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("kind"u8)) + { + kind = new MatchingPolicyKind(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new UnknownMatchingPolicy(kind, additionalBinaryDataProperties); + } + + /// The client options for reading and writing models. + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); + default: + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{options.Format}' format."); + } + } + + /// The data to parse. + /// The client options for reading and writing models. + MatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected override MatchingPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions)) + { + return DeserializeMatchingPolicy(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{options.Format}' format."); + } + } + + /// The client options for reading and writing models. + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.cs similarity index 55% rename from sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.cs rename to sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.cs index 6403144f2a07..9ad784cf95a8 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/Models/UnknownMatchingPolicy.cs @@ -10,18 +10,12 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - /// Unknown version of MatchingPolicy. internal partial class UnknownMatchingPolicy : MatchingPolicy { /// Initializes a new instance of . /// Kind of matching policy to be applied. - /// Keeps track of any properties unknown to the library. - internal UnknownMatchingPolicy(MatchingPolicyKind kind, IDictionary serializedAdditionalRawData) : base(kind, serializedAdditionalRawData) - { - } - - /// Initializes a new instance of for deserialization. - internal UnknownMatchingPolicy() + /// Keeps track of any properties unknown to the library. + internal UnknownMatchingPolicy(MatchingPolicyKind kind, IDictionary additionalBinaryDataProperties) : base(kind != default ? kind : "unknown", additionalBinaryDataProperties) { } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.cs deleted file mode 100644 index 37118ec525ad..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QueryPreferences.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Additional properties to fine tune query results. - public partial class QueryPreferences - { - /// - /// 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 QueryPreferences() - { - } - - /// Initializes a new instance of . - /// To specify what scoring algorithm is preferred. - /// - /// Policy for controling exact query match behavior - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - /// Keeps track of any properties unknown to the library. - internal QueryPreferences(Scorer? scorer, MatchingPolicy matchingPolicy, IDictionary serializedAdditionalRawData) - { - Scorer = scorer; - MatchingPolicy = matchingPolicy; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// To specify what scoring algorithm is preferred. - public Scorer? Scorer { get; set; } - /// - /// Policy for controling exact query match behavior - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include . - /// - public MatchingPolicy MatchingPolicy { get; set; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.RestClient.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.RestClient.cs new file mode 100644 index 000000000000..11351a67e72e --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.RestClient.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace Azure.AI.Language.QuestionAnswering.Inference +{ + /// + public partial class QuestionAnsweringClient + { + private static ResponseClassifier _pipelineMessageClassifier200; + + private static ResponseClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 = new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + internal HttpMessage CreateGetAnswersRequest(string projectName, string deploymentName, RequestContent content, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/language", false); + uri.AppendPath("/:query-knowledgebases", false); + uri.AppendQuery("api-version", _apiVersion, true); + uri.AppendQuery("projectName", projectName, true); + uri.AppendQuery("deploymentName", deploymentName, true); + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Post; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetAnswersFromTextRequest(RequestContent content, RequestContext context) + { + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/language", false); + uri.AppendPath("/:query-text", false); + uri.AppendQuery("api-version", _apiVersion, true); + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Uri = uri; + request.Method = RequestMethod.Post; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + } +} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.cs index 4bd352bb86a1..05081aac1d4f 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClient.cs @@ -8,104 +8,63 @@ using System; using System.Threading; using System.Threading.Tasks; +using Azure; using Azure.Core; using Azure.Core.Pipeline; namespace Azure.AI.Language.QuestionAnswering.Inference { - // Data plane generated client. - /// The QuestionAnswering service client. + /// The QuestionAnsweringClient. public partial class QuestionAnsweringClient { - private const string AuthorizationHeader = "Ocp-Apim-Subscription-Key"; + private readonly Uri _endpoint; + /// A credential used to authenticate to the service. private readonly AzureKeyCredential _keyCredential; - private static readonly string[] AuthorizationScopes = new string[] { "https://cognitiveservices.azure.com/.default" }; + private const string AuthorizationHeader = "Ocp-Apim-Subscription-Key"; + /// A credential used to authenticate to the service. private readonly TokenCredential _tokenCredential; - private readonly HttpPipeline _pipeline; - private readonly Uri _endpoint; + private static readonly string[] AuthorizationScopes = new string[] { "https://cognitiveservices.azure.com/.default" }; private readonly string _apiVersion; - /// The ClientDiagnostics is used to provide tracing support for the client library. - internal ClientDiagnostics ClientDiagnostics { get; } - - /// The HTTP pipeline for sending and receiving REST requests and responses. - public virtual HttpPipeline Pipeline => _pipeline; - /// Initializes a new instance of QuestionAnsweringClient for mocking. protected QuestionAnsweringClient() { } - /// Answers the specified question using your knowledge base. - /// The name of the project to use. - /// The name of the specific deployment of the project to use. - /// Post body of the request. - /// The cancellation token to use. - /// , or is null. - public virtual async Task> GetAnswersAsync(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(projectName, nameof(projectName)); - Argument.AssertNotNull(deploymentName, nameof(deploymentName)); - Argument.AssertNotNull(knowledgeBaseQueryOptions, nameof(knowledgeBaseQueryOptions)); - - using RequestContent content = knowledgeBaseQueryOptions.ToRequestContent(); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetAnswersAsync(projectName, deploymentName, content, context).ConfigureAwait(false); - return Response.FromValue(AnswersResult.FromResponse(response), response); - } - - /// Answers the specified question using your knowledge base. - /// The name of the project to use. - /// The name of the specific deployment of the project to use. - /// Post body of the request. - /// The cancellation token to use. - /// , or is null. - public virtual Response GetAnswers(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(projectName, nameof(projectName)); - Argument.AssertNotNull(deploymentName, nameof(deploymentName)); - Argument.AssertNotNull(knowledgeBaseQueryOptions, nameof(knowledgeBaseQueryOptions)); + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline { get; } - using RequestContent content = knowledgeBaseQueryOptions.ToRequestContent(); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetAnswers(projectName, deploymentName, content, context); - return Response.FromValue(AnswersResult.FromResponse(response), response); - } + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } /// /// [Protocol Method] Answers the specified question using your knowledge base. /// /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// /// /// The name of the project to use. /// The name of the specific deployment of the project to use. /// The content to send as the body of the request. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - public virtual async Task GetAnswersAsync(string projectName, string deploymentName, RequestContent content, RequestContext context = null) + public virtual Response GetAnswers(string projectName, string deploymentName, RequestContent content, RequestContext context = null) { - Argument.AssertNotNull(projectName, nameof(projectName)); - Argument.AssertNotNull(deploymentName, nameof(deploymentName)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswers"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswers"); scope.Start(); try { + Argument.AssertNotNullOrEmpty(projectName, nameof(projectName)); + Argument.AssertNotNullOrEmpty(deploymentName, nameof(deploymentName)); + Argument.AssertNotNull(content, nameof(content)); + using HttpMessage message = CreateGetAnswersRequest(projectName, deploymentName, content, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + return Pipeline.ProcessMessage(message, context); } catch (Exception e) { @@ -118,36 +77,30 @@ public virtual async Task GetAnswersAsync(string projectName, string d /// [Protocol Method] Answers the specified question using your knowledge base. /// /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// /// /// The name of the project to use. /// The name of the specific deployment of the project to use. /// The content to send as the body of the request. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - public virtual Response GetAnswers(string projectName, string deploymentName, RequestContent content, RequestContext context = null) + public virtual async Task GetAnswersAsync(string projectName, string deploymentName, RequestContent content, RequestContext context = null) { - Argument.AssertNotNull(projectName, nameof(projectName)); - Argument.AssertNotNull(deploymentName, nameof(deploymentName)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswers"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswers"); scope.Start(); try { + Argument.AssertNotNullOrEmpty(projectName, nameof(projectName)); + Argument.AssertNotNullOrEmpty(deploymentName, nameof(deploymentName)); + Argument.AssertNotNull(content, nameof(content)); + using HttpMessage message = CreateGetAnswersRequest(projectName, deploymentName, content, context); - return _pipeline.ProcessMessage(message, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) { @@ -156,64 +109,65 @@ public virtual Response GetAnswers(string projectName, string deploymentName, Re } } - /// Answers the specified question using the provided text in the body. - /// Post body of the request. - /// The cancellation token to use. - /// is null. - public virtual async Task> GetAnswersFromTextAsync(AnswersFromTextOptions textQueryOptions, CancellationToken cancellationToken = default) + /// Answers the specified question using your knowledge base. + /// The name of the project to use. + /// The name of the specific deployment of the project to use. + /// Post body of the request. + /// The cancellation token that can be used to cancel the operation. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + public virtual Response GetAnswers(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(textQueryOptions, nameof(textQueryOptions)); + Argument.AssertNotNullOrEmpty(projectName, nameof(projectName)); + Argument.AssertNotNullOrEmpty(deploymentName, nameof(deploymentName)); + Argument.AssertNotNull(knowledgeBaseQueryOptions, nameof(knowledgeBaseQueryOptions)); - using RequestContent content = textQueryOptions.ToRequestContent(); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetAnswersFromTextAsync(content, context).ConfigureAwait(false); - return Response.FromValue(AnswersFromTextResult.FromResponse(response), response); + Response result = GetAnswers(projectName, deploymentName, knowledgeBaseQueryOptions, cancellationToken.ToRequestContext()); + return Response.FromValue((AnswersResult)result, result); } - /// Answers the specified question using the provided text in the body. - /// Post body of the request. - /// The cancellation token to use. - /// is null. - public virtual Response GetAnswersFromText(AnswersFromTextOptions textQueryOptions, CancellationToken cancellationToken = default) + /// Answers the specified question using your knowledge base. + /// The name of the project to use. + /// The name of the specific deployment of the project to use. + /// Post body of the request. + /// The cancellation token that can be used to cancel the operation. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + public virtual async Task> GetAnswersAsync(string projectName, string deploymentName, AnswersOptions knowledgeBaseQueryOptions, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(textQueryOptions, nameof(textQueryOptions)); + Argument.AssertNotNullOrEmpty(projectName, nameof(projectName)); + Argument.AssertNotNullOrEmpty(deploymentName, nameof(deploymentName)); + Argument.AssertNotNull(knowledgeBaseQueryOptions, nameof(knowledgeBaseQueryOptions)); - using RequestContent content = textQueryOptions.ToRequestContent(); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetAnswersFromText(content, context); - return Response.FromValue(AnswersFromTextResult.FromResponse(response), response); + Response result = await GetAnswersAsync(projectName, deploymentName, knowledgeBaseQueryOptions, cancellationToken.ToRequestContext()).ConfigureAwait(false); + return Response.FromValue((AnswersResult)result, result); } /// /// [Protocol Method] Answers the specified question using the provided text in the body. /// /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// /// /// The content to send as the body of the request. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. /// The response returned from the service. - public virtual async Task GetAnswersFromTextAsync(RequestContent content, RequestContext context = null) + public virtual Response GetAnswersFromText(RequestContent content, RequestContext context = null) { - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswersFromText"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswersFromText"); scope.Start(); try { + Argument.AssertNotNull(content, nameof(content)); + using HttpMessage message = CreateGetAnswersFromTextRequest(content, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + return Pipeline.ProcessMessage(message, context); } catch (Exception e) { @@ -226,32 +180,25 @@ public virtual async Task GetAnswersFromTextAsync(RequestContent conte /// [Protocol Method] Answers the specified question using the provided text in the body. /// /// - /// - /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. - /// - /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// /// /// The content to send as the body of the request. - /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// Service returned a non-success status code. /// The response returned from the service. - public virtual Response GetAnswersFromText(RequestContent content, RequestContext context = null) + public virtual async Task GetAnswersFromTextAsync(RequestContent content, RequestContext context = null) { - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswersFromText"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope("QuestionAnsweringClient.GetAnswersFromText"); scope.Start(); try { + Argument.AssertNotNull(content, nameof(content)); + using HttpMessage message = CreateGetAnswersFromTextRequest(content, context); - return _pipeline.ProcessMessage(message, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) { @@ -260,54 +207,30 @@ public virtual Response GetAnswersFromText(RequestContent content, RequestContex } } - internal HttpMessage CreateGetAnswersRequest(string projectName, string deploymentName, RequestContent content, RequestContext context) + /// Answers the specified question using the provided text in the body. + /// Post body of the request. + /// The cancellation token that can be used to cancel the operation. + /// is null. + /// Service returned a non-success status code. + public virtual Response GetAnswersFromText(AnswersFromTextOptions textQueryOptions, CancellationToken cancellationToken = default) { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendRaw("/language", false); - uri.AppendPath("/:query-knowledgebases", false); - uri.AppendQuery("projectName", projectName, true); - uri.AppendQuery("deploymentName", deploymentName, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; - return message; - } + Argument.AssertNotNull(textQueryOptions, nameof(textQueryOptions)); - internal HttpMessage CreateGetAnswersFromTextRequest(RequestContent content, RequestContext context) - { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendRaw("/language", false); - uri.AppendPath("/:query-text", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; - return message; + Response result = GetAnswersFromText(textQueryOptions, cancellationToken.ToRequestContext()); + return Response.FromValue((AnswersFromTextResult)result, result); } - private static RequestContext DefaultRequestContext = new RequestContext(); - internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + /// Answers the specified question using the provided text in the body. + /// Post body of the request. + /// The cancellation token that can be used to cancel the operation. + /// is null. + /// Service returned a non-success status code. + public virtual async Task> GetAnswersFromTextAsync(AnswersFromTextOptions textQueryOptions, CancellationToken cancellationToken = default) { - if (!cancellationToken.CanBeCanceled) - { - return DefaultRequestContext; - } + Argument.AssertNotNull(textQueryOptions, nameof(textQueryOptions)); - return new RequestContext() { CancellationToken = cancellationToken }; + Response result = await GetAnswersFromTextAsync(textQueryOptions, cancellationToken.ToRequestContext()).ConfigureAwait(false); + return Response.FromValue((AnswersFromTextResult)result, result); } - - private static ResponseClassifier _responseClassifier200; - private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientOptions.cs index e5c57f9059e0..e76f74218baa 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientOptions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringClientOptions.cs @@ -10,23 +10,13 @@ namespace Azure.AI.Language.QuestionAnswering.Inference { - /// Client options for QuestionAnsweringClient. + /// Client options for . public partial class QuestionAnsweringClientOptions : ClientOptions { private const ServiceVersion LatestVersion = ServiceVersion.V2025_05_15_Preview; - /// The version of the service to use. - public enum ServiceVersion - { - /// Service version "2023-04-01". - V2023_04_01 = 1, - /// Service version "2025-05-15-preview". - V2025_05_15_Preview = 2, - } - - internal string Version { get; } - - /// Initializes new instance of QuestionAnsweringClientOptions. + /// Initializes a new instance of QuestionAnsweringClientOptions. + /// The service version. public QuestionAnsweringClientOptions(ServiceVersion version = LatestVersion) { Version = version switch @@ -36,5 +26,17 @@ public QuestionAnsweringClientOptions(ServiceVersion version = LatestVersion) _ => throw new NotSupportedException() }; } + + /// Gets the Version. + internal string Version { get; } + + /// The version of the service to use. + public enum ServiceVersion + { + /// The 2023-04-01 API version. + V2023_04_01 = 1, + /// Version 2025-05-15-preview. + V2025_05_15_Preview = 2 + } } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringModelFactory.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringModelFactory.cs deleted file mode 100644 index f044b2fa5996..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/QuestionAnsweringModelFactory.cs +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Model factory for models. - public static partial class QuestionAnsweringModelFactory - { - /// Initializes a new instance of . - /// Previous turn top answer result QnA ID. - /// Previous user query. - /// A new instance for mocking. - public static KnowledgeBaseAnswerContext KnowledgeBaseAnswerContext(int previousQnaId = default, string previousQuestion = null) - { - return new KnowledgeBaseAnswerContext(previousQnaId, previousQuestion, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Enable or disable Answer Span prediction. - /// - /// Minimum threshold score required to include an answer span, value ranges from 0 - /// to 1. - /// - /// Number of Top answers to be considered for span prediction from 1 to 10. - /// A new instance for mocking. - public static ShortAnswerOptions ShortAnswerOptions(bool isEnabled = default, double? confidenceThreshold = null, int? size = null) - { - return new ShortAnswerOptions(isEnabled, confidenceThreshold, size, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Represents Answer Result list. - /// A new instance for mocking. - public static AnswersResult AnswersResult(IEnumerable answers = null) - { - answers ??= new List(); - - return new AnswersResult(answers?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// List of questions associated with the answer. - /// Answer text. - /// Answer confidence score, value ranges from 0 to 1. - /// ID of the QnA result. - /// Source of QnA result. - /// - /// Metadata associated with the answer, useful to categorize or filter question - /// answers. - /// - /// Dialog associated with Answer. - /// Answer span object of QnA with respect to user's question. - /// A new instance for mocking. - public static KnowledgeBaseAnswer KnowledgeBaseAnswer(IEnumerable questions = null, string answer = null, double? confidence = null, int? qnaId = null, string source = null, IReadOnlyDictionary metadata = null, KnowledgeBaseAnswerDialog dialog = null, AnswerSpan shortAnswer = null) - { - questions ??= new List(); - metadata ??= new Dictionary(); - - return new KnowledgeBaseAnswer( - questions?.ToList(), - answer, - confidence, - qnaId, - source, - metadata, - dialog, - shortAnswer, - serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// To mark if a prompt is relevant only with a previous question or not. If true, - /// do not include this QnA as search result for queries without context; - /// otherwise, if false, ignores context and includes this QnA in search result. - /// - /// List of prompts associated with the answer. - /// A new instance for mocking. - public static KnowledgeBaseAnswerDialog KnowledgeBaseAnswerDialog(bool? isContextOnly = null, IEnumerable prompts = null) - { - prompts ??= new List(); - - return new KnowledgeBaseAnswerDialog(isContextOnly, prompts?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Index of the prompt - used in ordering of the prompts. - /// QnA ID corresponding to the prompt. - /// Text displayed to represent a follow up question prompt. - /// A new instance for mocking. - public static KnowledgeBaseAnswerPrompt KnowledgeBaseAnswerPrompt(int? displayOrder = null, int? id = null, string displayText = null) - { - return new KnowledgeBaseAnswerPrompt(displayOrder, id, displayText, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Predicted text of answer span. - /// Predicted score of answer span, value ranges from 0 to 1. - /// The answer span offset from the start of answer. - /// The length of the answer span. - /// A new instance for mocking. - public static AnswerSpan AnswerSpan(string text = null, double? confidence = null, int? offset = null, int? length = null) - { - return new AnswerSpan(text, confidence, offset, length, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// User question to query against the given text records. - /// Text records to be searched for given question. - /// - /// Language of the text records. This is BCP-47 representation of a language. For - /// example, use "en" for English; "es" for Spanish etc. If not set, use "en" for - /// English as default. - /// - /// - /// Specifies the method used to interpret string offsets. Defaults to Text - /// Elements (Graphemes) according to Unicode v8.0.0. For additional information - /// see https://aka.ms/text-analytics-offsets. - /// - /// A new instance for mocking. - public static AnswersFromTextOptions AnswersFromTextOptions(string question = null, IEnumerable textDocuments = null, string language = null, StringIndexType? stringIndexType = null) - { - textDocuments ??= new List(); - - return new AnswersFromTextOptions(question, textDocuments?.ToList(), language, stringIndexType, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Represents the answer results. - /// A new instance for mocking. - public static AnswersFromTextResult AnswersFromTextResult(IEnumerable answers = null) - { - answers ??= new List(); - - return new AnswersFromTextResult(answers?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// Answer. - /// answer confidence score, value ranges from 0 to 1. - /// record ID. - /// Answer span object with respect to user's question. - /// The sentence offset from the start of the document. - /// The length of the sentence. - /// A new instance for mocking. - public static TextAnswer TextAnswer(string answer = null, double? confidence = null, string id = null, AnswerSpan shortAnswer = null, int? offset = null, int? length = null) - { - return new TextAnswer( - answer, - confidence, - id, - shortAnswer, - offset, - length, - serializedAdditionalRawData: null); - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.Serialization.cs deleted file mode 100644 index bf8496e400cd..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.Serialization.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - public partial class ShortAnswerOptions : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("enable"u8); - writer.WriteBooleanValue(IsEnabled); - if (Optional.IsDefined(ConfidenceThreshold)) - { - writer.WritePropertyName("confidenceScoreThreshold"u8); - writer.WriteNumberValue(ConfidenceThreshold.Value); - } - if (Optional.IsDefined(Size)) - { - writer.WritePropertyName("topAnswersWithSpan"u8); - writer.WriteNumberValue(Size.Value); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - ShortAnswerOptions 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(ShortAnswerOptions)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeShortAnswerOptions(document.RootElement, options); - } - - internal static ShortAnswerOptions DeserializeShortAnswerOptions(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - bool enable = default; - double? confidenceScoreThreshold = default; - int? topAnswersWithSpan = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("enable"u8)) - { - enable = property.Value.GetBoolean(); - continue; - } - if (property.NameEquals("confidenceScoreThreshold"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - confidenceScoreThreshold = property.Value.GetDouble(); - continue; - } - if (property.NameEquals("topAnswersWithSpan"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - topAnswersWithSpan = property.Value.GetInt32(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new ShortAnswerOptions(enable, confidenceScoreThreshold, topAnswersWithSpan, 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, AzureAILanguageQuestionAnsweringInferenceContext.Default); - default: - throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support writing '{options.Format}' format."); - } - } - - ShortAnswerOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeShortAnswerOptions(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(ShortAnswerOptions)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static ShortAnswerOptions FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeShortAnswerOptions(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.cs deleted file mode 100644 index b785f19167d5..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/ShortAnswerOptions.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// To configure Answer span prediction feature. - public partial class ShortAnswerOptions - { - /// - /// 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 . - /// Enable or disable Answer Span prediction. - public ShortAnswerOptions(bool isEnabled) - { - IsEnabled = isEnabled; - } - - /// Initializes a new instance of . - /// Enable or disable Answer Span prediction. - /// - /// Minimum threshold score required to include an answer span, value ranges from 0 - /// to 1. - /// - /// Number of Top answers to be considered for span prediction from 1 to 10. - /// Keeps track of any properties unknown to the library. - internal ShortAnswerOptions(bool isEnabled, double? confidenceThreshold, int? size, IDictionary serializedAdditionalRawData) - { - IsEnabled = isEnabled; - ConfidenceThreshold = confidenceThreshold; - Size = size; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal ShortAnswerOptions() - { - } - - /// Enable or disable Answer Span prediction. - public bool IsEnabled { get; } - /// - /// Minimum threshold score required to include an answer span, value ranges from 0 - /// to 1. - /// - public double? ConfidenceThreshold { get; set; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.Serialization.cs deleted file mode 100644 index 638036f02d4a..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.Serialization.cs +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - public partial class TextDocument : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(TextDocument)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id); - writer.WritePropertyName("text"u8); - writer.WriteStringValue(Text); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - TextDocument 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(TextDocument)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeTextDocument(document.RootElement, options); - } - - internal static TextDocument DeserializeTextDocument(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string id = default; - string text = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("id"u8)) - { - id = property.Value.GetString(); - continue; - } - if (property.NameEquals("text"u8)) - { - text = property.Value.GetString(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new TextDocument(id, text, serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options, AzureAILanguageQuestionAnsweringInferenceContext.Default); - default: - throw new FormatException($"The model {nameof(TextDocument)} does not support writing '{options.Format}' format."); - } - } - - TextDocument IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeTextDocument(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(TextDocument)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static TextDocument FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeTextDocument(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.cs deleted file mode 100644 index 127f97604e12..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/TextDocument.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - /// Represent input text record to be queried. - public partial class TextDocument - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// Unique identifier for the text record. - /// Text contents of the record. - /// or is null. - public TextDocument(string id, string text) - { - Argument.AssertNotNull(id, nameof(id)); - Argument.AssertNotNull(text, nameof(text)); - - Id = id; - Text = text; - } - - /// Initializes a new instance of . - /// Unique identifier for the text record. - /// Text contents of the record. - /// Keeps track of any properties unknown to the library. - internal TextDocument(string id, string text, IDictionary serializedAdditionalRawData) - { - Id = id; - Text = text; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal TextDocument() - { - } - - /// Unique identifier for the text record. - public string Id { get; } - /// Text contents of the record. - public string Text { get; } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.Serialization.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.Serialization.cs deleted file mode 100644 index fd23a5f8e8a0..000000000000 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/Generated/UnknownMatchingPolicy.Serialization.cs +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Language.QuestionAnswering.Inference -{ - internal partial class UnknownMatchingPolicy : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{format}' format."); - } - - base.JsonModelWriteCore(writer, options); - } - - MatchingPolicy 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(MatchingPolicy)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeMatchingPolicy(document.RootElement, options); - } - - internal static UnknownMatchingPolicy DeserializeUnknownMatchingPolicy(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - MatchingPolicyKind kind = "Unknown"; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("kind"u8)) - { - kind = new MatchingPolicyKind(property.Value.GetString()); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new UnknownMatchingPolicy(kind, 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, AzureAILanguageQuestionAnsweringInferenceContext.Default); - default: - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support writing '{options.Format}' format."); - } - } - - MatchingPolicy IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMatchingPolicy(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(MatchingPolicy)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static new UnknownMatchingPolicy FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeUnknownMatchingPolicy(document.RootElement); - } - - /// Convert into a . - internal override RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClient.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClient.cs index aab117bfcab3..6e555ea26a0b 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClient.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClient.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Autorest.CSharp.Core; using Azure.Core; using Azure.Core.Pipeline; @@ -46,7 +45,7 @@ public QuestionAnsweringClient( ClientOptions = options; ClientDiagnostics = new ClientDiagnostics(options, true); _keyCredential = credential; - _pipeline = HttpPipelineBuilder.Build( + Pipeline = HttpPipelineBuilder.Build( options, Array.Empty(), new HttpPipelinePolicy[] @@ -88,7 +87,7 @@ public QuestionAnsweringClient( ClientOptions = options; ClientDiagnostics = new ClientDiagnostics(options, true); _tokenCredential = credential; - _pipeline = HttpPipelineBuilder.Build( + Pipeline = HttpPipelineBuilder.Build( options, Array.Empty(), new HttpPipelinePolicy[] diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClientExtensions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClientExtensions.cs index 4faa7e8f3565..10ff2f150625 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClientExtensions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringClientExtensions.cs @@ -1,21 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// - -#nullable disable - using System; using System.Diagnostics.CodeAnalysis; using Azure; using Azure.AI.Language.QuestionAnswering.Inference; using Azure.Core; using Azure.Core.Extensions; +using Microsoft.TypeSpec.Generator.Customizations; namespace Microsoft.Extensions.Azure { /// Extension methods to add to client builder. - [CodeGenType("AILanguageQuestionAnsweringInferenceClientBuilderExtensions")] + [CodeGenType("LanguageQuestionAnsweringInferenceClientBuilderExtensions")] public static partial class QuestionAnsweringClientExtensions { } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringModelFactory.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringModelFactory.cs index 0981d9810f42..f43211795ca4 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringModelFactory.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringModelFactory.cs @@ -1,10 +1,94 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Azure.Core; +using System.Collections.Generic; namespace Azure.AI.Language.QuestionAnswering.Inference { - [CodeGenType("AILanguageQuestionAnsweringInferenceModelFactory")] - public static partial class QuestionAnsweringModelFactory { } + /// A factory class for creating instances of the models for mocking. + public static partial class QuestionAnsweringModelFactory + { + /// Represents List of Question Answers. + /// Represents Answer Result list. + /// A new instance for mocking. + public static AnswersResult AnswersResult(IEnumerable answers = default) + => LanguageQuestionAnsweringInferenceModelFactory.AnswersResult(answers); + + /// Represents knowledge base answer. + /// List of questions associated with the answer. + /// Answer text. + /// Answer confidence score, value ranges from 0 to 1. + /// ID of the QnA result. + /// Source of QnA result. + /// Metadata associated with the answer. + /// Dialog associated with Answer. + /// Answer span object of QnA with respect to user's question. + /// A new instance for mocking. + public static KnowledgeBaseAnswer KnowledgeBaseAnswer( + IEnumerable questions = default, + string answer = default, + double? confidence = default, + int? qnaId = default, + string source = default, + IDictionary metadata = default, + KnowledgeBaseAnswerDialog dialog = default, + AnswerSpan shortAnswer = default) + => LanguageQuestionAnsweringInferenceModelFactory.KnowledgeBaseAnswer(questions, answer, confidence, qnaId, source, metadata, dialog, shortAnswer); + + /// Represents the answer results. + /// Represents the answer results. + /// A new instance for mocking. + public static AnswersFromTextResult AnswersFromTextResult(IEnumerable answers = default) + => LanguageQuestionAnsweringInferenceModelFactory.AnswersFromTextResult(answers); + + /// Represents answer result. + /// Answer. + /// answer confidence score, value ranges from 0 to 1. + /// record ID. + /// Answer span object with respect to user's question. + /// The sentence offset from the start of the document. + /// The length of the sentence. + /// A new instance for mocking. + public static TextAnswer TextAnswer( + string answer = default, + double? confidence = default, + string id = default, + AnswerSpan shortAnswer = default, + int? offset = default, + int? length = default) + => LanguageQuestionAnsweringInferenceModelFactory.TextAnswer(answer, confidence, id, shortAnswer, offset, length); + + /// Answer span object of QnA. + /// Predicted text of answer span. + /// Predicted score of answer span, value ranges from 0 to 1. + /// The answer span offset from the start of answer. + /// The length of the answer span. + /// A new instance for mocking. + public static AnswerSpan AnswerSpan( + string text = default, + double? confidence = default, + int? offset = default, + int? length = default) + => LanguageQuestionAnsweringInferenceModelFactory.AnswerSpan(text, confidence, offset, length); + + /// Dialog associated with Answer. + /// To mark if a prompt is relevant only with a previous question or not. + /// List of prompts associated with the answer. + /// A new instance for mocking. + public static KnowledgeBaseAnswerDialog KnowledgeBaseAnswerDialog( + bool? isContextOnly = default, + IEnumerable prompts = default) + => LanguageQuestionAnsweringInferenceModelFactory.KnowledgeBaseAnswerDialog(isContextOnly, prompts); + + /// Prompt for an answer. + /// Index of the prompt - used in ordering of the prompts. + /// QnA ID corresponding to the prompt. + /// Text displayed to represent a follow up question prompt. + /// A new instance for mocking. + public static KnowledgeBaseAnswerPrompt KnowledgeBaseAnswerPrompt( + int? displayOrder = default, + int? id = default, + string displayText = default) + => LanguageQuestionAnsweringInferenceModelFactory.KnowledgeBaseAnswerPrompt(displayOrder, id, displayText); + } } diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringProject.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringProject.cs index 0a0e91ed83cf..6ef090bceb3b 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringProject.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/QuestionAnsweringProject.cs @@ -19,8 +19,11 @@ public class QuestionAnsweringProject /// or is null. public QuestionAnsweringProject(string projectName, string deploymentName) { - ProjectName = Argument.CheckNotNull(projectName, nameof(projectName)); - DeploymentName = Argument.CheckNotNull(deploymentName, nameof(deploymentName)); + Argument.AssertNotNull(projectName, nameof(projectName)); + Argument.AssertNotNull(deploymentName, nameof(deploymentName)); + + ProjectName = projectName; + DeploymentName = deploymentName; } /// diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/ShortAnswerOptions.cs b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/ShortAnswerOptions.cs index dfdbec27bf07..55346f9a93dd 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/ShortAnswerOptions.cs +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/src/ShortAnswerOptions.cs @@ -1,7 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Azure.Core; +using Microsoft.TypeSpec.Generator.Customizations; namespace Azure.AI.Language.QuestionAnswering.Inference { diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tsp-location.yaml b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tsp-location.yaml index 15bea43ebc0d..7393edf985c9 100644 --- a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tsp-location.yaml +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tsp-location.yaml @@ -1,5 +1,4 @@ +directory: specification/cognitiveservices/data-plane/LanguageQuestionAnswering commit: 3d6f009ea2c460e9bf764f909791fd20e0a252be repo: Azure/azure-rest-api-specs -directory: specification/cognitiveservices/data-plane/LanguageQuestionAnswering - -emitterPackageJsonPath: eng/legacy-emitter-package.json +emitterPackageJsonPath: eng/azure-typespec-http-client-csharp-emitter-package.json diff --git a/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tspCodeModel.json b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tspCodeModel.json new file mode 100644 index 000000000000..35df4a111a3a --- /dev/null +++ b/sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering.Inference/tspCodeModel.json @@ -0,0 +1,4680 @@ +{ + "name": "Azure.AI.Language.QuestionAnswering.Inference", + "apiVersions": [ + "2023-04-01", + "2025-05-15-preview" + ], + "enums": [ + { + "$id": "1", + "kind": "enum", + "name": "RankerKind", + "crossLanguageDefinitionId": "Language.QuestionAnswering.RankerKind", + "valueType": { + "$id": "2", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "3", + "kind": "enumvalue", + "name": "QuestionOnly", + "value": "QuestionOnly", + "valueType": { + "$ref": "2" + }, + "enumType": { + "$ref": "1" + }, + "doc": "Question only ranker.", + "decorators": [] + }, + { + "$id": "4", + "kind": "enumvalue", + "name": "Default", + "value": "Default", + "valueType": { + "$ref": "2" + }, + "enumType": { + "$ref": "1" + }, + "doc": "Default ranker.", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Type of ranker to be used.", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "5", + "kind": "enum", + "name": "LogicalOperationKind", + "crossLanguageDefinitionId": "Language.QuestionAnswering.LogicalOperationKind", + "valueType": { + "$id": "6", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "7", + "kind": "enumvalue", + "name": "AND", + "value": "AND", + "valueType": { + "$ref": "6" + }, + "enumType": { + "$ref": "5" + }, + "doc": "'AND' for using corresponding logical operation.", + "decorators": [] + }, + { + "$id": "8", + "kind": "enumvalue", + "name": "OR", + "value": "OR", + "valueType": { + "$ref": "6" + }, + "enumType": { + "$ref": "5" + }, + "doc": "Set 'OR' for using corresponding logical operation.", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Set to 'OR' or 'AND' for using corresponding logical operation.", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "9", + "kind": "enum", + "name": "Scorer", + "crossLanguageDefinitionId": "Language.QuestionAnswering.Scorer", + "valueType": { + "$id": "10", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "11", + "kind": "enumvalue", + "name": "Classic", + "value": "Classic", + "valueType": { + "$ref": "10" + }, + "enumType": { + "$ref": "9" + }, + "doc": "Set this value for scoring based on classic algorithms like wordnet, tfidf, ngram etc.", + "decorators": [] + }, + { + "$id": "12", + "kind": "enumvalue", + "name": "Transformer", + "value": "Transformer", + "valueType": { + "$ref": "10" + }, + "enumType": { + "$ref": "9" + }, + "doc": "Set this value for scoring based on transformer based models.", + "decorators": [] + }, + { + "$id": "13", + "kind": "enumvalue", + "name": "Semantic", + "value": "Semantic", + "valueType": { + "$ref": "10" + }, + "enumType": { + "$ref": "9" + }, + "doc": "Set this scorer to use AI search semantic based ranking. Semantic ranking should be configured for this to be used.", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Type of scorer to be used", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "14", + "kind": "enum", + "name": "MatchingPolicyKind", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MatchingPolicyKind", + "valueType": { + "$id": "15", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "16", + "kind": "enumvalue", + "name": "Prebuilt", + "value": "Prebuilt", + "valueType": { + "$ref": "15" + }, + "enumType": { + "$ref": "14" + }, + "doc": "Prebuilt weights will be used for giving preference to question and answer columns when quering AI search", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Kind of matching policy to be used", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "17", + "kind": "enum", + "name": "MatchingPolicyFieldsType", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MatchingPolicyFieldsType", + "valueType": { + "$id": "18", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "19", + "kind": "enumvalue", + "name": "Questions", + "value": "Questions", + "valueType": { + "$ref": "18" + }, + "enumType": { + "$ref": "17" + }, + "doc": "Include 'Questions' field", + "decorators": [] + }, + { + "$id": "20", + "kind": "enumvalue", + "name": "Answer", + "value": "Answer", + "valueType": { + "$ref": "18" + }, + "enumType": { + "$ref": "17" + }, + "doc": "Include 'Answer' field", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Fields to be considred for matching policy", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "21", + "kind": "enum", + "name": "ErrorCode", + "crossLanguageDefinitionId": "Language.QuestionAnswering.ErrorCode", + "valueType": { + "$id": "22", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "23", + "kind": "enumvalue", + "name": "InvalidRequest", + "value": "InvalidRequest", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Invalid request error", + "decorators": [] + }, + { + "$id": "24", + "kind": "enumvalue", + "name": "InvalidArgument", + "value": "InvalidArgument", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Invalid argument error", + "decorators": [] + }, + { + "$id": "25", + "kind": "enumvalue", + "name": "Unauthorized", + "value": "Unauthorized", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Unauthorized access error", + "decorators": [] + }, + { + "$id": "26", + "kind": "enumvalue", + "name": "Forbidden", + "value": "Forbidden", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Forbidden access error", + "decorators": [] + }, + { + "$id": "27", + "kind": "enumvalue", + "name": "NotFound", + "value": "NotFound", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Not found error", + "decorators": [] + }, + { + "$id": "28", + "kind": "enumvalue", + "name": "ProjectNotFound", + "value": "ProjectNotFound", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Project not found error", + "decorators": [] + }, + { + "$id": "29", + "kind": "enumvalue", + "name": "OperationNotFound", + "value": "OperationNotFound", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Operation not found error", + "decorators": [] + }, + { + "$id": "30", + "kind": "enumvalue", + "name": "AzureCognitiveSearchNotFound", + "value": "AzureCognitiveSearchNotFound", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Azure Cognitive Search not found error", + "decorators": [] + }, + { + "$id": "31", + "kind": "enumvalue", + "name": "AzureCognitiveSearchIndexNotFound", + "value": "AzureCognitiveSearchIndexNotFound", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Azure Cognitive Search index not found error", + "decorators": [] + }, + { + "$id": "32", + "kind": "enumvalue", + "name": "TooManyRequests", + "value": "TooManyRequests", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Too many requests error", + "decorators": [] + }, + { + "$id": "33", + "kind": "enumvalue", + "name": "AzureCognitiveSearchThrottling", + "value": "AzureCognitiveSearchThrottling", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Azure Cognitive Search throttling error", + "decorators": [] + }, + { + "$id": "34", + "kind": "enumvalue", + "name": "AzureCognitiveSearchIndexLimitReached", + "value": "AzureCognitiveSearchIndexLimitReached", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Azure Cognitive Search index limit reached error", + "decorators": [] + }, + { + "$id": "35", + "kind": "enumvalue", + "name": "InternalServerError", + "value": "InternalServerError", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Internal server error", + "decorators": [] + }, + { + "$id": "36", + "kind": "enumvalue", + "name": "ServiceUnavailable", + "value": "ServiceUnavailable", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Service unavailable error", + "decorators": [] + }, + { + "$id": "37", + "kind": "enumvalue", + "name": "Timeout", + "value": "Timeout", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Timeout error", + "decorators": [] + }, + { + "$id": "38", + "kind": "enumvalue", + "name": "QuotaExceeded", + "value": "QuotaExceeded", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Quota exceeded error", + "decorators": [] + }, + { + "$id": "39", + "kind": "enumvalue", + "name": "Conflict", + "value": "Conflict", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Conflict error", + "decorators": [] + }, + { + "$id": "40", + "kind": "enumvalue", + "name": "Warning", + "value": "Warning", + "valueType": { + "$ref": "22" + }, + "enumType": { + "$ref": "21" + }, + "doc": "Warning error", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Human-readable error code.", + "isFixed": false, + "isFlags": false, + "usage": "Json,Exception", + "decorators": [] + }, + { + "$id": "41", + "kind": "enum", + "name": "InnerErrorCode", + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorCode", + "valueType": { + "$id": "42", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "43", + "kind": "enumvalue", + "name": "InvalidRequest", + "value": "InvalidRequest", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid request error", + "decorators": [] + }, + { + "$id": "44", + "kind": "enumvalue", + "name": "InvalidParameterValue", + "value": "InvalidParameterValue", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid parameter value error", + "decorators": [] + }, + { + "$id": "45", + "kind": "enumvalue", + "name": "KnowledgeBaseNotFound", + "value": "KnowledgeBaseNotFound", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Knowledge base not found error", + "decorators": [] + }, + { + "$id": "46", + "kind": "enumvalue", + "name": "AzureCognitiveSearchNotFound", + "value": "AzureCognitiveSearchNotFound", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Azure Cognitive Search not found error", + "decorators": [] + }, + { + "$id": "47", + "kind": "enumvalue", + "name": "AzureCognitiveSearchThrottling", + "value": "AzureCognitiveSearchThrottling", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Azure Cognitive Search throttling error", + "decorators": [] + }, + { + "$id": "48", + "kind": "enumvalue", + "name": "ExtractionFailure", + "value": "ExtractionFailure", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Extraction failure error", + "decorators": [] + }, + { + "$id": "49", + "kind": "enumvalue", + "name": "InvalidRequestBodyFormat", + "value": "InvalidRequestBodyFormat", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid request body format error", + "decorators": [] + }, + { + "$id": "50", + "kind": "enumvalue", + "name": "EmptyRequest", + "value": "EmptyRequest", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Empty request error", + "decorators": [] + }, + { + "$id": "51", + "kind": "enumvalue", + "name": "MissingInputDocuments", + "value": "MissingInputDocuments", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Missing input documents error", + "decorators": [] + }, + { + "$id": "52", + "kind": "enumvalue", + "name": "InvalidDocument", + "value": "InvalidDocument", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid document error", + "decorators": [] + }, + { + "$id": "53", + "kind": "enumvalue", + "name": "ModelVersionIncorrect", + "value": "ModelVersionIncorrect", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Model version incorrect error", + "decorators": [] + }, + { + "$id": "54", + "kind": "enumvalue", + "name": "InvalidDocumentBatch", + "value": "InvalidDocumentBatch", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid document batch error", + "decorators": [] + }, + { + "$id": "55", + "kind": "enumvalue", + "name": "UnsupportedLanguageCode", + "value": "UnsupportedLanguageCode", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Unsupported language code error", + "decorators": [] + }, + { + "$id": "56", + "kind": "enumvalue", + "name": "InvalidCountryHint", + "value": "InvalidCountryHint", + "valueType": { + "$ref": "42" + }, + "enumType": { + "$ref": "41" + }, + "doc": "Invalid country hint error", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Human-readable error code.", + "isFixed": false, + "isFlags": false, + "usage": "Json,Exception", + "decorators": [] + }, + { + "$id": "57", + "kind": "enum", + "name": "StringIndexType", + "crossLanguageDefinitionId": "Language.QuestionAnswering.StringIndexType", + "valueType": { + "$id": "58", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "59", + "kind": "enumvalue", + "name": "TextElements_v8", + "value": "TextElements_v8", + "valueType": { + "$ref": "58" + }, + "enumType": { + "$ref": "57" + }, + "doc": "Returned offset and length values will correspond to TextElements (Graphemes\nand Grapheme clusters) confirming to the Unicode 8.0.0 standard. Use this\noption if your application is written in .Net Framework or .Net Core and you\nwill be using StringInfo.", + "decorators": [] + }, + { + "$id": "60", + "kind": "enumvalue", + "name": "UnicodeCodePoint", + "value": "UnicodeCodePoint", + "valueType": { + "$ref": "58" + }, + "enumType": { + "$ref": "57" + }, + "doc": "Returned offset and length values will correspond to Unicode code points. Use\nthis option if your application is written in a language that support Unicode,\nfor example Python.", + "decorators": [] + }, + { + "$id": "61", + "kind": "enumvalue", + "name": "Utf16CodeUnit", + "value": "Utf16CodeUnit", + "valueType": { + "$ref": "58" + }, + "enumType": { + "$ref": "57" + }, + "doc": "Returned offset and length values will correspond to UTF-16 code units. Use\nthis option if your application is written in a language that support Unicode,\nfor example Java, JavaScript.", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "Specifies the method used to interpret string offsets. Defaults to Text\nElements (Graphemes) according to Unicode v8.0.0. For additional information\nsee https://aka.ms/text-analytics-offsets.", + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "decorators": [] + }, + { + "$id": "62", + "kind": "enum", + "name": "Versions", + "crossLanguageDefinitionId": "Language.QuestionAnswering.Versions", + "valueType": { + "$id": "63", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "64", + "kind": "enumvalue", + "name": "v2023_04_01", + "value": "2023-04-01", + "valueType": { + "$ref": "63" + }, + "enumType": { + "$ref": "62" + }, + "doc": "The 2023-04-01 API version.", + "decorators": [] + }, + { + "$id": "65", + "kind": "enumvalue", + "name": "v2025_05_15_preview", + "value": "2025-05-15-preview", + "valueType": { + "$ref": "63" + }, + "enumType": { + "$ref": "62" + }, + "doc": "Version 2025-05-15-preview", + "decorators": [] + } + ], + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "doc": "The available API versions.", + "isFixed": true, + "isFlags": false, + "usage": "ApiVersionEnum", + "decorators": [] + } + ], + "constants": [ + { + "$id": "66", + "kind": "constant", + "name": "getAnswersContentType", + "namespace": "", + "usage": "None", + "valueType": { + "$id": "67", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + { + "$id": "68", + "kind": "constant", + "name": "getAnswersContentType1", + "namespace": "", + "usage": "None", + "valueType": { + "$id": "69", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + { + "$id": "70", + "kind": "constant", + "name": "getAnswersFromTextContentType", + "namespace": "", + "usage": "None", + "valueType": { + "$id": "71", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + { + "$id": "72", + "kind": "constant", + "name": "getAnswersFromTextContentType1", + "namespace": "", + "usage": "None", + "valueType": { + "$id": "73", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + } + ], + "models": [ + { + "$id": "74", + "kind": "model", + "name": "AnswersOptions", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions", + "usage": "Input,Json", + "doc": "Parameters to query a knowledge base.", + "decorators": [], + "properties": [ + { + "$id": "75", + "kind": "property", + "name": "qnaId", + "serializedName": "qnaId", + "doc": "Exact QnA ID to fetch from the knowledge base, this field takes priority over\nquestion.", + "type": { + "$id": "76", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.qnaId", + "serializationOptions": { + "json": { + "name": "qnaId" + } + }, + "isHttpMetadata": false + }, + { + "$id": "77", + "kind": "property", + "name": "question", + "serializedName": "question", + "doc": "User question to query against the knowledge base.", + "type": { + "$id": "78", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.question", + "serializationOptions": { + "json": { + "name": "question" + } + }, + "isHttpMetadata": false + }, + { + "$id": "79", + "kind": "property", + "name": "top", + "serializedName": "top", + "doc": "Max number of answers to be returned for the question.", + "type": { + "$id": "80", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.top", + "serializationOptions": { + "json": { + "name": "top" + } + }, + "isHttpMetadata": false + }, + { + "$id": "81", + "kind": "property", + "name": "userId", + "serializedName": "userId", + "doc": "Unique identifier for the user.", + "type": { + "$id": "82", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.userId", + "serializationOptions": { + "json": { + "name": "userId" + } + }, + "isHttpMetadata": false + }, + { + "$id": "83", + "kind": "property", + "name": "confidenceThreshold", + "serializedName": "confidenceScoreThreshold", + "doc": "Minimum threshold score for answers, value ranges from 0 to 1.", + "type": { + "$id": "84", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.confidenceScoreThreshold", + "serializationOptions": { + "json": { + "name": "confidenceScoreThreshold" + } + }, + "isHttpMetadata": false + }, + { + "$id": "85", + "kind": "property", + "name": "answerContext", + "serializedName": "context", + "doc": "Context object with previous QnA's information.", + "type": { + "$id": "86", + "kind": "model", + "name": "KnowledgeBaseAnswerContext", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerContext", + "usage": "Input,Json", + "doc": "Context object with previous QnA's information.", + "decorators": [], + "properties": [ + { + "$id": "87", + "kind": "property", + "name": "previousQnaId", + "serializedName": "previousQnaId", + "doc": "Previous turn top answer result QnA ID.", + "type": { + "$id": "88", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerContext.previousQnaId", + "serializationOptions": { + "json": { + "name": "previousQnaId" + } + }, + "isHttpMetadata": false + }, + { + "$id": "89", + "kind": "property", + "name": "previousQuestion", + "serializedName": "previousUserQuery", + "doc": "Previous user query.", + "type": { + "$id": "90", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerContext.previousUserQuery", + "serializationOptions": { + "json": { + "name": "previousUserQuery" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.context", + "serializationOptions": { + "json": { + "name": "context" + } + }, + "isHttpMetadata": false + }, + { + "$id": "91", + "kind": "property", + "name": "rankerKind", + "serializedName": "rankerType", + "doc": "Type of ranker to be used.", + "type": { + "$ref": "1" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.rankerType", + "serializationOptions": { + "json": { + "name": "rankerType" + } + }, + "isHttpMetadata": false + }, + { + "$id": "92", + "kind": "property", + "name": "filters", + "serializedName": "filters", + "doc": "Filter QnAs based on given metadata list and knowledge base sources.", + "type": { + "$id": "93", + "kind": "model", + "name": "QueryFilters", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryFilters", + "usage": "Input,Json", + "doc": "filters over knowledge base.", + "decorators": [], + "properties": [ + { + "$id": "94", + "kind": "property", + "name": "metadataFilter", + "serializedName": "metadataFilter", + "doc": "Find QnAs that are associated with the given list of metadata.", + "type": { + "$id": "95", + "kind": "model", + "name": "MetadataFilter", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataFilter", + "usage": "Input,Json", + "doc": "Find QnAs that are associated with the given list of metadata.", + "decorators": [], + "properties": [ + { + "$id": "96", + "kind": "property", + "name": "MetadataRecords", + "serializedName": "metadata", + "doc": "Dictionary of string", + "type": { + "$id": "97", + "kind": "array", + "name": "ArrayMetadataRecord", + "valueType": { + "$id": "98", + "kind": "model", + "name": "MetadataRecord", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataRecord", + "usage": "Input,Json", + "doc": "Object to provide the key value pair for each metadata.", + "decorators": [], + "properties": [ + { + "$id": "99", + "kind": "property", + "name": "key", + "serializedName": "key", + "doc": "Metadata Key from Metadata dictionary used in the QnA.", + "type": { + "$id": "100", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataRecord.key", + "serializationOptions": { + "json": { + "name": "key" + } + }, + "isHttpMetadata": false + }, + { + "$id": "101", + "kind": "property", + "name": "value", + "serializedName": "value", + "doc": "Metadata Value from Metadata dictionary used in the QnA.", + "type": { + "$id": "102", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataRecord.value", + "serializationOptions": { + "json": { + "name": "value" + } + }, + "isHttpMetadata": false + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataFilter.metadata", + "serializationOptions": { + "json": { + "name": "metadata" + } + }, + "isHttpMetadata": false + }, + { + "$id": "103", + "kind": "property", + "name": "logicalOperation", + "serializedName": "logicalOperation", + "doc": "Operation used to join metadata filters.", + "type": { + "$ref": "5" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.MetadataFilter.logicalOperation", + "serializationOptions": { + "json": { + "name": "logicalOperation" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryFilters.metadataFilter", + "serializationOptions": { + "json": { + "name": "metadataFilter" + } + }, + "isHttpMetadata": false + }, + { + "$id": "104", + "kind": "property", + "name": "sourceFilter", + "serializedName": "sourceFilter", + "doc": "Find QnAs that are associated with any of the given list of sources in\nknowledge base.", + "type": { + "$id": "105", + "kind": "array", + "name": "Array", + "valueType": { + "$id": "106", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryFilters.sourceFilter", + "serializationOptions": { + "json": { + "name": "sourceFilter" + } + }, + "isHttpMetadata": false + }, + { + "$id": "107", + "kind": "property", + "name": "logicalOperation", + "serializedName": "logicalOperation", + "doc": "Logical operation used to join metadata filter with source filter.", + "type": { + "$ref": "5" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryFilters.logicalOperation", + "serializationOptions": { + "json": { + "name": "logicalOperation" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.filters", + "serializationOptions": { + "json": { + "name": "filters" + } + }, + "isHttpMetadata": false + }, + { + "$id": "108", + "kind": "property", + "name": "shortAnswerOptions", + "serializedName": "answerSpanRequest", + "doc": "To configure Answer span prediction feature.", + "type": { + "$id": "109", + "kind": "model", + "name": "ShortAnswerOptions", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.ShortAnswerOptions", + "usage": "Input,Json", + "doc": "To configure Answer span prediction feature.", + "decorators": [], + "properties": [ + { + "$id": "110", + "kind": "property", + "name": "IsEnabled", + "serializedName": "enable", + "doc": "Enable or disable Answer Span prediction.", + "type": { + "$id": "111", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.ShortAnswerOptions.enable", + "serializationOptions": { + "json": { + "name": "enable" + } + }, + "isHttpMetadata": false + }, + { + "$id": "112", + "kind": "property", + "name": "confidenceThreshold", + "serializedName": "confidenceScoreThreshold", + "doc": "Minimum threshold score required to include an answer span, value ranges from 0\nto 1.", + "type": { + "$id": "113", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.ShortAnswerOptions.confidenceScoreThreshold", + "serializationOptions": { + "json": { + "name": "confidenceScoreThreshold" + } + }, + "isHttpMetadata": false + }, + { + "$id": "114", + "kind": "property", + "name": "top", + "serializedName": "topAnswersWithSpan", + "doc": "Number of Top answers to be considered for span prediction from 1 to 10.", + "type": { + "$id": "115", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.ShortAnswerOptions.topAnswersWithSpan", + "serializationOptions": { + "json": { + "name": "topAnswersWithSpan" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.answerSpanRequest", + "serializationOptions": { + "json": { + "name": "answerSpanRequest" + } + }, + "isHttpMetadata": false + }, + { + "$id": "116", + "kind": "property", + "name": "includeUnstructuredSources", + "serializedName": "includeUnstructuredSources", + "doc": "(Optional) Flag to enable Query over Unstructured Sources.", + "type": { + "$id": "117", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.includeUnstructuredSources", + "serializationOptions": { + "json": { + "name": "includeUnstructuredSources" + } + }, + "isHttpMetadata": false + }, + { + "$id": "118", + "kind": "property", + "name": "queryPreferences", + "serializedName": "queryPreferences", + "doc": "To fine tune query results", + "type": { + "$id": "119", + "kind": "model", + "name": "QueryPreferences", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryPreferences", + "usage": "Input,Json", + "doc": "Additional properties to fine tune query results", + "decorators": [], + "properties": [ + { + "$id": "120", + "kind": "property", + "name": "scorer", + "serializedName": "scorer", + "doc": "To specify what scoring algorithm is preferred", + "type": { + "$ref": "9" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryPreferences.scorer", + "serializationOptions": { + "json": { + "name": "scorer" + } + }, + "isHttpMetadata": false + }, + { + "$id": "121", + "kind": "property", + "name": "matchingPolicy", + "serializedName": "matchingPolicy", + "doc": "Policy for controling exact query match behavior", + "type": { + "$id": "122", + "kind": "model", + "name": "MatchingPolicy", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MatchingPolicy", + "usage": "Input,Json", + "doc": "Specify parameters for query matching", + "decorators": [], + "discriminatorProperty": { + "$id": "123", + "kind": "property", + "name": "kind", + "serializedName": "kind", + "doc": "Kind of matching policy to be applied", + "type": { + "$ref": "14" + }, + "optional": false, + "readOnly": false, + "discriminator": true, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.MatchingPolicy.kind", + "serializationOptions": { + "json": { + "name": "kind" + } + }, + "isHttpMetadata": false + }, + "properties": [ + { + "$ref": "123" + } + ], + "discriminatedSubtypes": { + "Prebuilt": { + "$id": "124", + "kind": "model", + "name": "PrebuiltQueryMatchingPolicy", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.PrebuiltQueryMatchingPolicy", + "usage": "Input,Json", + "doc": "Represents fields for Prebuilt query matching. Prebuilt weights will be used for giving preference to question and answer columns when quering AI search", + "discriminatorValue": "Prebuilt", + "decorators": [], + "baseModel": { + "$ref": "122" + }, + "properties": [ + { + "$id": "125", + "kind": "property", + "name": "kind", + "serializedName": "kind", + "doc": "Matching policy kind", + "type": { + "$id": "126", + "kind": "enumvalue", + "name": "Prebuilt", + "value": "Prebuilt", + "valueType": { + "$ref": "15" + }, + "enumType": { + "$id": "127", + "kind": "enum", + "decorators": [], + "doc": "Kind of matching policy to be used", + "name": "MatchingPolicyKind", + "isGeneratedName": false, + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "valueType": { + "$id": "128", + "kind": "string", + "decorators": [], + "doc": "A sequence of textual characters.", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "values": [ + { + "$id": "129", + "kind": "enumvalue", + "decorators": [], + "doc": "Prebuilt weights will be used for giving preference to question and answer columns when quering AI search", + "name": "Prebuilt", + "value": "Prebuilt", + "valueType": { + "$ref": "128" + }, + "enumType": { + "$ref": "127" + } + } + ], + "isFixed": false, + "isFlags": false, + "usage": "Input,Json", + "access": "public", + "crossLanguageDefinitionId": "Language.QuestionAnswering.MatchingPolicyKind", + "apiVersions": [ + "2025-05-15-preview" + ], + "isUnionAsEnum": true, + "__accessSet": true + }, + "doc": "Prebuilt weights will be used for giving preference to question and answer columns when quering AI search", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": true, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.PrebuiltQueryMatchingPolicy.kind", + "serializationOptions": { + "json": { + "name": "kind" + } + }, + "isHttpMetadata": false + }, + { + "$id": "130", + "kind": "property", + "name": "fields", + "serializedName": "fields", + "doc": "List of fields to filter during query. For ex if only \"questions\" is used then query will be filtered on that column", + "type": { + "$id": "131", + "kind": "array", + "name": "ArrayMatchingPolicyFieldsType", + "valueType": { + "$ref": "17" + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.PrebuiltQueryMatchingPolicy.fields", + "serializationOptions": { + "json": { + "name": "fields" + } + }, + "isHttpMetadata": false + }, + { + "$id": "132", + "kind": "property", + "name": "IsFullMatchingDisabled", + "serializedName": "disableFullMatch", + "doc": "Disabling full match on query. Enabling this will give preference to qna pairs that have exact match.", + "type": { + "$id": "133", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.PrebuiltQueryMatchingPolicy.disableFullMatch", + "serializationOptions": { + "json": { + "name": "disableFullMatch" + } + }, + "isHttpMetadata": false + } + ] + } + } + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.QueryPreferences.matchingPolicy", + "serializationOptions": { + "json": { + "name": "matchingPolicy" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersOptions.queryPreferences", + "serializationOptions": { + "json": { + "name": "queryPreferences" + } + }, + "isHttpMetadata": false + } + ] + }, + { + "$ref": "86" + }, + { + "$ref": "93" + }, + { + "$ref": "95" + }, + { + "$ref": "98" + }, + { + "$ref": "109" + }, + { + "$ref": "119" + }, + { + "$ref": "122" + }, + { + "$ref": "124" + }, + { + "$id": "134", + "kind": "model", + "name": "AnswersResult", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersResult", + "usage": "Output,Json", + "doc": "Represents List of Question Answers.", + "decorators": [], + "properties": [ + { + "$id": "135", + "kind": "property", + "name": "answers", + "serializedName": "answers", + "doc": "Represents Answer Result list.", + "type": { + "$id": "136", + "kind": "array", + "name": "ArrayKnowledgeBaseAnswer", + "valueType": { + "$id": "137", + "kind": "model", + "name": "KnowledgeBaseAnswer", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer", + "usage": "Output,Json", + "doc": "Represents knowledge base answer.", + "decorators": [], + "properties": [ + { + "$id": "138", + "kind": "property", + "name": "questions", + "serializedName": "questions", + "doc": "List of questions associated with the answer.", + "type": { + "$ref": "105" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.questions", + "serializationOptions": { + "json": { + "name": "questions" + } + }, + "isHttpMetadata": false + }, + { + "$id": "139", + "kind": "property", + "name": "answer", + "serializedName": "answer", + "doc": "Answer text.", + "type": { + "$id": "140", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.answer", + "serializationOptions": { + "json": { + "name": "answer" + } + }, + "isHttpMetadata": false + }, + { + "$id": "141", + "kind": "property", + "name": "confidence", + "serializedName": "confidenceScore", + "doc": "Answer confidence score, value ranges from 0 to 1.", + "type": { + "$id": "142", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.confidenceScore", + "serializationOptions": { + "json": { + "name": "confidenceScore" + } + }, + "isHttpMetadata": false + }, + { + "$id": "143", + "kind": "property", + "name": "qnaId", + "serializedName": "id", + "doc": "ID of the QnA result.", + "type": { + "$id": "144", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.id", + "serializationOptions": { + "json": { + "name": "id" + } + }, + "isHttpMetadata": false + }, + { + "$id": "145", + "kind": "property", + "name": "source", + "serializedName": "source", + "doc": "Source of QnA result.", + "type": { + "$id": "146", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.source", + "serializationOptions": { + "json": { + "name": "source" + } + }, + "isHttpMetadata": false + }, + { + "$id": "147", + "kind": "property", + "name": "metadata", + "serializedName": "metadata", + "doc": "Metadata associated with the answer, useful to categorize or filter question\nanswers.", + "type": { + "$id": "148", + "kind": "dict", + "keyType": { + "$id": "149", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "valueType": { + "$id": "150", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.metadata", + "serializationOptions": { + "json": { + "name": "metadata" + } + }, + "isHttpMetadata": false + }, + { + "$id": "151", + "kind": "property", + "name": "dialog", + "serializedName": "dialog", + "doc": "Dialog associated with Answer.", + "type": { + "$id": "152", + "kind": "model", + "name": "KnowledgeBaseAnswerDialog", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerDialog", + "usage": "Output,Json", + "doc": "Dialog associated with Answer.", + "decorators": [], + "properties": [ + { + "$id": "153", + "kind": "property", + "name": "isContextOnly", + "serializedName": "isContextOnly", + "doc": "To mark if a prompt is relevant only with a previous question or not. If true,\ndo not include this QnA as search result for queries without context;\notherwise, if false, ignores context and includes this QnA in search result.", + "type": { + "$id": "154", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerDialog.isContextOnly", + "serializationOptions": { + "json": { + "name": "isContextOnly" + } + }, + "isHttpMetadata": false + }, + { + "$id": "155", + "kind": "property", + "name": "prompts", + "serializedName": "prompts", + "doc": "List of prompts associated with the answer.", + "type": { + "$id": "156", + "kind": "array", + "name": "ArrayKnowledgeBaseAnswerPrompt", + "valueType": { + "$id": "157", + "kind": "model", + "name": "KnowledgeBaseAnswerPrompt", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerPrompt", + "usage": "Output,Json", + "doc": "Prompt for an answer.", + "decorators": [], + "properties": [ + { + "$id": "158", + "kind": "property", + "name": "displayOrder", + "serializedName": "displayOrder", + "doc": "Index of the prompt - used in ordering of the prompts.", + "type": { + "$id": "159", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerPrompt.displayOrder", + "serializationOptions": { + "json": { + "name": "displayOrder" + } + }, + "isHttpMetadata": false + }, + { + "$id": "160", + "kind": "property", + "name": "Id", + "serializedName": "qnaId", + "doc": "QnA ID corresponding to the prompt.", + "type": { + "$id": "161", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerPrompt.qnaId", + "serializationOptions": { + "json": { + "name": "qnaId" + } + }, + "isHttpMetadata": false + }, + { + "$id": "162", + "kind": "property", + "name": "displayText", + "serializedName": "displayText", + "doc": "Text displayed to represent a follow up question prompt.", + "type": { + "$id": "163", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerPrompt.displayText", + "serializationOptions": { + "json": { + "name": "displayText" + } + }, + "isHttpMetadata": false + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswerDialog.prompts", + "serializationOptions": { + "json": { + "name": "prompts" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.dialog", + "serializationOptions": { + "json": { + "name": "dialog" + } + }, + "isHttpMetadata": false + }, + { + "$id": "164", + "kind": "property", + "name": "shortAnswer", + "serializedName": "answerSpan", + "doc": "Answer span object of QnA with respect to user's question.", + "type": { + "$id": "165", + "kind": "model", + "name": "AnswerSpan", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswerSpan", + "usage": "Output,Json", + "doc": "Answer span object of QnA.", + "decorators": [], + "properties": [ + { + "$id": "166", + "kind": "property", + "name": "text", + "serializedName": "text", + "doc": "Predicted text of answer span.", + "type": { + "$id": "167", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswerSpan.text", + "serializationOptions": { + "json": { + "name": "text" + } + }, + "isHttpMetadata": false + }, + { + "$id": "168", + "kind": "property", + "name": "confidence", + "serializedName": "confidenceScore", + "doc": "Predicted score of answer span, value ranges from 0 to 1.", + "type": { + "$id": "169", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswerSpan.confidenceScore", + "serializationOptions": { + "json": { + "name": "confidenceScore" + } + }, + "isHttpMetadata": false + }, + { + "$id": "170", + "kind": "property", + "name": "offset", + "serializedName": "offset", + "doc": "The answer span offset from the start of answer.", + "type": { + "$id": "171", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswerSpan.offset", + "serializationOptions": { + "json": { + "name": "offset" + } + }, + "isHttpMetadata": false + }, + { + "$id": "172", + "kind": "property", + "name": "length", + "serializedName": "length", + "doc": "The length of the answer span.", + "type": { + "$id": "173", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswerSpan.length", + "serializationOptions": { + "json": { + "name": "length" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.KnowledgeBaseAnswer.answerSpan", + "serializationOptions": { + "json": { + "name": "answerSpan" + } + }, + "isHttpMetadata": false + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersResult.answers", + "serializationOptions": { + "json": { + "name": "answers" + } + }, + "isHttpMetadata": false + } + ] + }, + { + "$ref": "137" + }, + { + "$ref": "152" + }, + { + "$ref": "157" + }, + { + "$ref": "165" + }, + { + "$id": "174", + "kind": "model", + "name": "ErrorResponse", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.ErrorResponse", + "usage": "Json,Exception", + "doc": "Error response.", + "decorators": [], + "properties": [ + { + "$id": "175", + "kind": "property", + "name": "error", + "serializedName": "error", + "doc": "The error object.", + "type": { + "$id": "176", + "kind": "model", + "name": "Error", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error", + "usage": "Json,Exception", + "doc": "The error response object returned when the service encounters some errors during processing the request.", + "decorators": [], + "properties": [ + { + "$id": "177", + "kind": "property", + "name": "code", + "serializedName": "code", + "doc": "One of a server-defined set of error codes.", + "type": { + "$ref": "21" + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error.code", + "serializationOptions": { + "json": { + "name": "code" + } + }, + "isHttpMetadata": false + }, + { + "$id": "178", + "kind": "property", + "name": "message", + "serializedName": "message", + "doc": "A human-readable representation of the error.", + "type": { + "$id": "179", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error.message", + "serializationOptions": { + "json": { + "name": "message" + } + }, + "isHttpMetadata": false + }, + { + "$id": "180", + "kind": "property", + "name": "target", + "serializedName": "target", + "doc": "The target of the error.", + "type": { + "$id": "181", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error.target", + "serializationOptions": { + "json": { + "name": "target" + } + }, + "isHttpMetadata": false + }, + { + "$id": "182", + "kind": "property", + "name": "details", + "serializedName": "details", + "doc": "An array of details about specific errors that led to this reported error.", + "type": { + "$id": "183", + "kind": "array", + "name": "ArrayError", + "valueType": { + "$ref": "176" + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error.details", + "serializationOptions": { + "json": { + "name": "details" + } + }, + "isHttpMetadata": false + }, + { + "$id": "184", + "kind": "property", + "name": "innererror", + "serializedName": "innererror", + "doc": "An object containing more specific information than the current object about the error.", + "type": { + "$id": "185", + "kind": "model", + "name": "InnerErrorModel", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel", + "usage": "Json,Exception", + "doc": "An object containing more specific information about the error. As per\nMicrosoft One API guidelines -\nhttps://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.", + "decorators": [], + "properties": [ + { + "$id": "186", + "kind": "property", + "name": "code", + "serializedName": "code", + "doc": "One of a server-defined set of error codes.", + "type": { + "$ref": "41" + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel.code", + "serializationOptions": { + "json": { + "name": "code" + } + }, + "isHttpMetadata": false + }, + { + "$id": "187", + "kind": "property", + "name": "message", + "serializedName": "message", + "doc": "Error message.", + "type": { + "$id": "188", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel.message", + "serializationOptions": { + "json": { + "name": "message" + } + }, + "isHttpMetadata": false + }, + { + "$id": "189", + "kind": "property", + "name": "details", + "serializedName": "details", + "doc": "Error details.", + "type": { + "$ref": "148" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel.details", + "serializationOptions": { + "json": { + "name": "details" + } + }, + "isHttpMetadata": false + }, + { + "$id": "190", + "kind": "property", + "name": "target", + "serializedName": "target", + "doc": "Error target.", + "type": { + "$id": "191", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel.target", + "serializationOptions": { + "json": { + "name": "target" + } + }, + "isHttpMetadata": false + }, + { + "$id": "192", + "kind": "property", + "name": "innererror", + "serializedName": "innererror", + "doc": "An object containing more specific information than the current object about\nthe error.", + "type": { + "$ref": "185" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.InnerErrorModel.innererror", + "serializationOptions": { + "json": { + "name": "innererror" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.Error.innererror", + "serializationOptions": { + "json": { + "name": "innererror" + } + }, + "isHttpMetadata": false + } + ] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.ErrorResponse.error", + "serializationOptions": { + "json": { + "name": "error" + } + }, + "isHttpMetadata": false + }, + { + "$id": "193", + "kind": "property", + "name": "errorCode", + "serializedName": "errorCode", + "doc": "String error code indicating what went wrong.", + "type": { + "$id": "194", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.ErrorResponse.errorCode", + "serializationOptions": { + "json": { + "name": "errorCode" + } + }, + "isHttpMetadata": true + } + ] + }, + { + "$ref": "176" + }, + { + "$ref": "185" + }, + { + "$id": "195", + "kind": "model", + "name": "AnswersFromTextOptions", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextOptions", + "usage": "Input,Json", + "doc": "The question and text record parameters to answer.", + "decorators": [], + "properties": [ + { + "$id": "196", + "kind": "property", + "name": "question", + "serializedName": "question", + "doc": "User question to query against the given text records.", + "type": { + "$id": "197", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextOptions.question", + "serializationOptions": { + "json": { + "name": "question" + } + }, + "isHttpMetadata": false + }, + { + "$id": "198", + "kind": "property", + "name": "textDocuments", + "serializedName": "records", + "doc": "Text records to be searched for given question.", + "type": { + "$id": "199", + "kind": "array", + "name": "ArrayTextDocument", + "valueType": { + "$id": "200", + "kind": "model", + "name": "TextDocument", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextDocument", + "usage": "Input,Json", + "doc": "Represent input text record to be queried.", + "decorators": [], + "properties": [ + { + "$id": "201", + "kind": "property", + "name": "id", + "serializedName": "id", + "doc": "Unique identifier for the text record.", + "type": { + "$id": "202", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextDocument.id", + "serializationOptions": { + "json": { + "name": "id" + } + }, + "isHttpMetadata": false + }, + { + "$id": "203", + "kind": "property", + "name": "text", + "serializedName": "text", + "doc": "Text contents of the record.", + "type": { + "$id": "204", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextDocument.text", + "serializationOptions": { + "json": { + "name": "text" + } + }, + "isHttpMetadata": false + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextOptions.records", + "serializationOptions": { + "json": { + "name": "records" + } + }, + "isHttpMetadata": false + }, + { + "$id": "205", + "kind": "property", + "name": "language", + "serializedName": "language", + "doc": "Language of the text records. This is BCP-47 representation of a language. For\nexample, use \"en\" for English; \"es\" for Spanish etc. If not set, use \"en\" for\nEnglish as default.", + "type": { + "$id": "206", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextOptions.language", + "serializationOptions": { + "json": { + "name": "language" + } + }, + "isHttpMetadata": false + }, + { + "$id": "207", + "kind": "property", + "name": "stringIndexType", + "serializedName": "stringIndexType", + "doc": "Specifies the method used to interpret string offsets. Defaults to Text\nElements (Graphemes) according to Unicode v8.0.0. For additional information\nsee https://aka.ms/text-analytics-offsets.", + "type": { + "$ref": "57" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextOptions.stringIndexType", + "serializationOptions": { + "json": { + "name": "stringIndexType" + } + }, + "isHttpMetadata": false + } + ] + }, + { + "$ref": "200" + }, + { + "$id": "208", + "kind": "model", + "name": "AnswersFromTextResult", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextResult", + "usage": "Output,Json", + "doc": "Represents the answer results.", + "decorators": [], + "properties": [ + { + "$id": "209", + "kind": "property", + "name": "answers", + "serializedName": "answers", + "doc": "Represents the answer results.", + "type": { + "$id": "210", + "kind": "array", + "name": "ArrayTextAnswer", + "valueType": { + "$id": "211", + "kind": "model", + "name": "TextAnswer", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer", + "usage": "Output,Json", + "doc": "Represents answer result.", + "decorators": [], + "properties": [ + { + "$id": "212", + "kind": "property", + "name": "answer", + "serializedName": "answer", + "doc": "Answer.", + "type": { + "$id": "213", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.answer", + "serializationOptions": { + "json": { + "name": "answer" + } + }, + "isHttpMetadata": false + }, + { + "$id": "214", + "kind": "property", + "name": "confidence", + "serializedName": "confidenceScore", + "doc": "answer confidence score, value ranges from 0 to 1.", + "type": { + "$id": "215", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.confidenceScore", + "serializationOptions": { + "json": { + "name": "confidenceScore" + } + }, + "isHttpMetadata": false + }, + { + "$id": "216", + "kind": "property", + "name": "id", + "serializedName": "id", + "doc": "record ID.", + "type": { + "$id": "217", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.id", + "serializationOptions": { + "json": { + "name": "id" + } + }, + "isHttpMetadata": false + }, + { + "$id": "218", + "kind": "property", + "name": "shortAnswer", + "serializedName": "answerSpan", + "doc": "Answer span object with respect to user's question.", + "type": { + "$ref": "165" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.answerSpan", + "serializationOptions": { + "json": { + "name": "answerSpan" + } + }, + "isHttpMetadata": false + }, + { + "$id": "219", + "kind": "property", + "name": "offset", + "serializedName": "offset", + "doc": "The sentence offset from the start of the document.", + "type": { + "$id": "220", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.offset", + "serializationOptions": { + "json": { + "name": "offset" + } + }, + "isHttpMetadata": false + }, + { + "$id": "221", + "kind": "property", + "name": "length", + "serializedName": "length", + "doc": "The length of the sentence.", + "type": { + "$id": "222", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.TextAnswer.length", + "serializationOptions": { + "json": { + "name": "length" + } + }, + "isHttpMetadata": false + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnswering.AnswersFromTextResult.answers", + "serializationOptions": { + "json": { + "name": "answers" + } + }, + "isHttpMetadata": false + } + ] + }, + { + "$ref": "211" + } + ], + "clients": [ + { + "$id": "223", + "kind": "client", + "name": "QuestionAnsweringClient", + "namespace": "Azure.AI.Language.QuestionAnswering.Inference", + "methods": [ + { + "$id": "224", + "kind": "basic", + "name": "getAnswers", + "accessibility": "public", + "apiVersions": [ + "2023-04-01", + "2025-05-15-preview" + ], + "doc": "Answers the specified question using your knowledge base.", + "operation": { + "$id": "225", + "name": "getAnswers", + "resourceName": "QuestionAnsweringClientOperations", + "doc": "Answers the specified question using your knowledge base.", + "accessibility": "public", + "parameters": [ + { + "$id": "226", + "kind": "query", + "name": "apiVersion", + "serializedName": "api-version", + "doc": "The API version to use for this operation.", + "type": { + "$id": "227", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "isApiVersion": true, + "explode": false, + "defaultValue": { + "type": { + "$id": "228", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "value": "2025-05-15-preview" + }, + "optional": false, + "scope": "Client", + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.apiVersion", + "readOnly": false + }, + { + "$id": "229", + "kind": "query", + "name": "projectName", + "serializedName": "projectName", + "doc": "The name of the project to use.", + "type": { + "$id": "230", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "isApiVersion": false, + "explode": false, + "optional": false, + "scope": "Method", + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.projectName", + "readOnly": false + }, + { + "$id": "231", + "kind": "query", + "name": "deploymentName", + "serializedName": "deploymentName", + "doc": "The name of the specific deployment of the project to use.", + "type": { + "$id": "232", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "isApiVersion": false, + "explode": false, + "optional": false, + "scope": "Method", + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.deploymentName", + "readOnly": false + }, + { + "$id": "233", + "kind": "header", + "name": "contentType", + "serializedName": "Content-Type", + "doc": "Body parameter's content type. Known values are application/json", + "type": { + "$ref": "66" + }, + "isApiVersion": false, + "optional": false, + "isContentType": true, + "scope": "Constant", + "readOnly": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.contentType" + }, + { + "$id": "234", + "kind": "header", + "name": "accept", + "serializedName": "Accept", + "type": { + "$ref": "68" + }, + "isApiVersion": false, + "optional": false, + "isContentType": false, + "scope": "Constant", + "readOnly": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.accept" + }, + { + "$id": "235", + "kind": "body", + "name": "knowledgeBaseQueryOptions", + "serializedName": "knowledgeBaseQueryOptions", + "doc": "Post body of the request.", + "type": { + "$ref": "74" + }, + "isApiVersion": false, + "contentTypes": [ + "application/json" + ], + "defaultContentType": "application/json", + "optional": false, + "scope": "Method", + "decorators": [], + "readOnly": false, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.knowledgeBaseQueryOptions" + } + ], + "responses": [ + { + "statusCodes": [ + 200 + ], + "bodyType": { + "$ref": "134" + }, + "headers": [], + "isErrorResponse": false, + "contentTypes": [ + "application/json" + ] + } + ], + "httpMethod": "POST", + "uri": "{Endpoint}/language", + "path": "/:query-knowledgebases", + "requestMediaTypes": [ + "application/json" + ], + "bufferResponse": true, + "generateProtocolMethod": true, + "generateConvenienceMethod": true, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers", + "decorators": [], + "examples": [ + { + "$id": "236", + "kind": "http", + "name": "Successful query", + "description": "Successful query", + "filePath": "2025-05-15-preview/SuccessfulQueryKnowledgebases.json", + "parameters": [ + { + "parameter": { + "$ref": "233" + }, + "value": { + "$id": "237", + "kind": "string", + "type": { + "$ref": "66" + }, + "value": "application/json" + } + }, + { + "parameter": { + "$ref": "226" + }, + "value": { + "$id": "238", + "kind": "string", + "type": { + "$ref": "227" + }, + "value": "2025-05-15-preview" + } + }, + { + "parameter": { + "$ref": "231" + }, + "value": { + "$id": "239", + "kind": "string", + "type": { + "$ref": "232" + }, + "value": "production" + } + }, + { + "parameter": { + "$ref": "235" + }, + "value": { + "$id": "240", + "kind": "model", + "type": { + "$ref": "74" + }, + "value": { + "answerSpanRequest": { + "$id": "241", + "kind": "model", + "type": { + "$ref": "109" + }, + "value": { + "confidenceScoreThreshold": { + "$id": "242", + "kind": "number", + "type": { + "$ref": "113" + }, + "value": 0.2 + }, + "enable": { + "$id": "243", + "kind": "boolean", + "type": { + "$ref": "111" + }, + "value": true + }, + "topAnswersWithSpan": { + "$id": "244", + "kind": "number", + "type": { + "$ref": "115" + }, + "value": 1 + } + } + }, + "confidenceScoreThreshold": { + "$id": "245", + "kind": "number", + "type": { + "$ref": "84" + }, + "value": 0.2 + }, + "context": { + "$id": "246", + "kind": "model", + "type": { + "$ref": "86" + }, + "value": { + "previousQnaId": { + "$id": "247", + "kind": "number", + "type": { + "$ref": "88" + }, + "value": 9 + }, + "previousUserQuery": { + "$id": "248", + "kind": "string", + "type": { + "$ref": "90" + }, + "value": "Where are QnA Maker quickstarts?" + } + } + }, + "filters": { + "$id": "249", + "kind": "model", + "type": { + "$ref": "93" + }, + "value": { + "logicalOperation": { + "$id": "250", + "kind": "string", + "type": { + "$ref": "5" + }, + "value": "AND" + }, + "metadataFilter": { + "$id": "251", + "kind": "model", + "type": { + "$ref": "95" + }, + "value": { + "logicalOperation": { + "$id": "252", + "kind": "string", + "type": { + "$ref": "5" + }, + "value": "AND" + }, + "metadata": { + "$id": "253", + "kind": "array", + "type": { + "$ref": "97" + }, + "value": [ + { + "$id": "254", + "kind": "model", + "type": { + "$ref": "98" + }, + "value": { + "key": { + "$id": "255", + "kind": "string", + "type": { + "$ref": "100" + }, + "value": "category" + }, + "value": { + "$id": "256", + "kind": "string", + "type": { + "$ref": "102" + }, + "value": "api" + } + } + }, + { + "$id": "257", + "kind": "model", + "type": { + "$ref": "98" + }, + "value": { + "key": { + "$id": "258", + "kind": "string", + "type": { + "$ref": "100" + }, + "value": "editorial" + }, + "value": { + "$id": "259", + "kind": "string", + "type": { + "$ref": "102" + }, + "value": "chitchat" + } + } + } + ] + } + } + }, + "sourceFilter": { + "$id": "260", + "kind": "array", + "type": { + "$ref": "105" + }, + "value": [ + { + "$id": "261", + "kind": "string", + "type": { + "$ref": "106" + }, + "value": "filename1.pdf" + }, + { + "$id": "262", + "kind": "string", + "type": { + "$ref": "106" + }, + "value": "https://www.wikipedia.org/microsoft" + } + ] + } + } + }, + "queryPreferences": { + "$id": "263", + "kind": "model", + "type": { + "$ref": "119" + }, + "value": { + "scorer": { + "$id": "264", + "kind": "string", + "type": { + "$ref": "9" + }, + "value": "Transformer" + }, + "matchingPolicy": { + "$id": "265", + "kind": "model", + "type": { + "$ref": "124" + }, + "value": { + "$id": "266", + "kind": { + "$id": "267", + "kind": "string", + "type": { + "$ref": "126" + }, + "value": "Prebuilt" + }, + "fields": { + "$id": "268", + "kind": "array", + "type": { + "$ref": "131" + }, + "value": [ + { + "$id": "269", + "kind": "string", + "type": { + "$ref": "17" + }, + "value": "Questions" + }, + { + "$id": "270", + "kind": "string", + "type": { + "$ref": "17" + }, + "value": "Answer" + } + ] + }, + "disableFullMatch": { + "$id": "271", + "kind": "boolean", + "type": { + "$ref": "133" + }, + "value": false + } + } + } + } + }, + "includeUnstructuredSources": { + "$id": "272", + "kind": "boolean", + "type": { + "$ref": "117" + }, + "value": true + }, + "question": { + "$id": "273", + "kind": "string", + "type": { + "$ref": "78" + }, + "value": "how long it takes to charge surface?" + }, + "top": { + "$id": "274", + "kind": "number", + "type": { + "$ref": "80" + }, + "value": 3 + }, + "userId": { + "$id": "275", + "kind": "string", + "type": { + "$ref": "82" + }, + "value": "sd53lsY=" + } + } + } + }, + { + "parameter": { + "$ref": "229" + }, + "value": { + "$id": "276", + "kind": "string", + "type": { + "$ref": "230" + }, + "value": "proj1" + } + } + ], + "responses": [ + { + "response": { + "statusCodes": [ + 200 + ], + "bodyType": { + "$ref": "134" + }, + "headers": [], + "isErrorResponse": false, + "contentTypes": [ + "application/json" + ] + }, + "statusCode": 200, + "bodyValue": { + "$id": "277", + "kind": "model", + "type": { + "$ref": "134" + }, + "value": { + "answers": { + "$id": "278", + "kind": "array", + "type": { + "$ref": "136" + }, + "value": [ + { + "$id": "279", + "kind": "model", + "type": { + "$ref": "137" + }, + "value": { + "answer": { + "$id": "280", + "kind": "string", + "type": { + "$ref": "140" + }, + "value": "Power and charging**\n\nIt takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it.\n\nYou can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface." + }, + "answerSpan": { + "$id": "281", + "kind": "model", + "type": { + "$ref": "165" + }, + "value": { + "confidenceScore": { + "$id": "282", + "kind": "number", + "type": { + "$ref": "169" + }, + "value": 0.3 + }, + "length": { + "$id": "283", + "kind": "number", + "type": { + "$ref": "173" + }, + "value": 50 + }, + "offset": { + "$id": "284", + "kind": "number", + "type": { + "$ref": "171" + }, + "value": 33 + }, + "text": { + "$id": "285", + "kind": "string", + "type": { + "$ref": "167" + }, + "value": "two to four hours" + } + } + }, + "confidenceScore": { + "$id": "286", + "kind": "number", + "type": { + "$ref": "142" + }, + "value": 0.65 + }, + "dialog": { + "$id": "287", + "kind": "model", + "type": { + "$ref": "152" + }, + "value": { + "isContextOnly": { + "$id": "288", + "kind": "boolean", + "type": { + "$ref": "154" + }, + "value": false + }, + "prompts": { + "$id": "289", + "kind": "array", + "type": { + "$ref": "156" + }, + "value": [ + { + "$id": "290", + "kind": "model", + "type": { + "$ref": "157" + }, + "value": { + "displayOrder": { + "$id": "291", + "kind": "number", + "type": { + "$ref": "159" + }, + "value": 1 + }, + "displayText": { + "$id": "292", + "kind": "string", + "type": { + "$ref": "163" + }, + "value": "prompt1" + }, + "qnaId": { + "$id": "293", + "kind": "number", + "type": { + "$ref": "161" + }, + "value": 23 + } + } + }, + { + "$id": "294", + "kind": "model", + "type": { + "$ref": "157" + }, + "value": { + "displayOrder": { + "$id": "295", + "kind": "number", + "type": { + "$ref": "159" + }, + "value": 2 + }, + "displayText": { + "$id": "296", + "kind": "string", + "type": { + "$ref": "163" + }, + "value": "prompt2" + }, + "qnaId": { + "$id": "297", + "kind": "number", + "type": { + "$ref": "161" + }, + "value": 36 + } + } + } + ] + } + } + }, + "id": { + "$id": "298", + "kind": "number", + "type": { + "$ref": "144" + }, + "value": 20 + }, + "metadata": { + "$id": "299", + "kind": "dict", + "type": { + "$ref": "148" + }, + "value": { + "category": { + "$id": "300", + "kind": "string", + "type": { + "$ref": "150" + }, + "value": "api" + }, + "editorial": { + "$id": "301", + "kind": "string", + "type": { + "$ref": "150" + }, + "value": "chitchat" + } + } + }, + "questions": { + "$id": "302", + "kind": "array", + "type": { + "$ref": "105" + }, + "value": [ + { + "$id": "303", + "kind": "string", + "type": { + "$ref": "106" + }, + "value": "Power and charging" + } + ] + }, + "source": { + "$id": "304", + "kind": "string", + "type": { + "$ref": "146" + }, + "value": "surface-pro-4-user-guide-EN.pdf" + } + } + }, + { + "$id": "305", + "kind": "model", + "type": { + "$ref": "137" + }, + "value": { + "answer": { + "$id": "306", + "kind": "string", + "type": { + "$ref": "140" + }, + "value": "**Charge your Surface Pro 4**\n\n1. Connect the two parts of the power cord.\n\n2. Connect the power cord securely to the charging port.\n\n3. Plug the power supply into an electrical outlet." + }, + "confidenceScore": { + "$id": "307", + "kind": "number", + "type": { + "$ref": "142" + }, + "value": 0.32 + }, + "id": { + "$id": "308", + "kind": "number", + "type": { + "$ref": "144" + }, + "value": 13 + }, + "questions": { + "$id": "309", + "kind": "array", + "type": { + "$ref": "105" + }, + "value": [ + { + "$id": "310", + "kind": "string", + "type": { + "$ref": "106" + }, + "value": "Charge your Surface Pro 4" + } + ] + }, + "source": { + "$id": "311", + "kind": "string", + "type": { + "$ref": "146" + }, + "value": "surface-pro-4-user-guide-EN.pdf" + } + } + } + ] + } + } + } + } + ] + } + ] + }, + "parameters": [ + { + "$id": "312", + "kind": "method", + "name": "projectName", + "serializedName": "projectName", + "doc": "The name of the project to use.", + "type": { + "$id": "313", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "location": "Query", + "isApiVersion": false, + "optional": false, + "scope": "Method", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.projectName", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "314", + "kind": "method", + "name": "deploymentName", + "serializedName": "deploymentName", + "doc": "The name of the specific deployment of the project to use.", + "type": { + "$id": "315", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "location": "Query", + "isApiVersion": false, + "optional": false, + "scope": "Method", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.deploymentName", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "316", + "kind": "method", + "name": "knowledgeBaseQueryOptions", + "serializedName": "knowledgeBaseQueryOptions", + "doc": "Post body of the request.", + "type": { + "$ref": "74" + }, + "location": "Body", + "isApiVersion": false, + "optional": false, + "scope": "Method", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.knowledgeBaseQueryOptions", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "317", + "kind": "method", + "name": "contentType", + "serializedName": "Content-Type", + "doc": "Body parameter's content type. Known values are application/json", + "type": { + "$ref": "66" + }, + "location": "Header", + "isApiVersion": false, + "optional": false, + "scope": "Constant", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.contentType", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "318", + "kind": "method", + "name": "accept", + "serializedName": "Accept", + "type": { + "$ref": "68" + }, + "location": "Header", + "isApiVersion": false, + "optional": false, + "scope": "Constant", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.accept", + "readOnly": false, + "access": "public", + "decorators": [] + } + ], + "response": { + "type": { + "$ref": "134" + } + }, + "isOverride": false, + "generateConvenient": true, + "generateProtocol": true, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers" + }, + { + "$id": "319", + "kind": "basic", + "name": "getAnswersFromText", + "accessibility": "public", + "apiVersions": [ + "2023-04-01", + "2025-05-15-preview" + ], + "doc": "Answers the specified question using the provided text in the body.", + "operation": { + "$id": "320", + "name": "getAnswersFromText", + "resourceName": "QuestionAnsweringClientOperations", + "doc": "Answers the specified question using the provided text in the body.", + "accessibility": "public", + "parameters": [ + { + "$id": "321", + "kind": "query", + "name": "apiVersion", + "serializedName": "api-version", + "doc": "The API version to use for this operation.", + "type": { + "$id": "322", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "isApiVersion": true, + "explode": false, + "defaultValue": { + "type": { + "$id": "323", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "value": "2025-05-15-preview" + }, + "optional": false, + "scope": "Client", + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.apiVersion", + "readOnly": false + }, + { + "$id": "324", + "kind": "header", + "name": "contentType", + "serializedName": "Content-Type", + "doc": "Body parameter's content type. Known values are application/json", + "type": { + "$ref": "70" + }, + "isApiVersion": false, + "optional": false, + "isContentType": true, + "scope": "Constant", + "readOnly": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.contentType" + }, + { + "$id": "325", + "kind": "header", + "name": "accept", + "serializedName": "Accept", + "type": { + "$ref": "72" + }, + "isApiVersion": false, + "optional": false, + "isContentType": false, + "scope": "Constant", + "readOnly": false, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.accept" + }, + { + "$id": "326", + "kind": "body", + "name": "textQueryOptions", + "serializedName": "textQueryOptions", + "doc": "Post body of the request.", + "type": { + "$ref": "195" + }, + "isApiVersion": false, + "contentTypes": [ + "application/json" + ], + "defaultContentType": "application/json", + "optional": false, + "scope": "Method", + "decorators": [], + "readOnly": false, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.textQueryOptions" + } + ], + "responses": [ + { + "statusCodes": [ + 200 + ], + "bodyType": { + "$ref": "208" + }, + "headers": [], + "isErrorResponse": false, + "contentTypes": [ + "application/json" + ] + } + ], + "httpMethod": "POST", + "uri": "{Endpoint}/language", + "path": "/:query-text", + "requestMediaTypes": [ + "application/json" + ], + "bufferResponse": true, + "generateProtocolMethod": true, + "generateConvenienceMethod": true, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText", + "decorators": [], + "examples": [ + { + "$id": "327", + "kind": "http", + "name": "Successful query", + "description": "Successful query", + "filePath": "2025-05-15-preview/SuccessfulQueryText.json", + "parameters": [ + { + "parameter": { + "$ref": "324" + }, + "value": { + "$id": "328", + "kind": "string", + "type": { + "$ref": "70" + }, + "value": "application/json" + } + }, + { + "parameter": { + "$ref": "321" + }, + "value": { + "$id": "329", + "kind": "string", + "type": { + "$ref": "322" + }, + "value": "2025-05-15-preview" + } + }, + { + "parameter": { + "$ref": "326" + }, + "value": { + "$id": "330", + "kind": "model", + "type": { + "$ref": "195" + }, + "value": { + "question": { + "$id": "331", + "kind": "string", + "type": { + "$ref": "197" + }, + "value": "how long it takes to charge surface?" + }, + "records": { + "$id": "332", + "kind": "array", + "type": { + "$ref": "199" + }, + "value": [ + { + "$id": "333", + "kind": "model", + "type": { + "$ref": "200" + }, + "value": { + "id": { + "$id": "334", + "kind": "string", + "type": { + "$ref": "202" + }, + "value": "1" + }, + "text": { + "$id": "335", + "kind": "string", + "type": { + "$ref": "204" + }, + "value": "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it." + } + } + }, + { + "$id": "336", + "kind": "model", + "type": { + "$ref": "200" + }, + "value": { + "id": { + "$id": "337", + "kind": "string", + "type": { + "$ref": "202" + }, + "value": "2" + }, + "text": { + "$id": "338", + "kind": "string", + "type": { + "$ref": "204" + }, + "value": "You can use the USB port on your Surface Pro 4 power supply to charge other devices, like a phone, while your Surface charges. The USB port on the power supply is only for charging, not for data transfer. If you want to use a USB device, plug it into the USB port on your Surface." + } + } + } + ] + }, + "language": { + "$id": "339", + "kind": "string", + "type": { + "$ref": "206" + }, + "value": "en" + } + } + } + } + ], + "responses": [ + { + "response": { + "statusCodes": [ + 200 + ], + "bodyType": { + "$ref": "208" + }, + "headers": [], + "isErrorResponse": false, + "contentTypes": [ + "application/json" + ] + }, + "statusCode": 200, + "bodyValue": { + "$id": "340", + "kind": "model", + "type": { + "$ref": "208" + }, + "value": { + "answers": { + "$id": "341", + "kind": "array", + "type": { + "$ref": "210" + }, + "value": [ + { + "$id": "342", + "kind": "model", + "type": { + "$ref": "211" + }, + "value": { + "answer": { + "$id": "343", + "kind": "string", + "type": { + "$ref": "213" + }, + "value": "Power and charging. It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it." + }, + "answerSpan": { + "$id": "344", + "kind": "model", + "type": { + "$ref": "165" + }, + "value": { + "confidenceScore": { + "$id": "345", + "kind": "number", + "type": { + "$ref": "169" + }, + "value": 0 + }, + "length": { + "$id": "346", + "kind": "number", + "type": { + "$ref": "173" + }, + "value": 45 + }, + "offset": { + "$id": "347", + "kind": "number", + "type": { + "$ref": "171" + }, + "value": 28 + }, + "text": { + "$id": "348", + "kind": "string", + "type": { + "$ref": "167" + }, + "value": "two to four hours" + } + } + }, + "confidenceScore": { + "$id": "349", + "kind": "number", + "type": { + "$ref": "215" + }, + "value": 0.93 + }, + "id": { + "$id": "350", + "kind": "string", + "type": { + "$ref": "217" + }, + "value": "1" + }, + "length": { + "$id": "351", + "kind": "number", + "type": { + "$ref": "222" + }, + "value": 224 + }, + "offset": { + "$id": "352", + "kind": "number", + "type": { + "$ref": "220" + }, + "value": 0 + } + } + }, + { + "$id": "353", + "kind": "model", + "type": { + "$ref": "211" + }, + "value": { + "answer": { + "$id": "354", + "kind": "string", + "type": { + "$ref": "213" + }, + "value": "It takes two to four hours to charge the Surface Pro 4 battery fully from an empty state. It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it." + }, + "answerSpan": { + "$id": "355", + "kind": "model", + "type": { + "$ref": "165" + }, + "value": { + "confidenceScore": { + "$id": "356", + "kind": "number", + "type": { + "$ref": "169" + }, + "value": 0 + }, + "length": { + "$id": "357", + "kind": "number", + "type": { + "$ref": "173" + }, + "value": 25 + }, + "offset": { + "$id": "358", + "kind": "number", + "type": { + "$ref": "171" + }, + "value": 8 + }, + "text": { + "$id": "359", + "kind": "string", + "type": { + "$ref": "167" + }, + "value": "two to four hours" + } + } + }, + "confidenceScore": { + "$id": "360", + "kind": "number", + "type": { + "$ref": "215" + }, + "value": 0.92 + }, + "id": { + "$id": "361", + "kind": "string", + "type": { + "$ref": "217" + }, + "value": "1" + }, + "length": { + "$id": "362", + "kind": "number", + "type": { + "$ref": "222" + }, + "value": 224 + }, + "offset": { + "$id": "363", + "kind": "number", + "type": { + "$ref": "220" + }, + "value": 20 + } + } + }, + { + "$id": "364", + "kind": "model", + "type": { + "$ref": "211" + }, + "value": { + "answer": { + "$id": "365", + "kind": "string", + "type": { + "$ref": "213" + }, + "value": "It can take longer if you’re using your Surface for power-intensive activities like gaming or video streaming while you’re charging it." + }, + "confidenceScore": { + "$id": "366", + "kind": "number", + "type": { + "$ref": "215" + }, + "value": 0.05 + }, + "id": { + "$id": "367", + "kind": "string", + "type": { + "$ref": "217" + }, + "value": "1" + }, + "length": { + "$id": "368", + "kind": "number", + "type": { + "$ref": "222" + }, + "value": 244 + }, + "offset": { + "$id": "369", + "kind": "number", + "type": { + "$ref": "220" + }, + "value": 110 + } + } + } + ] + } + } + } + } + ] + } + ] + }, + "parameters": [ + { + "$id": "370", + "kind": "method", + "name": "textQueryOptions", + "serializedName": "textQueryOptions", + "doc": "Post body of the request.", + "type": { + "$ref": "195" + }, + "location": "Body", + "isApiVersion": false, + "optional": false, + "scope": "Method", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.textQueryOptions", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "371", + "kind": "method", + "name": "contentType", + "serializedName": "Content-Type", + "doc": "Body parameter's content type. Known values are application/json", + "type": { + "$ref": "70" + }, + "location": "Header", + "isApiVersion": false, + "optional": false, + "scope": "Constant", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.contentType", + "readOnly": false, + "access": "public", + "decorators": [] + }, + { + "$id": "372", + "kind": "method", + "name": "accept", + "serializedName": "Accept", + "type": { + "$ref": "72" + }, + "location": "Header", + "isApiVersion": false, + "optional": false, + "scope": "Constant", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText.accept", + "readOnly": false, + "access": "public", + "decorators": [] + } + ], + "response": { + "type": { + "$ref": "208" + } + }, + "isOverride": false, + "generateConvenient": true, + "generateProtocol": true, + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswersFromText" + } + ], + "parameters": [ + { + "$id": "373", + "kind": "endpoint", + "name": "Endpoint", + "serializedName": "Endpoint", + "doc": "Supported Cognitive Services endpoint (e.g., https://.api.cognitiveservices.azure.com).", + "type": { + "$id": "374", + "kind": "url", + "name": "endpoint", + "crossLanguageDefinitionId": "TypeSpec.url" + }, + "isApiVersion": false, + "optional": false, + "scope": "Client", + "isEndpoint": true, + "serverUrlTemplate": "{Endpoint}/language", + "skipUrlEncoding": false, + "readOnly": false, + "crossLanguageDefinitionId": "Language.QuestionAnswering.Endpoint" + }, + { + "$id": "375", + "kind": "method", + "name": "apiVersion", + "serializedName": "apiVersion", + "doc": "The API version to use for this operation.", + "type": { + "$id": "376", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "location": "", + "isApiVersion": true, + "defaultValue": { + "type": { + "$id": "377", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "value": "2025-05-15-preview" + }, + "optional": false, + "scope": "Method", + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations.getAnswers.apiVersion", + "readOnly": false, + "access": "public", + "decorators": [] + } + ], + "initializedBy": 1, + "decorators": [], + "crossLanguageDefinitionId": "Language.QuestionAnsweringClientCustomizations.QuestionAnsweringClientOperations", + "apiVersions": [ + "2023-04-01", + "2025-05-15-preview" + ] + } + ], + "auth": { + "apiKey": { + "name": "Ocp-Apim-Subscription-Key", + "in": "header" + }, + "oAuth2": { + "flows": [ + { + "scopes": [ + "https://cognitiveservices.azure.com/.default" + ], + "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize" + } + ] + } + } +}