diff --git a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.net8.0.cs b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.net8.0.cs index 545f8461f4b6..f6d8cb22734f 100644 --- a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.net8.0.cs +++ b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.net8.0.cs @@ -6,6 +6,17 @@ internal AzureAITranslationDocumentContext() { } public static Azure.AI.Translation.Document.AzureAITranslationDocumentContext Default { get { throw null; } } protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; } } + public partial class BatchOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public BatchOptions() { } + public bool? TranslateTextWithinImage { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Translation.Document.BatchOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Translation.Document.BatchOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class DocumentFilterOrder { public DocumentFilterOrder(Azure.AI.Translation.Document.DocumentFilterProperty property, bool ascending = true) { } @@ -26,6 +37,8 @@ internal DocumentStatusResult() { } public System.DateTimeOffset LastModified { get { throw null; } } public System.Uri SourceDocumentUri { get { throw null; } } public Azure.AI.Translation.Document.DocumentTranslationStatus Status { get { throw null; } } + public int? TotalImageScansFailed { get { throw null; } } + public int? TotalImageScansSucceeded { get { throw null; } } public System.Uri TranslatedDocumentUri { get { throw null; } } public string TranslatedToLanguageCode { get { throw null; } } public float TranslationProgressPercentage { get { throw null; } } @@ -121,11 +134,12 @@ public DocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential } public partial class DocumentTranslationClientOptions : Azure.Core.ClientOptions { - public DocumentTranslationClientOptions(Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion version = Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion.V2024_05_01) { } + public DocumentTranslationClientOptions(Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion version = Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion.V2024_11_01_Preview) { } public Azure.AI.Translation.Document.DocumentTranslationAudience? Audience { get { throw null; } set { } } public enum ServiceVersion { V2024_05_01 = 1, + V2024_11_01_Preview = 2, } } public partial class DocumentTranslationFileFormat : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel @@ -281,10 +295,10 @@ public SingleDocumentTranslationClient(System.Uri endpoint, Azure.AzureKeyCreden public SingleDocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } public SingleDocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.AI.Translation.Document.DocumentTranslationClientOptions options) { } public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } - public virtual Azure.Response Translate(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response Translate(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), Azure.RequestContext context = null) { throw null; } - public virtual System.Threading.Tasks.Task> TranslateAsync(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task TranslateAsync(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), Azure.RequestContext context = null) { throw null; } + public virtual Azure.Response Translate(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Translate(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), Azure.RequestContext context = null) { throw null; } + public virtual System.Threading.Tasks.Task> TranslateAsync(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task TranslateAsync(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), Azure.RequestContext context = null) { throw null; } } public enum StorageInputUriKind { @@ -306,6 +320,7 @@ public partial class TranslationBatch : System.ClientModel.Primitives.IJsonModel { public TranslationBatch(System.Collections.Generic.IEnumerable inputs) { } public System.Collections.Generic.IList Inputs { get { throw null; } } + public Azure.AI.Translation.Document.BatchOptions Options { get { throw null; } set { } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.AI.Translation.Document.TranslationBatch System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs index 545f8461f4b6..f6d8cb22734f 100644 --- a/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs +++ b/sdk/translation/Azure.AI.Translation.Document/api/Azure.AI.Translation.Document.netstandard2.0.cs @@ -6,6 +6,17 @@ internal AzureAITranslationDocumentContext() { } public static Azure.AI.Translation.Document.AzureAITranslationDocumentContext Default { get { throw null; } } protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; } } + public partial class BatchOptions : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public BatchOptions() { } + public bool? TranslateTextWithinImage { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Translation.Document.BatchOptions System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.AI.Translation.Document.BatchOptions System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public partial class DocumentFilterOrder { public DocumentFilterOrder(Azure.AI.Translation.Document.DocumentFilterProperty property, bool ascending = true) { } @@ -26,6 +37,8 @@ internal DocumentStatusResult() { } public System.DateTimeOffset LastModified { get { throw null; } } public System.Uri SourceDocumentUri { get { throw null; } } public Azure.AI.Translation.Document.DocumentTranslationStatus Status { get { throw null; } } + public int? TotalImageScansFailed { get { throw null; } } + public int? TotalImageScansSucceeded { get { throw null; } } public System.Uri TranslatedDocumentUri { get { throw null; } } public string TranslatedToLanguageCode { get { throw null; } } public float TranslationProgressPercentage { get { throw null; } } @@ -121,11 +134,12 @@ public DocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential } public partial class DocumentTranslationClientOptions : Azure.Core.ClientOptions { - public DocumentTranslationClientOptions(Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion version = Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion.V2024_05_01) { } + public DocumentTranslationClientOptions(Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion version = Azure.AI.Translation.Document.DocumentTranslationClientOptions.ServiceVersion.V2024_11_01_Preview) { } public Azure.AI.Translation.Document.DocumentTranslationAudience? Audience { get { throw null; } set { } } public enum ServiceVersion { V2024_05_01 = 1, + V2024_11_01_Preview = 2, } } public partial class DocumentTranslationFileFormat : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel @@ -281,10 +295,10 @@ public SingleDocumentTranslationClient(System.Uri endpoint, Azure.AzureKeyCreden public SingleDocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential credential) { } public SingleDocumentTranslationClient(System.Uri endpoint, Azure.Core.TokenCredential credential, Azure.AI.Translation.Document.DocumentTranslationClientOptions options) { } public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } - public virtual Azure.Response Translate(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response Translate(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), Azure.RequestContext context = null) { throw null; } - public virtual System.Threading.Tasks.Task> TranslateAsync(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task TranslateAsync(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), Azure.RequestContext context = null) { throw null; } + public virtual Azure.Response Translate(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Translate(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), Azure.RequestContext context = null) { throw null; } + public virtual System.Threading.Tasks.Task> TranslateAsync(string targetLanguage, Azure.AI.Translation.Document.DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task TranslateAsync(string targetLanguage, Azure.Core.RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = default(bool?), bool? translateTextWithinImage = default(bool?), Azure.RequestContext context = null) { throw null; } } public enum StorageInputUriKind { @@ -306,6 +320,7 @@ public partial class TranslationBatch : System.ClientModel.Primitives.IJsonModel { public TranslationBatch(System.Collections.Generic.IEnumerable inputs) { } public System.Collections.Generic.IList Inputs { get { throw null; } } + public Azure.AI.Translation.Document.BatchOptions Options { get { throw null; } set { } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.AI.Translation.Document.TranslationBatch System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.Serialization.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.Serialization.cs similarity index 60% rename from sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.Serialization.cs rename to sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.Serialization.cs index 77a62593fc33..63b40bd6ab24 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.Serialization.cs @@ -11,13 +11,13 @@ using System.Text.Json; using Azure.Core; -namespace Azure.AI.Translation.Text +namespace Azure.AI.Translation.Document { - public partial class TranslatedTextAlignment : IUtf8JsonSerializable, IJsonModel + public partial class BatchOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,14 +28,17 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(TranslatedTextAlignment)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(BatchOptions)} does not support writing '{format}' format."); } - writer.WritePropertyName("proj"u8); - writer.WriteStringValue(Projections); + if (Optional.IsDefined(TranslateTextWithinImage)) + { + writer.WritePropertyName("translateTextWithinImage"u8); + writer.WriteBooleanValue(TranslateTextWithinImage.Value); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -53,19 +56,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - TranslatedTextAlignment IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + BatchOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(TranslatedTextAlignment)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(BatchOptions)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeTranslatedTextAlignment(document.RootElement, options); + return DeserializeBatchOptions(document.RootElement, options); } - internal static TranslatedTextAlignment DeserializeTranslatedTextAlignment(JsonElement element, ModelReaderWriterOptions options = null) + internal static BatchOptions DeserializeBatchOptions(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -73,14 +76,18 @@ internal static TranslatedTextAlignment DeserializeTranslatedTextAlignment(JsonE { return null; } - string proj = default; + bool? translateTextWithinImage = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("proj"u8)) + if (property.NameEquals("translateTextWithinImage"u8)) { - proj = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + translateTextWithinImage = property.Value.GetBoolean(); continue; } if (options.Format != "W") @@ -89,46 +96,46 @@ internal static TranslatedTextAlignment DeserializeTranslatedTextAlignment(JsonE } } serializedAdditionalRawData = rawDataDictionary; - return new TranslatedTextAlignment(proj, serializedAdditionalRawData); + return new BatchOptions(translateTextWithinImage, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": - return ModelReaderWriter.Write(this, options, AzureAITranslationTextContext.Default); + return ModelReaderWriter.Write(this, options, AzureAITranslationDocumentContext.Default); default: - throw new FormatException($"The model {nameof(TranslatedTextAlignment)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(BatchOptions)} does not support writing '{options.Format}' format."); } } - TranslatedTextAlignment IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + BatchOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeTranslatedTextAlignment(document.RootElement, options); + return DeserializeBatchOptions(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(TranslatedTextAlignment)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(BatchOptions)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static TranslatedTextAlignment FromResponse(Response response) + internal static BatchOptions FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeTranslatedTextAlignment(document.RootElement); + return DeserializeBatchOptions(document.RootElement); } /// Convert into a . diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.cs new file mode 100644 index 000000000000..8ddbbf8d7ceb --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/BatchOptions.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Translation.Document +{ + /// Translation batch request options. + public partial class BatchOptions + { + /// + /// 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 BatchOptions() + { + } + + /// Initializes a new instance of . + /// Translation text within an image option. + /// Keeps track of any properties unknown to the library. + internal BatchOptions(bool? translateTextWithinImage, IDictionary serializedAdditionalRawData) + { + TranslateTextWithinImage = translateTextWithinImage; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Translation text within an image option. + public bool? TranslateTextWithinImage { get; set; } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.Serialization.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.Serialization.cs index 450aa2cdbf5e..aabaa99afba0 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.Serialization.cs @@ -60,6 +60,16 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteStringValue(Id); writer.WritePropertyName("characterCharged"u8); writer.WriteNumberValue(CharactersCharged); + if (Optional.IsDefined(TotalImageScansSucceeded)) + { + writer.WritePropertyName("totalImageScansSucceeded"u8); + writer.WriteNumberValue(TotalImageScansSucceeded.Value); + } + if (Optional.IsDefined(TotalImageScansFailed)) + { + writer.WritePropertyName("totalImageScansFailed"u8); + writer.WriteNumberValue(TotalImageScansFailed.Value); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -107,6 +117,8 @@ internal static DocumentStatusResult DeserializeDocumentStatusResult(JsonElement float progress = default; string id = default; long characterCharged = default; + int? totalImageScansSucceeded = default; + int? totalImageScansFailed = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -169,6 +181,24 @@ internal static DocumentStatusResult DeserializeDocumentStatusResult(JsonElement characterCharged = property.Value.GetInt64(); continue; } + if (property.NameEquals("totalImageScansSucceeded"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + totalImageScansSucceeded = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("totalImageScansFailed"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + totalImageScansFailed = property.Value.GetInt32(); + continue; + } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); @@ -186,6 +216,8 @@ internal static DocumentStatusResult DeserializeDocumentStatusResult(JsonElement progress, id, characterCharged, + totalImageScansSucceeded, + totalImageScansFailed, serializedAdditionalRawData); } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.cs index ad2734f53e62..70297a750585 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentStatusResult.cs @@ -84,8 +84,10 @@ internal DocumentStatusResult(Uri sourceDocumentUri, DateTimeOffset createdOn, D /// Progress of the translation if available. /// Document Id. /// Character charged by the API. + /// Total image scans charged by the API. + /// Total image scans failed. /// Keeps track of any properties unknown to the library. - internal DocumentStatusResult(Uri translatedDocumentUri, Uri sourceDocumentUri, DateTimeOffset createdOn, DateTimeOffset lastModified, DocumentTranslationStatus status, string translatedToLanguageCode, JsonElement error, float progress, string id, long charactersCharged, IDictionary serializedAdditionalRawData) + internal DocumentStatusResult(Uri translatedDocumentUri, Uri sourceDocumentUri, DateTimeOffset createdOn, DateTimeOffset lastModified, DocumentTranslationStatus status, string translatedToLanguageCode, JsonElement error, float progress, string id, long charactersCharged, int? totalImageScansSucceeded, int? totalImageScansFailed, IDictionary serializedAdditionalRawData) { TranslatedDocumentUri = translatedDocumentUri; SourceDocumentUri = sourceDocumentUri; @@ -97,6 +99,8 @@ internal DocumentStatusResult(Uri translatedDocumentUri, Uri sourceDocumentUri, Progress = progress; Id = id; CharactersCharged = charactersCharged; + TotalImageScansSucceeded = totalImageScansSucceeded; + TotalImageScansFailed = totalImageScansFailed; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -104,5 +108,9 @@ internal DocumentStatusResult(Uri translatedDocumentUri, Uri sourceDocumentUri, internal DocumentStatusResult() { } + /// Total image scans charged by the API. + public int? TotalImageScansSucceeded { get; } + /// Total image scans failed. + public int? TotalImageScansFailed { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentTranslationClientOptions.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentTranslationClientOptions.cs index fc44e6926c9c..973affa55f5d 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentTranslationClientOptions.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/DocumentTranslationClientOptions.cs @@ -13,13 +13,15 @@ namespace Azure.AI.Translation.Document /// Client options for Azure.AI.Translation.Document library clients. public partial class DocumentTranslationClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V2024_05_01; + private const ServiceVersion LatestVersion = ServiceVersion.V2024_11_01_Preview; /// The version of the service to use. public enum ServiceVersion { /// Service version "2024-05-01". V2024_05_01 = 1, + /// Service version "2024-11-01-preview". + V2024_11_01_Preview = 2, } internal string Version { get; } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/SingleDocumentTranslationClient.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/SingleDocumentTranslationClient.cs index 2f99db2b3d0d..25acf7194b2f 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/SingleDocumentTranslationClient.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/SingleDocumentTranslationClient.cs @@ -109,17 +109,18 @@ public SingleDocumentTranslationClient(Uri endpoint, TokenCredential credential, /// Specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. /// Possible values are: true (default) or false. /// + /// Optional boolean parameter to translate text within an image in the document. /// The cancellation token to use. /// or is null. /// Use this API to submit a single translation request to the Document Translation Service. - public virtual async Task> TranslateAsync(string targetLanguage, DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = null, CancellationToken cancellationToken = default) + public virtual async Task> TranslateAsync(string targetLanguage, DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = null, bool? translateTextWithinImage = null, CancellationToken cancellationToken = default) { Argument.AssertNotNull(targetLanguage, nameof(targetLanguage)); Argument.AssertNotNull(documentTranslateContent, nameof(documentTranslateContent)); using MultipartFormDataRequestContent content = documentTranslateContent.ToMultipartRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await TranslateAsync(targetLanguage, content, content.ContentType, sourceLanguage, category, allowFallback, context).ConfigureAwait(false); + Response response = await TranslateAsync(targetLanguage, content, content.ContentType, sourceLanguage, category, allowFallback, translateTextWithinImage, context).ConfigureAwait(false); return Response.FromValue(response.Content, response); } @@ -144,17 +145,18 @@ public virtual async Task> TranslateAsync(string targetLang /// Specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. /// Possible values are: true (default) or false. /// + /// Optional boolean parameter to translate text within an image in the document. /// The cancellation token to use. /// or is null. /// Use this API to submit a single translation request to the Document Translation Service. - public virtual Response Translate(string targetLanguage, DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = null, CancellationToken cancellationToken = default) + public virtual Response Translate(string targetLanguage, DocumentTranslateContent documentTranslateContent, string sourceLanguage = null, string category = null, bool? allowFallback = null, bool? translateTextWithinImage = null, CancellationToken cancellationToken = default) { Argument.AssertNotNull(targetLanguage, nameof(targetLanguage)); Argument.AssertNotNull(documentTranslateContent, nameof(documentTranslateContent)); using MultipartFormDataRequestContent content = documentTranslateContent.ToMultipartRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = Translate(targetLanguage, content, content.ContentType, sourceLanguage, category, allowFallback, context); + Response response = Translate(targetLanguage, content, content.ContentType, sourceLanguage, category, allowFallback, translateTextWithinImage, context); return Response.FromValue(response.Content, response); } @@ -168,7 +170,7 @@ public virtual Response Translate(string targetLanguage, DocumentTra /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -194,11 +196,12 @@ public virtual Response Translate(string targetLanguage, DocumentTra /// Specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. /// Possible values are: true (default) or false. /// + /// Optional boolean parameter to translate text within an image in the document. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// Service returned a non-success status code. /// The response returned from the service. - public virtual async Task TranslateAsync(string targetLanguage, RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = null, RequestContext context = null) + public virtual async Task TranslateAsync(string targetLanguage, RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = null, bool? translateTextWithinImage = null, RequestContext context = null) { Argument.AssertNotNull(targetLanguage, nameof(targetLanguage)); Argument.AssertNotNull(content, nameof(content)); @@ -207,7 +210,7 @@ public virtual async Task TranslateAsync(string targetLanguage, Reques scope.Start(); try { - using HttpMessage message = CreateTranslateRequest(targetLanguage, content, contentType, sourceLanguage, category, allowFallback, context); + using HttpMessage message = CreateTranslateRequest(targetLanguage, content, contentType, sourceLanguage, category, allowFallback, translateTextWithinImage, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -227,7 +230,7 @@ public virtual async Task TranslateAsync(string targetLanguage, Reques /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// @@ -253,11 +256,12 @@ public virtual async Task TranslateAsync(string targetLanguage, Reques /// Specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. /// Possible values are: true (default) or false. /// + /// Optional boolean parameter to translate text within an image in the document. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// Service returned a non-success status code. /// The response returned from the service. - public virtual Response Translate(string targetLanguage, RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = null, RequestContext context = null) + public virtual Response Translate(string targetLanguage, RequestContent content, string contentType, string sourceLanguage = null, string category = null, bool? allowFallback = null, bool? translateTextWithinImage = null, RequestContext context = null) { Argument.AssertNotNull(targetLanguage, nameof(targetLanguage)); Argument.AssertNotNull(content, nameof(content)); @@ -266,7 +270,7 @@ public virtual Response Translate(string targetLanguage, RequestContent content, scope.Start(); try { - using HttpMessage message = CreateTranslateRequest(targetLanguage, content, contentType, sourceLanguage, category, allowFallback, context); + using HttpMessage message = CreateTranslateRequest(targetLanguage, content, contentType, sourceLanguage, category, allowFallback, translateTextWithinImage, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -276,7 +280,7 @@ public virtual Response Translate(string targetLanguage, RequestContent content, } } - internal HttpMessage CreateTranslateRequest(string targetLanguage, RequestContent content, string contentType, string sourceLanguage, string category, bool? allowFallback, RequestContext context) + internal HttpMessage CreateTranslateRequest(string targetLanguage, RequestContent content, string contentType, string sourceLanguage, string category, bool? allowFallback, bool? translateTextWithinImage, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); var request = message.Request; @@ -299,6 +303,10 @@ internal HttpMessage CreateTranslateRequest(string targetLanguage, RequestConten { uri.AppendQuery("allowFallback", allowFallback.Value, true); } + if (translateTextWithinImage != null) + { + uri.AppendQuery("translateTextWithinImage", translateTextWithinImage.Value, true); + } request.Uri = uri; request.Headers.Add("Accept", "application/octet-stream"); request.Headers.Add("Content-Type", contentType); diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.Serialization.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.Serialization.cs index 7a20c5f761d6..24c2baa78dd3 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.Serialization.cs @@ -41,6 +41,11 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item, options); } writer.WriteEndArray(); + if (Optional.IsDefined(Options)) + { + writer.WritePropertyName("options"u8); + writer.WriteObjectValue(Options, options); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -79,6 +84,7 @@ internal static TranslationBatch DeserializeTranslationBatch(JsonElement element return null; } IList inputs = default; + BatchOptions options0 = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -93,13 +99,22 @@ internal static TranslationBatch DeserializeTranslationBatch(JsonElement element inputs = array; continue; } + if (property.NameEquals("options"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + options0 = BatchOptions.DeserializeBatchOptions(property.Value, options); + continue; + } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new TranslationBatch(inputs, serializedAdditionalRawData); + return new TranslationBatch(inputs, options0, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.cs index 82b309b8ec6a..5309362b29dc 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationBatch.cs @@ -58,10 +58,12 @@ public TranslationBatch(IEnumerable inputs) /// Initializes a new instance of . /// The input list of documents or folders containing documents. + /// The batch operation options. /// Keeps track of any properties unknown to the library. - internal TranslationBatch(IList inputs, IDictionary serializedAdditionalRawData) + internal TranslationBatch(IList inputs, BatchOptions options, IDictionary serializedAdditionalRawData) { Inputs = inputs; + Options = options; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -72,5 +74,7 @@ internal TranslationBatch() /// The input list of documents or folders containing documents. public IList Inputs { get; } + /// The batch operation options. + public BatchOptions Options { get; set; } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.Serialization.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.Serialization.cs index 0381f5e650f5..b9185314505b 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.Serialization.cs @@ -48,6 +48,16 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteNumberValue(Cancelled); writer.WritePropertyName("totalCharacterCharged"u8); writer.WriteNumberValue(TotalCharacterCharged); + if (Optional.IsDefined(TotalImageScansSucceeded)) + { + writer.WritePropertyName("totalImageScansSucceeded"u8); + writer.WriteNumberValue(TotalImageScansSucceeded.Value); + } + if (Optional.IsDefined(TotalImageScansFailed)) + { + writer.WritePropertyName("totalImageScansFailed"u8); + writer.WriteNumberValue(TotalImageScansFailed.Value); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -92,6 +102,8 @@ internal static TranslationStatusSummary DeserializeTranslationStatusSummary(Jso int notYetStarted = default; int cancelled = default; long totalCharacterCharged = default; + int? totalImageScansSucceeded = default; + int? totalImageScansFailed = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -131,6 +143,24 @@ internal static TranslationStatusSummary DeserializeTranslationStatusSummary(Jso totalCharacterCharged = property.Value.GetInt64(); continue; } + if (property.NameEquals("totalImageScansSucceeded"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + totalImageScansSucceeded = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("totalImageScansFailed"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + totalImageScansFailed = property.Value.GetInt32(); + continue; + } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); @@ -145,6 +175,8 @@ internal static TranslationStatusSummary DeserializeTranslationStatusSummary(Jso notYetStarted, cancelled, totalCharacterCharged, + totalImageScansSucceeded, + totalImageScansFailed, serializedAdditionalRawData); } diff --git a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.cs b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.cs index 624bb2883520..b855d6e543b7 100644 --- a/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.cs +++ b/sdk/translation/Azure.AI.Translation.Document/src/Generated/TranslationStatusSummary.cs @@ -72,8 +72,10 @@ internal TranslationStatusSummary(int total, int failed, int success, int inProg /// Count of not yet started. /// Number of cancelled. /// Total characters charged by the API. + /// Total image scans charged by the API. + /// Total image scans failed. /// Keeps track of any properties unknown to the library. - internal TranslationStatusSummary(int total, int failed, int success, int inProgress, int notYetStarted, int cancelled, long totalCharacterCharged, IDictionary serializedAdditionalRawData) + internal TranslationStatusSummary(int total, int failed, int success, int inProgress, int notYetStarted, int cancelled, long totalCharacterCharged, int? totalImageScansSucceeded, int? totalImageScansFailed, IDictionary serializedAdditionalRawData) { Total = total; Failed = failed; @@ -82,6 +84,8 @@ internal TranslationStatusSummary(int total, int failed, int success, int inProg NotYetStarted = notYetStarted; Cancelled = cancelled; TotalCharacterCharged = totalCharacterCharged; + TotalImageScansSucceeded = totalImageScansSucceeded; + TotalImageScansFailed = totalImageScansFailed; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -104,5 +108,9 @@ internal TranslationStatusSummary() public int Cancelled { get; } /// Total characters charged by the API. public long TotalCharacterCharged { get; } + /// Total image scans charged by the API. + public int? TotalImageScansSucceeded { get; } + /// Total image scans failed. + public int? TotalImageScansFailed { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml b/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml index 6acb879247c8..0334d2c58708 100644 --- a/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml +++ b/sdk/translation/Azure.AI.Translation.Document/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/translation/Azure.AI.DocumentTranslation -commit: dde20d195ffc89fab6f08b58a368e353cd89ac06 +commit: 147495e1b6cfe5607d481278e31857dc929b42fa repo: Azure/azure-rest-api-specs +additionalDirectories: diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/AITranslationTextModelFactory.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/AITranslationTextModelFactory.cs index 2348b6d02f3d..3d1d5ffb386b 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/AITranslationTextModelFactory.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/AITranslationTextModelFactory.cs @@ -30,11 +30,11 @@ public static GetSupportedLanguagesResult GetSupportedLanguagesResult(IReadOnlyD /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// A new instance for mocking. - public static TranslationLanguage TranslationLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default) + public static TranslationLanguage TranslationLanguage(string name = null, string nativeName = null, LanguageDirectionality dir = default) { - return new TranslationLanguage(name, nativeName, directionality, serializedAdditionalRawData: null); + return new TranslationLanguage(name, nativeName, dir, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -53,55 +53,85 @@ public static TransliterationLanguage TransliterationLanguage(string name = null /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - /// List of scripts available to convert text to. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// List of scripts available to convert text to. /// A new instance for mocking. - public static TransliterableScript TransliterableScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality directionality = default, IEnumerable targetLanguageScripts = null) + public static TransliterableScript TransliterableScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality dir = default, IEnumerable toScripts = null) { - targetLanguageScripts ??= new List(); + toScripts ??= new List(); return new TransliterableScript( code, name, nativeName, - directionality, + dir, serializedAdditionalRawData: null, - targetLanguageScripts?.ToList()); + toScripts?.ToList()); } /// Initializes a new instance of . /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// A new instance for mocking. - public static LanguageScript LanguageScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality directionality = default) + public static LanguageScript LanguageScript(string code = null, string name = null, string nativeName = null, LanguageDirectionality dir = default) { - return new LanguageScript(code, name, nativeName, directionality, serializedAdditionalRawData: null); + return new LanguageScript(code, name, nativeName, dir, serializedAdditionalRawData: null); } /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// List of languages with alterative translations and examples for the query expressed in the source language. /// A new instance for mocking. - public static SourceDictionaryLanguage SourceDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default, IEnumerable translations = null) + public static SourceDictionaryLanguage SourceDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality dir = default, IEnumerable translations = null) { translations ??= new List(); - return new SourceDictionaryLanguage(name, nativeName, directionality, translations?.ToList(), serializedAdditionalRawData: null); + return new SourceDictionaryLanguage(name, nativeName, dir, translations?.ToList(), serializedAdditionalRawData: null); } /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Language code identifying the target language. /// A new instance for mocking. - public static TargetDictionaryLanguage TargetDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality directionality = default, string code = null) + public static TargetDictionaryLanguage TargetDictionaryLanguage(string name = null, string nativeName = null, LanguageDirectionality dir = default, string code = null) { - return new TargetDictionaryLanguage(name, nativeName, directionality, code, serializedAdditionalRawData: null); + return new TargetDictionaryLanguage(name, nativeName, dir, code, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Text to translate. + /// Specifies the script of the input text. + /// + /// Specifies the language of the input text. Find which languages are available to translate by + /// looking up supported languages using the translation scope. If the language parameter isn't + /// specified, automatic language detection is applied to determine the source language. + /// + /// You must use the language parameter rather than autodetection when using the dynamic dictionary feature. + /// Note: the dynamic dictionary feature is case-sensitive. + /// + /// + /// Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, + /// complete element. Possible values are: plain (default) or html. + /// + /// Translation target parameters. + /// A new instance for mocking. + public static TranslateBody TranslateBody(string text = null, string script = null, string language = null, TextType? textType = null, IEnumerable targets = null) + { + targets ??= new List(); + + return new TranslateBody( + text, + serializedAdditionalRawData: null, + script, + language, + textType, + targets?.ToList()); } /// Initializes a new instance of . @@ -126,32 +156,24 @@ public static TranslatedTextItem TranslatedTextItem(DetectedLanguage detectedLan /// Initializes a new instance of . /// A string representing the code of the detected language. - /// + /// /// A float value indicating the confidence in the result. /// The score is between zero and one and a low score indicates a low confidence. /// /// A new instance for mocking. - public static DetectedLanguage DetectedLanguage(string language = null, float confidence = default) + public static DetectedLanguage DetectedLanguage(string language = null, float score = default) { - return new DetectedLanguage(language, confidence, serializedAdditionalRawData: null); + return new DetectedLanguage(language, score, serializedAdditionalRawData: null); } /// Initializes a new instance of . - /// A string representing the language code of the target language. + /// A string representing the language code of the target language. /// A string giving the translated text. /// An object giving the translated text in the script specified by the toScript parameter. - /// Alignment information. - /// Sentence boundaries in the input and output texts. /// A new instance for mocking. - public static TranslationText TranslationText(string targetLanguage = null, string text = null, TransliteratedText transliteration = null, TranslatedTextAlignment alignment = null, SentenceBoundaries sentenceBoundaries = null) + public static TranslationText TranslationText(string to = null, string text = null, TransliteratedText transliteration = null) { - return new TranslationText( - targetLanguage, - text, - transliteration, - alignment, - sentenceBoundaries, - serializedAdditionalRawData: null); + return new TranslationText(to, text, transliteration, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -163,39 +185,6 @@ public static TransliteratedText TransliteratedText(string text = null, string s return new TransliteratedText(text, script, serializedAdditionalRawData: null); } - /// Initializes a new instance of . - /// - /// Maps input text to translated text. The alignment information is only provided when the request - /// parameter includeAlignment is true. Alignment is returned as a string value of the following - /// format: [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]. - /// The colon separates start and end index, the dash separates the languages, and space separates the words. - /// One word may align with zero, one, or multiple words in the other language, and the aligned words may - /// be non-contiguous. When no alignment information is available, the alignment element will be empty. - /// - /// A new instance for mocking. - public static TranslatedTextAlignment TranslatedTextAlignment(string projections = null) - { - return new TranslatedTextAlignment(projections, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// - /// An integer array representing the lengths of the sentences in the translated text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// A new instance for mocking. - public static SentenceBoundaries SentenceBoundaries(IEnumerable sourceSentencesLengths = null, IEnumerable translatedSentencesLengths = null) - { - sourceSentencesLengths ??= new List(); - translatedSentencesLengths ??= new List(); - - return new SentenceBoundaries(sourceSentencesLengths?.ToList(), translatedSentencesLengths?.ToList(), serializedAdditionalRawData: null); - } - /// Initializes a new instance of . /// Input text in the default script of the source language. /// A new instance for mocking. @@ -203,162 +192,5 @@ public static SourceText SourceText(string text = null) { return new SourceText(text, serializedAdditionalRawData: null); } - - /// Initializes a new instance of . - /// The detectedLanguage property is only present in the result object when language auto-detection is requested. - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// A new instance for mocking. - public static BreakSentenceItem BreakSentenceItem(DetectedLanguage detectedLanguage = null, IEnumerable sentencesLengths = null) - { - sentencesLengths ??= new List(); - - return new BreakSentenceItem(detectedLanguage, sentencesLengths?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. - /// For example, if the request is "JOHN", the normalized form will be "john". - /// The content of this field becomes the input to lookup examples. - /// - /// - /// A string giving the source term in a form best suited for end-user display. - /// For example, if the input is "JOHN", the display form will reflect the usual - /// spelling of the name: "John". - /// - /// A list of translations for the source term. - /// A new instance for mocking. - public static DictionaryLookupItem DictionaryLookupItem(string normalizedSource = null, string displaySource = null, IEnumerable translations = null) - { - translations ??= new List(); - - return new DictionaryLookupItem(normalizedSource, displaySource, translations?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of this term in the target language. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the term in the target language and in a form best suited - /// for end-user display. Generally, this will only differ from the normalizedTarget - /// in terms of capitalization. For example, a proper noun like "Juan" will have - /// normalizedTarget = "juan" and displayTarget = "Juan". - /// - /// A string associating this term with a part-of-speech tag. - /// - /// A value between 0.0 and 1.0 which represents the "confidence" - /// (or perhaps more accurately, "probability in the training data") of that translation pair. - /// The sum of confidence scores for one source word may or may not sum to 1.0. - /// - /// - /// A string giving the word to display as a prefix of the translation. Currently, - /// this is the gendered determiner of nouns, in languages that have gendered determiners. - /// For example, the prefix of the Spanish word "mosca" is "la", since "mosca" is a feminine noun in Spanish. - /// This is only dependent on the translation, and not on the source. - /// If there is no prefix, it will be the empty string. - /// - /// - /// A list of "back translations" of the target. For example, source words that the target can translate to. - /// The list is guaranteed to contain the source word that was requested (e.g., if the source word being - /// looked up is "fly", then it is guaranteed that "fly" will be in the backTranslations list). - /// However, it is not guaranteed to be in the first position, and often will not be. - /// - /// A new instance for mocking. - public static DictionaryTranslation DictionaryTranslation(string normalizedTarget = null, string displayTarget = null, string posTag = null, float confidence = default, string prefixWord = null, IEnumerable backTranslations = null) - { - backTranslations ??= new List(); - - return new DictionaryTranslation( - normalizedTarget, - displayTarget, - posTag, - confidence, - prefixWord, - backTranslations?.ToList(), - serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term that is a back-translation of the target. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the source term that is a back-translation of the target in a form best - /// suited for end-user display. - /// - /// - /// An integer representing the number of examples that are available for this translation pair. - /// Actual examples must be retrieved with a separate call to lookup examples. The number is mostly - /// intended to facilitate display in a UX. For example, a user interface may add a hyperlink - /// to the back-translation if the number of examples is greater than zero and show the back-translation - /// as plain text if there are no examples. Note that the actual number of examples returned - /// by a call to lookup examples may be less than numExamples, because additional filtering may be - /// applied on the fly to remove "bad" examples. - /// - /// - /// An integer representing the frequency of this translation pair in the data. The main purpose of this - /// field is to provide a user interface with a means to sort back-translations so the most frequent terms are first. - /// - /// A new instance for mocking. - public static BackTranslation BackTranslation(string normalizedText = null, string displayText = null, int examplesCount = default, int frequencyCount = default) - { - return new BackTranslation(normalizedText, displayText, examplesCount, frequencyCount, serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. Generally, this should be identical - /// to the value of the Text field at the matching list index in the body of the request. - /// - /// - /// A string giving the normalized form of the target term. Generally, this should be identical - /// to the value of the Translation field at the matching list index in the body of the request. - /// - /// A list of examples for the (source term, target term) pair. - /// A new instance for mocking. - public static DictionaryExampleItem DictionaryExampleItem(string normalizedSource = null, string normalizedTarget = null, IEnumerable examples = null) - { - examples ??= new List(); - - return new DictionaryExampleItem(normalizedSource, normalizedTarget, examples?.ToList(), serializedAdditionalRawData: null); - } - - /// Initializes a new instance of . - /// - /// The string to concatenate before the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// - /// A string equal to the actual term looked up. The string is added with sourcePrefix - /// and sourceSuffix to form the complete example. Its value is separated so it can be - /// marked in a user interface, e.g., by bolding it. - /// - /// - /// The string to concatenate after the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// A string similar to sourcePrefix but for the target. - /// A string similar to sourceTerm but for the target. - /// A string similar to sourceSuffix but for the target. - /// A new instance for mocking. - public static DictionaryExample DictionaryExample(string sourcePrefix = null, string sourceTerm = null, string sourceSuffix = null, string targetPrefix = null, string targetTerm = null, string targetSuffix = null) - { - return new DictionaryExample( - sourcePrefix, - sourceTerm, - sourceSuffix, - targetPrefix, - targetTerm, - targetSuffix, - serializedAdditionalRawData: null); - } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.Serialization.cs deleted file mode 100644 index f6adad28a965..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.Serialization.cs +++ /dev/null @@ -1,166 +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.Translation.Text -{ - public partial class BackTranslation : 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(BackTranslation)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("normalizedText"u8); - writer.WriteStringValue(NormalizedText); - writer.WritePropertyName("displayText"u8); - writer.WriteStringValue(DisplayText); - writer.WritePropertyName("numExamples"u8); - writer.WriteNumberValue(ExamplesCount); - writer.WritePropertyName("frequencyCount"u8); - writer.WriteNumberValue(FrequencyCount); - 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 - } - } - } - - BackTranslation 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(BackTranslation)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeBackTranslation(document.RootElement, options); - } - - internal static BackTranslation DeserializeBackTranslation(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string normalizedText = default; - string displayText = default; - int numExamples = default; - int frequencyCount = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("normalizedText"u8)) - { - normalizedText = property.Value.GetString(); - continue; - } - if (property.NameEquals("displayText"u8)) - { - displayText = property.Value.GetString(); - continue; - } - if (property.NameEquals("numExamples"u8)) - { - numExamples = property.Value.GetInt32(); - continue; - } - if (property.NameEquals("frequencyCount"u8)) - { - frequencyCount = property.Value.GetInt32(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new BackTranslation(normalizedText, displayText, numExamples, frequencyCount, 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(BackTranslation)} does not support writing '{options.Format}' format."); - } - } - - BackTranslation 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 DeserializeBackTranslation(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(BackTranslation)} 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 BackTranslation FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeBackTranslation(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/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.cs deleted file mode 100644 index 5eeb74c3c083..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BackTranslation.cs +++ /dev/null @@ -1,145 +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.Translation.Text -{ - /// Back Translation. - public partial class BackTranslation - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term that is a back-translation of the target. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the source term that is a back-translation of the target in a form best - /// suited for end-user display. - /// - /// - /// An integer representing the number of examples that are available for this translation pair. - /// Actual examples must be retrieved with a separate call to lookup examples. The number is mostly - /// intended to facilitate display in a UX. For example, a user interface may add a hyperlink - /// to the back-translation if the number of examples is greater than zero and show the back-translation - /// as plain text if there are no examples. Note that the actual number of examples returned - /// by a call to lookup examples may be less than numExamples, because additional filtering may be - /// applied on the fly to remove "bad" examples. - /// - /// - /// An integer representing the frequency of this translation pair in the data. The main purpose of this - /// field is to provide a user interface with a means to sort back-translations so the most frequent terms are first. - /// - /// or is null. - internal BackTranslation(string normalizedText, string displayText, int examplesCount, int frequencyCount) - { - Argument.AssertNotNull(normalizedText, nameof(normalizedText)); - Argument.AssertNotNull(displayText, nameof(displayText)); - - NormalizedText = normalizedText; - DisplayText = displayText; - ExamplesCount = examplesCount; - FrequencyCount = frequencyCount; - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term that is a back-translation of the target. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the source term that is a back-translation of the target in a form best - /// suited for end-user display. - /// - /// - /// An integer representing the number of examples that are available for this translation pair. - /// Actual examples must be retrieved with a separate call to lookup examples. The number is mostly - /// intended to facilitate display in a UX. For example, a user interface may add a hyperlink - /// to the back-translation if the number of examples is greater than zero and show the back-translation - /// as plain text if there are no examples. Note that the actual number of examples returned - /// by a call to lookup examples may be less than numExamples, because additional filtering may be - /// applied on the fly to remove "bad" examples. - /// - /// - /// An integer representing the frequency of this translation pair in the data. The main purpose of this - /// field is to provide a user interface with a means to sort back-translations so the most frequent terms are first. - /// - /// Keeps track of any properties unknown to the library. - internal BackTranslation(string normalizedText, string displayText, int examplesCount, int frequencyCount, IDictionary serializedAdditionalRawData) - { - NormalizedText = normalizedText; - DisplayText = displayText; - ExamplesCount = examplesCount; - FrequencyCount = frequencyCount; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal BackTranslation() - { - } - - /// - /// A string giving the normalized form of the source term that is a back-translation of the target. - /// This value should be used as input to lookup examples. - /// - public string NormalizedText { get; } - /// - /// A string giving the source term that is a back-translation of the target in a form best - /// suited for end-user display. - /// - public string DisplayText { get; } - /// - /// An integer representing the number of examples that are available for this translation pair. - /// Actual examples must be retrieved with a separate call to lookup examples. The number is mostly - /// intended to facilitate display in a UX. For example, a user interface may add a hyperlink - /// to the back-translation if the number of examples is greater than zero and show the back-translation - /// as plain text if there are no examples. Note that the actual number of examples returned - /// by a call to lookup examples may be less than numExamples, because additional filtering may be - /// applied on the fly to remove "bad" examples. - /// - public int ExamplesCount { get; } - /// - /// An integer representing the frequency of this translation pair in the data. The main purpose of this - /// field is to provide a user interface with a means to sort back-translations so the most frequent terms are first. - /// - public int FrequencyCount { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.Serialization.cs deleted file mode 100644 index 3798c2a1beee..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.Serialization.cs +++ /dev/null @@ -1,167 +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.Translation.Text -{ - public partial class BreakSentenceItem : 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(BreakSentenceItem)} does not support writing '{format}' format."); - } - - if (Optional.IsDefined(DetectedLanguage)) - { - writer.WritePropertyName("detectedLanguage"u8); - writer.WriteObjectValue(DetectedLanguage, options); - } - writer.WritePropertyName("sentLen"u8); - writer.WriteStartArray(); - foreach (var item in SentencesLengths) - { - writer.WriteNumberValue(item); - } - writer.WriteEndArray(); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - BreakSentenceItem 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(BreakSentenceItem)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeBreakSentenceItem(document.RootElement, options); - } - - internal static BreakSentenceItem DeserializeBreakSentenceItem(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - DetectedLanguage detectedLanguage = default; - IReadOnlyList sentLen = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("detectedLanguage"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - detectedLanguage = DetectedLanguage.DeserializeDetectedLanguage(property.Value, options); - continue; - } - if (property.NameEquals("sentLen"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetInt32()); - } - sentLen = array; - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new BreakSentenceItem(detectedLanguage, sentLen, 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(BreakSentenceItem)} does not support writing '{options.Format}' format."); - } - } - - BreakSentenceItem 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 DeserializeBreakSentenceItem(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(BreakSentenceItem)} 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 BreakSentenceItem FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeBreakSentenceItem(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/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.cs deleted file mode 100644 index c1d283a64f86..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/BreakSentenceItem.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Translation.Text -{ - /// Item containing break sentence result. - public partial class BreakSentenceItem - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// is null. - internal BreakSentenceItem(IEnumerable sentencesLengths) - { - Argument.AssertNotNull(sentencesLengths, nameof(sentencesLengths)); - - SentencesLengths = sentencesLengths.ToList(); - } - - /// Initializes a new instance of . - /// The detectedLanguage property is only present in the result object when language auto-detection is requested. - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// Keeps track of any properties unknown to the library. - internal BreakSentenceItem(DetectedLanguage detectedLanguage, IReadOnlyList sentencesLengths, IDictionary serializedAdditionalRawData) - { - DetectedLanguage = detectedLanguage; - SentencesLengths = sentencesLengths; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal BreakSentenceItem() - { - } - - /// The detectedLanguage property is only present in the result object when language auto-detection is requested. - public DetectedLanguage DetectedLanguage { get; } - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - public IReadOnlyList SentencesLengths { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.Serialization.cs index a26a23f36cc5..cbe2c88d4c94 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.Serialization.cs @@ -37,7 +37,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("language"u8); writer.WriteStringValue(Language); writer.WritePropertyName("score"u8); - writer.WriteNumberValue(Confidence); + writer.WriteNumberValue(Score); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.cs index 22b9c2194b90..3be254c3db19 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DetectedLanguage.cs @@ -47,30 +47,30 @@ public partial class DetectedLanguage /// Initializes a new instance of . /// A string representing the code of the detected language. - /// + /// /// A float value indicating the confidence in the result. /// The score is between zero and one and a low score indicates a low confidence. /// /// is null. - internal DetectedLanguage(string language, float confidence) + internal DetectedLanguage(string language, float score) { Argument.AssertNotNull(language, nameof(language)); Language = language; - Confidence = confidence; + Score = score; } /// Initializes a new instance of . /// A string representing the code of the detected language. - /// + /// /// A float value indicating the confidence in the result. /// The score is between zero and one and a low score indicates a low confidence. /// /// Keeps track of any properties unknown to the library. - internal DetectedLanguage(string language, float confidence, IDictionary serializedAdditionalRawData) + internal DetectedLanguage(string language, float score, IDictionary serializedAdditionalRawData) { Language = language; - Confidence = confidence; + Score = score; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -85,6 +85,6 @@ internal DetectedLanguage() /// A float value indicating the confidence in the result. /// The score is between zero and one and a low score indicates a low confidence. /// - public float Confidence { get; } + public float Score { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.Serialization.cs deleted file mode 100644 index e7afe740f463..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.Serialization.cs +++ /dev/null @@ -1,189 +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.Translation.Text -{ - public partial class DictionaryExample : 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(DictionaryExample)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("sourcePrefix"u8); - writer.WriteStringValue(SourcePrefix); - writer.WritePropertyName("sourceTerm"u8); - writer.WriteStringValue(SourceTerm); - writer.WritePropertyName("sourceSuffix"u8); - writer.WriteStringValue(SourceSuffix); - writer.WritePropertyName("targetPrefix"u8); - writer.WriteStringValue(TargetPrefix); - writer.WritePropertyName("targetTerm"u8); - writer.WriteStringValue(TargetTerm); - writer.WritePropertyName("targetSuffix"u8); - writer.WriteStringValue(TargetSuffix); - 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 - } - } - } - - DictionaryExample 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(DictionaryExample)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeDictionaryExample(document.RootElement, options); - } - - internal static DictionaryExample DeserializeDictionaryExample(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string sourcePrefix = default; - string sourceTerm = default; - string sourceSuffix = default; - string targetPrefix = default; - string targetTerm = default; - string targetSuffix = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("sourcePrefix"u8)) - { - sourcePrefix = property.Value.GetString(); - continue; - } - if (property.NameEquals("sourceTerm"u8)) - { - sourceTerm = property.Value.GetString(); - continue; - } - if (property.NameEquals("sourceSuffix"u8)) - { - sourceSuffix = property.Value.GetString(); - continue; - } - if (property.NameEquals("targetPrefix"u8)) - { - targetPrefix = property.Value.GetString(); - continue; - } - if (property.NameEquals("targetTerm"u8)) - { - targetTerm = property.Value.GetString(); - continue; - } - if (property.NameEquals("targetSuffix"u8)) - { - targetSuffix = property.Value.GetString(); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new DictionaryExample( - sourcePrefix, - sourceTerm, - sourceSuffix, - targetPrefix, - targetTerm, - targetSuffix, - 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(DictionaryExample)} does not support writing '{options.Format}' format."); - } - } - - DictionaryExample 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 DeserializeDictionaryExample(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(DictionaryExample)} 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 DictionaryExample FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryExample(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/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.cs deleted file mode 100644 index f273add1258e..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExample.cs +++ /dev/null @@ -1,146 +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.Translation.Text -{ - /// Dictionary Example. - public partial class DictionaryExample - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// The string to concatenate before the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// - /// A string equal to the actual term looked up. The string is added with sourcePrefix - /// and sourceSuffix to form the complete example. Its value is separated so it can be - /// marked in a user interface, e.g., by bolding it. - /// - /// - /// The string to concatenate after the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// A string similar to sourcePrefix but for the target. - /// A string similar to sourceTerm but for the target. - /// A string similar to sourceSuffix but for the target. - /// , , , , or is null. - internal DictionaryExample(string sourcePrefix, string sourceTerm, string sourceSuffix, string targetPrefix, string targetTerm, string targetSuffix) - { - Argument.AssertNotNull(sourcePrefix, nameof(sourcePrefix)); - Argument.AssertNotNull(sourceTerm, nameof(sourceTerm)); - Argument.AssertNotNull(sourceSuffix, nameof(sourceSuffix)); - Argument.AssertNotNull(targetPrefix, nameof(targetPrefix)); - Argument.AssertNotNull(targetTerm, nameof(targetTerm)); - Argument.AssertNotNull(targetSuffix, nameof(targetSuffix)); - - SourcePrefix = sourcePrefix; - SourceTerm = sourceTerm; - SourceSuffix = sourceSuffix; - TargetPrefix = targetPrefix; - TargetTerm = targetTerm; - TargetSuffix = targetSuffix; - } - - /// Initializes a new instance of . - /// - /// The string to concatenate before the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// - /// A string equal to the actual term looked up. The string is added with sourcePrefix - /// and sourceSuffix to form the complete example. Its value is separated so it can be - /// marked in a user interface, e.g., by bolding it. - /// - /// - /// The string to concatenate after the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - /// A string similar to sourcePrefix but for the target. - /// A string similar to sourceTerm but for the target. - /// A string similar to sourceSuffix but for the target. - /// Keeps track of any properties unknown to the library. - internal DictionaryExample(string sourcePrefix, string sourceTerm, string sourceSuffix, string targetPrefix, string targetTerm, string targetSuffix, IDictionary serializedAdditionalRawData) - { - SourcePrefix = sourcePrefix; - SourceTerm = sourceTerm; - SourceSuffix = sourceSuffix; - TargetPrefix = targetPrefix; - TargetTerm = targetTerm; - TargetSuffix = targetSuffix; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal DictionaryExample() - { - } - - /// - /// The string to concatenate before the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - public string SourcePrefix { get; } - /// - /// A string equal to the actual term looked up. The string is added with sourcePrefix - /// and sourceSuffix to form the complete example. Its value is separated so it can be - /// marked in a user interface, e.g., by bolding it. - /// - public string SourceTerm { get; } - /// - /// The string to concatenate after the value of sourceTerm to form a complete example. - /// Do not add a space character, since it is already there when it should be. - /// This value may be an empty string. - /// - public string SourceSuffix { get; } - /// A string similar to sourcePrefix but for the target. - public string TargetPrefix { get; } - /// A string similar to sourceTerm but for the target. - public string TargetTerm { get; } - /// A string similar to sourceSuffix but for the target. - public string TargetSuffix { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.cs deleted file mode 100644 index e966305aaa81..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Translation.Text -{ - /// Dictionary Example element. - public partial class DictionaryExampleItem - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. Generally, this should be identical - /// to the value of the Text field at the matching list index in the body of the request. - /// - /// - /// A string giving the normalized form of the target term. Generally, this should be identical - /// to the value of the Translation field at the matching list index in the body of the request. - /// - /// A list of examples for the (source term, target term) pair. - /// , or is null. - internal DictionaryExampleItem(string normalizedSource, string normalizedTarget, IEnumerable examples) - { - Argument.AssertNotNull(normalizedSource, nameof(normalizedSource)); - Argument.AssertNotNull(normalizedTarget, nameof(normalizedTarget)); - Argument.AssertNotNull(examples, nameof(examples)); - - NormalizedSource = normalizedSource; - NormalizedTarget = normalizedTarget; - Examples = examples.ToList(); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. Generally, this should be identical - /// to the value of the Text field at the matching list index in the body of the request. - /// - /// - /// A string giving the normalized form of the target term. Generally, this should be identical - /// to the value of the Translation field at the matching list index in the body of the request. - /// - /// A list of examples for the (source term, target term) pair. - /// Keeps track of any properties unknown to the library. - internal DictionaryExampleItem(string normalizedSource, string normalizedTarget, IReadOnlyList examples, IDictionary serializedAdditionalRawData) - { - NormalizedSource = normalizedSource; - NormalizedTarget = normalizedTarget; - Examples = examples; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal DictionaryExampleItem() - { - } - - /// - /// A string giving the normalized form of the source term. Generally, this should be identical - /// to the value of the Text field at the matching list index in the body of the request. - /// - public string NormalizedSource { get; } - /// - /// A string giving the normalized form of the target term. Generally, this should be identical - /// to the value of the Translation field at the matching list index in the body of the request. - /// - public string NormalizedTarget { get; } - /// A list of examples for the (source term, target term) pair. - public IReadOnlyList Examples { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.Serialization.cs deleted file mode 100644 index 937462d8f137..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.Serialization.cs +++ /dev/null @@ -1,134 +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.Translation.Text -{ - public partial class DictionaryExampleTextItem : 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(DictionaryExampleTextItem)} does not support writing '{format}' format."); - } - - base.JsonModelWriteCore(writer, options); - writer.WritePropertyName("translation"u8); - writer.WriteStringValue(Translation); - } - - DictionaryExampleTextItem 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(DictionaryExampleTextItem)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeDictionaryExampleTextItem(document.RootElement, options); - } - - internal static DictionaryExampleTextItem DeserializeDictionaryExampleTextItem(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string translation = default; - string text = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("translation"u8)) - { - translation = 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 DictionaryExampleTextItem(text, serializedAdditionalRawData, translation); - } - - 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(DictionaryExampleTextItem)} does not support writing '{options.Format}' format."); - } - } - - DictionaryExampleTextItem 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 DeserializeDictionaryExampleTextItem(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(DictionaryExampleTextItem)} 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 DictionaryExampleTextItem FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryExampleTextItem(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/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.cs deleted file mode 100644 index 17dbd8f016c5..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleTextItem.cs +++ /dev/null @@ -1,57 +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.Translation.Text -{ - /// Element containing the text with translation. - public partial class DictionaryExampleTextItem : InputTextItem - { - /// Initializes a new instance of . - /// Text to translate. - /// - /// A string specifying the translated text previously returned by the Dictionary lookup operation. - /// This should be the value from the normalizedTarget field in the translations list of the Dictionary - /// lookup response. The service will return examples for the specific source-target word-pair. - /// - /// or is null. - public DictionaryExampleTextItem(string text, string translation) : base(text) - { - Argument.AssertNotNull(text, nameof(text)); - Argument.AssertNotNull(translation, nameof(translation)); - - Translation = translation; - } - - /// Initializes a new instance of . - /// Text to translate. - /// Keeps track of any properties unknown to the library. - /// - /// A string specifying the translated text previously returned by the Dictionary lookup operation. - /// This should be the value from the normalizedTarget field in the translations list of the Dictionary - /// lookup response. The service will return examples for the specific source-target word-pair. - /// - internal DictionaryExampleTextItem(string text, IDictionary serializedAdditionalRawData, string translation) : base(text, serializedAdditionalRawData) - { - Translation = translation; - } - - /// Initializes a new instance of for deserialization. - internal DictionaryExampleTextItem() - { - } - - /// - /// A string specifying the translated text previously returned by the Dictionary lookup operation. - /// This should be the value from the normalizedTarget field in the translations list of the Dictionary - /// lookup response. The service will return examples for the specific source-target word-pair. - /// - public string Translation { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.Serialization.cs deleted file mode 100644 index 2b04ab74f91d..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.Serialization.cs +++ /dev/null @@ -1,168 +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.Translation.Text -{ - public partial class DictionaryLookupItem : 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(DictionaryLookupItem)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("normalizedSource"u8); - writer.WriteStringValue(NormalizedSource); - writer.WritePropertyName("displaySource"u8); - writer.WriteStringValue(DisplaySource); - writer.WritePropertyName("translations"u8); - writer.WriteStartArray(); - foreach (var item in Translations) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - DictionaryLookupItem 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(DictionaryLookupItem)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeDictionaryLookupItem(document.RootElement, options); - } - - internal static DictionaryLookupItem DeserializeDictionaryLookupItem(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string normalizedSource = default; - string displaySource = default; - IReadOnlyList translations = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("normalizedSource"u8)) - { - normalizedSource = property.Value.GetString(); - continue; - } - if (property.NameEquals("displaySource"u8)) - { - displaySource = property.Value.GetString(); - continue; - } - if (property.NameEquals("translations"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(DictionaryTranslation.DeserializeDictionaryTranslation(item, options)); - } - translations = array; - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new DictionaryLookupItem(normalizedSource, displaySource, translations, 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(DictionaryLookupItem)} does not support writing '{options.Format}' format."); - } - } - - DictionaryLookupItem 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 DeserializeDictionaryLookupItem(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(DictionaryLookupItem)} 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 DictionaryLookupItem FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryLookupItem(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/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.cs deleted file mode 100644 index b4f0318142cf..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryLookupItem.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Translation.Text -{ - /// Dictionary Lookup Element. - public partial class DictionaryLookupItem - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. - /// For example, if the request is "JOHN", the normalized form will be "john". - /// The content of this field becomes the input to lookup examples. - /// - /// - /// A string giving the source term in a form best suited for end-user display. - /// For example, if the input is "JOHN", the display form will reflect the usual - /// spelling of the name: "John". - /// - /// A list of translations for the source term. - /// , or is null. - internal DictionaryLookupItem(string normalizedSource, string displaySource, IEnumerable translations) - { - Argument.AssertNotNull(normalizedSource, nameof(normalizedSource)); - Argument.AssertNotNull(displaySource, nameof(displaySource)); - Argument.AssertNotNull(translations, nameof(translations)); - - NormalizedSource = normalizedSource; - DisplaySource = displaySource; - Translations = translations.ToList(); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of the source term. - /// For example, if the request is "JOHN", the normalized form will be "john". - /// The content of this field becomes the input to lookup examples. - /// - /// - /// A string giving the source term in a form best suited for end-user display. - /// For example, if the input is "JOHN", the display form will reflect the usual - /// spelling of the name: "John". - /// - /// A list of translations for the source term. - /// Keeps track of any properties unknown to the library. - internal DictionaryLookupItem(string normalizedSource, string displaySource, IReadOnlyList translations, IDictionary serializedAdditionalRawData) - { - NormalizedSource = normalizedSource; - DisplaySource = displaySource; - Translations = translations; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal DictionaryLookupItem() - { - } - - /// - /// A string giving the normalized form of the source term. - /// For example, if the request is "JOHN", the normalized form will be "john". - /// The content of this field becomes the input to lookup examples. - /// - public string NormalizedSource { get; } - /// - /// A string giving the source term in a form best suited for end-user display. - /// For example, if the input is "JOHN", the display form will reflect the usual - /// spelling of the name: "John". - /// - public string DisplaySource { get; } - /// A list of translations for the source term. - public IReadOnlyList Translations { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.Serialization.cs deleted file mode 100644 index 2aa6ee959c5e..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.Serialization.cs +++ /dev/null @@ -1,199 +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.Translation.Text -{ - public partial class DictionaryTranslation : 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(DictionaryTranslation)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("normalizedTarget"u8); - writer.WriteStringValue(NormalizedTarget); - writer.WritePropertyName("displayTarget"u8); - writer.WriteStringValue(DisplayTarget); - writer.WritePropertyName("posTag"u8); - writer.WriteStringValue(PosTag); - writer.WritePropertyName("confidence"u8); - writer.WriteNumberValue(Confidence); - writer.WritePropertyName("prefixWord"u8); - writer.WriteStringValue(PrefixWord); - writer.WritePropertyName("backTranslations"u8); - writer.WriteStartArray(); - foreach (var item in BackTranslations) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - DictionaryTranslation 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(DictionaryTranslation)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeDictionaryTranslation(document.RootElement, options); - } - - internal static DictionaryTranslation DeserializeDictionaryTranslation(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string normalizedTarget = default; - string displayTarget = default; - string posTag = default; - float confidence = default; - string prefixWord = default; - IReadOnlyList backTranslations = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("normalizedTarget"u8)) - { - normalizedTarget = property.Value.GetString(); - continue; - } - if (property.NameEquals("displayTarget"u8)) - { - displayTarget = property.Value.GetString(); - continue; - } - if (property.NameEquals("posTag"u8)) - { - posTag = property.Value.GetString(); - continue; - } - if (property.NameEquals("confidence"u8)) - { - confidence = property.Value.GetSingle(); - continue; - } - if (property.NameEquals("prefixWord"u8)) - { - prefixWord = property.Value.GetString(); - continue; - } - if (property.NameEquals("backTranslations"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(BackTranslation.DeserializeBackTranslation(item, options)); - } - backTranslations = array; - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new DictionaryTranslation( - normalizedTarget, - displayTarget, - posTag, - confidence, - prefixWord, - backTranslations, - 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(DictionaryTranslation)} does not support writing '{options.Format}' format."); - } - } - - DictionaryTranslation 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 DeserializeDictionaryTranslation(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(DictionaryTranslation)} 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 DictionaryTranslation FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryTranslation(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/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.cs deleted file mode 100644 index 39974ef7659c..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryTranslation.cs +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Translation.Text -{ - /// Translation source term. - public partial class DictionaryTranslation - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of this term in the target language. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the term in the target language and in a form best suited - /// for end-user display. Generally, this will only differ from the normalizedTarget - /// in terms of capitalization. For example, a proper noun like "Juan" will have - /// normalizedTarget = "juan" and displayTarget = "Juan". - /// - /// A string associating this term with a part-of-speech tag. - /// - /// A value between 0.0 and 1.0 which represents the "confidence" - /// (or perhaps more accurately, "probability in the training data") of that translation pair. - /// The sum of confidence scores for one source word may or may not sum to 1.0. - /// - /// - /// A string giving the word to display as a prefix of the translation. Currently, - /// this is the gendered determiner of nouns, in languages that have gendered determiners. - /// For example, the prefix of the Spanish word "mosca" is "la", since "mosca" is a feminine noun in Spanish. - /// This is only dependent on the translation, and not on the source. - /// If there is no prefix, it will be the empty string. - /// - /// - /// A list of "back translations" of the target. For example, source words that the target can translate to. - /// The list is guaranteed to contain the source word that was requested (e.g., if the source word being - /// looked up is "fly", then it is guaranteed that "fly" will be in the backTranslations list). - /// However, it is not guaranteed to be in the first position, and often will not be. - /// - /// , , , or is null. - internal DictionaryTranslation(string normalizedTarget, string displayTarget, string posTag, float confidence, string prefixWord, IEnumerable backTranslations) - { - Argument.AssertNotNull(normalizedTarget, nameof(normalizedTarget)); - Argument.AssertNotNull(displayTarget, nameof(displayTarget)); - Argument.AssertNotNull(posTag, nameof(posTag)); - Argument.AssertNotNull(prefixWord, nameof(prefixWord)); - Argument.AssertNotNull(backTranslations, nameof(backTranslations)); - - NormalizedTarget = normalizedTarget; - DisplayTarget = displayTarget; - PosTag = posTag; - Confidence = confidence; - PrefixWord = prefixWord; - BackTranslations = backTranslations.ToList(); - } - - /// Initializes a new instance of . - /// - /// A string giving the normalized form of this term in the target language. - /// This value should be used as input to lookup examples. - /// - /// - /// A string giving the term in the target language and in a form best suited - /// for end-user display. Generally, this will only differ from the normalizedTarget - /// in terms of capitalization. For example, a proper noun like "Juan" will have - /// normalizedTarget = "juan" and displayTarget = "Juan". - /// - /// A string associating this term with a part-of-speech tag. - /// - /// A value between 0.0 and 1.0 which represents the "confidence" - /// (or perhaps more accurately, "probability in the training data") of that translation pair. - /// The sum of confidence scores for one source word may or may not sum to 1.0. - /// - /// - /// A string giving the word to display as a prefix of the translation. Currently, - /// this is the gendered determiner of nouns, in languages that have gendered determiners. - /// For example, the prefix of the Spanish word "mosca" is "la", since "mosca" is a feminine noun in Spanish. - /// This is only dependent on the translation, and not on the source. - /// If there is no prefix, it will be the empty string. - /// - /// - /// A list of "back translations" of the target. For example, source words that the target can translate to. - /// The list is guaranteed to contain the source word that was requested (e.g., if the source word being - /// looked up is "fly", then it is guaranteed that "fly" will be in the backTranslations list). - /// However, it is not guaranteed to be in the first position, and often will not be. - /// - /// Keeps track of any properties unknown to the library. - internal DictionaryTranslation(string normalizedTarget, string displayTarget, string posTag, float confidence, string prefixWord, IReadOnlyList backTranslations, IDictionary serializedAdditionalRawData) - { - NormalizedTarget = normalizedTarget; - DisplayTarget = displayTarget; - PosTag = posTag; - Confidence = confidence; - PrefixWord = prefixWord; - BackTranslations = backTranslations; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal DictionaryTranslation() - { - } - - /// - /// A string giving the normalized form of this term in the target language. - /// This value should be used as input to lookup examples. - /// - public string NormalizedTarget { get; } - /// - /// A string giving the term in the target language and in a form best suited - /// for end-user display. Generally, this will only differ from the normalizedTarget - /// in terms of capitalization. For example, a proper noun like "Juan" will have - /// normalizedTarget = "juan" and displayTarget = "Juan". - /// - public string DisplayTarget { get; } - /// A string associating this term with a part-of-speech tag. - public string PosTag { get; } - /// - /// A value between 0.0 and 1.0 which represents the "confidence" - /// (or perhaps more accurately, "probability in the training data") of that translation pair. - /// The sum of confidence scores for one source word may or may not sum to 1.0. - /// - public float Confidence { get; } - /// - /// A string giving the word to display as a prefix of the translation. Currently, - /// this is the gendered determiner of nouns, in languages that have gendered determiners. - /// For example, the prefix of the Spanish word "mosca" is "la", since "mosca" is a feminine noun in Spanish. - /// This is only dependent on the translation, and not on the source. - /// If there is no prefix, it will be the empty string. - /// - public string PrefixWord { get; } - /// - /// A list of "back translations" of the target. For example, source words that the target can translate to. - /// The list is guaranteed to contain the source word that was requested (e.g., if the source word being - /// looked up is "fly", then it is guaranteed that "fly" will be in the backTranslations list). - /// However, it is not guaranteed to be in the first position, and often will not be. - /// - public IReadOnlyList BackTranslations { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/Docs/TextTranslationClient.xml b/sdk/translation/Azure.AI.Translation.Text/src/Generated/Docs/TextTranslationClient.xml index 75fdeb76b84f..8b5ae095d35e 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/Docs/TextTranslationClient.xml +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/Docs/TextTranslationClient.xml @@ -79,6 +79,256 @@ Response response = client.GetSupportedLanguages(null, null, null, null, null); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call TranslateAsync. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +Response> response = await client.TranslateAsync(new TranslateBody[] +{ + new TranslateBody("This is a test.", new TranslateTarget[] + { + new TranslateTarget(new string[]{"cs"}) + { + Script = "Latn", + ProfanityAction = ProfanityAction.NoAction, + ProfanityMarker = ProfanityMarker.Asterisk, + DeploymentNameModel = "general", + AllowFallback = true, + Grade = "basic", + Tone = "formal", + Gender = "neutral", + AdaptiveDatasetId = "21000", + ReferenceTextPairs = {new ReferenceSentencePair("Please test this out.", "Vyzkoušejte si to.")}, + } + }) + { + Script = "Latn", + Language = "en", + TextType = TextType.Plain, + } +}); +]]> +This sample shows how to call TranslateAsync. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +Response> response = await client.TranslateAsync(new TranslateBody[] +{ + new TranslateBody("This is a test.", new TranslateTarget[] + { + new TranslateTarget(new string[]{"cs"}) + }) +}); +]]> + + + +This sample shows how to call Translate. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +Response> response = client.Translate(new TranslateBody[] +{ + new TranslateBody("This is a test.", new TranslateTarget[] + { + new TranslateTarget(new string[]{"cs"}) + { + Script = "Latn", + ProfanityAction = ProfanityAction.NoAction, + ProfanityMarker = ProfanityMarker.Asterisk, + DeploymentNameModel = "general", + AllowFallback = true, + Grade = "basic", + Tone = "formal", + Gender = "neutral", + AdaptiveDatasetId = "21000", + ReferenceTextPairs = {new ReferenceSentencePair("Please test this out.", "Vyzkoušejte si to.")}, + } + }) + { + Script = "Latn", + Language = "en", + TextType = TextType.Plain, + } +}); +]]> +This sample shows how to call Translate. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +Response> response = client.Translate(new TranslateBody[] +{ + new TranslateBody("This is a test.", new TranslateTarget[] + { + new TranslateTarget(new string[]{"cs"}) + }) +}); +]]> + + + +This sample shows how to call TranslateAsync and parse the result. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +using RequestContent content = RequestContent.Create(new object[] +{ + new + { + text = "This is a test.", + script = "Latn", + language = "en", + textType = "Plain", + targets = new object[] + { + new + { + language = new object[] + { + "cs" + }, + script = "Latn", + profanityAction = "NoAction", + profanityMarker = "Asterisk", + deploymentNameModel = "general", + allowFallback = true, + grade = "basic", + tone = "formal", + gender = "neutral", + adaptiveDatasetId = "21000", + referenceTextPairs = new object[] + { + new + { + referenceTextPairsSource = "Please test this out.", + referenceTextPairsTarget = "Vyzkoušejte si to.", + } + }, + } + }, + } +}); +Response response = await client.TranslateAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); +]]> +This sample shows how to call TranslateAsync and parse the result. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +using RequestContent content = RequestContent.Create(new object[] +{ + new + { + text = "This is a test.", + targets = new object[] + { + new + { + language = new object[] + { + "cs" + }, + } + }, + } +}); +Response response = await client.TranslateAsync(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); +]]> + + + +This sample shows how to call Translate and parse the result. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +using RequestContent content = RequestContent.Create(new object[] +{ + new + { + text = "This is a test.", + script = "Latn", + language = "en", + textType = "Plain", + targets = new object[] + { + new + { + language = new object[] + { + "cs" + }, + script = "Latn", + profanityAction = "NoAction", + profanityMarker = "Asterisk", + deploymentNameModel = "general", + allowFallback = true, + grade = "basic", + tone = "formal", + gender = "neutral", + adaptiveDatasetId = "21000", + referenceTextPairs = new object[] + { + new + { + referenceTextPairsSource = "Please test this out.", + referenceTextPairsTarget = "Vyzkoušejte si to.", + } + }, + } + }, + } +}); +Response response = client.Translate(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); +]]> +This sample shows how to call Translate and parse the result. +"); +TextTranslationClient client = new TextTranslationClient(endpoint); + +using RequestContent content = RequestContent.Create(new object[] +{ + new + { + text = "This is a test.", + targets = new object[] + { + new + { + language = new object[] + { + "cs" + }, + } + }, + } +}); +Response response = client.Translate(content); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); +Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); ]]> diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.Serialization.cs index 54b66bfbb5b0..eff44f75b17e 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.Serialization.cs @@ -41,7 +41,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("nativeName"u8); writer.WriteStringValue(NativeName); writer.WritePropertyName("dir"u8); - writer.WriteStringValue(Directionality.ToSerialString()); + writer.WriteStringValue(Dir.ToSerialString()); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.cs index 94eb100e4809..314371ec9c64 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/LanguageScript.cs @@ -49,9 +49,9 @@ public partial class LanguageScript /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// , or is null. - internal LanguageScript(string code, string name, string nativeName, LanguageDirectionality directionality) + internal LanguageScript(string code, string name, string nativeName, LanguageDirectionality dir) { Argument.AssertNotNull(code, nameof(code)); Argument.AssertNotNull(name, nameof(name)); @@ -60,21 +60,21 @@ internal LanguageScript(string code, string name, string nativeName, LanguageDir Code = code; Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; } /// Initializes a new instance of . /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Keeps track of any properties unknown to the library. - internal LanguageScript(string code, string name, string nativeName, LanguageDirectionality directionality, IDictionary serializedAdditionalRawData) + internal LanguageScript(string code, string name, string nativeName, LanguageDirectionality dir, IDictionary serializedAdditionalRawData) { Code = code; Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -90,6 +90,6 @@ internal LanguageScript() /// Display name of the language in the locale native for the language. public string NativeName { get; } /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - public LanguageDirectionality Directionality { get; } + public LanguageDirectionality Dir { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.Serialization.cs similarity index 59% rename from sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.Serialization.cs rename to sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.Serialization.cs index d9505193d63c..78a3246037df 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/DictionaryExampleItem.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.Translation.Text { - public partial class DictionaryExampleItem : IUtf8JsonSerializable, IJsonModel + public partial class ReferenceSentencePair : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,23 +28,16 @@ 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; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(DictionaryExampleItem)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ReferenceSentencePair)} does not support writing '{format}' format."); } - writer.WritePropertyName("normalizedSource"u8); - writer.WriteStringValue(NormalizedSource); - writer.WritePropertyName("normalizedTarget"u8); - writer.WriteStringValue(NormalizedTarget); - writer.WritePropertyName("examples"u8); - writer.WriteStartArray(); - foreach (var item in Examples) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); + writer.WritePropertyName("referenceTextPairsSource"u8); + writer.WriteStringValue(ReferenceTextPairsSource); + writer.WritePropertyName("referenceTextPairsTarget"u8); + writer.WriteStringValue(ReferenceTextPairsTarget); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -62,19 +55,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - DictionaryExampleItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ReferenceSentencePair IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(DictionaryExampleItem)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ReferenceSentencePair)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeDictionaryExampleItem(document.RootElement, options); + return DeserializeReferenceSentencePair(document.RootElement, options); } - internal static DictionaryExampleItem DeserializeDictionaryExampleItem(JsonElement element, ModelReaderWriterOptions options = null) + internal static ReferenceSentencePair DeserializeReferenceSentencePair(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -82,31 +75,20 @@ internal static DictionaryExampleItem DeserializeDictionaryExampleItem(JsonEleme { return null; } - string normalizedSource = default; - string normalizedTarget = default; - IReadOnlyList examples = default; + string referenceTextPairsSource = default; + string referenceTextPairsTarget = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("normalizedSource"u8)) + if (property.NameEquals("referenceTextPairsSource"u8)) { - normalizedSource = property.Value.GetString(); + referenceTextPairsSource = property.Value.GetString(); continue; } - if (property.NameEquals("normalizedTarget"u8)) + if (property.NameEquals("referenceTextPairsTarget"u8)) { - normalizedTarget = property.Value.GetString(); - continue; - } - if (property.NameEquals("examples"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(DictionaryExample.DeserializeDictionaryExample(item, options)); - } - examples = array; + referenceTextPairsTarget = property.Value.GetString(); continue; } if (options.Format != "W") @@ -115,46 +97,46 @@ internal static DictionaryExampleItem DeserializeDictionaryExampleItem(JsonEleme } } serializedAdditionalRawData = rawDataDictionary; - return new DictionaryExampleItem(normalizedSource, normalizedTarget, examples, serializedAdditionalRawData); + return new ReferenceSentencePair(referenceTextPairsSource, referenceTextPairsTarget, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options, AzureAITranslationTextContext.Default); default: - throw new FormatException($"The model {nameof(DictionaryExampleItem)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ReferenceSentencePair)} does not support writing '{options.Format}' format."); } } - DictionaryExampleItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ReferenceSentencePair IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryExampleItem(document.RootElement, options); + return DeserializeReferenceSentencePair(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(DictionaryExampleItem)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ReferenceSentencePair)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static DictionaryExampleItem FromResponse(Response response) + internal static ReferenceSentencePair FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeDictionaryExampleItem(document.RootElement); + return DeserializeReferenceSentencePair(document.RootElement); } /// Convert into a . diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.cs new file mode 100644 index 000000000000..424c8977b4ee --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/ReferenceSentencePair.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.Translation.Text +{ + /// Reference sentence pair. + public partial class ReferenceSentencePair + { + /// + /// 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 . + /// Source reference sentence. + /// Target reference sentence. + /// or is null. + public ReferenceSentencePair(string referenceTextPairsSource, string referenceTextPairsTarget) + { + Argument.AssertNotNull(referenceTextPairsSource, nameof(referenceTextPairsSource)); + Argument.AssertNotNull(referenceTextPairsTarget, nameof(referenceTextPairsTarget)); + + ReferenceTextPairsSource = referenceTextPairsSource; + ReferenceTextPairsTarget = referenceTextPairsTarget; + } + + /// Initializes a new instance of . + /// Source reference sentence. + /// Target reference sentence. + /// Keeps track of any properties unknown to the library. + internal ReferenceSentencePair(string referenceTextPairsSource, string referenceTextPairsTarget, IDictionary serializedAdditionalRawData) + { + ReferenceTextPairsSource = referenceTextPairsSource; + ReferenceTextPairsTarget = referenceTextPairsTarget; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ReferenceSentencePair() + { + } + + /// Source reference sentence. + public string ReferenceTextPairsSource { get; } + /// Target reference sentence. + public string ReferenceTextPairsTarget { get; } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.Serialization.cs deleted file mode 100644 index 5a3b5111fd77..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.Serialization.cs +++ /dev/null @@ -1,170 +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.Translation.Text -{ - public partial class SentenceBoundaries : 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(SentenceBoundaries)} does not support writing '{format}' format."); - } - - writer.WritePropertyName("srcSentLen"u8); - writer.WriteStartArray(); - foreach (var item in SourceSentencesLengths) - { - writer.WriteNumberValue(item); - } - writer.WriteEndArray(); - writer.WritePropertyName("transSentLen"u8); - writer.WriteStartArray(); - foreach (var item in TranslatedSentencesLengths) - { - writer.WriteNumberValue(item); - } - writer.WriteEndArray(); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - SentenceBoundaries 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(SentenceBoundaries)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeSentenceBoundaries(document.RootElement, options); - } - - internal static SentenceBoundaries DeserializeSentenceBoundaries(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IReadOnlyList srcSentLen = default; - IReadOnlyList transSentLen = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("srcSentLen"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetInt32()); - } - srcSentLen = array; - continue; - } - if (property.NameEquals("transSentLen"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetInt32()); - } - transSentLen = array; - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new SentenceBoundaries(srcSentLen, transSentLen, 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, AzureAITranslationTextContext.Default); - default: - throw new FormatException($"The model {nameof(SentenceBoundaries)} does not support writing '{options.Format}' format."); - } - } - - SentenceBoundaries 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 DeserializeSentenceBoundaries(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(SentenceBoundaries)} 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 SentenceBoundaries FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeSentenceBoundaries(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/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.cs deleted file mode 100644 index 70fd3b61c965..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SentenceBoundaries.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Azure.AI.Translation.Text -{ - /// An object returning sentence boundaries in the input and output texts. - public partial class SentenceBoundaries - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// - /// An integer array representing the lengths of the sentences in the translated text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// or is null. - internal SentenceBoundaries(IEnumerable sourceSentencesLengths, IEnumerable translatedSentencesLengths) - { - Argument.AssertNotNull(sourceSentencesLengths, nameof(sourceSentencesLengths)); - Argument.AssertNotNull(translatedSentencesLengths, nameof(translatedSentencesLengths)); - - SourceSentencesLengths = sourceSentencesLengths.ToList(); - TranslatedSentencesLengths = translatedSentencesLengths.ToList(); - } - - /// Initializes a new instance of . - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// - /// An integer array representing the lengths of the sentences in the translated text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - /// Keeps track of any properties unknown to the library. - internal SentenceBoundaries(IReadOnlyList sourceSentencesLengths, IReadOnlyList translatedSentencesLengths, IDictionary serializedAdditionalRawData) - { - SourceSentencesLengths = sourceSentencesLengths; - TranslatedSentencesLengths = translatedSentencesLengths; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal SentenceBoundaries() - { - } - - /// - /// An integer array representing the lengths of the sentences in the input text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - public IReadOnlyList SourceSentencesLengths { get; } - /// - /// An integer array representing the lengths of the sentences in the translated text. - /// The length of the array is the number of sentences, and the values are the length of each sentence. - /// - public IReadOnlyList TranslatedSentencesLengths { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.Serialization.cs index 5835ec5e8160..caa9f1784faf 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.Serialization.cs @@ -39,7 +39,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("nativeName"u8); writer.WriteStringValue(NativeName); writer.WritePropertyName("dir"u8); - writer.WriteStringValue(Directionality.ToSerialString()); + writer.WriteStringValue(Dir.ToSerialString()); writer.WritePropertyName("translations"u8); writer.WriteStartArray(); foreach (var item in Translations) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.cs index cf0a057a1b7b..4ab55b7eac91 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/SourceDictionaryLanguage.cs @@ -49,10 +49,10 @@ public partial class SourceDictionaryLanguage /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// List of languages with alterative translations and examples for the query expressed in the source language. /// , or is null. - internal SourceDictionaryLanguage(string name, string nativeName, LanguageDirectionality directionality, IEnumerable translations) + internal SourceDictionaryLanguage(string name, string nativeName, LanguageDirectionality dir, IEnumerable translations) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(nativeName, nameof(nativeName)); @@ -60,21 +60,21 @@ internal SourceDictionaryLanguage(string name, string nativeName, LanguageDirect Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; Translations = translations.ToList(); } /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// List of languages with alterative translations and examples for the query expressed in the source language. /// Keeps track of any properties unknown to the library. - internal SourceDictionaryLanguage(string name, string nativeName, LanguageDirectionality directionality, IReadOnlyList translations, IDictionary serializedAdditionalRawData) + internal SourceDictionaryLanguage(string name, string nativeName, LanguageDirectionality dir, IReadOnlyList translations, IDictionary serializedAdditionalRawData) { Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; Translations = translations; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -89,7 +89,7 @@ internal SourceDictionaryLanguage() /// Display name of the language in the locale native for this language. public string NativeName { get; } /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - public LanguageDirectionality Directionality { get; } + public LanguageDirectionality Dir { get; } /// List of languages with alterative translations and examples for the query expressed in the source language. public IReadOnlyList Translations { get; } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.Serialization.cs index 7bbb5449a712..2f97806fe13a 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.Serialization.cs @@ -39,7 +39,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("nativeName"u8); writer.WriteStringValue(NativeName); writer.WritePropertyName("dir"u8); - writer.WriteStringValue(Directionality.ToSerialString()); + writer.WriteStringValue(Dir.ToSerialString()); writer.WritePropertyName("code"u8); writer.WriteStringValue(Code); if (options.Format != "W" && _serializedAdditionalRawData != null) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.cs index 81845ba309e5..c296c28456bf 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TargetDictionaryLanguage.cs @@ -48,10 +48,10 @@ public partial class TargetDictionaryLanguage /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Language code identifying the target language. /// , or is null. - internal TargetDictionaryLanguage(string name, string nativeName, LanguageDirectionality directionality, string code) + internal TargetDictionaryLanguage(string name, string nativeName, LanguageDirectionality dir, string code) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(nativeName, nameof(nativeName)); @@ -59,21 +59,21 @@ internal TargetDictionaryLanguage(string name, string nativeName, LanguageDirect Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; Code = code; } /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Language code identifying the target language. /// Keeps track of any properties unknown to the library. - internal TargetDictionaryLanguage(string name, string nativeName, LanguageDirectionality directionality, string code, IDictionary serializedAdditionalRawData) + internal TargetDictionaryLanguage(string name, string nativeName, LanguageDirectionality dir, string code, IDictionary serializedAdditionalRawData) { Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; Code = code; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -88,7 +88,7 @@ internal TargetDictionaryLanguage() /// Display name of the language in the locale native for this language. public string NativeName { get; } /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - public LanguageDirectionality Directionality { get; } + public LanguageDirectionality Dir { get; } /// Language code identifying the target language. public string Code { get; } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClient.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClient.cs index a109230e24f6..ec6c55a2f674 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClient.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClient.cs @@ -30,10 +30,6 @@ namespace Azure.AI.Translation.Text /// Transliterate. Converts characters or letters of a source language to the corresponding characters or letters of a target language. /// /// Detect. Returns the source code language code and a boolean variable denoting whether the detected language is supported for text translation and transliteration. - /// - /// Dictionary lookup. Returns equivalent words for the source term in the target language. - /// - /// Dictionary example Returns grammatical structure and context examples for the source term and target term pair. /// public partial class TextTranslationClient { @@ -222,118 +218,146 @@ public virtual Response GetSupportedLanguages(string clientTraceId, string scope } } - internal HttpMessage CreateGetSupportedLanguagesRequest(string clientTraceId, string scope, string acceptLanguage, ETag? ifNoneMatch, RequestContext context) + /// Translate Text. + /// Defines the content of the request. + /// A client-generated GUID to uniquely identify the request. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task>> TranslateAsync(IEnumerable body, string clientTraceId = null, CancellationToken cancellationToken = default) { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/languages", false); - if (scope != null) - { - uri.AppendQuery("scope", scope, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - if (clientTraceId != null) - { - request.Headers.Add("X-ClientTraceId", clientTraceId); - } - if (acceptLanguage != null) + Argument.AssertNotNull(body, nameof(body)); + + using RequestContent content = RequestContentHelper.FromEnumerable(body); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await TranslateAsync(content, clientTraceId, context).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions, cancellationToken).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) { - request.Headers.Add("Accept-Language", acceptLanguage); + array.Add(TranslatedTextItem.DeserializeTranslatedTextItem(item)); } - if (ifNoneMatch != null) - { - request.Headers.Add("If-None-Match", ifNoneMatch.Value); - } - return message; + value = array; + return Response.FromValue(value, response); } - internal HttpMessage CreateTranslateRequest(IEnumerable targetLanguages, RequestContent content, string clientTraceId, string sourceLanguage, string textType, string category, string profanityAction, string profanityMarker, bool? includeAlignment, bool? includeSentenceLength, string suggestedSourceLanguage, string sourceLanguageScript, string targetLanguageScript, bool? allowFallback, RequestContext context) + /// Translate Text. + /// Defines the content of the request. + /// A client-generated GUID to uniquely identify the request. + /// The cancellation token to use. + /// is null. + /// + public virtual Response> Translate(IEnumerable body, string clientTraceId = null, 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.AppendPath("/translate", false); - if (targetLanguages != null && !(targetLanguages is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined)) - { - foreach (var param in targetLanguages) - { - uri.AppendQuery("to", param, true); - } - } - if (sourceLanguage != null) - { - uri.AppendQuery("from", sourceLanguage, true); - } - if (textType != null) - { - uri.AppendQuery("textType", textType, true); - } - if (category != null) - { - uri.AppendQuery("category", category, true); - } - if (profanityAction != null) - { - uri.AppendQuery("profanityAction", profanityAction, true); - } - if (profanityMarker != null) - { - uri.AppendQuery("profanityMarker", profanityMarker, true); - } - if (includeAlignment != null) - { - uri.AppendQuery("includeAlignment", includeAlignment.Value, true); - } - if (includeSentenceLength != null) - { - uri.AppendQuery("includeSentenceLength", includeSentenceLength.Value, true); - } - if (suggestedSourceLanguage != null) + Argument.AssertNotNull(body, nameof(body)); + + using RequestContent content = RequestContentHelper.FromEnumerable(body); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = Translate(content, clientTraceId, context); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) { - uri.AppendQuery("suggestedFrom", suggestedSourceLanguage, true); + array.Add(TranslatedTextItem.DeserializeTranslatedTextItem(item)); } - if (sourceLanguageScript != null) + value = array; + return Response.FromValue(value, response); + } + + /// + /// [Protocol Method] Translate Text + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// A client-generated GUID to uniquely identify the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task TranslateAsync(RequestContent content, string clientTraceId = null, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("TextTranslationClient.Translate"); + scope.Start(); + try { - uri.AppendQuery("fromScript", sourceLanguageScript, true); + using HttpMessage message = CreateTranslateRequest(content, clientTraceId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } - if (targetLanguageScript != null) + catch (Exception e) { - uri.AppendQuery("toScript", targetLanguageScript, true); + scope.Failed(e); + throw; } - if (allowFallback != null) + } + + /// + /// [Protocol Method] Translate Text + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// A client-generated GUID to uniquely identify the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response Translate(RequestContent content, string clientTraceId = null, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("TextTranslationClient.Translate"); + scope.Start(); + try { - uri.AppendQuery("allowFallback", allowFallback.Value, true); + using HttpMessage message = CreateTranslateRequest(content, clientTraceId, context); + return _pipeline.ProcessMessage(message, context); } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - if (clientTraceId != null) + catch (Exception e) { - request.Headers.Add("X-ClientTraceId", clientTraceId); + scope.Failed(e); + throw; } - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; - return message; } - internal HttpMessage CreateTransliterateRequest(string language, string sourceLanguageScript, string targetLanguageScript, RequestContent content, string clientTraceId, RequestContext context) + internal HttpMessage CreateGetSupportedLanguagesRequest(string clientTraceId, string scope, string acceptLanguage, ETag? ifNoneMatch, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); var request = message.Request; - request.Method = RequestMethod.Post; + request.Method = RequestMethod.Get; var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); - uri.AppendPath("/transliterate", false); - uri.AppendQuery("language", language, true); - uri.AppendQuery("fromScript", sourceLanguageScript, true); - uri.AppendQuery("toScript", targetLanguageScript, true); + uri.AppendPath("/languages", false); + if (scope != null) + { + uri.AppendQuery("scope", scope, true); + } uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); @@ -341,49 +365,25 @@ internal HttpMessage CreateTransliterateRequest(string language, string sourceLa { request.Headers.Add("X-ClientTraceId", clientTraceId); } - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; - return message; - } - - internal HttpMessage CreateFindSentenceBoundariesRequest(RequestContent content, string clientTraceId, string language, string script, RequestContext context) - { - var message = _pipeline.CreateMessage(context, ResponseClassifier200); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/breaksentence", false); - if (language != null) - { - uri.AppendQuery("language", language, true); - } - if (script != null) + if (acceptLanguage != null) { - uri.AppendQuery("script", script, true); + request.Headers.Add("Accept-Language", acceptLanguage); } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - if (clientTraceId != null) + if (ifNoneMatch != null) { - request.Headers.Add("X-ClientTraceId", clientTraceId); + request.Headers.Add("If-None-Match", ifNoneMatch.Value); } - request.Headers.Add("Content-Type", "application/json"); - request.Content = content; return message; } - internal HttpMessage CreateLookupDictionaryEntriesRequest(string sourceLanguage, string targetLanguage, RequestContent content, string clientTraceId, RequestContext context) + internal HttpMessage CreateTranslateRequest(RequestContent content, string clientTraceId, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); - uri.AppendPath("/dictionary/lookup", false); - uri.AppendQuery("from", sourceLanguage, true); - uri.AppendQuery("to", targetLanguage, true); + uri.AppendPath("/translate", false); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); @@ -396,16 +396,17 @@ internal HttpMessage CreateLookupDictionaryEntriesRequest(string sourceLanguage, return message; } - internal HttpMessage CreateLookupDictionaryExamplesRequest(string sourceLanguage, string targetLanguage, RequestContent content, string clientTraceId, RequestContext context) + internal HttpMessage CreateTransliterateRequest(string language, string fromScript, string toScript, RequestContent content, string clientTraceId, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier200); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); - uri.AppendPath("/dictionary/examples", false); - uri.AppendQuery("from", sourceLanguage, true); - uri.AppendQuery("to", targetLanguage, true); + uri.AppendPath("/transliterate", false); + uri.AppendQuery("language", language, true); + uri.AppendQuery("fromScript", fromScript, true); + uri.AppendQuery("toScript", toScript, true); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClientOptions.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClientOptions.cs index ed829fbc2feb..620e6d12b8ef 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClientOptions.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TextTranslationClientOptions.cs @@ -13,13 +13,15 @@ namespace Azure.AI.Translation.Text /// Client options for TextTranslationClient. public partial class TextTranslationClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V3_0; + private const ServiceVersion LatestVersion = ServiceVersion.V2025_05_01_Preview; /// The version of the service to use. public enum ServiceVersion { - /// Service version "3.0". + /// Service version "v3.0". V3_0 = 1, + /// Service version "2025-05-01-preview". + V2025_05_01_Preview = 2, } internal string Version { get; } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.Serialization.cs new file mode 100644 index 000000000000..93215b3ecb90 --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.Serialization.cs @@ -0,0 +1,187 @@ +// 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.Translation.Text +{ + public partial class TranslateBody : 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(TranslateBody)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Script)) + { + writer.WritePropertyName("script"u8); + writer.WriteStringValue(Script); + } + if (Optional.IsDefined(Language)) + { + writer.WritePropertyName("language"u8); + writer.WriteStringValue(Language); + } + if (Optional.IsDefined(TextType)) + { + writer.WritePropertyName("textType"u8); + writer.WriteStringValue(TextType.Value.ToString()); + } + writer.WritePropertyName("targets"u8); + writer.WriteStartArray(); + foreach (var item in Targets) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + + TranslateBody 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(TranslateBody)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTranslateBody(document.RootElement, options); + } + + internal static TranslateBody DeserializeTranslateBody(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string script = default; + string language = default; + TextType? textType = default; + IList targets = default; + string text = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("script"u8)) + { + script = property.Value.GetString(); + continue; + } + if (property.NameEquals("language"u8)) + { + language = property.Value.GetString(); + continue; + } + if (property.NameEquals("textType"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + textType = new TextType(property.Value.GetString()); + continue; + } + if (property.NameEquals("targets"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(TranslateTarget.DeserializeTranslateTarget(item, options)); + } + targets = array; + 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 TranslateBody( + text, + serializedAdditionalRawData, + script, + language, + textType, + targets); + } + + 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, AzureAITranslationTextContext.Default); + default: + throw new FormatException($"The model {nameof(TranslateBody)} does not support writing '{options.Format}' format."); + } + } + + TranslateBody 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 DeserializeTranslateBody(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TranslateBody)} 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 TranslateBody FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeTranslateBody(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/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.cs new file mode 100644 index 000000000000..44088deeae91 --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateBody.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.Translation.Text +{ + /// Element containing the text for translation. + public partial class TranslateBody : InputTextItem + { + /// Initializes a new instance of . + /// Text to translate. + /// Translation target parameters. + /// or is null. + public TranslateBody(string text, IEnumerable targets) : base(text) + { + Argument.AssertNotNull(text, nameof(text)); + Argument.AssertNotNull(targets, nameof(targets)); + + Targets = targets.ToList(); + } + + /// Initializes a new instance of . + /// Text to translate. + /// Keeps track of any properties unknown to the library. + /// Specifies the script of the input text. + /// + /// Specifies the language of the input text. Find which languages are available to translate by + /// looking up supported languages using the translation scope. If the language parameter isn't + /// specified, automatic language detection is applied to determine the source language. + /// + /// You must use the language parameter rather than autodetection when using the dynamic dictionary feature. + /// Note: the dynamic dictionary feature is case-sensitive. + /// + /// + /// Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, + /// complete element. Possible values are: plain (default) or html. + /// + /// Translation target parameters. + internal TranslateBody(string text, IDictionary serializedAdditionalRawData, string script, string language, TextType? textType, IList targets) : base(text, serializedAdditionalRawData) + { + Script = script; + Language = language; + TextType = textType; + Targets = targets; + } + + /// Initializes a new instance of for deserialization. + internal TranslateBody() + { + } + + /// Specifies the script of the input text. + public string Script { get; set; } + /// + /// Specifies the language of the input text. Find which languages are available to translate by + /// looking up supported languages using the translation scope. If the language parameter isn't + /// specified, automatic language detection is applied to determine the source language. + /// + /// You must use the language parameter rather than autodetection when using the dynamic dictionary feature. + /// Note: the dynamic dictionary feature is case-sensitive. + /// + public string Language { get; set; } + /// + /// Defines whether the text being translated is plain text or HTML text. Any HTML needs to be a well-formed, + /// complete element. Possible values are: plain (default) or html. + /// + public TextType? TextType { get; set; } + /// Translation target parameters. + public IList Targets { get; } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.Serialization.cs new file mode 100644 index 000000000000..bbf45ca6f330 --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.Serialization.cs @@ -0,0 +1,300 @@ +// 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.Translation.Text +{ + public partial class TranslateTarget : 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(TranslateTarget)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("language"u8); + writer.WriteStartArray(); + foreach (var item in Language) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(Script)) + { + writer.WritePropertyName("script"u8); + writer.WriteStringValue(Script); + } + if (Optional.IsDefined(ProfanityAction)) + { + writer.WritePropertyName("profanityAction"u8); + writer.WriteStringValue(ProfanityAction.Value.ToSerialString()); + } + if (Optional.IsDefined(ProfanityMarker)) + { + writer.WritePropertyName("profanityMarker"u8); + writer.WriteStringValue(ProfanityMarker.Value.ToSerialString()); + } + if (Optional.IsDefined(DeploymentNameModel)) + { + writer.WritePropertyName("deploymentNameModel"u8); + writer.WriteStringValue(DeploymentNameModel); + } + if (Optional.IsDefined(AllowFallback)) + { + writer.WritePropertyName("allowFallback"u8); + writer.WriteBooleanValue(AllowFallback.Value); + } + if (Optional.IsDefined(Grade)) + { + writer.WritePropertyName("grade"u8); + writer.WriteStringValue(Grade); + } + if (Optional.IsDefined(Tone)) + { + writer.WritePropertyName("tone"u8); + writer.WriteStringValue(Tone); + } + if (Optional.IsDefined(Gender)) + { + writer.WritePropertyName("gender"u8); + writer.WriteStringValue(Gender); + } + if (Optional.IsDefined(AdaptiveDatasetId)) + { + writer.WritePropertyName("adaptiveDatasetId"u8); + writer.WriteStringValue(AdaptiveDatasetId); + } + if (Optional.IsCollectionDefined(ReferenceTextPairs)) + { + writer.WritePropertyName("referenceTextPairs"u8); + writer.WriteStartArray(); + foreach (var item in ReferenceTextPairs) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + TranslateTarget 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(TranslateTarget)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTranslateTarget(document.RootElement, options); + } + + internal static TranslateTarget DeserializeTranslateTarget(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList language = default; + string script = default; + ProfanityAction? profanityAction = default; + ProfanityMarker? profanityMarker = default; + string deploymentNameModel = default; + bool? allowFallback = default; + string grade = default; + string tone = default; + string gender = default; + string adaptiveDatasetId = default; + IList referenceTextPairs = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("language"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + language = array; + continue; + } + if (property.NameEquals("script"u8)) + { + script = property.Value.GetString(); + continue; + } + if (property.NameEquals("profanityAction"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + profanityAction = property.Value.GetString().ToProfanityAction(); + continue; + } + if (property.NameEquals("profanityMarker"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + profanityMarker = property.Value.GetString().ToProfanityMarker(); + continue; + } + if (property.NameEquals("deploymentNameModel"u8)) + { + deploymentNameModel = property.Value.GetString(); + continue; + } + if (property.NameEquals("allowFallback"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + allowFallback = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("grade"u8)) + { + grade = property.Value.GetString(); + continue; + } + if (property.NameEquals("tone"u8)) + { + tone = property.Value.GetString(); + continue; + } + if (property.NameEquals("gender"u8)) + { + gender = property.Value.GetString(); + continue; + } + if (property.NameEquals("adaptiveDatasetId"u8)) + { + adaptiveDatasetId = property.Value.GetString(); + continue; + } + if (property.NameEquals("referenceTextPairs"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ReferenceSentencePair.DeserializeReferenceSentencePair(item, options)); + } + referenceTextPairs = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new TranslateTarget( + language, + script, + profanityAction, + profanityMarker, + deploymentNameModel, + allowFallback, + grade, + tone, + gender, + adaptiveDatasetId, + referenceTextPairs ?? new ChangeTrackingList(), + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureAITranslationTextContext.Default); + default: + throw new FormatException($"The model {nameof(TranslateTarget)} does not support writing '{options.Format}' format."); + } + } + + TranslateTarget 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 DeserializeTranslateTarget(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TranslateTarget)} 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 TranslateTarget FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeTranslateTarget(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/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.cs new file mode 100644 index 000000000000..5985acfa7d1c --- /dev/null +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslateTarget.cs @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.Translation.Text +{ + /// Translate targets parameters. + public partial class TranslateTarget + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// + /// Specifies the language of the output text. The target language must be one of the supported languages included + /// in the translation scope. It's possible to translate to multiple languages simultaneously by including + /// multiple string values in the targetsLanguage array. + /// + /// is null. + public TranslateTarget(IEnumerable language) + { + Argument.AssertNotNull(language, nameof(language)); + + Language = language.ToList(); + ReferenceTextPairs = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// + /// Specifies the language of the output text. The target language must be one of the supported languages included + /// in the translation scope. It's possible to translate to multiple languages simultaneously by including + /// multiple string values in the targetsLanguage array. + /// + /// Specifies the script of the translated text. + /// + /// Specifies how profanities should be treated in translations. + /// Possible values are: NoAction (default), Marked or Deleted. + /// + /// + /// Specifies how profanities should be marked in translations. + /// Possible values are: Asterisk (default) or Tag. + /// + /// + /// Default is ‘general’, which uses NMT system. + /// ‘abc-inc-gpt-4o’, and ‘abc-inc-gpt-4o-mini’ are examples of deployment names which use GPT-4o uses or + /// GPT-4o-mini model. ‘gpt-4o’ uses GPT-4o model. + /// + /// ‘<custom model id>’ uses the custom NMT model tuned by customer. + /// ‘best’ system determines which is the best model to use for the request. This intelligence could be introduced + /// in future. Customer should have deployed it in their resource. + /// + /// + /// + /// In the case where a custom system is being used, specifies that the service is allowed to fall back to a + /// general system when a custom system doesn't exist. + /// In the case where a Large Language Model is being used, specifies that the service is allowed to fall + /// back to a Small Language Model if an error occurs. + /// Possible values are: true (default) or false. + /// + /// allowFallback=false specifies that the translation should only use systems trained for the category specified + /// by the request. If a translation for language X to language Y requires chaining through a pivot language E, + /// then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. + /// If no system is found with the specific category, the request will return a 400 status code. allowFallback=true + /// specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. + /// + /// Defines complexity of LLM prompts to provide high accuracy translation. + /// Desired tone of target translation. + /// Desired gender of target translation. + /// Reference dataset ID having sentence pair to generate adaptive customized translation. + /// Reference sentence pairs to generate adaptive results. + /// Keeps track of any properties unknown to the library. + internal TranslateTarget(IList language, string script, ProfanityAction? profanityAction, ProfanityMarker? profanityMarker, string deploymentNameModel, bool? allowFallback, string grade, string tone, string gender, string adaptiveDatasetId, IList referenceTextPairs, IDictionary serializedAdditionalRawData) + { + Language = language; + Script = script; + ProfanityAction = profanityAction; + ProfanityMarker = profanityMarker; + DeploymentNameModel = deploymentNameModel; + AllowFallback = allowFallback; + Grade = grade; + Tone = tone; + Gender = gender; + AdaptiveDatasetId = adaptiveDatasetId; + ReferenceTextPairs = referenceTextPairs; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal TranslateTarget() + { + } + + /// + /// Specifies the language of the output text. The target language must be one of the supported languages included + /// in the translation scope. It's possible to translate to multiple languages simultaneously by including + /// multiple string values in the targetsLanguage array. + /// + public IList Language { get; } + /// Specifies the script of the translated text. + public string Script { get; set; } + /// + /// Specifies how profanities should be treated in translations. + /// Possible values are: NoAction (default), Marked or Deleted. + /// + public ProfanityAction? ProfanityAction { get; set; } + /// + /// Specifies how profanities should be marked in translations. + /// Possible values are: Asterisk (default) or Tag. + /// + public ProfanityMarker? ProfanityMarker { get; set; } + /// + /// Default is ‘general’, which uses NMT system. + /// ‘abc-inc-gpt-4o’, and ‘abc-inc-gpt-4o-mini’ are examples of deployment names which use GPT-4o uses or + /// GPT-4o-mini model. ‘gpt-4o’ uses GPT-4o model. + /// + /// ‘<custom model id>’ uses the custom NMT model tuned by customer. + /// ‘best’ system determines which is the best model to use for the request. This intelligence could be introduced + /// in future. Customer should have deployed it in their resource. + /// + /// + public string DeploymentNameModel { get; set; } + /// + /// In the case where a custom system is being used, specifies that the service is allowed to fall back to a + /// general system when a custom system doesn't exist. + /// In the case where a Large Language Model is being used, specifies that the service is allowed to fall + /// back to a Small Language Model if an error occurs. + /// Possible values are: true (default) or false. + /// + /// allowFallback=false specifies that the translation should only use systems trained for the category specified + /// by the request. If a translation for language X to language Y requires chaining through a pivot language E, + /// then all the systems in the chain (X → E and E → Y) will need to be custom and have the same category. + /// If no system is found with the specific category, the request will return a 400 status code. allowFallback=true + /// specifies that the service is allowed to fall back to a general system when a custom system doesn't exist. + /// + public bool? AllowFallback { get; set; } + /// Defines complexity of LLM prompts to provide high accuracy translation. + public string Grade { get; set; } + /// Desired tone of target translation. + public string Tone { get; set; } + /// Desired gender of target translation. + public string Gender { get; set; } + /// Reference dataset ID having sentence pair to generate adaptive customized translation. + public string AdaptiveDatasetId { get; set; } + /// Reference sentence pairs to generate adaptive results. + public IList ReferenceTextPairs { get; } + } +} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.cs deleted file mode 100644 index 410a73875cfe..000000000000 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslatedTextAlignment.cs +++ /dev/null @@ -1,96 +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.Translation.Text -{ - /// Alignment information object. - public partial class TranslatedTextAlignment - { - /// - /// 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 . - /// - /// Maps input text to translated text. The alignment information is only provided when the request - /// parameter includeAlignment is true. Alignment is returned as a string value of the following - /// format: [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]. - /// The colon separates start and end index, the dash separates the languages, and space separates the words. - /// One word may align with zero, one, or multiple words in the other language, and the aligned words may - /// be non-contiguous. When no alignment information is available, the alignment element will be empty. - /// - /// is null. - internal TranslatedTextAlignment(string projections) - { - Argument.AssertNotNull(projections, nameof(projections)); - - Projections = projections; - } - - /// Initializes a new instance of . - /// - /// Maps input text to translated text. The alignment information is only provided when the request - /// parameter includeAlignment is true. Alignment is returned as a string value of the following - /// format: [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]. - /// The colon separates start and end index, the dash separates the languages, and space separates the words. - /// One word may align with zero, one, or multiple words in the other language, and the aligned words may - /// be non-contiguous. When no alignment information is available, the alignment element will be empty. - /// - /// Keeps track of any properties unknown to the library. - internal TranslatedTextAlignment(string projections, IDictionary serializedAdditionalRawData) - { - Projections = projections; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal TranslatedTextAlignment() - { - } - - /// - /// Maps input text to translated text. The alignment information is only provided when the request - /// parameter includeAlignment is true. Alignment is returned as a string value of the following - /// format: [[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]. - /// The colon separates start and end index, the dash separates the languages, and space separates the words. - /// One word may align with zero, one, or multiple words in the other language, and the aligned words may - /// be non-contiguous. When no alignment information is available, the alignment element will be empty. - /// - public string Projections { get; } - } -} diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.Serialization.cs index 8badbbf4056c..d0c36fca8307 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.Serialization.cs @@ -39,7 +39,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("nativeName"u8); writer.WriteStringValue(NativeName); writer.WritePropertyName("dir"u8); - writer.WriteStringValue(Directionality.ToSerialString()); + writer.WriteStringValue(Dir.ToSerialString()); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.cs index 9fe1669f9945..3f73d4dfb717 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationLanguage.cs @@ -51,28 +51,28 @@ public partial class TranslationLanguage /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// or is null. - internal TranslationLanguage(string name, string nativeName, LanguageDirectionality directionality) + internal TranslationLanguage(string name, string nativeName, LanguageDirectionality dir) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(nativeName, nameof(nativeName)); Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; } /// Initializes a new instance of . /// Display name of the language in the locale requested via Accept-Language header. /// Display name of the language in the locale native for this language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Keeps track of any properties unknown to the library. - internal TranslationLanguage(string name, string nativeName, LanguageDirectionality directionality, IDictionary serializedAdditionalRawData) + internal TranslationLanguage(string name, string nativeName, LanguageDirectionality dir, IDictionary serializedAdditionalRawData) { Name = name; NativeName = nativeName; - Directionality = directionality; + Dir = dir; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -86,6 +86,6 @@ internal TranslationLanguage() /// Display name of the language in the locale native for this language. public string NativeName { get; } /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - public LanguageDirectionality Directionality { get; } + public LanguageDirectionality Dir { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.Serialization.cs index 14143ea78441..130a76cde4a4 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.Serialization.cs @@ -35,7 +35,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WritePropertyName("to"u8); - writer.WriteStringValue(TargetLanguage); + writer.WriteStringValue(To); writer.WritePropertyName("text"u8); writer.WriteStringValue(Text); if (Optional.IsDefined(Transliteration)) @@ -43,16 +43,6 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("transliteration"u8); writer.WriteObjectValue(Transliteration, options); } - if (Optional.IsDefined(Alignment)) - { - writer.WritePropertyName("alignment"u8); - writer.WriteObjectValue(Alignment, options); - } - if (Optional.IsDefined(SentenceBoundaries)) - { - writer.WritePropertyName("sentLen"u8); - writer.WriteObjectValue(SentenceBoundaries, options); - } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -93,8 +83,6 @@ internal static TranslationText DeserializeTranslationText(JsonElement element, string to = default; string text = default; TransliteratedText transliteration = default; - TranslatedTextAlignment alignment = default; - SentenceBoundaries sentLen = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -118,37 +106,13 @@ internal static TranslationText DeserializeTranslationText(JsonElement element, transliteration = TransliteratedText.DeserializeTransliteratedText(property.Value, options); continue; } - if (property.NameEquals("alignment"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - alignment = TranslatedTextAlignment.DeserializeTranslatedTextAlignment(property.Value, options); - continue; - } - if (property.NameEquals("sentLen"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - sentLen = SentenceBoundaries.DeserializeSentenceBoundaries(property.Value, options); - continue; - } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new TranslationText( - to, - text, - transliteration, - alignment, - sentLen, - serializedAdditionalRawData); + return new TranslationText(to, text, transliteration, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.cs index e283bbf676d4..e3bad2c5e39a 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TranslationText.cs @@ -46,32 +46,28 @@ public partial class TranslationText private IDictionary _serializedAdditionalRawData; /// Initializes a new instance of . - /// A string representing the language code of the target language. + /// A string representing the language code of the target language. /// A string giving the translated text. - /// or is null. - internal TranslationText(string targetLanguage, string text) + /// or is null. + internal TranslationText(string to, string text) { - Argument.AssertNotNull(targetLanguage, nameof(targetLanguage)); + Argument.AssertNotNull(to, nameof(to)); Argument.AssertNotNull(text, nameof(text)); - TargetLanguage = targetLanguage; + To = to; Text = text; } /// Initializes a new instance of . - /// A string representing the language code of the target language. + /// A string representing the language code of the target language. /// A string giving the translated text. /// An object giving the translated text in the script specified by the toScript parameter. - /// Alignment information. - /// Sentence boundaries in the input and output texts. /// Keeps track of any properties unknown to the library. - internal TranslationText(string targetLanguage, string text, TransliteratedText transliteration, TranslatedTextAlignment alignment, SentenceBoundaries sentenceBoundaries, IDictionary serializedAdditionalRawData) + internal TranslationText(string to, string text, TransliteratedText transliteration, IDictionary serializedAdditionalRawData) { - TargetLanguage = targetLanguage; + To = to; Text = text; Transliteration = transliteration; - Alignment = alignment; - SentenceBoundaries = sentenceBoundaries; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -81,14 +77,10 @@ internal TranslationText() } /// A string representing the language code of the target language. - public string TargetLanguage { get; } + public string To { get; } /// A string giving the translated text. public string Text { get; } /// An object giving the translated text in the script specified by the toScript parameter. public TransliteratedText Transliteration { get; } - /// Alignment information. - public TranslatedTextAlignment Alignment { get; } - /// Sentence boundaries in the input and output texts. - public SentenceBoundaries SentenceBoundaries { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.Serialization.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.Serialization.cs index ed78327a9ab0..be86d95ef5c7 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.Serialization.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.Serialization.cs @@ -37,7 +37,7 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri base.JsonModelWriteCore(writer, options); writer.WritePropertyName("toScripts"u8); writer.WriteStartArray(); - foreach (var item in TargetLanguageScripts) + foreach (var item in ToScripts) { writer.WriteObjectValue(item, options); } diff --git a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.cs b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.cs index 24de9ee02a96..9297e7b27e47 100644 --- a/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.cs +++ b/sdk/translation/Azure.AI.Translation.Text/src/Generated/TransliterableScript.cs @@ -18,29 +18,29 @@ public partial class TransliterableScript : LanguageScript /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - /// List of scripts available to convert text to. - /// , , or is null. - internal TransliterableScript(string code, string name, string nativeName, LanguageDirectionality directionality, IEnumerable targetLanguageScripts) : base(code, name, nativeName, directionality) + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// List of scripts available to convert text to. + /// , , or is null. + internal TransliterableScript(string code, string name, string nativeName, LanguageDirectionality dir, IEnumerable toScripts) : base(code, name, nativeName, dir) { Argument.AssertNotNull(code, nameof(code)); Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(nativeName, nameof(nativeName)); - Argument.AssertNotNull(targetLanguageScripts, nameof(targetLanguageScripts)); + Argument.AssertNotNull(toScripts, nameof(toScripts)); - TargetLanguageScripts = targetLanguageScripts.ToList(); + ToScripts = toScripts.ToList(); } /// Initializes a new instance of . /// Code identifying the script. /// Display name of the script in the locale requested via Accept-Language header. /// Display name of the language in the locale native for the language. - /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + /// Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. /// Keeps track of any properties unknown to the library. - /// List of scripts available to convert text to. - internal TransliterableScript(string code, string name, string nativeName, LanguageDirectionality directionality, IDictionary serializedAdditionalRawData, IReadOnlyList targetLanguageScripts) : base(code, name, nativeName, directionality, serializedAdditionalRawData) + /// List of scripts available to convert text to. + internal TransliterableScript(string code, string name, string nativeName, LanguageDirectionality dir, IDictionary serializedAdditionalRawData, IReadOnlyList toScripts) : base(code, name, nativeName, dir, serializedAdditionalRawData) { - TargetLanguageScripts = targetLanguageScripts; + ToScripts = toScripts; } /// Initializes a new instance of for deserialization. @@ -49,6 +49,6 @@ internal TransliterableScript() } /// List of scripts available to convert text to. - public IReadOnlyList TargetLanguageScripts { get; } + public IReadOnlyList ToScripts { get; } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/tests/Generated/Samples/Samples_TextTranslationClient.cs b/sdk/translation/Azure.AI.Translation.Text/tests/Generated/Samples/Samples_TextTranslationClient.cs index 0eacc69c761f..25beffd216ba 100644 --- a/sdk/translation/Azure.AI.Translation.Text/tests/Generated/Samples/Samples_TextTranslationClient.cs +++ b/sdk/translation/Azure.AI.Translation.Text/tests/Generated/Samples/Samples_TextTranslationClient.cs @@ -6,8 +6,10 @@ #nullable disable using System; +using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; +using Azure.Core; using Azure.Identity; using NUnit.Framework; @@ -106,5 +108,267 @@ public async Task Example_TextTranslation_GetSupportedLanguages_GetsTheSetOfLang Response response = await client.GetSupportedLanguagesAsync(); } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_TextTranslation_Translate_TranslateText() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +text = "This is a test.", +script = "Latn", +language = "en", +textType = "Plain", +targets = new object[] +{ +new +{ +language = new object[] +{ +"cs" +}, +script = "Latn", +profanityAction = "NoAction", +profanityMarker = "Asterisk", +deploymentNameModel = "general", +allowFallback = true, +grade = "basic", +tone = "formal", +gender = "neutral", +adaptiveDatasetId = "21000", +referenceTextPairs = new object[] +{ +new +{ +referenceTextPairsSource = "Please test this out.", +referenceTextPairsTarget = "Vyzkoušejte si to.", +} +}, +} +}, +} + }); + Response response = client.Translate(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_TextTranslation_Translate_TranslateText_Async() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +text = "This is a test.", +script = "Latn", +language = "en", +textType = "Plain", +targets = new object[] +{ +new +{ +language = new object[] +{ +"cs" +}, +script = "Latn", +profanityAction = "NoAction", +profanityMarker = "Asterisk", +deploymentNameModel = "general", +allowFallback = true, +grade = "basic", +tone = "formal", +gender = "neutral", +adaptiveDatasetId = "21000", +referenceTextPairs = new object[] +{ +new +{ +referenceTextPairsSource = "Please test this out.", +referenceTextPairsTarget = "Vyzkoušejte si to.", +} +}, +} +}, +} + }); + Response response = await client.TranslateAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_TextTranslation_Translate_TranslateText_Convenience() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + Response> response = client.Translate(new TranslateBody[] + { +new TranslateBody("This is a test.", new TranslateTarget[] +{ +new TranslateTarget(new string[]{"cs"}) +{ +Script = "Latn", +ProfanityAction = ProfanityAction.NoAction, +ProfanityMarker = ProfanityMarker.Asterisk, +DeploymentNameModel = "general", +AllowFallback = true, +Grade = "basic", +Tone = "formal", +Gender = "neutral", +AdaptiveDatasetId = "21000", +ReferenceTextPairs = {new ReferenceSentencePair("Please test this out.", "Vyzkoušejte si to.")}, +} +}) +{ +Script = "Latn", +Language = "en", +TextType = TextType.Plain, +} + }); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_TextTranslation_Translate_TranslateText_Convenience_Async() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + Response> response = await client.TranslateAsync(new TranslateBody[] + { +new TranslateBody("This is a test.", new TranslateTarget[] +{ +new TranslateTarget(new string[]{"cs"}) +{ +Script = "Latn", +ProfanityAction = ProfanityAction.NoAction, +ProfanityMarker = ProfanityMarker.Asterisk, +DeploymentNameModel = "general", +AllowFallback = true, +Grade = "basic", +Tone = "formal", +Gender = "neutral", +AdaptiveDatasetId = "21000", +ReferenceTextPairs = {new ReferenceSentencePair("Please test this out.", "Vyzkoušejte si to.")}, +} +}) +{ +Script = "Latn", +Language = "en", +TextType = TextType.Plain, +} + }); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_TextTranslation_Translate_TranslateTextWithMinimumProperties() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +text = "This is a test.", +targets = new object[] +{ +new +{ +language = new object[] +{ +"cs" +}, +} +}, +} + }); + Response response = client.Translate(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_TextTranslation_Translate_TranslateTextWithMinimumProperties_Async() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + using RequestContent content = RequestContent.Create(new object[] + { +new +{ +text = "This is a test.", +targets = new object[] +{ +new +{ +language = new object[] +{ +"cs" +}, +} +}, +} + }); + Response response = await client.TranslateAsync(content); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("to").ToString()); + Console.WriteLine(result[0].GetProperty("translations")[0].GetProperty("text").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_TextTranslation_Translate_TranslateTextWithMinimumProperties_Convenience() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + Response> response = client.Translate(new TranslateBody[] + { +new TranslateBody("This is a test.", new TranslateTarget[] +{ +new TranslateTarget(new string[]{"cs"}) +}) + }); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_TextTranslation_Translate_TranslateTextWithMinimumProperties_Convenience_Async() + { + Uri endpoint = new Uri(""); + TextTranslationClient client = new TextTranslationClient(endpoint); + + Response> response = await client.TranslateAsync(new TranslateBody[] + { +new TranslateBody("This is a test.", new TranslateTarget[] +{ +new TranslateTarget(new string[]{"cs"}) +}) + }); + } } } diff --git a/sdk/translation/Azure.AI.Translation.Text/tsp-location.yaml b/sdk/translation/Azure.AI.Translation.Text/tsp-location.yaml index 8989b77ba540..0451f5a6157c 100644 --- a/sdk/translation/Azure.AI.Translation.Text/tsp-location.yaml +++ b/sdk/translation/Azure.AI.Translation.Text/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 2aad49a1fcf08aedde3d281f893ddc744d5224cf +commit: 147495e1b6cfe5607d481278e31857dc929b42fa repo: Azure/azure-rest-api-specs +additionalDirectories: