From aaf544a624ecc1f815badcbb7c6075726604f8ac Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Wed, 1 May 2024 16:48:32 -0700 Subject: [PATCH 01/32] [Text Translation] Updating the SDK from the latest TypeSpec --- .../azure-ai-translation-text/README.md | 24 +- .../azure-ai-translation-text/assets.json | 2 +- .../azure/ai/translation/text/__init__.py | 5 +- .../azure/ai/translation/text/_model_base.py | 147 +++---- .../text/_operations/_operations.py | 356 +++++++++-------- .../ai/translation/text/_operations/_patch.py | 200 +++++----- .../azure/ai/translation/text/_patch.py | 27 +- .../azure/ai/translation/text/_version.py | 2 +- .../azure/ai/translation/text/aio/__init__.py | 5 +- .../text/aio/_operations/_operations.py | 295 +++++++------- .../text/aio/_operations/_patch.py | 200 +++++----- .../azure/ai/translation/text/aio/_patch.py | 22 +- .../ai/translation/text/models/__init__.py | 18 +- .../ai/translation/text/models/_enums.py | 7 + .../ai/translation/text/models/_models.py | 377 ++++++++---------- .../samples/README.md | 64 +-- .../sample_text_translation_break_sentence.py | 8 +- .../samples/sample_text_translation_client.py | 1 + ...le_text_translation_dictionary_examples.py | 3 +- ...mple_text_translation_dictionary_lookup.py | 3 +- .../sample_text_translation_languages.py | 7 +- .../sample_text_translation_translate.py | 41 +- .../sample_text_translation_transliterate.py | 7 +- .../tests/preparer.py | 2 +- .../tests/test_break_sentence.py | 12 +- .../tests/test_break_sentence_async.py | 12 +- .../tests/test_dictionary_examples.py | 4 +- .../tests/test_dictionary_examples_async.py | 4 +- .../tests/test_dictionary_lookup.py | 4 +- .../tests/test_dictionary_lookup_async.py | 4 +- .../tests/test_get_languages.py | 26 +- .../tests/test_get_languages_async.py | 26 +- .../tests/test_translation.py | 78 ++-- .../tests/test_translation_async.py | 72 ++-- .../tests/test_transliteration.py | 6 +- .../tests/test_transliteration_async.py | 6 +- .../tests/testcase.py | 12 +- .../tsp-location.yaml | 4 +- 38 files changed, 1084 insertions(+), 1009 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 0dc338f0bf76..639e8125cbfb 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -92,7 +92,7 @@ Gets the set of languages currently supported by other operations of the Transla ```python try: - response = text_translator.get_languages() + response = text_translator.get_supported_languages() print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -150,7 +150,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -177,12 +177,12 @@ Converts characters or letters of a source language to the corresponding charact ```python try: language = "zh-Hans" - from_script = "Hans" - to_script = "Latn" + source_language_script = "Hans" + target_language_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, from_script=from_script, to_script=to_script + request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script ) transliteration = response[0] if response else None @@ -224,13 +224,15 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sent_len: - print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") - print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") + if translated_text.lengths_of_sentences: + print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + print( + f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + ) except HttpResponseError as exception: if exception.error is not None: @@ -257,7 +259,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None @@ -293,7 +295,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, from_parameter=source_language, to=target_language + content=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/assets.json b/sdk/translation/azure-ai-translation-text/assets.json index 56df30dbc113..4f0bd1f71741 100644 --- a/sdk/translation/azure-ai-translation-text/assets.json +++ b/sdk/translation/azure-ai-translation-text/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "python", "TagPrefix": "python/translation/azure-ai-translation-text", - "Tag": "python/translation/azure-ai-translation-text_afde2bdc8c" + "Tag": "python/translation/azure-ai-translation-text_35ab9367d7" } diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py index 052ec7a7213e..b1abb04c1ba4 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py @@ -6,11 +6,14 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._patch import TextTranslationClient, TranslatorCredential, TranslatorAADCredential +from ._patch import TextTranslationClient from ._version import VERSION __version__ = VERSION + +from ._patch import TranslatorCredential +from ._patch import TranslatorAADCredential from ._patch import patch_sdk as _patch_sdk __all__ = [ diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_model_base.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_model_base.py index 1ddc071517d6..5cf70733404d 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_model_base.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_model_base.py @@ -6,6 +6,7 @@ # -------------------------------------------------------------------------- # pylint: disable=protected-access, arguments-differ, signature-differs, broad-except +import copy import calendar import decimal import functools @@ -13,7 +14,6 @@ import logging import base64 import re -import copy import typing import enum import email.utils @@ -339,7 +339,7 @@ def _get_model(module_name: str, model_name: str): class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=unsubscriptable-object def __init__(self, data: typing.Dict[str, typing.Any]) -> None: - self._data = copy.deepcopy(data) + self._data = data def __contains__(self, key: typing.Any) -> bool: return key in self._data @@ -378,16 +378,13 @@ def get(self, key: str, default: typing.Any = None) -> typing.Any: return default @typing.overload - def pop(self, key: str) -> typing.Any: - ... + def pop(self, key: str) -> typing.Any: ... @typing.overload - def pop(self, key: str, default: _T) -> _T: - ... + def pop(self, key: str, default: _T) -> _T: ... @typing.overload - def pop(self, key: str, default: typing.Any) -> typing.Any: - ... + def pop(self, key: str, default: typing.Any) -> typing.Any: ... def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any: if default is _UNSET: @@ -404,12 +401,10 @@ def update(self, *args: typing.Any, **kwargs: typing.Any) -> None: self._data.update(*args, **kwargs) @typing.overload - def setdefault(self, key: str, default: None = None) -> None: - ... + def setdefault(self, key: str, default: None = None) -> None: ... @typing.overload - def setdefault(self, key: str, default: typing.Any) -> typing.Any: - ... + def setdefault(self, key: str, default: typing.Any) -> typing.Any: ... def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any: if default is _UNSET: @@ -594,6 +589,64 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v +def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj): + if _is_model(obj): + return obj + return _deserialize(model_deserializer, obj) + + +def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj): + if obj is None: + return obj + return _deserialize_with_callable(if_obj_deserializer, obj) + + +def _deserialize_with_union(deserializers, obj): + for deserializer in deserializers: + try: + return _deserialize(deserializer, obj) + except DeserializationError: + pass + raise DeserializationError() + + +def _deserialize_dict( + value_deserializer: typing.Optional[typing.Callable], + module: typing.Optional[str], + obj: typing.Dict[typing.Any, typing.Any], +): + if obj is None: + return obj + return {k: _deserialize(value_deserializer, v, module) for k, v in obj.items()} + + +def _deserialize_multiple_sequence( + entry_deserializers: typing.List[typing.Optional[typing.Callable]], + module: typing.Optional[str], + obj, +): + if obj is None: + return obj + return type(obj)(_deserialize(deserializer, entry, module) for entry, deserializer in zip(obj, entry_deserializers)) + + +def _deserialize_sequence( + deserializer: typing.Optional[typing.Callable], + module: typing.Optional[str], + obj, +): + if obj is None: + return obj + return type(obj)(_deserialize(deserializer, entry, module) for entry in obj) + + +def _sorted_annotations(types: typing.List[typing.Any]) -> typing.List[typing.Any]: + return sorted( + types, + key=lambda x: hasattr(x, "__name__") and x.__name__.lower() in ("str", "float", "int", "bool"), + ) + + def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915, R0912 annotation: typing.Any, module: typing.Optional[str], @@ -621,11 +674,6 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915, if rf: rf._is_model = True - def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj): - if _is_model(obj): - return obj - return _deserialize(model_deserializer, obj) - return functools.partial(_deserialize_model, annotation) # pyright: ignore except Exception: pass @@ -640,36 +688,27 @@ def _deserialize_model(model_deserializer: typing.Optional[typing.Callable], obj # is it optional? try: if any(a for a in annotation.__args__ if a == type(None)): # pyright: ignore - if_obj_deserializer = _get_deserialize_callable_from_annotation( - next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore - ) - - def _deserialize_with_optional(if_obj_deserializer: typing.Optional[typing.Callable], obj): - if obj is None: - return obj - return _deserialize_with_callable(if_obj_deserializer, obj) - - return functools.partial(_deserialize_with_optional, if_obj_deserializer) + if len(annotation.__args__) <= 2: # pyright: ignore + if_obj_deserializer = _get_deserialize_callable_from_annotation( + next(a for a in annotation.__args__ if a != type(None)), module, rf # pyright: ignore + ) + + return functools.partial(_deserialize_with_optional, if_obj_deserializer) + # the type is Optional[Union[...]], we need to remove the None type from the Union + annotation_copy = copy.copy(annotation) + annotation_copy.__args__ = [a for a in annotation_copy.__args__ if a != type(None)] # pyright: ignore + return _get_deserialize_callable_from_annotation(annotation_copy, module, rf) except AttributeError: pass + # is it union? if getattr(annotation, "__origin__", None) is typing.Union: # initial ordering is we make `string` the last deserialization option, because it is often them most generic deserializers = [ _get_deserialize_callable_from_annotation(arg, module, rf) - for arg in sorted( - annotation.__args__, key=lambda x: hasattr(x, "__name__") and x.__name__ == "str" # pyright: ignore - ) + for arg in _sorted_annotations(annotation.__args__) # pyright: ignore ] - def _deserialize_with_union(deserializers, obj): - for deserializer in deserializers: - try: - return _deserialize(deserializer, obj) - except DeserializationError: - pass - raise DeserializationError() - return functools.partial(_deserialize_with_union, deserializers) try: @@ -678,17 +717,10 @@ def _deserialize_with_union(deserializers, obj): annotation.__args__[1], module, rf # pyright: ignore ) - def _deserialize_dict( - value_deserializer: typing.Optional[typing.Callable], - obj: typing.Dict[typing.Any, typing.Any], - ): - if obj is None: - return obj - return {k: _deserialize(value_deserializer, v, module) for k, v in obj.items()} - return functools.partial( _deserialize_dict, value_deserializer, + module, ) except (AttributeError, IndexError): pass @@ -696,35 +728,16 @@ def _deserialize_dict( if annotation._name in ["List", "Set", "Tuple", "Sequence"]: # pyright: ignore if len(annotation.__args__) > 1: # pyright: ignore - def _deserialize_multiple_sequence( - entry_deserializers: typing.List[typing.Optional[typing.Callable]], - obj, - ): - if obj is None: - return obj - return type(obj)( - _deserialize(deserializer, entry, module) - for entry, deserializer in zip(obj, entry_deserializers) - ) - entry_deserializers = [ _get_deserialize_callable_from_annotation(dt, module, rf) for dt in annotation.__args__ # pyright: ignore ] - return functools.partial(_deserialize_multiple_sequence, entry_deserializers) + return functools.partial(_deserialize_multiple_sequence, entry_deserializers, module) deserializer = _get_deserialize_callable_from_annotation( annotation.__args__[0], module, rf # pyright: ignore ) - def _deserialize_sequence( - deserializer: typing.Optional[typing.Callable], - obj, - ): - if obj is None: - return obj - return type(obj)(_deserialize(deserializer, entry, module) for entry in obj) - - return functools.partial(_deserialize_sequence, deserializer) + return functools.partial(_deserialize_sequence, deserializer, module) except (TypeError, IndexError, AttributeError, SyntaxError): pass diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py index 2cad8d4badf9..6e55fdf324ec 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py @@ -8,7 +8,8 @@ # -------------------------------------------------------------------------- from io import IOBase import json -from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload +import sys +from typing import Any, Callable, Dict, IO, List, Optional, Type, TypeVar, Union, overload from azure.core import MatchConditions from azure.core.exceptions import ( @@ -30,6 +31,10 @@ from .._serialization import Serializer from .._vendor import TextTranslationClientMixinABC, prep_if_match, prep_if_none_match +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -37,7 +42,7 @@ _SERIALIZER.client_side_validation = False -def build_text_translation_get_languages_request( # pylint: disable=name-too-long +def build_text_translation_get_supported_languages_request( # pylint: disable=name-too-long *, client_trace_id: Optional[str] = None, scope: Optional[str] = None, @@ -78,18 +83,18 @@ def build_text_translation_get_languages_request( # pylint: disable=name-too-lo def build_text_translation_translate_request( *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> HttpRequest: @@ -104,9 +109,9 @@ def build_text_translation_translate_request( _url = "/translate" # Construct parameters - _params["to"] = [_SERIALIZER.query("to", q, "str") if q is not None else "" for q in to] - if from_parameter is not None: - _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") + _params["to"] = [_SERIALIZER.query("target_languages", q, "str") if q is not None else "" for q in target_languages] + if source_language is not None: + _params["from"] = _SERIALIZER.query("source_language", source_language, "str") if text_type is not None: _params["textType"] = _SERIALIZER.query("text_type", text_type, "str") if category is not None: @@ -119,12 +124,12 @@ def build_text_translation_translate_request( _params["includeAlignment"] = _SERIALIZER.query("include_alignment", include_alignment, "bool") if include_sentence_length is not None: _params["includeSentenceLength"] = _SERIALIZER.query("include_sentence_length", include_sentence_length, "bool") - if suggested_from is not None: - _params["suggestedFrom"] = _SERIALIZER.query("suggested_from", suggested_from, "str") - if from_script is not None: - _params["fromScript"] = _SERIALIZER.query("from_script", from_script, "str") - if to_script is not None: - _params["toScript"] = _SERIALIZER.query("to_script", to_script, "str") + if suggested_source_language is not None: + _params["suggestedFrom"] = _SERIALIZER.query("suggested_source_language", suggested_source_language, "str") + if source_language_script is not None: + _params["fromScript"] = _SERIALIZER.query("source_language_script", source_language_script, "str") + if target_language_script is not None: + _params["toScript"] = _SERIALIZER.query("target_language_script", target_language_script, "str") if allow_fallback is not None: _params["allowFallback"] = _SERIALIZER.query("allow_fallback", allow_fallback, "bool") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -132,15 +137,20 @@ def build_text_translation_translate_request( # Construct headers if client_trace_id is not None: _headers["X-ClientTraceId"] = _SERIALIZER.header("client_trace_id", client_trace_id, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_text_translation_transliterate_request( # pylint: disable=name-too-long - *, language: str, from_script: str, to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any + *, + language: str, + source_language_script: str, + target_language_script: str, + client_trace_id: Optional[str] = None, + **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -154,16 +164,16 @@ def build_text_translation_transliterate_request( # pylint: disable=name-too-lo # Construct parameters _params["language"] = _SERIALIZER.query("language", language, "str") - _params["fromScript"] = _SERIALIZER.query("from_script", from_script, "str") - _params["toScript"] = _SERIALIZER.query("to_script", to_script, "str") + _params["fromScript"] = _SERIALIZER.query("source_language_script", source_language_script, "str") + _params["toScript"] = _SERIALIZER.query("target_language_script", target_language_script, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if client_trace_id is not None: _headers["X-ClientTraceId"] = _SERIALIZER.header("client_trace_id", client_trace_id, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) @@ -195,15 +205,15 @@ def build_text_translation_find_sentence_boundaries_request( # pylint: disable= # Construct headers if client_trace_id is not None: _headers["X-ClientTraceId"] = _SERIALIZER.header("client_trace_id", client_trace_id, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_text_translation_lookup_dictionary_entries_request( # pylint: disable=name-too-long - *, from_parameter: str, to: str, client_trace_id: Optional[str] = None, **kwargs: Any + *, source_language: str, target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -216,22 +226,22 @@ def build_text_translation_lookup_dictionary_entries_request( # pylint: disable _url = "/dictionary/lookup" # Construct parameters - _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") - _params["to"] = _SERIALIZER.query("to", to, "str") + _params["from"] = _SERIALIZER.query("source_language", source_language, "str") + _params["to"] = _SERIALIZER.query("target_language", target_language, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if client_trace_id is not None: _headers["X-ClientTraceId"] = _SERIALIZER.header("client_trace_id", client_trace_id, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) def build_text_translation_lookup_dictionary_examples_request( # pylint: disable=name-too-long - *, from_parameter: str, to: str, client_trace_id: Optional[str] = None, **kwargs: Any + *, source_language: str, target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -244,23 +254,24 @@ def build_text_translation_lookup_dictionary_examples_request( # pylint: disabl _url = "/dictionary/examples" # Construct parameters - _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") - _params["to"] = _SERIALIZER.query("to", to, "str") + _params["from"] = _SERIALIZER.query("source_language", source_language, "str") + _params["to"] = _SERIALIZER.query("target_language", target_language, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers if client_trace_id is not None: _headers["X-ClientTraceId"] = _SERIALIZER.header("client_trace_id", client_trace_id, "str") - _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") if content_type is not None: _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs) class TextTranslationClientOperationsMixin(TextTranslationClientMixinABC): + @distributed_trace - def get_languages( + def get_supported_languages( self, *, client_trace_id: Optional[str] = None, @@ -269,7 +280,7 @@ def get_languages( etag: Optional[str] = None, match_condition: Optional[MatchConditions] = None, **kwargs: Any - ) -> _models.GetLanguagesResult: + ) -> _models.GetSupportedLanguagesResult: # pylint: disable=line-too-long """Gets the set of languages currently supported by other operations of the Translator. @@ -279,7 +290,7 @@ def get_languages( value is None. :paramtype client_trace_id: str :keyword scope: A comma-separated list of names defining the group of languages to return. - Allowed group names are: ``translation``\ , ``transliteration`` and ``dictionary``. + Allowed group names are: ``translation``\\ , ``transliteration`` and ``dictionary``. If no scope is given, then all groups are returned, which is equivalent to passing ``scope=translation,transliteration,dictionary``. To decide which set of supported languages is appropriate for your scenario, see the description of the `response object @@ -301,8 +312,9 @@ def get_languages( :paramtype etag: str :keyword match_condition: The match condition to use upon the etag. Default value is None. :paramtype match_condition: ~azure.core.MatchConditions - :return: GetLanguagesResult. The GetLanguagesResult is compatible with MutableMapping - :rtype: ~azure.ai.translation.text.models.GetLanguagesResult + :return: GetSupportedLanguagesResult. The GetSupportedLanguagesResult is compatible with + MutableMapping + :rtype: ~azure.ai.translation.text.models.GetSupportedLanguagesResult :raises ~azure.core.exceptions.HttpResponseError: Example: @@ -314,6 +326,7 @@ def get_languages( "str": { "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. + Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. "nativeName": "str", # Display name of the language in the @@ -324,7 +337,7 @@ def get_languages( the target language. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required. + Required. Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. @@ -338,6 +351,7 @@ def get_languages( "str": { "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. + Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. "nativeName": "str" # Display name of the language in the @@ -356,7 +370,7 @@ def get_languages( script. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required. + Required. Known values are: "ltr" and "rtl". "name": "str", # Display name of the script in the locale requested via Accept-Language header. Required. "nativeName": "str", # Display name of the @@ -367,7 +381,8 @@ def get_languages( identifying the script. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages - or ltr for left-to-right languages. Required. + or ltr for left-to-right languages. Required. Known + values are: "ltr" and "rtl". "name": "str", # Display name of the script in the locale requested via Accept-Language header. Required. @@ -382,7 +397,7 @@ def get_languages( } } """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -399,9 +414,9 @@ def get_languages( _headers = kwargs.pop("headers", {}) or {} _params = kwargs.pop("params", {}) or {} - cls: ClsType[_models.GetLanguagesResult] = kwargs.pop("cls", None) + cls: ClsType[_models.GetSupportedLanguagesResult] = kwargs.pop("cls", None) - _request = build_text_translation_get_languages_request( + _request = build_text_translation_get_supported_languages_request( client_trace_id=client_trace_id, scope=scope, accept_language=accept_language, @@ -437,7 +452,7 @@ def get_languages( if _stream: deserialized = response.iter_bytes() else: - deserialized = _deserialize(_models.GetLanguagesResult, response.json()) + deserialized = _deserialize(_models.GetSupportedLanguagesResult, response.json()) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -449,18 +464,18 @@ def translate( self, request_body: List[_models.InputTextItem], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -472,17 +487,17 @@ def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -491,7 +506,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -520,15 +535,16 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -625,18 +641,18 @@ def translate( self, request_body: IO[bytes], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -648,17 +664,17 @@ def translate( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -667,7 +683,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -696,15 +712,16 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -794,18 +811,18 @@ def translate( self, request_body: Union[List[_models.InputTextItem], IO[bytes]], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -817,17 +834,17 @@ def translate( :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -836,7 +853,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -865,15 +882,16 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -954,7 +972,7 @@ def translate( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -976,18 +994,18 @@ def translate( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( - to=to, + target_languages=target_languages, client_trace_id=client_trace_id, - from_parameter=from_parameter, + source_language=source_language, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_from=suggested_from, - from_script=from_script, - to_script=to_script, + suggested_source_language=suggested_source_language, + source_language_script=source_language_script, + target_language_script=target_language_script, allow_fallback=allow_fallback, content_type=content_type, api_version=self._config.api_version, @@ -1035,8 +1053,8 @@ def transliterate( request_body: List[_models.InputTextItem], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1051,14 +1069,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1096,8 +1114,8 @@ def transliterate( request_body: IO[bytes], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1112,14 +1130,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1150,8 +1168,8 @@ def transliterate( request_body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -1166,14 +1184,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1194,7 +1212,7 @@ def transliterate( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1217,8 +1235,8 @@ def transliterate( _request = build_text_translation_transliterate_request( language=language, - from_script=from_script, - to_script=to_script, + source_language_script=source_language_script, + target_language_script=target_language_script, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1435,7 +1453,7 @@ def find_sentence_boundaries( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1503,8 +1521,8 @@ def lookup_dictionary_entries( self, request_body: List[_models.InputTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1516,14 +1534,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1618,8 +1636,8 @@ def lookup_dictionary_entries( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1631,14 +1649,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1726,8 +1744,8 @@ def lookup_dictionary_entries( self, request_body: Union[List[_models.InputTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1739,14 +1757,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1825,7 +1843,7 @@ def lookup_dictionary_entries( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1847,8 +1865,8 @@ def lookup_dictionary_entries( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( - from_parameter=from_parameter, - to=to, + source_language=source_language, + target_language=target_language, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1893,8 +1911,8 @@ def lookup_dictionary_examples( self, request_body: List[_models.DictionaryExampleTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1906,14 +1924,14 @@ def lookup_dictionary_examples( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1980,8 +1998,8 @@ def lookup_dictionary_examples( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1993,14 +2011,14 @@ def lookup_dictionary_examples( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -2055,8 +2073,8 @@ def lookup_dictionary_examples( self, request_body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryExampleItem]: @@ -2069,14 +2087,14 @@ def lookup_dictionary_examples( [DictionaryExampleTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -2122,7 +2140,7 @@ def lookup_dictionary_examples( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2144,8 +2162,8 @@ def lookup_dictionary_examples( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( - from_parameter=from_parameter, - to=to, + source_language=source_language, + target_language=target_language, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index 47dc2df2c1a0..d39ffc0b7e73 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -17,18 +17,18 @@ def translate( self, request_body: List[str], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -40,17 +40,17 @@ def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[str] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -59,7 +59,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -88,15 +88,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -191,18 +191,18 @@ def translate( self, request_body: List[_models.InputTextItem], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -214,17 +214,17 @@ def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -233,7 +233,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -262,15 +262,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -367,18 +367,18 @@ def translate( self, request_body: IO[bytes], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -390,17 +390,17 @@ def translate( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -409,7 +409,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -438,15 +438,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -535,18 +535,18 @@ def translate( self, request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -561,18 +561,18 @@ def translate( return super().translate( request_body=body, - to=to, + target_languages=target_languages, client_trace_id=client_trace_id, - from_parameter=from_parameter, + source_language=source_language, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_from=suggested_from, - from_script=from_script, - to_script=to_script, + suggested_source_language=suggested_source_language, + source_language_script=source_language_script, + target_language_script=target_language_script, allow_fallback=allow_fallback, **kwargs ) @@ -583,8 +583,8 @@ def transliterate( request_body: List[str], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -599,14 +599,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -644,8 +644,8 @@ def transliterate( request_body: List[_models.InputTextItem], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -660,14 +660,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -705,8 +705,8 @@ def transliterate( request_body: IO[bytes], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -721,14 +721,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -758,8 +758,8 @@ def transliterate( request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -775,8 +775,8 @@ def transliterate( return super().transliterate( request_body=body, language=language, - from_script=from_script, - to_script=to_script, + source_language_script=source_language_script, + target_language_script=target_language_script, client_trace_id=client_trace_id, **kwargs ) @@ -997,8 +997,8 @@ def lookup_dictionary_entries( self, request_body: List[str], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1010,14 +1010,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[str] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1112,8 +1112,8 @@ def lookup_dictionary_entries( self, request_body: List[_models.InputTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1125,14 +1125,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1227,8 +1227,8 @@ def lookup_dictionary_entries( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1240,14 +1240,14 @@ def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1334,8 +1334,8 @@ def lookup_dictionary_entries( self, request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1349,7 +1349,11 @@ def lookup_dictionary_entries( body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) return super().lookup_dictionary_entries( - request_body=body, from_parameter=from_parameter, to=to, client_trace_id=client_trace_id, **kwargs + request_body=body, + source_language=source_language, + target_language=target_language, + client_trace_id=client_trace_id, + **kwargs ) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index ff215ce4fd24..99a4493851e5 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -56,21 +56,23 @@ def on_request(self, request: PipelineRequest) -> None: request.http_request.headers["Ocp-Apim-Subscription-Key"] = self.credential.key request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.credential.region + class TranslatorAADCredential: """Credential for Translator Service when using AAD authentication. - :param tokenCredential: An object which can provide an access token for the Translator Resource, such as a credential from + :param token_credential: An object which can provide an access token for the Translator Resource, such as a credential from :mod:`azure.identity` - :type tokenCredential: ~azure.core.credentials.TokenCredential - :param str resourceId: Azure Resource Id of the Translation Resource. + :type token_credential: ~azure.core.credentials.TokenCredential + :param str resource_id: Azure Resource Id of the Translation Resource. :param str region: Azure Region of the Translation Resource. """ - def __init__(self, tokenCredential: TokenCredential, resourceId: str, region: str) -> None: - self.tokenCredential = tokenCredential - self.resourceId = resourceId + def __init__(self, token_credential: TokenCredential, resource_id: str, region: str) -> None: + self.token_credential = token_credential + self.resource_id = resource_id self.region = region + class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): """Translator AAD Authentication Policy. Adds headers that are required by Translator Service when global endpoint is used with AAD policy. @@ -81,15 +83,18 @@ class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): :type credential: ~azure.ai.translation.text.TranslatorAADCredential """ - def __init__(self, credential: TranslatorAADCredential, **kwargs: Any)-> None: - super(TranslatorAADAuthenticationPolicy, self).__init__(credential.tokenCredential, "https://cognitiveservices.azure.com/.default", **kwargs) + def __init__(self, credential: TranslatorAADCredential, **kwargs: Any) -> None: + super(TranslatorAADAuthenticationPolicy, self).__init__( + credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs + ) self.translatorCredential = credential def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resourceId + request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resource_id request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translatorCredential.region super().on_request(request) + def get_translation_endpoint(endpoint, api_version): if not endpoint: endpoint = "https://api.cognitive.microsofttranslator.com" @@ -167,7 +172,9 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: Optional[Union[AzureKeyCredential, TokenCredential, TranslatorCredential, TranslatorAADCredential]] = None, + credential: Optional[ + Union[AzureKeyCredential, TokenCredential, TranslatorCredential, TranslatorAADCredential] + ] = None, endpoint: Optional[str] = None, api_version="3.0", **kwargs diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py index bbcd28b4aa67..be71c81bd282 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b2" +VERSION = "1.0.0b1" diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py index 65945cb3200f..a0e21c127d4c 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py @@ -6,14 +6,15 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._patch import TextTranslationClient, AsyncTranslatorAADCredential +from ._patch import TextTranslationClient +from ._patch import AsyncTranslatorAADCredential from ._patch import patch_sdk as _patch_sdk __all__ = [ + "AsyncTranslatorAADCredential", "TextTranslationClient", - "AsyncTranslatorAADCredential" ] diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py index 343a01ff22e4..b2caf25ce07c 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py @@ -8,7 +8,8 @@ # -------------------------------------------------------------------------- from io import IOBase import json -from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload +import sys +from typing import Any, Callable, Dict, IO, List, Optional, Type, TypeVar, Union, overload from azure.core import MatchConditions from azure.core.exceptions import ( @@ -29,7 +30,7 @@ from ..._model_base import SdkJSONEncoder, _deserialize from ..._operations._operations import ( build_text_translation_find_sentence_boundaries_request, - build_text_translation_get_languages_request, + build_text_translation_get_supported_languages_request, build_text_translation_lookup_dictionary_entries_request, build_text_translation_lookup_dictionary_examples_request, build_text_translation_translate_request, @@ -37,13 +38,18 @@ ) from .._vendor import TextTranslationClientMixinABC +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] class TextTranslationClientOperationsMixin(TextTranslationClientMixinABC): + @distributed_trace_async - async def get_languages( + async def get_supported_languages( self, *, client_trace_id: Optional[str] = None, @@ -52,7 +58,7 @@ async def get_languages( etag: Optional[str] = None, match_condition: Optional[MatchConditions] = None, **kwargs: Any - ) -> _models.GetLanguagesResult: + ) -> _models.GetSupportedLanguagesResult: # pylint: disable=line-too-long """Gets the set of languages currently supported by other operations of the Translator. @@ -62,7 +68,7 @@ async def get_languages( value is None. :paramtype client_trace_id: str :keyword scope: A comma-separated list of names defining the group of languages to return. - Allowed group names are: ``translation``\ , ``transliteration`` and ``dictionary``. + Allowed group names are: ``translation``\\ , ``transliteration`` and ``dictionary``. If no scope is given, then all groups are returned, which is equivalent to passing ``scope=translation,transliteration,dictionary``. To decide which set of supported languages is appropriate for your scenario, see the description of the `response object @@ -84,8 +90,9 @@ async def get_languages( :paramtype etag: str :keyword match_condition: The match condition to use upon the etag. Default value is None. :paramtype match_condition: ~azure.core.MatchConditions - :return: GetLanguagesResult. The GetLanguagesResult is compatible with MutableMapping - :rtype: ~azure.ai.translation.text.models.GetLanguagesResult + :return: GetSupportedLanguagesResult. The GetSupportedLanguagesResult is compatible with + MutableMapping + :rtype: ~azure.ai.translation.text.models.GetSupportedLanguagesResult :raises ~azure.core.exceptions.HttpResponseError: Example: @@ -97,6 +104,7 @@ async def get_languages( "str": { "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. + Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. "nativeName": "str", # Display name of the language in the @@ -107,7 +115,7 @@ async def get_languages( the target language. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required. + Required. Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. @@ -121,6 +129,7 @@ async def get_languages( "str": { "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. + Known values are: "ltr" and "rtl". "name": "str", # Display name of the language in the locale requested via Accept-Language header. Required. "nativeName": "str" # Display name of the language in the @@ -139,7 +148,7 @@ async def get_languages( script. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required. + Required. Known values are: "ltr" and "rtl". "name": "str", # Display name of the script in the locale requested via Accept-Language header. Required. "nativeName": "str", # Display name of the @@ -150,7 +159,8 @@ async def get_languages( identifying the script. Required. "dir": "str", # Directionality, which is rtl for right-to-left languages - or ltr for left-to-right languages. Required. + or ltr for left-to-right languages. Required. Known + values are: "ltr" and "rtl". "name": "str", # Display name of the script in the locale requested via Accept-Language header. Required. @@ -165,7 +175,7 @@ async def get_languages( } } """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -182,9 +192,9 @@ async def get_languages( _headers = kwargs.pop("headers", {}) or {} _params = kwargs.pop("params", {}) or {} - cls: ClsType[_models.GetLanguagesResult] = kwargs.pop("cls", None) + cls: ClsType[_models.GetSupportedLanguagesResult] = kwargs.pop("cls", None) - _request = build_text_translation_get_languages_request( + _request = build_text_translation_get_supported_languages_request( client_trace_id=client_trace_id, scope=scope, accept_language=accept_language, @@ -220,7 +230,7 @@ async def get_languages( if _stream: deserialized = response.iter_bytes() else: - deserialized = _deserialize(_models.GetLanguagesResult, response.json()) + deserialized = _deserialize(_models.GetSupportedLanguagesResult, response.json()) if cls: return cls(pipeline_response, deserialized, response_headers) # type: ignore @@ -232,18 +242,18 @@ async def translate( self, request_body: List[_models.InputTextItem], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -255,17 +265,17 @@ async def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -274,7 +284,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -303,15 +313,16 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -408,18 +419,18 @@ async def translate( self, request_body: IO[bytes], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -431,17 +442,17 @@ async def translate( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -450,7 +461,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -479,15 +490,16 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -577,18 +589,18 @@ async def translate( self, request_body: Union[List[_models.InputTextItem], IO[bytes]], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -600,17 +612,17 @@ async def translate( :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the - supported languages included + :keyword target_languages: Specifies the language of the output text. The target language must + be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -619,7 +631,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -648,15 +660,16 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't - be identified. + :keyword suggested_source_language: Specifies a fallback language if the language of the input + text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is + None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -737,7 +750,7 @@ async def translate( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -759,18 +772,18 @@ async def translate( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( - to=to, + target_languages=target_languages, client_trace_id=client_trace_id, - from_parameter=from_parameter, + source_language=source_language, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_from=suggested_from, - from_script=from_script, - to_script=to_script, + suggested_source_language=suggested_source_language, + source_language_script=source_language_script, + target_language_script=target_language_script, allow_fallback=allow_fallback, content_type=content_type, api_version=self._config.api_version, @@ -818,8 +831,8 @@ async def transliterate( request_body: List[_models.InputTextItem], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -834,14 +847,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -879,8 +892,8 @@ async def transliterate( request_body: IO[bytes], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -895,14 +908,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -933,8 +946,8 @@ async def transliterate( request_body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -949,14 +962,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages - using the transliteration scope, + :keyword source_language_script: Specifies the script used by the input text. Look up supported + languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the - transliteration scope, to find output + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using + the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -977,7 +990,7 @@ async def transliterate( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1000,8 +1013,8 @@ async def transliterate( _request = build_text_translation_transliterate_request( language=language, - from_script=from_script, - to_script=to_script, + source_language_script=source_language_script, + target_language_script=target_language_script, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1218,7 +1231,7 @@ async def find_sentence_boundaries( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1286,8 +1299,8 @@ async def lookup_dictionary_entries( self, request_body: List[_models.InputTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1299,14 +1312,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1401,8 +1414,8 @@ async def lookup_dictionary_entries( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1414,14 +1427,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1509,8 +1522,8 @@ async def lookup_dictionary_entries( self, request_body: Union[List[_models.InputTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1522,14 +1535,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1608,7 +1621,7 @@ async def lookup_dictionary_entries( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1630,8 +1643,8 @@ async def lookup_dictionary_entries( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( - from_parameter=from_parameter, - to=to, + source_language=source_language, + target_language=target_language, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1676,8 +1689,8 @@ async def lookup_dictionary_examples( self, request_body: List[_models.DictionaryExampleTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1689,14 +1702,14 @@ async def lookup_dictionary_examples( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1763,8 +1776,8 @@ async def lookup_dictionary_examples( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1776,14 +1789,14 @@ async def lookup_dictionary_examples( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1838,8 +1851,8 @@ async def lookup_dictionary_examples( self, request_body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryExampleItem]: @@ -1852,14 +1865,14 @@ async def lookup_dictionary_examples( [DictionaryExampleTextItem] type or a IO[bytes] type. Required. :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1905,7 +1918,7 @@ async def lookup_dictionary_examples( } ] """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1927,8 +1940,8 @@ async def lookup_dictionary_examples( _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( - from_parameter=from_parameter, - to=to, + source_language=source_language, + target_language=target_language, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index e3b46470f0aa..c1d133f67cb6 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -17,18 +17,18 @@ async def translate( self, request_body: List[str], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -40,17 +40,17 @@ async def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[str] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -59,7 +59,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -88,15 +88,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -191,18 +191,18 @@ async def translate( self, request_body: List[_models.InputTextItem], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -214,17 +214,17 @@ async def translate( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -233,7 +233,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -262,15 +262,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -367,18 +367,18 @@ async def translate( self, request_body: IO[bytes], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -390,17 +390,17 @@ async def translate( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword to: Specifies the language of the output text. The target language must be one of the + :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype to: list[str] + :paramtype target_languages: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword from_parameter: Specifies the language of the input text. Find which languages are + :keyword source_language: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -409,7 +409,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype from_parameter: str + :paramtype source_language: str :keyword text_type: 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. Known values are: "Plain" and @@ -438,15 +438,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_from: Specifies a fallback language if the language of the input text can't + :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_from: str - :keyword from_script: Specifies the script of the input text. Default value is None. - :paramtype from_script: str - :keyword to_script: Specifies the script of the translated text. Default value is None. - :paramtype to_script: str + :paramtype suggested_source_language: str + :keyword source_language_script: Specifies the script of the input text. Default value is None. + :paramtype source_language_script: str + :keyword target_language_script: Specifies the script of the translated text. Default value is None. + :paramtype target_language_script: str :keyword allow_fallback: 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. @@ -535,18 +535,18 @@ async def translate( self, request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - to: List[str], + target_languages: List[str], client_trace_id: Optional[str] = None, - from_parameter: Optional[str] = None, + source_language: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_from: Optional[str] = None, - from_script: Optional[str] = None, - to_script: Optional[str] = None, + suggested_source_language: Optional[str] = None, + source_language_script: Optional[str] = None, + target_language_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -561,18 +561,18 @@ async def translate( return await super().translate( request_body=body, - to=to, + target_languages=target_languages, client_trace_id=client_trace_id, - from_parameter=from_parameter, + source_language=source_language, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_from=suggested_from, - from_script=from_script, - to_script=to_script, + suggested_source_language=suggested_source_language, + source_language_script=source_language_script, + target_language_script=target_language_script, allow_fallback=allow_fallback, **kwargs ) @@ -583,8 +583,8 @@ async def transliterate( request_body: List[str], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -599,14 +599,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -644,8 +644,8 @@ async def transliterate( request_body: List[_models.InputTextItem], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -660,14 +660,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -705,8 +705,8 @@ async def transliterate( request_body: IO[bytes], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -721,14 +721,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword from_script: Specifies the script used by the input text. Look up supported languages + :keyword source_language_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype from_script: str - :keyword to_script: Specifies the output script. Look up supported languages using the + :paramtype source_language_script: str + :keyword target_language_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype to_script: str + :paramtype target_language_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -758,8 +758,8 @@ async def transliterate( request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, - from_script: str, - to_script: str, + source_language_script: str, + target_language_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -775,8 +775,8 @@ async def transliterate( return await super().transliterate( request_body=body, language=language, - from_script=from_script, - to_script=to_script, + source_language_script=source_language_script, + target_language_script=target_language_script, client_trace_id=client_trace_id, **kwargs ) @@ -997,8 +997,8 @@ async def lookup_dictionary_entries( self, request_body: List[str], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1010,14 +1010,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[str] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1112,8 +1112,8 @@ async def lookup_dictionary_entries( self, request_body: List[_models.InputTextItem], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1125,14 +1125,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1227,8 +1227,8 @@ async def lookup_dictionary_entries( self, request_body: IO[bytes], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1240,14 +1240,14 @@ async def lookup_dictionary_entries( :param request_body: Defines the content of the request. Required. :type request_body: IO[bytes] - :keyword from_parameter: Specifies the language of the input text. + :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype from_parameter: str - :keyword to: Specifies the language of the output text. + :paramtype source_language: str + :keyword target_language: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype to: str + :paramtype target_language: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1334,8 +1334,8 @@ async def lookup_dictionary_entries( self, request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - from_parameter: str, - to: str, + source_language: str, + target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1349,7 +1349,11 @@ async def lookup_dictionary_entries( body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) return await super().lookup_dictionary_entries( - request_body=body, from_parameter=from_parameter, to=to, client_trace_id=client_trace_id, **kwargs + request_body=body, + source_language=source_language, + target_language=target_language, + client_trace_id=client_trace_id, + **kwargs ) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index a38265f74657..af1f74b89d06 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -25,21 +25,23 @@ def patch_sdk(): https://aka.ms/azsdk/python/dpcodegen/python/customize """ + class AsyncTranslatorAADCredential: """Credential for Translator Service when using AAD authentication. - :param tokenCredential: An object which can provide an access token for the Translator Resource, such as a credential from + :param token_credential: An object which can provide an access token for the Translator Resource, such as a credential from :mod:`azure.identity` - :type tokenCredential: ~azure.core.credentials.TokenCredential - :param str resourceId: Azure Resource Id of the Translation Resource. + :type token_credential: ~azure.core.credentials.TokenCredential + :param str resource_id: Azure Resource Id of the Translation Resource. :param str region: Azure Region of the Translation Resource. """ - def __init__(self, tokenCredential: AsyncTokenCredential, resourceId: str, region: str) -> None: - self.tokenCredential = tokenCredential - self.resourceId = resourceId + def __init__(self, token_credential: AsyncTokenCredential, resource_id: str, region: str) -> None: + self.token_credential = token_credential + self.resource_id = resource_id self.region = region + class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): """Translator AAD Authentication Policy. Adds headers that are required by Translator Service when global endpoint is used with AAD policy. @@ -50,12 +52,14 @@ class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): :type credential: ~azure.ai.translation.text.AsyncTranslatorAADCredential """ - def __init__(self, credential: AsyncTranslatorAADCredential, **kwargs: Any)-> None: - super(AsyncTranslatorAADAuthenticationPolicy, self).__init__(credential.tokenCredential, "https://cognitiveservices.azure.com/.default", **kwargs) + def __init__(self, credential: AsyncTranslatorAADCredential, **kwargs: Any) -> None: + super(AsyncTranslatorAADAuthenticationPolicy, self).__init__( + credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs + ) self.translatorCredential = credential async def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resourceId + request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resource_id request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translatorCredential.region await super().on_request(request) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py index 3b2df9b8ca1f..da99621bc1e2 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py @@ -8,7 +8,6 @@ from ._models import BackTranslation from ._models import BreakSentenceItem -from ._models import CommonScriptModel from ._models import DetectedLanguage from ._models import DictionaryExample from ._models import DictionaryExampleItem @@ -17,20 +16,22 @@ from ._models import DictionaryTranslation from ._models import ErrorDetails from ._models import ErrorResponse -from ._models import GetLanguagesResult +from ._models import GetSupportedLanguagesResult from ._models import InputTextItem -from ._models import SentenceLength +from ._models import LanguageScript +from ._models import SentenceBoundaries from ._models import SourceDictionaryLanguage from ._models import SourceText from ._models import TargetDictionaryLanguage from ._models import TranslatedTextAlignment from ._models import TranslatedTextItem -from ._models import Translation from ._models import TranslationLanguage +from ._models import TranslationText from ._models import TransliterableScript from ._models import TransliteratedText from ._models import TransliterationLanguage +from ._enums import LanguageDirectionality from ._enums import ProfanityAction from ._enums import ProfanityMarker from ._enums import TextType @@ -41,7 +42,6 @@ __all__ = [ "BackTranslation", "BreakSentenceItem", - "CommonScriptModel", "DetectedLanguage", "DictionaryExample", "DictionaryExampleItem", @@ -50,19 +50,21 @@ "DictionaryTranslation", "ErrorDetails", "ErrorResponse", - "GetLanguagesResult", + "GetSupportedLanguagesResult", "InputTextItem", - "SentenceLength", + "LanguageScript", + "SentenceBoundaries", "SourceDictionaryLanguage", "SourceText", "TargetDictionaryLanguage", "TranslatedTextAlignment", "TranslatedTextItem", - "Translation", "TranslationLanguage", + "TranslationText", "TransliterableScript", "TransliteratedText", "TransliterationLanguage", + "LanguageDirectionality", "ProfanityAction", "ProfanityMarker", "TextType", diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py index 5eac3900be23..8ed1ec727def 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py @@ -10,6 +10,13 @@ from azure.core import CaseInsensitiveEnumMeta +class LanguageDirectionality(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Language Directionality.""" + + LEFT_TO_RIGHT = "ltr" + RIGHT_TO_LEFT = "rtl" + + class ProfanityAction(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Translator profanity actions.""" diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py index 0cfaa8725737..d2278bded2a4 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, overload +from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, Union, overload from .. import _model_base from .._model_base import rest_field @@ -30,8 +30,8 @@ class BackTranslation(_model_base.Model): a form best suited for end-user display. Required. :vartype display_text: str - :ivar num_examples: An integer representing the number of examples that are available for this - translation pair. + :ivar examples_count: 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 @@ -40,7 +40,7 @@ class BackTranslation(_model_base.Model): 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. Required. - :vartype num_examples: int + :vartype examples_count: int :ivar frequency_count: 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 @@ -55,7 +55,7 @@ class BackTranslation(_model_base.Model): display_text: str = rest_field(name="displayText") """A string giving the source term that is a back-translation of the target in a form best suited for end-user display. Required.""" - num_examples: int = rest_field(name="numExamples") + examples_count: int = rest_field(name="numExamples") """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 @@ -76,10 +76,9 @@ def __init__( *, normalized_text: str, display_text: str, - num_examples: int, + examples_count: int, frequency_count: int, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -100,16 +99,17 @@ class BreakSentenceItem(_model_base.Model): :ivar detected_language: The detectedLanguage property is only present in the result object when language auto-detection is requested. :vartype detected_language: ~azure.ai.translation.text.models.DetectedLanguage - :ivar sent_len: An integer array representing the lengths of the sentences in the input text. + :ivar lengths_of_sentences: 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. Required. - :vartype sent_len: list[int] + :vartype lengths_of_sentences: list[int] """ detected_language: Optional["_models.DetectedLanguage"] = rest_field(name="detectedLanguage") """The detectedLanguage property is only present in the result object when language auto-detection is requested.""" - sent_len: List[int] = rest_field(name="sentLen") + lengths_of_sentences: List[int] = rest_field(name="sentLen") """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. Required.""" @@ -118,60 +118,9 @@ class BreakSentenceItem(_model_base.Model): def __init__( self, *, - sent_len: List[int], + lengths_of_sentences: List[int], detected_language: Optional["_models.DetectedLanguage"] = None, - ): - ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): - """ - :param mapping: raw JSON to initialize the model. - :type mapping: Mapping[str, Any] - """ - - def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useless-super-delegation - super().__init__(*args, **kwargs) - - -class CommonScriptModel(_model_base.Model): - """Common properties of language script. - - All required parameters must be populated in order to send to server. - - :ivar code: Code identifying the script. Required. - :vartype code: str - :ivar name: Display name of the script in the locale requested via Accept-Language header. - Required. - :vartype name: str - :ivar native_name: Display name of the language in the locale native for the language. - Required. - :vartype native_name: str - :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right - languages. Required. - :vartype dir: str - """ - - code: str = rest_field() - """Code identifying the script. Required.""" - name: str = rest_field() - """Display name of the script in the locale requested via Accept-Language header. Required.""" - native_name: str = rest_field(name="nativeName") - """Display name of the language in the locale native for the language. Required.""" - dir: str = rest_field() - """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required.""" - - @overload - def __init__( - self, - *, - code: str, - name: str, - native_name: str, - dir: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -191,14 +140,14 @@ class DetectedLanguage(_model_base.Model): :ivar language: A string representing the code of the detected language. Required. :vartype language: str - :ivar score: A float value indicating the confidence in the result. + :ivar confidence: A float value indicating the confidence in the result. The score is between zero and one and a low score indicates a low confidence. Required. - :vartype score: float + :vartype confidence: float """ language: str = rest_field() """A string representing the code of the detected language. Required.""" - score: float = rest_field() + confidence: float = rest_field(name="score") """A float value indicating the confidence in the result. The score is between zero and one and a low score indicates a low confidence. Required.""" @@ -207,9 +156,8 @@ def __init__( self, *, language: str, - score: float, - ): - ... + confidence: float, + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -279,8 +227,7 @@ def __init__( target_prefix: str, target_term: str, target_suffix: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -329,8 +276,7 @@ def __init__( normalized_source: str, normalized_target: str, examples: List["_models.DictionaryExample"], - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -360,8 +306,7 @@ def __init__( self, *, text: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -403,8 +348,7 @@ def __init__( *, text: str, translation: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -453,8 +397,7 @@ def __init__( normalized_source: str, display_source: str, translations: List["_models.DictionaryTranslation"], - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -543,8 +486,7 @@ def __init__( confidence: float, prefix_word: str, back_translations: List["_models.BackTranslation"], - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -579,8 +521,7 @@ def __init__( *, code: int, message: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -610,8 +551,7 @@ def __init__( self, *, error: "_models.ErrorDetails", - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -624,7 +564,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useles super().__init__(*args, **kwargs) -class GetLanguagesResult(_model_base.Model): +class GetSupportedLanguagesResult(_model_base.Model): """Response for the languages API. :ivar translation: Languages that support translate API. @@ -649,8 +589,56 @@ def __init__( translation: Optional[Dict[str, "_models.TranslationLanguage"]] = None, transliteration: Optional[Dict[str, "_models.TransliterationLanguage"]] = None, dictionary: Optional[Dict[str, "_models.SourceDictionaryLanguage"]] = None, - ): - ... + ): ... + + @overload + def __init__(self, mapping: Mapping[str, Any]): + """ + :param mapping: raw JSON to initialize the model. + :type mapping: Mapping[str, Any] + """ + + def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useless-super-delegation + super().__init__(*args, **kwargs) + + +class LanguageScript(_model_base.Model): + """Common properties of language script. + + All required parameters must be populated in order to send to server. + + :ivar code: Code identifying the script. Required. + :vartype code: str + :ivar name: Display name of the script in the locale requested via Accept-Language header. + Required. + :vartype name: str + :ivar native_name: Display name of the language in the locale native for the language. + Required. + :vartype native_name: str + :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for + left-to-right languages. Required. Known values are: "ltr" and "rtl". + :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + """ + + code: str = rest_field() + """Code identifying the script. Required.""" + name: str = rest_field() + """Display name of the script in the locale requested via Accept-Language header. Required.""" + native_name: str = rest_field(name="nativeName") + """Display name of the language in the locale native for the language. Required.""" + directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + Required. Known values are: \"ltr\" and \"rtl\".""" + + @overload + def __init__( + self, + *, + code: str, + name: str, + native_name: str, + directionality: Union[str, "_models.LanguageDirectionality"], + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -663,28 +651,28 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useles super().__init__(*args, **kwargs) -class SentenceLength(_model_base.Model): +class SentenceBoundaries(_model_base.Model): """An object returning sentence boundaries in the input and output texts. All required parameters must be populated in order to send to server. - :ivar src_sent_len: An integer array representing the lengths of the sentences in the input - text. + :ivar source_sentences_lengths: 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. Required. - :vartype src_sent_len: list[int] - :ivar trans_sent_len: An integer array representing the lengths of the sentences in the - translated text. + :vartype source_sentences_lengths: list[int] + :ivar translated_sentences_lengths: 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. Required. - :vartype trans_sent_len: list[int] + :vartype translated_sentences_lengths: list[int] """ - src_sent_len: List[int] = rest_field(name="srcSentLen") + source_sentences_lengths: List[int] = rest_field(name="srcSentLen") """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. Required.""" - trans_sent_len: List[int] = rest_field(name="transSentLen") + translated_sentences_lengths: List[int] = rest_field(name="transSentLen") """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. Required.""" @@ -693,10 +681,9 @@ class SentenceLength(_model_base.Model): def __init__( self, *, - src_sent_len: List[int], - trans_sent_len: List[int], - ): - ... + source_sentences_lengths: List[int], + translated_sentences_lengths: List[int], + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -720,9 +707,9 @@ class SourceDictionaryLanguage(_model_base.Model): :ivar native_name: Display name of the language in the locale native for this language. Required. :vartype native_name: str - :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right - languages. Required. - :vartype dir: str + :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for + left-to-right languages. Required. Known values are: "ltr" and "rtl". + :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality :ivar translations: List of languages with alterative translations and examples for the query expressed in the source language. Required. :vartype translations: list[~azure.ai.translation.text.models.TargetDictionaryLanguage] @@ -732,9 +719,9 @@ class SourceDictionaryLanguage(_model_base.Model): """Display name of the language in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for this language. Required.""" - dir: str = rest_field() + directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required.""" + Required. Known values are: \"ltr\" and \"rtl\".""" translations: List["_models.TargetDictionaryLanguage"] = rest_field() """List of languages with alterative translations and examples for the query expressed in the source language. Required.""" @@ -745,10 +732,9 @@ def __init__( *, name: str, native_name: str, - dir: str, + directionality: Union[str, "_models.LanguageDirectionality"], translations: List["_models.TargetDictionaryLanguage"], - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -778,8 +764,7 @@ def __init__( self, *, text: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -803,9 +788,9 @@ class TargetDictionaryLanguage(_model_base.Model): :ivar native_name: Display name of the language in the locale native for this language. Required. :vartype native_name: str - :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right - languages. Required. - :vartype dir: str + :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for + left-to-right languages. Required. Known values are: "ltr" and "rtl". + :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality :ivar code: Language code identifying the target language. Required. :vartype code: str """ @@ -814,9 +799,9 @@ class TargetDictionaryLanguage(_model_base.Model): """Display name of the language in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for this language. Required.""" - dir: str = rest_field() + directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required.""" + Required. Known values are: \"ltr\" and \"rtl\".""" code: str = rest_field() """Language code identifying the target language. Required.""" @@ -826,10 +811,9 @@ def __init__( *, name: str, native_name: str, - dir: str, + directionality: Union[str, "_models.LanguageDirectionality"], code: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -847,8 +831,8 @@ class TranslatedTextAlignment(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar proj: Maps input text to translated text. The alignment information is only provided when - the request + :ivar projections: 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 @@ -857,10 +841,10 @@ class TranslatedTextAlignment(_model_base.Model): words may be non-contiguous. When no alignment information is available, the alignment element will be empty. Required. - :vartype proj: str + :vartype projections: str """ - proj: str = rest_field() + projections: str = rest_field(name="proj") """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]]. @@ -875,9 +859,8 @@ class TranslatedTextAlignment(_model_base.Model): def __init__( self, *, - proj: str, - ): - ... + projections: str, + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -901,7 +884,7 @@ class TranslatedTextItem(_model_base.Model): :ivar translations: An array of translation results. The size of the array matches the number of target languages specified through the to query parameter. Required. - :vartype translations: list[~azure.ai.translation.text.models.Translation] + :vartype translations: list[~azure.ai.translation.text.models.TranslationText] :ivar source_text: Input text in the default script of the source language. sourceText property is present only when the input is expressed in a script that's not the usual script for the language. For example, @@ -914,7 +897,7 @@ class TranslatedTextItem(_model_base.Model): detected_language: Optional["_models.DetectedLanguage"] = rest_field(name="detectedLanguage") """The detectedLanguage property is only present in the result object when language auto-detection is requested.""" - translations: List["_models.Translation"] = rest_field() + translations: List["_models.TranslationText"] = rest_field() """An array of translation results. The size of the array matches the number of target languages specified through the to query parameter. Required.""" source_text: Optional["_models.SourceText"] = rest_field(name="sourceText") @@ -929,11 +912,10 @@ class TranslatedTextItem(_model_base.Model): def __init__( self, *, - translations: List["_models.Translation"], + translations: List["_models.TranslationText"], detected_language: Optional["_models.DetectedLanguage"] = None, source_text: Optional["_models.SourceText"] = None, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -946,7 +928,53 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useles super().__init__(*args, **kwargs) -class Translation(_model_base.Model): +class TranslationLanguage(_model_base.Model): + """The value of the translation property is a dictionary of (key, value) pairs. Each key is a BCP + 47 language tag. + A key identifies a language for which text can be translated to or translated from. + + All required parameters must be populated in order to send to server. + + :ivar name: Display name of the language in the locale requested via Accept-Language header. + Required. + :vartype name: str + :ivar native_name: Display name of the language in the locale native for this language. + Required. + :vartype native_name: str + :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for + left-to-right languages. Required. Known values are: "ltr" and "rtl". + :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + """ + + name: str = rest_field() + """Display name of the language in the locale requested via Accept-Language header. Required.""" + native_name: str = rest_field(name="nativeName") + """Display name of the language in the locale native for this language. Required.""" + directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. + Required. Known values are: \"ltr\" and \"rtl\".""" + + @overload + def __init__( + self, + *, + name: str, + native_name: str, + directionality: Union[str, "_models.LanguageDirectionality"], + ): ... + + @overload + def __init__(self, mapping: Mapping[str, Any]): + """ + :param mapping: raw JSON to initialize the model. + :type mapping: Mapping[str, Any] + """ + + def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useless-super-delegation + super().__init__(*args, **kwargs) + + +class TranslationText(_model_base.Model): """Translation result. All required parameters must be populated in order to send to server. @@ -960,8 +988,8 @@ class Translation(_model_base.Model): :vartype transliteration: ~azure.ai.translation.text.models.TransliteratedText :ivar alignment: Alignment information. :vartype alignment: ~azure.ai.translation.text.models.TranslatedTextAlignment - :ivar sent_len: Sentence boundaries in the input and output texts. - :vartype sent_len: ~azure.ai.translation.text.models.SentenceLength + :ivar sentence_boundaries: Sentence boundaries in the input and output texts. + :vartype sentence_boundaries: ~azure.ai.translation.text.models.SentenceBoundaries """ to: str = rest_field() @@ -972,7 +1000,7 @@ class Translation(_model_base.Model): """An object giving the translated text in the script specified by the toScript parameter.""" alignment: Optional["_models.TranslatedTextAlignment"] = rest_field() """Alignment information.""" - sent_len: Optional["_models.SentenceLength"] = rest_field(name="sentLen") + sentence_boundaries: Optional["_models.SentenceBoundaries"] = rest_field(name="sentLen") """Sentence boundaries in the input and output texts.""" @overload @@ -983,56 +1011,8 @@ def __init__( text: str, transliteration: Optional["_models.TransliteratedText"] = None, alignment: Optional["_models.TranslatedTextAlignment"] = None, - sent_len: Optional["_models.SentenceLength"] = None, - ): - ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): - """ - :param mapping: raw JSON to initialize the model. - :type mapping: Mapping[str, Any] - """ - - def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useless-super-delegation - super().__init__(*args, **kwargs) - - -class TranslationLanguage(_model_base.Model): - """The value of the translation property is a dictionary of (key, value) pairs. Each key is a BCP - 47 language tag. - A key identifies a language for which text can be translated to or translated from. - - All required parameters must be populated in order to send to server. - - :ivar name: Display name of the language in the locale requested via Accept-Language header. - Required. - :vartype name: str - :ivar native_name: Display name of the language in the locale native for this language. - Required. - :vartype native_name: str - :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right - languages. Required. - :vartype dir: str - """ - - name: str = rest_field() - """Display name of the language in the locale requested via Accept-Language header. Required.""" - native_name: str = rest_field(name="nativeName") - """Display name of the language in the locale native for this language. Required.""" - dir: str = rest_field() - """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. - Required.""" - - @overload - def __init__( - self, - *, - name: str, - native_name: str, - dir: str, - ): - ... + sentence_boundaries: Optional["_models.SentenceBoundaries"] = None, + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -1045,7 +1025,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useles super().__init__(*args, **kwargs) -class TransliterableScript(CommonScriptModel): +class TransliterableScript(LanguageScript): """Script definition with list of script into which given script can be translitered. All required parameters must be populated in order to send to server. @@ -1058,14 +1038,14 @@ class TransliterableScript(CommonScriptModel): :ivar native_name: Display name of the language in the locale native for the language. Required. :vartype native_name: str - :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right - languages. Required. - :vartype dir: str + :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for + left-to-right languages. Required. Known values are: "ltr" and "rtl". + :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality :ivar to_scripts: List of scripts available to convert text to. Required. - :vartype to_scripts: list[~azure.ai.translation.text.models.CommonScriptModel] + :vartype to_scripts: list[~azure.ai.translation.text.models.LanguageScript] """ - to_scripts: List["_models.CommonScriptModel"] = rest_field(name="toScripts") + to_scripts: List["_models.LanguageScript"] = rest_field(name="toScripts") """List of scripts available to convert text to. Required.""" @overload @@ -1075,10 +1055,9 @@ def __init__( code: str, name: str, native_name: str, - dir: str, - to_scripts: List["_models.CommonScriptModel"], - ): - ... + directionality: Union[str, "_models.LanguageDirectionality"], + to_scripts: List["_models.LanguageScript"], + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -1114,8 +1093,7 @@ def __init__( *, text: str, script: str, - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): @@ -1160,8 +1138,7 @@ def __init__( name: str, native_name: str, scripts: List["_models.TransliterableScript"], - ): - ... + ): ... @overload def __init__(self, mapping: Mapping[str, Any]): diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 6d1482b726bb..8288e2b58e5a 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -66,7 +66,7 @@ This will return language metadata from all supported scopes. ```python try: - response = text_translator.get_languages() + response = text_translator.get_supported_languages() print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -111,7 +111,7 @@ You can limit the scope of the response of the languages API by providing the op ```python try: scope = "translation" - response = text_translator.get_languages(scope=scope) + response = text_translator.get_supported_languages(scope=scope) print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -157,7 +157,7 @@ Names are provided in the English language when a target language is not specifi ```python try: accept_language = "es" - response = text_translator.get_languages(accept_language=accept_language) + response = text_translator.get_supported_languages(accept_language=accept_language) print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -208,7 +208,7 @@ try: input_text_elements = ["This is a test"] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -247,7 +247,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -269,18 +269,18 @@ You can combine both Translation and Transliteration in one Translate call. Your ```python try: - from_script = "Latn" + source_language_script = "Latn" from_language = "ar" - to_script = "Latn" + target_language_script = "Latn" target_languages = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = text_translator.translate( request_body=input_text_elements, to=target_languages, - from_script=from_script, - from_parameter=from_language, - to_script=to_script, + source_language_script=source_language_script, + source_language=from_language, + target_language_script=target_language_script, ) translation = response[0] if response else None @@ -322,7 +322,7 @@ try: for translation in translations: print( - f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.score if translation.detected_language else None}." + f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.confidence if translation.detected_language else None}." ) print( f"Text was translated to: '{translation.translations[0].to if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." @@ -354,7 +354,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -386,7 +386,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -415,7 +415,7 @@ try: ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language, text_type=text_type + request_body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -448,7 +448,7 @@ try: ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -491,7 +491,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -525,7 +525,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -561,13 +561,15 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sent_len: - print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") - print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") + if translated_text.lengths_of_sentences: + print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + print( + f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + ) except HttpResponseError as exception: if exception.error is not None: @@ -600,7 +602,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -624,12 +626,12 @@ Converts characters or letters of a source language to the corresponding charact ```python try: language = "zh-Hans" - from_script = "Hans" - to_script = "Latn" + source_language_script = "Hans" + target_language_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, from_script=from_script, to_script=to_script + request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script ) transliteration = response[0] if response else None @@ -670,10 +672,10 @@ try: detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sent_len: + for boundary in sentence_boundaries.lengths_of_sentences: print(boundary) except HttpResponseError as exception: @@ -702,10 +704,10 @@ try: detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sent_len: + for boundary in sentence_boundaries.lengths_of_sentences: print(boundary) except HttpResponseError as exception: @@ -731,7 +733,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None @@ -763,7 +765,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, from_parameter=source_language, to=target_language + content=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py index 8e89ebaaa544..1233d6092f2d 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py @@ -50,10 +50,10 @@ def get_text_sentence_boundaries(): detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sent_len: + for boundary in sentence_boundaries.lengths_of_sentences: print(boundary) except HttpResponseError as exception: @@ -76,10 +76,10 @@ def get_text_sentence_boundaries_auto(): detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sent_len: + for boundary in sentence_boundaries.lengths_of_sentences: print(boundary) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py index 121c71f2eba7..9983652e60a5 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py @@ -26,6 +26,7 @@ import os + # ------------------------------------------------------------------------- # Text translation client # ------------------------------------------------------------------------- diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py index bc86ce8105fc..3d4e554b7257 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py @@ -33,6 +33,7 @@ text_translator = sample_text_translation_client.create_text_translation_client_with_credential() + # ------------------------------------------------------------------------- # Dictionary Lookup # ------------------------------------------------------------------------- @@ -44,7 +45,7 @@ def get_text_translation_dictionary_examples(): input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, from_parameter=source_language, to=target_language + content=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py index c517ab630184..19da46c28f8d 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py @@ -33,6 +33,7 @@ text_translator = sample_text_translation_client.create_text_translation_client_with_credential() + # ------------------------------------------------------------------------- # Dictionary Lookup # ------------------------------------------------------------------------- @@ -44,7 +45,7 @@ def get_text_translation_dictionary_lookup(): input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_languages.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_languages.py index 6ab53599ec69..66f3cb8c0ee1 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_languages.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_languages.py @@ -32,13 +32,14 @@ text_translator = sample_text_translation_client.create_text_translation_client_with_endpoint() + # ------------------------------------------------------------------------- # Get text translation languages # ------------------------------------------------------------------------- def get_text_translation_languages(): # [START get_text_translation_languages] try: - response = text_translator.get_languages() + response = text_translator.get_supported_languages() print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -77,7 +78,7 @@ def get_text_translation_languages_scope(): # [START get_text_translation_languages_scope] try: scope = "translation" - response = text_translator.get_languages(scope=scope) + response = text_translator.get_supported_languages(scope=scope) print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" @@ -116,7 +117,7 @@ def get_text_translation_languages_culture(): # [START get_text_translation_languages_culture] try: accept_language = "es" - response = text_translator.get_languages(accept_language=accept_language) + response = text_translator.get_supported_languages(accept_language=accept_language) print( f"Number of supported languages for translate operation: {len(response.translation) if response.translation is not None else 0}" diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index f3020bfea3af..e09ef0a9148e 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -34,6 +34,7 @@ text_translator = sample_text_translation_client.create_text_translation_client_with_credential() + # ------------------------------------------------------------------------- # Get text translation # ------------------------------------------------------------------------- @@ -45,7 +46,7 @@ def get_text_translation(): input_text_elements = ["This is a test"] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -74,7 +75,7 @@ def get_text_translation_auto(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -90,18 +91,18 @@ def get_text_translation_auto(): def get_text_translation_with_transliteration(): # [START get_text_translation_with_transliteration] try: - from_script = "Latn" + source_language_script = "Latn" from_language = "ar" - to_script = "Latn" + target_language_script = "Latn" target_languages = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = text_translator.translate( request_body=input_text_elements, to=target_languages, - from_script=from_script, - from_parameter=from_language, - to_script=to_script, + source_language_script=source_language_script, + source_language=from_language, + target_language_script=target_language_script, ) translation = response[0] if response else None @@ -137,7 +138,7 @@ def get_text_translation_multiple_inputs(): for translation in translations: print( - f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.score if translation.detected_language else None}." + f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.confidence if translation.detected_language else None}." ) print( f"Text was translated to: '{translation.translations[0].to if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." @@ -163,7 +164,7 @@ def get_text_translation_multiple_languages(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -189,7 +190,7 @@ def get_text_translation_type(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -212,7 +213,7 @@ def get_text_translation_exclude(): ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language, text_type=text_type + request_body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -237,7 +238,7 @@ def get_text_translation_entity(): ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -272,7 +273,7 @@ def get_text_translation_profanity(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -300,7 +301,7 @@ def get_text_translation_alignment(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -330,13 +331,15 @@ def get_text_translation_sentence_length(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sent_len: - print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") - print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") + if translated_text.lengths_of_sentences: + print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + print( + f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + ) except HttpResponseError as exception: if exception.error is not None: @@ -359,7 +362,7 @@ def get_text_translation_custom(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py index 50170ced1f83..284c75695c20 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py @@ -33,6 +33,7 @@ text_translator = sample_text_translation_client.create_text_translation_client_with_credential() + # ------------------------------------------------------------------------- # Text translation transliteration # ------------------------------------------------------------------------- @@ -40,12 +41,12 @@ def get_text_transliteration(): # [START get_text_transliteration] try: language = "zh-Hans" - from_script = "Hans" - to_script = "Latn" + source_language_script = "Hans" + target_language_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, from_script=from_script, to_script=to_script + request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script ) transliteration = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/tests/preparer.py b/sdk/translation/azure-ai-translation-text/tests/preparer.py index 416e545b0207..01e6f4e4d1b8 100644 --- a/sdk/translation/azure-ai-translation-text/tests/preparer.py +++ b/sdk/translation/azure-ai-translation-text/tests/preparer.py @@ -16,5 +16,5 @@ text_translation_aadClientId="fakeAADClientId", text_translation_aadTenantId="fakeAADTenantId", text_translation_aadSecret="fakeAADSecret", - text_translation_aadResourceId="fakeResourceId" + text_translation_aadResourceId="fakeResourceId", ) diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py index 24c869d7cbdb..616353bc1b19 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py @@ -21,8 +21,8 @@ def test_autodetect(self, **kwargs): response = client.find_sentence_boundaries(request_body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" - assert response[0].detected_language.score > 0.9 - assert response[0].sent_len[0] == 11 + assert response[0].detected_language.confidence > 0.9 + assert response[0].lengths_of_sentences[0] == 11 @TextTranslationPreparer() @recorded_by_proxy @@ -40,7 +40,7 @@ def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].sent_len[i] + assert expected_length == response[0].lengths_of_sentences[i] @TextTranslationPreparer() @recorded_by_proxy @@ -54,7 +54,7 @@ def test_with_language_script(self, **kwargs): response = client.find_sentence_boundaries(request_body=input_text_elements, language="zh-Hans", script="Latn") assert response is not None - assert response[0].sent_len[0] == 18 + assert response[0].lengths_of_sentences[0] == 18 @TextTranslationPreparer() @recorded_by_proxy @@ -73,5 +73,5 @@ def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].sent_len[0] == 11 - assert response[1].sent_len[0] == 32 + assert response[0].lengths_of_sentences[0] == 11 + assert response[1].lengths_of_sentences[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py index d04f64279a46..3f47a07c7f95 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py @@ -22,8 +22,8 @@ async def test_autodetect(self, **kwargs): response = await client.find_sentence_boundaries(request_body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" - assert response[0].detected_language.score > 0.9 - assert response[0].sent_len[0] == 11 + assert response[0].detected_language.confidence > 0.9 + assert response[0].lengths_of_sentences[0] == 11 @TextTranslationPreparer() @recorded_by_proxy_async @@ -42,7 +42,7 @@ async def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].sent_len[i] + assert expected_length == response[0].lengths_of_sentences[i] @TextTranslationPreparer() @recorded_by_proxy_async @@ -59,7 +59,7 @@ async def test_with_language_script(self, **kwargs): request_body=input_text_elements, language="zh-Hans", script="Latn" ) assert response is not None - assert response[0].sent_len[0] == 18 + assert response[0].lengths_of_sentences[0] == 18 @TextTranslationPreparer() @recorded_by_proxy_async @@ -79,5 +79,5 @@ async def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].sent_len[0] == 11 - assert response[1].sent_len[0] == 32 + assert response[0].lengths_of_sentences[0] == 11 + assert response[1].lengths_of_sentences[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py index 1d90e09fb667..0ed0801b81a4 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py @@ -23,7 +23,7 @@ def test_single_input_element(self, **kwargs): input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = client.lookup_dictionary_examples( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -45,7 +45,7 @@ def test_multiple_input_elements(self, **kwargs): ] response = client.lookup_dictionary_examples( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py index 7a1a05760d7f..845e31e843ed 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py @@ -24,7 +24,7 @@ async def test_single_input_element(self, **kwargs): async with client: response = await client.lookup_dictionary_examples( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -47,7 +47,7 @@ async def test_multiple_input_elements(self, **kwargs): async with client: response = await client.lookup_dictionary_examples( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py index 13bf74f5fcc3..0fea3cf99cd5 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py @@ -22,7 +22,7 @@ def test_single_input_element(self, **kwargs): input_text_elements = ["fly"] response = client.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -41,7 +41,7 @@ def test_multiple_input_elements(self, **kwargs): input_text_elements = ["fly", "fox"] response = client.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py index 88a899033c33..8614d3066f45 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py @@ -23,7 +23,7 @@ async def test_single_input_element(self, **kwargs): async with client: response = await client.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -43,7 +43,7 @@ async def test_multiple_input_elements(self, **kwargs): async with client: response = await client.lookup_dictionary_entries( - request_body=input_text_elements, from_parameter=source_language, to=target_language + request_body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py index 72a6436744dd..bbff3859a38d 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py @@ -14,7 +14,7 @@ class TestGetLanguages(TextTranslationTest): def test_all_scopes(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages() + response = client.get_supported_languages() assert len(response.translation) > 0 assert len(response.transliteration) > 0 @@ -25,11 +25,11 @@ def test_all_scopes(self, **kwargs): def test_translation_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(scope="translation") + response = client.get_supported_languages(scope="translation") assert len(response.translation) > 0 translations = response.translation["af"] - assert translations.dir is not None + assert translations.directionality is not None assert translations.name is not None assert translations.native_name is not None @@ -38,7 +38,7 @@ def test_translation_scope(self, **kwargs): def test_transliteration_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(scope="transliteration") + response = client.get_supported_languages(scope="transliteration") assert len(response.transliteration) > 0 transliterations = response.transliteration["be"] @@ -50,21 +50,21 @@ def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].name is not None assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None - assert transliterations.scripts[0].dir is not None + assert transliterations.scripts[0].directionality is not None assert transliterations.scripts[0].to_scripts is not None assert len(transliterations.scripts[0].to_scripts) > 0 assert transliterations.scripts[0].to_scripts[0].name is not None assert transliterations.scripts[0].to_scripts[0].native_name is not None assert transliterations.scripts[0].to_scripts[0].code is not None - assert transliterations.scripts[0].to_scripts[0].dir is not None + assert transliterations.scripts[0].to_scripts[0].directionality is not None @TextTranslationPreparer() @recorded_by_proxy def test_transliteration_multiple_scripts(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(scope="transliteration") + response = client.get_supported_languages(scope="transliteration") assert len(response.transliteration) > 0 transliterations = response.transliteration["zh-Hant"] @@ -81,7 +81,7 @@ def test_transliteration_multiple_scripts(self, **kwargs): def test_dictionary_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(scope="dictionary") + response = client.get_supported_languages(scope="dictionary") assert len(response.dictionary) > 0 dictionaries = response.dictionary["de"] @@ -90,7 +90,7 @@ def test_dictionary_scope(self, **kwargs): assert len(dictionaries.translations) > 0 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].dir is not None + assert dictionaries.translations[0].directionality is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -99,7 +99,7 @@ def test_dictionary_scope(self, **kwargs): def test_dictionary_multiple_translations(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(scope="dictionary") + response = client.get_supported_languages(scope="dictionary") assert len(response.dictionary) > 0 dictionaries = response.dictionary["en"] @@ -108,7 +108,7 @@ def test_dictionary_multiple_translations(self, **kwargs): assert len(dictionaries.translations) > 1 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].dir is not None + assert dictionaries.translations[0].directionality is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -117,12 +117,12 @@ def test_dictionary_multiple_translations(self, **kwargs): def test_with_culture(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_getlanguage_client(endpoint) - response = client.get_languages(accept_language="es") + response = client.get_supported_languages(accept_language="es") assert len(response.translation.items()) > 0 assert len(response.transliteration.items()) > 0 assert len(response.dictionary.items()) > 0 translations = response.translation["en"] - assert translations.dir is not None + assert translations.directionality is not None assert translations.name is not None assert translations.native_name is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py index 2bea4c6b2b5c..93afeab796a5 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py @@ -15,7 +15,7 @@ async def test_all_scopes(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages() + response = await client.get_supported_languages() assert len(response.translation) > 0 assert len(response.transliteration) > 0 @@ -27,11 +27,11 @@ async def test_translation_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(scope="translation") + response = await client.get_supported_languages(scope="translation") assert len(response.translation) > 0 translations = response.translation["af"] - assert translations.dir is not None + assert translations.directionality is not None assert translations.name is not None assert translations.native_name is not None @@ -41,7 +41,7 @@ async def test_transliteration_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(scope="transliteration") + response = await client.get_supported_languages(scope="transliteration") assert len(response.transliteration) > 0 transliterations = response.transliteration["be"] @@ -53,14 +53,14 @@ async def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].name is not None assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None - assert transliterations.scripts[0].dir is not None + assert transliterations.scripts[0].directionality is not None assert transliterations.scripts[0].to_scripts is not None assert len(transliterations.scripts[0].to_scripts) > 0 assert transliterations.scripts[0].to_scripts[0].name is not None assert transliterations.scripts[0].to_scripts[0].native_name is not None assert transliterations.scripts[0].to_scripts[0].code is not None - assert transliterations.scripts[0].to_scripts[0].dir is not None + assert transliterations.scripts[0].to_scripts[0].directionality is not None @TextTranslationPreparer() @recorded_by_proxy_async @@ -68,7 +68,7 @@ async def test_transliteration_multiple_scripts(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(scope="transliteration") + response = await client.get_supported_languages(scope="transliteration") assert len(response.transliteration) > 0 transliterations = response.transliteration["zh-Hant"] @@ -86,7 +86,7 @@ async def test_dictionary_scope(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(scope="dictionary") + response = await client.get_supported_languages(scope="dictionary") assert len(response.dictionary) > 0 dictionaries = response.dictionary["de"] @@ -95,7 +95,7 @@ async def test_dictionary_scope(self, **kwargs): assert len(dictionaries.translations) > 0 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].dir is not None + assert dictionaries.translations[0].directionality is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -105,7 +105,7 @@ async def test_dictionary_multiple_translations(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(scope="dictionary") + response = await client.get_supported_languages(scope="dictionary") assert len(response.dictionary) > 0 dictionaries = response.dictionary["en"] @@ -114,7 +114,7 @@ async def test_dictionary_multiple_translations(self, **kwargs): assert len(dictionaries.translations) > 1 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].dir is not None + assert dictionaries.translations[0].directionality is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -124,12 +124,12 @@ async def test_with_culture(self, **kwargs): endpoint = kwargs.get("text_translation_endpoint") client = self.create_async_getlanguage_client(endpoint) async with client: - response = await client.get_languages(accept_language="es") + response = await client.get_supported_languages(accept_language="es") assert len(response.translation.items()) > 0 assert len(response.transliteration.items()) > 0 assert len(response.dictionary.items()) > 0 translations = response.translation["en"] - assert translations.dir is not None + assert translations.directionality is not None assert translations.name is not None assert translations.native_name is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation.py b/sdk/translation/azure-ai-translation-text/tests/test_translation.py index ff669ae85f9d..80884555f3bc 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation.py @@ -23,7 +23,7 @@ def test_translate(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -41,12 +41,12 @@ def test_autodetect(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, to=target_languages) + response = client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @@ -63,8 +63,8 @@ def test_no_translate_tag(self, **kwargs): input_text_elements = ["今天是怎么回事是非常可怕的"] response = client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, + target_languages=target_languages, + source_language=source_language, text_type=TextType.HTML, ) @@ -86,7 +86,7 @@ def test_dictionary_tag(self, **kwargs): 'The word < mstrans:dictionary translation ="wordomatic">wordomatic is a dictionary entry.' ] response = client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -107,10 +107,10 @@ def test_transliteration(self, **kwargs): input_text_elements = ["hudha akhtabar."] response = client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, - from_script="Latn", - to_script="Latn", + target_languages=target_languages, + source_language=source_language, + source_language_script="Latn", + target_language_script="Latn", ) assert len(response) == 1 @@ -132,10 +132,10 @@ def test_from_to_latin(self, **kwargs): input_text_elements = ["ap kaise ho"] response = client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, - from_script="Latn", - to_script="Latn", + target_languages=target_languages, + source_language=source_language, + source_language_script="Latn", + target_language_script="Latn", ) assert len(response) == 1 @@ -157,15 +157,15 @@ def test_multiple_input(self, **kwargs): "Esto es una prueba.", "Dies ist ein Test.", ] - response = client.translate(request_body=input_text_elements, to=target_languages) + response = client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 3 assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "es" assert response[2].detected_language.language == "de" - assert response[0].detected_language.score == 1 - assert response[1].detected_language.score == 1 - assert response[2].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 + assert response[1].detected_language.confidence == 1 + assert response[2].detected_language.confidence == 1 assert response[0].translations[0].text is not None assert response[1].translations[0].text is not None @@ -181,12 +181,12 @@ def test_multiple_target_languages(self, **kwargs): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, to=target_languages) + response = client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 3 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert response[0].translations[0].text is not None assert response[0].translations[1].text is not None assert response[0].translations[2].text is not None @@ -201,12 +201,14 @@ def test_different_texttypes(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, to=target_languages, text_type=TextType.HTML) + response = client.translate( + request_body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML + ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @TextTranslationPreparer() @recorded_by_proxy @@ -220,7 +222,7 @@ def test_profanity(self, **kwargs): input_text_elements = ["shit this is fucking crazy"] response = client.translate( request_body=input_text_elements, - to=target_languages, + target_languages=target_languages, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, ) @@ -228,7 +230,7 @@ def test_profanity(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert "***" in response[0].translations[0].text @TextTranslationPreparer() @@ -241,13 +243,15 @@ def test_alignment(self, **kwargs): target_languages = ["cs"] input_text_elements = ["It is a beautiful morning"] - response = client.translate(request_body=input_text_elements, to=target_languages, include_alignment=True) + response = client.translate( + request_body=input_text_elements, target_languages=target_languages, include_alignment=True + ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 - assert response[0].translations[0].alignment.proj is not None + assert response[0].detected_language.confidence == 1 + assert response[0].translations[0].alignment.projections is not None @TextTranslationPreparer() @recorded_by_proxy @@ -261,14 +265,16 @@ def test_sentence_length(self, **kwargs): input_text_elements = [ "La réponse se trouve dans la traduction automatique. La meilleure technologie de traduction automatique ne peut pas toujours fournir des traductions adaptées à un site ou des utilisateurs comme un être humain. Il suffit de copier et coller un extrait de code n'importe où." ] - response = client.translate(request_body=input_text_elements, to=target_languages, include_sentence_length=True) + response = client.translate( + request_body=input_text_elements, target_languages=target_languages, include_sentence_length=True + ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "fr" - assert response[0].detected_language.score == 1 - assert len(response[0].translations[0].sent_len.src_sent_len) == 3 - assert len(response[0].translations[0].sent_len.trans_sent_len) == 3 + assert response[0].detected_language.confidence == 1 + assert len(response[0].translations[0].sentence_boundaries.source_sentences_lengths) == 3 + assert len(response[0].translations[0].sentence_boundaries.translated_sentences_lengths) == 3 @TextTranslationPreparer() @recorded_by_proxy @@ -280,12 +286,12 @@ def test_custom_endpoint(self, **kwargs): target_languages = ["fr"] input_text_elements = ["It is a beautiful morning"] - response = client.translate(request_body=input_text_elements, to=target_languages) + response = client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -298,12 +304,12 @@ def test_token(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, to=target_languages) + response = client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -318,7 +324,7 @@ def test_translate_aad(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py index b5f33bf04426..9eb899470d3f 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py @@ -25,7 +25,7 @@ async def test_translate(self, **kwargs): input_text_elements = ["Hola mundo"] async with client: response = await client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -44,12 +44,12 @@ async def test_autodetect(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, to=target_languages) + response = await client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @@ -67,8 +67,8 @@ async def test_no_translate_tag(self, **kwargs): async with client: response = await client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, + target_languages=target_languages, + source_language=source_language, text_type=TextType.HTML, ) @@ -91,7 +91,7 @@ async def test_dictionary_tag(self, **kwargs): ] async with client: response = await client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -113,10 +113,10 @@ async def test_transliteration(self, **kwargs): async with client: response = await client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, - from_script="Latn", - to_script="Latn", + target_languages=target_languages, + source_language=source_language, + source_language_script="Latn", + target_language_script="Latn", ) assert len(response) == 1 @@ -139,10 +139,10 @@ async def test_from_to_latin(self, **kwargs): async with client: response = await client.translate( request_body=input_text_elements, - to=target_languages, - from_parameter=source_language, - from_script="Latn", - to_script="Latn", + target_languages=target_languages, + source_language=source_language, + source_language_script="Latn", + target_language_script="Latn", ) assert len(response) == 1 @@ -165,15 +165,15 @@ async def test_multiple_input(self, **kwargs): "Dies ist ein Test.", ] async with client: - response = await client.translate(request_body=input_text_elements, to=target_languages) + response = await client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 3 assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "es" assert response[2].detected_language.language == "de" - assert response[0].detected_language.score == 1 - assert response[1].detected_language.score == 1 - assert response[2].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 + assert response[1].detected_language.confidence == 1 + assert response[2].detected_language.confidence == 1 assert response[0].translations[0].text is not None assert response[1].translations[0].text is not None @@ -190,12 +190,12 @@ async def test_multiple_target_languages(self, **kwargs): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, to=target_languages) + response = await client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 3 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert response[0].translations[0].text is not None assert response[0].translations[1].text is not None assert response[0].translations[2].text is not None @@ -212,13 +212,13 @@ async def test_different_texttypes(self, **kwargs): input_text_elements = ["This is a test."] async with client: response = await client.translate( - request_body=input_text_elements, to=target_languages, text_type=TextType.HTML + request_body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @TextTranslationPreparer() @recorded_by_proxy_async @@ -233,7 +233,7 @@ async def test_profanity(self, **kwargs): async with client: response = await client.translate( request_body=input_text_elements, - to=target_languages, + target_languages=target_languages, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, ) @@ -241,7 +241,7 @@ async def test_profanity(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 assert "***" in response[0].translations[0].text @TextTranslationPreparer() @@ -256,14 +256,14 @@ async def test_alignment(self, **kwargs): input_text_elements = ["It is a beautiful morning"] async with client: response = await client.translate( - request_body=input_text_elements, to=target_languages, include_alignment=True + request_body=input_text_elements, target_languages=target_languages, include_alignment=True ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 - assert response[0].translations[0].alignment.proj is not None + assert response[0].detected_language.confidence == 1 + assert response[0].translations[0].alignment.projections is not None @TextTranslationPreparer() @recorded_by_proxy_async @@ -279,15 +279,15 @@ async def test_sentence_length(self, **kwargs): ] async with client: response = await client.translate( - request_body=input_text_elements, to=target_languages, include_sentence_length=True + request_body=input_text_elements, target_languages=target_languages, include_sentence_length=True ) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "fr" - assert response[0].detected_language.score == 1 - assert len(response[0].translations[0].sent_len.src_sent_len) == 3 - assert len(response[0].translations[0].sent_len.trans_sent_len) == 3 + assert response[0].detected_language.confidence == 1 + assert len(response[0].translations[0].sentence_boundaries.source_sentences_lengths) == 3 + assert len(response[0].translations[0].sentence_boundaries.translated_sentences_lengths) == 3 @TextTranslationPreparer() @recorded_by_proxy_async @@ -300,12 +300,12 @@ async def test_custom_endpoint(self, **kwargs): target_languages = ["fr"] input_text_elements = ["It is a beautiful morning"] async with client: - response = await client.translate(request_body=input_text_elements, to=target_languages) + response = await client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -319,12 +319,12 @@ async def test_token(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, to=target_languages) + response = await client.translate(request_body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.score == 1 + assert response[0].detected_language.confidence == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -339,7 +339,7 @@ async def test_translate_aad(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = await client.translate( - request_body=input_text_elements, to=target_languages, from_parameter=source_language + request_body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py index 4e90d55641de..00faacb1cd4e 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py @@ -20,7 +20,7 @@ def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] response = client.transliterate( - request_body=input_text_elements, language="zh-Hans", from_script="Hans", to_script="Latn" + request_body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn" ) assert response is not None @@ -36,7 +36,7 @@ def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] response = client.transliterate( - request_body=input_text_elements, language="hi", from_script="Deva", to_script="Latn" + request_body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn" ) assert response is not None @@ -57,7 +57,7 @@ def test_edit_distance(self, **kwargs): "hukkabar", ] response = client.transliterate( - request_body=input_text_elements, language="gu", from_script="Latn", to_script="Gujr" + request_body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr" ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py index f1dd54e252a2..adf8489ad095 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py @@ -21,7 +21,7 @@ async def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] async with client: response = await client.transliterate( - request_body=input_text_elements, language="zh-Hans", from_script="Hans", to_script="Latn" + request_body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn" ) assert response is not None @@ -38,7 +38,7 @@ async def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] async with client: response = await client.transliterate( - request_body=input_text_elements, language="hi", from_script="Deva", to_script="Latn" + request_body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn" ) assert response is not None @@ -60,7 +60,7 @@ async def test_edit_distance(self, **kwargs): ] async with client: response = await client.transliterate( - request_body=input_text_elements, language="gu", from_script="Latn", to_script="Gujr" + request_body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr" ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/testcase.py b/sdk/translation/azure-ai-translation-text/tests/testcase.py index 31f37bc828b1..3e99cfda3f08 100644 --- a/sdk/translation/azure-ai-translation-text/tests/testcase.py +++ b/sdk/translation/azure-ai-translation-text/tests/testcase.py @@ -11,6 +11,7 @@ from static_access_token_credential import StaticAccessTokenCredential + class TextTranslationTest(AzureRecordedTestCase): def create_getlanguage_client(self, endpoint): client = TextTranslationClient(endpoint=endpoint, credential=None) @@ -25,7 +26,7 @@ def create_client_token(self, endpoint, apikey, region): credential = StaticAccessTokenCredential(apikey, region) client = TextTranslationClient(endpoint=endpoint, credential=credential) return client - + def create_text_translation_client_with_aad(self, innerCredential, aadRegion, aadResourceId): credential = TranslatorAADCredential(innerCredential, aadResourceId, aadRegion) text_translator = TextTranslationClient(credential=credential) @@ -50,9 +51,13 @@ def create_async_client_token(self, endpoint, apikey, region): client = TextTranslationClientAsync(endpoint=endpoint, credential=credential) return client - + def create_async_text_translation_client_with_aad(self, innerCredential, aadRegion, aadResourceId): - from azure.ai.translation.text.aio import TextTranslationClient as TextTranslationClientAsync, AsyncTranslatorAADCredential + from azure.ai.translation.text.aio import ( + TextTranslationClient as TextTranslationClientAsync, + AsyncTranslatorAADCredential, + ) + credential = AsyncTranslatorAADCredential(innerCredential, aadResourceId, aadRegion) text_translator = TextTranslationClientAsync(credential=credential) return text_translator @@ -65,7 +70,6 @@ def get_mt_credential(self, is_async, **kwargs): if is_async: from azure.identity.aio import ClientSecretCredential - tenant_id = os.environ.get("AZURE_TENANT_ID", getattr(os.environ, "TENANT_ID", None)) client_id = os.environ.get("AZURE_CLIENT_ID", getattr(os.environ, "CLIENT_ID", None)) secret = os.environ.get("AZURE_CLIENT_SECRET", getattr(os.environ, "CLIENT_SECRET", None)) diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index 2870e7447ece..4c0e108be8c4 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 7b097c7e91a72a8930b94282274158b71e604695 -repo: Azure/azure-rest-api-specs +commit: dcf145204ca8ac0a8ac09995d1ec7acf9bed3edf +repo: MikeyMCZ/azure-rest-api-specs From dfe043657d227a1aa0c0a0f784e36b92b6bf83c9 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 3 May 2024 16:05:01 -0700 Subject: [PATCH 02/32] Using latest TypeSpec --- .../azure-ai-translation-text/README.md | 11 +++++++---- .../azure/ai/translation/text/models/_models.py | 8 ++++---- .../azure-ai-translation-text/samples/README.md | 15 +++++++++------ .../sample_text_translation_break_sentence.py | 4 ++-- .../samples/sample_text_translation_translate.py | 6 +++--- .../sample_text_translation_transliterate.py | 5 ++++- .../tests/test_break_sentence.py | 10 +++++----- .../tests/test_break_sentence_async.py | 10 +++++----- .../tests/test_transliteration.py | 15 ++++++++++++--- .../tests/test_transliteration_async.py | 15 ++++++++++++--- .../azure-ai-translation-text/tsp-location.yaml | 2 +- 11 files changed, 64 insertions(+), 37 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 639e8125cbfb..010e6de4093d 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -182,7 +182,10 @@ try: input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script + request_body=input_text_elements, + language=language, + source_language_script=source_language_script, + target_language_script=target_language_script, ) transliteration = response[0] if response else None @@ -228,10 +231,10 @@ try: ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.lengths_of_sentences: - print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + if translated_text.sentences_lengths: + print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py index d2278bded2a4..7378d83c2c2e 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py @@ -99,17 +99,17 @@ class BreakSentenceItem(_model_base.Model): :ivar detected_language: The detectedLanguage property is only present in the result object when language auto-detection is requested. :vartype detected_language: ~azure.ai.translation.text.models.DetectedLanguage - :ivar lengths_of_sentences: An integer array representing the lengths of the sentences in the + :ivar sentences_lengths: 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. Required. - :vartype lengths_of_sentences: list[int] + :vartype sentences_lengths: list[int] """ detected_language: Optional["_models.DetectedLanguage"] = rest_field(name="detectedLanguage") """The detectedLanguage property is only present in the result object when language auto-detection is requested.""" - lengths_of_sentences: List[int] = rest_field(name="sentLen") + sentences_lengths: List[int] = rest_field(name="sentLen") """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. Required.""" @@ -118,7 +118,7 @@ class BreakSentenceItem(_model_base.Model): def __init__( self, *, - lengths_of_sentences: List[int], + sentences_lengths: List[int], detected_language: Optional["_models.DetectedLanguage"] = None, ): ... diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 8288e2b58e5a..14335613b0e8 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -565,10 +565,10 @@ try: ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.lengths_of_sentences: - print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + if translated_text.sentences_lengths: + print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" ) except HttpResponseError as exception: @@ -631,7 +631,10 @@ try: input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script + request_body=input_text_elements, + language=language, + source_language_script=source_language_script, + target_language_script=target_language_script, ) transliteration = response[0] if response else None @@ -675,7 +678,7 @@ try: f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.lengths_of_sentences: + for boundary in sentence_boundaries.sentences_lengths: print(boundary) except HttpResponseError as exception: @@ -707,7 +710,7 @@ try: f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.lengths_of_sentences: + for boundary in sentence_boundaries.sentences_lengths: print(boundary) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py index 1233d6092f2d..f6f892d2a8ff 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py @@ -53,7 +53,7 @@ def get_text_sentence_boundaries(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.lengths_of_sentences: + for boundary in sentence_boundaries.sentences_lengths: print(boundary) except HttpResponseError as exception: @@ -79,7 +79,7 @@ def get_text_sentence_boundaries_auto(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.lengths_of_sentences: + for boundary in sentence_boundaries.sentences_lengths: print(boundary) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index e09ef0a9148e..a6961fcdc2fc 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -335,10 +335,10 @@ def get_text_translation_sentence_length(): ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.lengths_of_sentences: - print(f"Source Sentence length: {translated_text.lengths_of_sentences.src_lengths_of_sentences}") + if translated_text.sentences_lengths: + print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.lengths_of_sentences.trans_lengths_of_sentences}" + f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py index 284c75695c20..e08aa699c2c2 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py @@ -46,7 +46,10 @@ def get_text_transliteration(): input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script + request_body=input_text_elements, + language=language, + source_language_script=source_language_script, + target_language_script=target_language_script, ) transliteration = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py index 616353bc1b19..c9161392952b 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py @@ -22,7 +22,7 @@ def test_autodetect(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence > 0.9 - assert response[0].lengths_of_sentences[0] == 11 + assert response[0].sentences_lengths[0] == 11 @TextTranslationPreparer() @recorded_by_proxy @@ -40,7 +40,7 @@ def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].lengths_of_sentences[i] + assert expected_length == response[0].sentences_lengths[i] @TextTranslationPreparer() @recorded_by_proxy @@ -54,7 +54,7 @@ def test_with_language_script(self, **kwargs): response = client.find_sentence_boundaries(request_body=input_text_elements, language="zh-Hans", script="Latn") assert response is not None - assert response[0].lengths_of_sentences[0] == 18 + assert response[0].sentences_lengths[0] == 18 @TextTranslationPreparer() @recorded_by_proxy @@ -73,5 +73,5 @@ def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].lengths_of_sentences[0] == 11 - assert response[1].lengths_of_sentences[0] == 32 + assert response[0].sentences_lengths[0] == 11 + assert response[1].sentences_lengths[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py index 3f47a07c7f95..0270b54a2797 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py @@ -23,7 +23,7 @@ async def test_autodetect(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence > 0.9 - assert response[0].lengths_of_sentences[0] == 11 + assert response[0].sentences_lengths[0] == 11 @TextTranslationPreparer() @recorded_by_proxy_async @@ -42,7 +42,7 @@ async def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].lengths_of_sentences[i] + assert expected_length == response[0].sentences_lengths[i] @TextTranslationPreparer() @recorded_by_proxy_async @@ -59,7 +59,7 @@ async def test_with_language_script(self, **kwargs): request_body=input_text_elements, language="zh-Hans", script="Latn" ) assert response is not None - assert response[0].lengths_of_sentences[0] == 18 + assert response[0].sentences_lengths[0] == 18 @TextTranslationPreparer() @recorded_by_proxy_async @@ -79,5 +79,5 @@ async def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].lengths_of_sentences[0] == 11 - assert response[1].lengths_of_sentences[0] == 32 + assert response[0].sentences_lengths[0] == 11 + assert response[1].sentences_lengths[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py index 00faacb1cd4e..6a21ac382369 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py @@ -20,7 +20,10 @@ def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] response = client.transliterate( - request_body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn" + request_body=input_text_elements, + language="zh-Hans", + source_language_script="Hans", + target_language_script="Latn", ) assert response is not None @@ -36,7 +39,10 @@ def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] response = client.transliterate( - request_body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn" + request_body=input_text_elements, + language="hi", + source_language_script="Deva", + target_language_script="Latn", ) assert response is not None @@ -57,7 +63,10 @@ def test_edit_distance(self, **kwargs): "hukkabar", ] response = client.transliterate( - request_body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr" + request_body=input_text_elements, + language="gu", + source_language_script="Latn", + target_language_script="Gujr", ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py index adf8489ad095..9c21395b9b0f 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py @@ -21,7 +21,10 @@ async def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] async with client: response = await client.transliterate( - request_body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn" + request_body=input_text_elements, + language="zh-Hans", + source_language_script="Hans", + target_language_script="Latn", ) assert response is not None @@ -38,7 +41,10 @@ async def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] async with client: response = await client.transliterate( - request_body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn" + request_body=input_text_elements, + language="hi", + source_language_script="Deva", + target_language_script="Latn", ) assert response is not None @@ -60,7 +66,10 @@ async def test_edit_distance(self, **kwargs): ] async with client: response = await client.transliterate( - request_body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr" + request_body=input_text_elements, + language="gu", + source_language_script="Latn", + target_language_script="Gujr", ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index 4c0e108be8c4..f41cd7cbf12d 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: dcf145204ca8ac0a8ac09995d1ec7acf9bed3edf +commit: fc277f3e8b299b84a8a39105353cdb5a5df4b890 repo: MikeyMCZ/azure-rest-api-specs From 5148ea246169feb1a16081b90671c9c698003e82 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 7 May 2024 09:27:35 -0700 Subject: [PATCH 03/32] Fixing PR comments --- sdk/translation/azure-ai-translation-text/README.md | 2 +- .../azure/ai/translation/text/_patch.py | 6 +++--- .../azure/ai/translation/text/_version.py | 2 +- .../azure/ai/translation/text/aio/_patch.py | 6 +++--- sdk/translation/azure-ai-translation-text/pyproject.toml | 8 ++++---- .../azure-ai-translation-text/samples/README.md | 2 +- .../samples/sample_text_translation_translate.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 010e6de4093d..24f930f9c7d2 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -234,7 +234,7 @@ try: if translated_text.sentences_lengths: print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" + f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 99a4493851e5..e71510f86752 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -87,11 +87,11 @@ def __init__(self, credential: TranslatorAADCredential, **kwargs: Any) -> None: super(TranslatorAADAuthenticationPolicy, self).__init__( credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs ) - self.translatorCredential = credential + self.translator_credential = credential def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resource_id - request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translatorCredential.region + request.http_request.headers["Ocp-Apim-ResourceId"] = self.translator_credential.resource_id + request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translator_credential.region super().on_request(request) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py index be71c81bd282..bbcd28b4aa67 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b1" +VERSION = "1.0.0b2" diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index af1f74b89d06..14025e4fd14d 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -56,11 +56,11 @@ def __init__(self, credential: AsyncTranslatorAADCredential, **kwargs: Any) -> N super(AsyncTranslatorAADAuthenticationPolicy, self).__init__( credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs ) - self.translatorCredential = credential + self.translator_credential = credential async def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translatorCredential.resource_id - request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translatorCredential.region + request.http_request.headers["Ocp-Apim-ResourceId"] = self.translator_credential.resource_id + request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translator_credential.region await super().on_request(request) diff --git a/sdk/translation/azure-ai-translation-text/pyproject.toml b/sdk/translation/azure-ai-translation-text/pyproject.toml index 51e3830e1f50..07364590ca6f 100644 --- a/sdk/translation/azure-ai-translation-text/pyproject.toml +++ b/sdk/translation/azure-ai-translation-text/pyproject.toml @@ -1,8 +1,8 @@ [tool.azure-sdk-build] -pylint = false -type_check_samples = false -verifytypes = false -pyright = false +pylint = true +type_check_samples = true +verifytypes = true +pyright = true strict_sphinx = true [tool.generate] diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 14335613b0e8..6994266d65dd 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -568,7 +568,7 @@ try: if translated_text.sentences_lengths: print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" + f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index a6961fcdc2fc..173fdd8cde4c 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -338,7 +338,7 @@ def get_text_translation_sentence_length(): if translated_text.sentences_lengths: print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.sentences_lengths.trans_sentences_lengths}" + f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" ) except HttpResponseError as exception: From 79f53c696ea90e59fbede2c5b7cb6f768f3cd07d Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 7 May 2024 12:16:51 -0700 Subject: [PATCH 04/32] Lint fixes --- .../azure/ai/translation/text/_operations/_operations.py | 1 + .../azure/ai/translation/text/_operations/_patch.py | 2 ++ .../azure/ai/translation/text/_patch.py | 4 +++- .../ai/translation/text/aio/_operations/_operations.py | 1 + .../azure/ai/translation/text/aio/_operations/_patch.py | 2 ++ .../azure/ai/translation/text/aio/_patch.py | 7 +++++-- 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py index 6e55fdf324ec..ee8cebc528da 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +# pylint: disable=R0914 from io import IOBase import json import sys diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index d39ffc0b7e73..0ec1abed3726 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -2,6 +2,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: disable=C0302 + """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index e71510f86752..508732d0a919 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -2,6 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: disable=C4717, C4722 from typing import Union, Optional, Any from azure.core.pipeline import PipelineRequest @@ -60,7 +61,8 @@ def on_request(self, request: PipelineRequest) -> None: class TranslatorAADCredential: """Credential for Translator Service when using AAD authentication. - :param token_credential: An object which can provide an access token for the Translator Resource, such as a credential from + :param token_credential: An object which can provide an access token for the Translator Resource, + such as a credential from :mod:`azure.identity` :type token_credential: ~azure.core.credentials.TokenCredential :param str resource_id: Azure Resource Id of the Translation Resource. diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py index b2caf25ce07c..6f6db4eb6afc 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +# pylint: disable=R0914 from io import IOBase import json import sys diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index c1d133f67cb6..cb132aaced61 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -2,6 +2,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: disable=C0302 + """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 14025e4fd14d..7bb199a702c0 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -2,6 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ +# pylint: disable=C4717, C4722 """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize @@ -29,7 +30,8 @@ def patch_sdk(): class AsyncTranslatorAADCredential: """Credential for Translator Service when using AAD authentication. - :param token_credential: An object which can provide an access token for the Translator Resource, such as a credential from + :param token_credential: An object which can provide an access token for the Translator Resource, + such as a credential from :mod:`azure.identity` :type token_credential: ~azure.core.credentials.TokenCredential :param str resource_id: Azure Resource Id of the Translation Resource. @@ -119,7 +121,8 @@ class TextTranslationClient(ServiceClientGenerated): https://api.cognitive.microsofttranslator.com). Required. :type endpoint: str :param credential: Credential used to authenticate with the Translator service - :type credential: Union[AzureKeyCredential , AsyncTokenCredential , TranslatorCredential, AsyncTranslatorAADCredential] + :type credential: Union[AzureKeyCredential , AsyncTokenCredential , TranslatorCredential, + AsyncTranslatorAADCredential] :keyword api_version: Default value is "3.0". Note that overriding this default value may result in unsupported behavior. :paramtype api_version: str From 735651a3d9dec64d0476208619989a4eafda1827 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 7 May 2024 16:53:28 -0700 Subject: [PATCH 05/32] Using the latest TypeSpec --- .../azure/ai/translation/text/models/_enums.py | 7 +++++++ .../azure-ai-translation-text/tsp-location.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py index 8ed1ec727def..693b4db76228 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py @@ -14,22 +14,29 @@ class LanguageDirectionality(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Language Directionality.""" LEFT_TO_RIGHT = "ltr" + """Language is written left to right.""" RIGHT_TO_LEFT = "rtl" + """Language is written right to left.""" class ProfanityAction(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Translator profanity actions.""" NO_ACTION = "NoAction" + """No Action is taken on profanity""" MARKED = "Marked" + """Profanity is marked.""" DELETED = "Deleted" + """Profanity is deteled from the translated text.""" class ProfanityMarker(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Translator profanity markers.""" ASTERISK = "Asterisk" + """Profanity is marked with asterisk.""" TAG = "Tag" + """Profanity is marked with the tags.""" class TextType(str, Enum, metaclass=CaseInsensitiveEnumMeta): diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index f41cd7cbf12d..f938c2399b22 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: fc277f3e8b299b84a8a39105353cdb5a5df4b890 +commit: 3af1f0b4582e775d1dfefe578781671fc599296f repo: MikeyMCZ/azure-rest-api-specs From 15323f4dd9d3531761320de6bcbc099cb050ee3b Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 13 May 2024 11:47:41 -0700 Subject: [PATCH 06/32] Fixing PR comments --- .../azure-ai-translation-text/CHANGELOG.md | 2 +- .../azure-ai-translation-text/README.md | 14 +- .../azure/ai/translation/text/__init__.py | 4 - .../text/_operations/_operations.py | 130 ++++++++--------- .../ai/translation/text/_operations/_patch.py | 128 ++++++++--------- .../azure/ai/translation/text/_patch.py | 134 ++++++++---------- .../azure/ai/translation/text/_version.py | 2 +- .../azure/ai/translation/text/aio/__init__.py | 2 - .../text/aio/_operations/_operations.py | 130 ++++++++--------- .../text/aio/_operations/_patch.py | 128 ++++++++--------- .../azure/ai/translation/text/aio/_patch.py | 113 ++++++++------- .../samples/README.md | 36 ++--- .../sample_text_translation_break_sentence.py | 4 +- .../samples/sample_text_translation_client.py | 7 +- ...mple_text_translation_dictionary_lookup.py | 2 +- .../sample_text_translation_translate.py | 24 ++-- .../sample_text_translation_transliterate.py | 2 +- .../tests/test_break_sentence.py | 8 +- .../tests/test_break_sentence_async.py | 8 +- .../tests/test_dictionary_examples.py | 4 +- .../tests/test_dictionary_examples_async.py | 4 +- .../tests/test_dictionary_lookup.py | 4 +- .../tests/test_dictionary_lookup_async.py | 4 +- .../tests/test_translation.py | 32 ++--- .../tests/test_translation_async.py | 30 ++-- .../tests/test_transliteration.py | 6 +- .../tests/test_transliteration_async.py | 6 +- .../tests/testcase.py | 25 ++-- 28 files changed, 484 insertions(+), 509 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index a1cfabc1ffbd..e30620591eeb 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -7,7 +7,7 @@ ### Breaking Changes - - All calls to the client using parameter 'content' have been changed to use parameter 'request_body'. + - All calls to the client using parameter 'content' have been changed to use parameter 'body'. - Users can call methods using just a string type instead of complex objects. ### Bugs Fixed diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 24f930f9c7d2..85a34d88653c 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -55,7 +55,7 @@ az cognitiveservices account keys list --resource-group ```python -credential = TranslatorCredential(apikey, region) -text_translator = TextTranslationClient(credential=credential, endpoint=endpoint) +credential = AzureKeyCredential(apikey) +text_translator = TextTranslationClient(credential=credential, endpoint=endpoint, region=region) ``` @@ -143,7 +143,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -182,7 +182,7 @@ try: input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, + body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -219,7 +219,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -262,7 +262,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py index b1abb04c1ba4..4b66a9e2dde2 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py @@ -12,13 +12,9 @@ __version__ = VERSION -from ._patch import TranslatorCredential -from ._patch import TranslatorAADCredential from ._patch import patch_sdk as _patch_sdk __all__ = [ - "TranslatorCredential", - "TranslatorAADCredential", "TextTranslationClient", ] diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py index ee8cebc528da..4f73ca2758a0 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py @@ -463,7 +463,7 @@ def get_supported_languages( @overload def translate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -486,8 +486,8 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -572,7 +572,7 @@ def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -640,7 +640,7 @@ def translate( @overload def translate( self, - request_body: IO[bytes], + body: IO[bytes], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -663,8 +663,8 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -810,7 +810,7 @@ def translate( @distributed_trace def translate( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -832,9 +832,9 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -989,10 +989,10 @@ def translate( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( target_languages=target_languages, @@ -1051,7 +1051,7 @@ def translate( @overload def transliterate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, language: str, source_language_script: str, @@ -1064,8 +1064,8 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -1092,7 +1092,7 @@ def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1112,7 +1112,7 @@ def transliterate( @overload def transliterate( self, - request_body: IO[bytes], + body: IO[bytes], *, language: str, source_language_script: str, @@ -1125,8 +1125,8 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -1166,7 +1166,7 @@ def transliterate( @distributed_trace def transliterate( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, source_language_script: str, @@ -1178,9 +1178,9 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -1229,10 +1229,10 @@ def transliterate( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_transliterate_request( language=language, @@ -1280,7 +1280,7 @@ def transliterate( @overload def find_sentence_boundaries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1293,8 +1293,8 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1317,7 +1317,7 @@ def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1345,7 +1345,7 @@ def find_sentence_boundaries( @overload def find_sentence_boundaries( self, - request_body: IO[bytes], + body: IO[bytes], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1358,8 +1358,8 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1403,7 +1403,7 @@ def find_sentence_boundaries( @distributed_trace def find_sentence_boundaries( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1415,9 +1415,9 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1470,10 +1470,10 @@ def find_sentence_boundaries( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_find_sentence_boundaries_request( client_trace_id=client_trace_id, @@ -1520,7 +1520,7 @@ def find_sentence_boundaries( @overload def lookup_dictionary_entries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, source_language: str, target_language: str, @@ -1533,8 +1533,8 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1557,7 +1557,7 @@ def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1635,7 +1635,7 @@ def lookup_dictionary_entries( @overload def lookup_dictionary_entries( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -1648,8 +1648,8 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1743,7 +1743,7 @@ def lookup_dictionary_entries( @distributed_trace def lookup_dictionary_entries( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -1755,9 +1755,9 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1860,10 +1860,10 @@ def lookup_dictionary_entries( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( source_language=source_language, @@ -1910,7 +1910,7 @@ def lookup_dictionary_entries( @overload def lookup_dictionary_examples( self, - request_body: List[_models.DictionaryExampleTextItem], + body: List[_models.DictionaryExampleTextItem], *, source_language: str, target_language: str, @@ -1923,8 +1923,8 @@ def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1947,7 +1947,7 @@ def lookup_dictionary_examples( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str", # Text to translate. Required. "translation": "str" # A string specifying the translated text @@ -1997,7 +1997,7 @@ def lookup_dictionary_examples( @overload def lookup_dictionary_examples( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -2010,8 +2010,8 @@ def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -2072,7 +2072,7 @@ def lookup_dictionary_examples( @distributed_trace def lookup_dictionary_examples( self, - request_body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], + body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -2084,9 +2084,9 @@ def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Is either a + :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. @@ -2157,10 +2157,10 @@ def lookup_dictionary_examples( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( source_language=source_language, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index 0ec1abed3726..a3a3f462ff51 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -17,7 +17,7 @@ class TextTranslationClientOperationsMixin(TextTranslationClientOperationsMixinG @overload def translate( self, - request_body: List[str], + body: List[str], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -40,8 +40,8 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -125,7 +125,7 @@ def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ str" # Text to translate. Required. ] @@ -191,7 +191,7 @@ def translate( @overload def translate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -214,8 +214,8 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -299,7 +299,7 @@ def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -367,7 +367,7 @@ def translate( @overload def translate( self, - request_body: IO[bytes], + body: IO[bytes], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -390,8 +390,8 @@ def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -535,7 +535,7 @@ def translate( def translate( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -553,16 +553,16 @@ def translate( **kwargs: Any ) -> List[_models.TranslatedTextItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().translate( - request_body=body, + body=body, target_languages=target_languages, client_trace_id=client_trace_id, source_language=source_language, @@ -582,7 +582,7 @@ def translate( @overload def transliterate( self, - request_body: List[str], + body: List[str], *, language: str, source_language_script: str, @@ -595,8 +595,8 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -623,7 +623,7 @@ def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -643,7 +643,7 @@ def transliterate( @overload def transliterate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, language: str, source_language_script: str, @@ -656,8 +656,8 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -684,7 +684,7 @@ def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -704,7 +704,7 @@ def transliterate( @overload def transliterate( self, - request_body: IO[bytes], + body: IO[bytes], *, language: str, source_language_script: str, @@ -717,8 +717,8 @@ def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -757,7 +757,7 @@ def transliterate( def transliterate( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, source_language_script: str, @@ -766,16 +766,16 @@ def transliterate( **kwargs: Any ) -> List[_models.TransliteratedText]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().transliterate( - request_body=body, + body=body, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -786,7 +786,7 @@ def transliterate( @overload def find_sentence_boundaries( self, - request_body: List[str], + body: List[str], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -799,8 +799,8 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -823,7 +823,7 @@ def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -851,7 +851,7 @@ def find_sentence_boundaries( @overload def find_sentence_boundaries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -864,8 +864,8 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -888,7 +888,7 @@ def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -916,7 +916,7 @@ def find_sentence_boundaries( @overload def find_sentence_boundaries( self, - request_body: IO[bytes], + body: IO[bytes], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -929,8 +929,8 @@ def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -973,7 +973,7 @@ def find_sentence_boundaries( def find_sentence_boundaries( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -981,23 +981,23 @@ def find_sentence_boundaries( **kwargs: Any ) -> List[_models.BreakSentenceItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().find_sentence_boundaries( - request_body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs + body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs ) @overload def lookup_dictionary_entries( self, - request_body: List[str], + body: List[str], *, source_language: str, target_language: str, @@ -1010,8 +1010,8 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1034,7 +1034,7 @@ def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1112,7 +1112,7 @@ def lookup_dictionary_entries( @overload def lookup_dictionary_entries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, source_language: str, target_language: str, @@ -1125,8 +1125,8 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1149,7 +1149,7 @@ def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1227,7 +1227,7 @@ def lookup_dictionary_entries( @overload def lookup_dictionary_entries( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -1240,8 +1240,8 @@ def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1334,7 +1334,7 @@ def lookup_dictionary_entries( def lookup_dictionary_entries( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -1342,16 +1342,16 @@ def lookup_dictionary_entries( **kwargs: Any ) -> List[_models.DictionaryLookupItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().lookup_dictionary_entries( - request_body=body, + body=body, source_language=source_language, target_language=target_language, client_trace_id=client_trace_id, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 508732d0a919..cfb72717a2f2 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -4,7 +4,7 @@ # ------------------------------------ # pylint: disable=C4717, C4722 -from typing import Union, Optional, Any +from typing import Union, Optional, Any, overload from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import SansIOHTTPPolicy, BearerTokenCredentialPolicy, AzureKeyCredentialPolicy from azure.core.credentials import TokenCredential, AzureKeyCredential @@ -23,56 +23,19 @@ def patch_sdk(): """ -class TranslatorCredential: - """Credential for Translator Service. It is using combination of Resource key and region.""" - - def __init__(self, key: str, region: str) -> None: - self.key = key - self.region = region - - def update(self, key: str) -> None: - """Update the key. - This can be used when you've regenerated your service key and want - to update long-lived clients. - :param str key: The key used to authenticate to an Azure service - :raises: ValueError or TypeError - """ - if not key: - raise ValueError("The key used for updating can not be None or empty") - if not isinstance(key, str): - raise TypeError("The key used for updating must be a string.") - self.key = key - - class TranslatorAuthenticationPolicy(SansIOHTTPPolicy): """Translator Authentication Policy. Adds both authentication headers that are required. Ocp-Apim-Subscription-Region header contains region of the Translator resource. Ocp-Apim-Subscription-Key header contains API key of the Translator resource. """ - def __init__(self, credential: TranslatorCredential): + def __init__(self, credential: AzureKeyCredential, region: str): self.credential = credential + self.region = region def on_request(self, request: PipelineRequest) -> None: request.http_request.headers["Ocp-Apim-Subscription-Key"] = self.credential.key - request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.credential.region - - -class TranslatorAADCredential: - """Credential for Translator Service when using AAD authentication. - - :param token_credential: An object which can provide an access token for the Translator Resource, - such as a credential from - :mod:`azure.identity` - :type token_credential: ~azure.core.credentials.TokenCredential - :param str resource_id: Azure Resource Id of the Translation Resource. - :param str region: Azure Region of the Translation Resource. - """ - - def __init__(self, token_credential: TokenCredential, resource_id: str, region: str) -> None: - self.token_credential = token_credential - self.resource_id = resource_id - self.region = region + request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.region class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): @@ -85,15 +48,17 @@ class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): :type credential: ~azure.ai.translation.text.TranslatorAADCredential """ - def __init__(self, credential: TranslatorAADCredential, **kwargs: Any) -> None: + def __init__(self, credential: TokenCredential, resource_id: str, region: str, **kwargs: Any) -> None: super(TranslatorAADAuthenticationPolicy, self).__init__( credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs ) + self.resource_id = resource_id + self.region = region self.translator_credential = credential def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translator_credential.resource_id - request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translator_credential.region + request.http_request.headers["Ocp-Apim-ResourceId"] = self.resource_id + request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.region super().on_request(request) @@ -111,22 +76,28 @@ def get_translation_endpoint(endpoint, api_version): def set_authentication_policy(credential, kwargs): - if isinstance(credential, TranslatorCredential): + if isinstance(credential, AzureKeyCredential): if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = TranslatorAuthenticationPolicy(credential) - elif isinstance(credential, TranslatorAADCredential): - if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = TranslatorAADAuthenticationPolicy(credential) - elif isinstance(credential, AzureKeyCredential): - if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = AzureKeyCredentialPolicy( - name="Ocp-Apim-Subscription-Key", credential=credential - ) + if kwargs.get("region"): + kwargs["authentication_policy"] = TranslatorAuthenticationPolicy(credential, kwargs["region"]) + else: + kwargs["authentication_policy"] = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential + ) elif hasattr(credential, "get_token"): if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = BearerTokenCredentialPolicy( - credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs - ) + if kwargs.get("region") and kwargs.get("resource_id"): + kwargs["authentication_policy"] = TranslatorAADAuthenticationPolicy( + credential, kwargs["resource_id"], kwargs["region"] + ) + else: + if kwargs.get("resource_id") or kwargs.get("region"): + raise ValueError( + "Both 'resource_id' and 'region' must be provided with a TokenCredential for Translator authentication." + ) + kwargs["authentication_policy"] = BearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs + ) class TextTranslationClient(ServiceClientGenerated): @@ -155,38 +126,49 @@ class TextTranslationClient(ServiceClientGenerated): Combinations of endpoint and credential values: str + AzureKeyCredential - used custom domain translator endpoint + str + AzureKeyCredential + Region - used for global translator endpoint str + TokenCredential - used for regional endpoint with token authentication - str + TranslatorCredential - used for National Clouds None + AzureKeyCredential - used for global translator endpoint with global Translator resource - None + Token - general translator endpoint with token authentication - None + TranslatorCredential - general translator endpoint with regional Translator resource - - :param endpoint: Supported Text Translation endpoints (protocol and hostname, for example: - https://api.cognitive.microsofttranslator.com). Required. - :type endpoint: str - :param credential: Credential used to authenticate with the Translator service - :type credential: Union[AzureKeyCredential , TokenCredential , TranslatorCredential, TranslatorAADCredential] - :keyword api_version: Default value is "3.0". Note that overriding this default value may + None + TokenCredential - general translator endpoint with token authentication + None + TokenCredential + Region - general translator endpoint with regional Translator resource + :keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example: + https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. + :keyword credential: Credential used to authenticate with the Translator service + :paramtype credential: Union[AzureKeyCredential, TokenCredential] + :keyword str region: Used for National Clouds. + :keyword str resource_id: Used with both a TokenCredential combined with a region. + :keyword str api_version: Default value is "3.0". Note that overriding this default value may result in unsupported behavior. - :paramtype api_version: str """ + @overload def __init__( self, *, - credential: Optional[ - Union[AzureKeyCredential, TokenCredential, TranslatorCredential, TranslatorAADCredential] - ] = None, + credential: Optional[Union[AzureKeyCredential]] = None, + region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", **kwargs - ): - - set_authentication_policy(credential, kwargs) + ): ... - translation_endpoint = get_translation_endpoint(endpoint, api_version) + @overload + def __init__( + self, + *, + credential: Optional[Union[TokenCredential]] = None, + region: Optional[str] = None, + resource_id: Optional[str] = None, + endpoint: Optional[str] = None, + api_version="3.0", + **kwargs + ): ... + def __init__(self, **kwargs): + api_version = kwargs.get("api_version", "3.0") + set_authentication_policy(kwargs.get("credential"), kwargs) + translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint"), api_version) super().__init__(endpoint=translation_endpoint, api_version=api_version, **kwargs) -__all__ = ["TextTranslationClient", "TranslatorCredential", "TranslatorAADCredential"] +__all__ = ["TextTranslationClient"] diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py index bbcd28b4aa67..be71c81bd282 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b2" +VERSION = "1.0.0b1" diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py index a0e21c127d4c..0d279090135b 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/__init__.py @@ -9,11 +9,9 @@ from ._patch import TextTranslationClient -from ._patch import AsyncTranslatorAADCredential from ._patch import patch_sdk as _patch_sdk __all__ = [ - "AsyncTranslatorAADCredential", "TextTranslationClient", ] diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py index 6f6db4eb6afc..f0c1aa4fa5cf 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py @@ -241,7 +241,7 @@ async def get_supported_languages( @overload async def translate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -264,8 +264,8 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -350,7 +350,7 @@ async def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -418,7 +418,7 @@ async def translate( @overload async def translate( self, - request_body: IO[bytes], + body: IO[bytes], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -441,8 +441,8 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -588,7 +588,7 @@ async def translate( @distributed_trace_async async def translate( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -610,9 +610,9 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -767,10 +767,10 @@ async def translate( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( target_languages=target_languages, @@ -829,7 +829,7 @@ async def translate( @overload async def transliterate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, language: str, source_language_script: str, @@ -842,8 +842,8 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -870,7 +870,7 @@ async def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -890,7 +890,7 @@ async def transliterate( @overload async def transliterate( self, - request_body: IO[bytes], + body: IO[bytes], *, language: str, source_language_script: str, @@ -903,8 +903,8 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -944,7 +944,7 @@ async def transliterate( @distributed_trace_async async def transliterate( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, source_language_script: str, @@ -956,9 +956,9 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -1007,10 +1007,10 @@ async def transliterate( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_transliterate_request( language=language, @@ -1058,7 +1058,7 @@ async def transliterate( @overload async def find_sentence_boundaries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1071,8 +1071,8 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1095,7 +1095,7 @@ async def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1123,7 +1123,7 @@ async def find_sentence_boundaries( @overload async def find_sentence_boundaries( self, - request_body: IO[bytes], + body: IO[bytes], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1136,8 +1136,8 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1181,7 +1181,7 @@ async def find_sentence_boundaries( @distributed_trace_async async def find_sentence_boundaries( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -1193,9 +1193,9 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1248,10 +1248,10 @@ async def find_sentence_boundaries( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_find_sentence_boundaries_request( client_trace_id=client_trace_id, @@ -1298,7 +1298,7 @@ async def find_sentence_boundaries( @overload async def lookup_dictionary_entries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, source_language: str, target_language: str, @@ -1311,8 +1311,8 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1335,7 +1335,7 @@ async def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1413,7 +1413,7 @@ async def lookup_dictionary_entries( @overload async def lookup_dictionary_entries( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -1426,8 +1426,8 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1521,7 +1521,7 @@ async def lookup_dictionary_entries( @distributed_trace_async async def lookup_dictionary_entries( self, - request_body: Union[List[_models.InputTextItem], IO[bytes]], + body: Union[List[_models.InputTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -1533,9 +1533,9 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Is either a [InputTextItem] type or a + :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] + :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1638,10 +1638,10 @@ async def lookup_dictionary_entries( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( source_language=source_language, @@ -1688,7 +1688,7 @@ async def lookup_dictionary_entries( @overload async def lookup_dictionary_examples( self, - request_body: List[_models.DictionaryExampleTextItem], + body: List[_models.DictionaryExampleTextItem], *, source_language: str, target_language: str, @@ -1701,8 +1701,8 @@ async def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1725,7 +1725,7 @@ async def lookup_dictionary_examples( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str", # Text to translate. Required. "translation": "str" # A string specifying the translated text @@ -1775,7 +1775,7 @@ async def lookup_dictionary_examples( @overload async def lookup_dictionary_examples( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -1788,8 +1788,8 @@ async def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1850,7 +1850,7 @@ async def lookup_dictionary_examples( @distributed_trace_async async def lookup_dictionary_examples( self, - request_body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], + body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -1862,9 +1862,9 @@ async def lookup_dictionary_examples( Lookup Dictionary Examples. - :param request_body: Defines the content of the request. Is either a + :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type or a IO[bytes] type. Required. - :type request_body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. @@ -1935,10 +1935,10 @@ async def lookup_dictionary_examples( content_type = content_type or "application/json" _content = None - if isinstance(request_body, (IOBase, bytes)): - _content = request_body + if isinstance(body, (IOBase, bytes)): + _content = body else: - _content = json.dumps(request_body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore + _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( source_language=source_language, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index cb132aaced61..79b6c71cf773 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -17,7 +17,7 @@ class TextTranslationClientOperationsMixin(TextTranslationClientOperationsMixinG @overload async def translate( self, - request_body: List[str], + body: List[str], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -40,8 +40,8 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -125,7 +125,7 @@ async def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ str" # Text to translate. Required. ] @@ -191,7 +191,7 @@ async def translate( @overload async def translate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -214,8 +214,8 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -299,7 +299,7 @@ async def translate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -367,7 +367,7 @@ async def translate( @overload async def translate( self, - request_body: IO[bytes], + body: IO[bytes], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -390,8 +390,8 @@ async def translate( Translate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword target_languages: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. @@ -535,7 +535,7 @@ async def translate( async def translate( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, target_languages: List[str], client_trace_id: Optional[str] = None, @@ -553,16 +553,16 @@ async def translate( **kwargs: Any ) -> List[_models.TranslatedTextItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().translate( - request_body=body, + body=body, target_languages=target_languages, client_trace_id=client_trace_id, source_language=source_language, @@ -582,7 +582,7 @@ async def translate( @overload async def transliterate( self, - request_body: List[str], + body: List[str], *, language: str, source_language_script: str, @@ -595,8 +595,8 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -623,7 +623,7 @@ async def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -643,7 +643,7 @@ async def transliterate( @overload async def transliterate( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, language: str, source_language_script: str, @@ -656,8 +656,8 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -684,7 +684,7 @@ async def transliterate( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -704,7 +704,7 @@ async def transliterate( @overload async def transliterate( self, - request_body: IO[bytes], + body: IO[bytes], *, language: str, source_language_script: str, @@ -717,8 +717,8 @@ async def transliterate( Transliterate Text. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword language: Specifies the language of the text to convert from one script to another. Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. @@ -757,7 +757,7 @@ async def transliterate( async def transliterate( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, source_language_script: str, @@ -766,16 +766,16 @@ async def transliterate( **kwargs: Any ) -> List[_models.TransliteratedText]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().transliterate( - request_body=body, + body=body, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -786,7 +786,7 @@ async def transliterate( @overload async def find_sentence_boundaries( self, - request_body: List[str], + body: List[str], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -799,8 +799,8 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -823,7 +823,7 @@ async def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -851,7 +851,7 @@ async def find_sentence_boundaries( @overload async def find_sentence_boundaries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -864,8 +864,8 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -888,7 +888,7 @@ async def find_sentence_boundaries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -916,7 +916,7 @@ async def find_sentence_boundaries( @overload async def find_sentence_boundaries( self, - request_body: IO[bytes], + body: IO[bytes], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -929,8 +929,8 @@ async def find_sentence_boundaries( Find Sentence Boundaries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -973,7 +973,7 @@ async def find_sentence_boundaries( async def find_sentence_boundaries( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, client_trace_id: Optional[str] = None, language: Optional[str] = None, @@ -981,23 +981,23 @@ async def find_sentence_boundaries( **kwargs: Any ) -> List[_models.BreakSentenceItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().find_sentence_boundaries( - request_body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs + body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs ) @overload async def lookup_dictionary_entries( self, - request_body: List[str], + body: List[str], *, source_language: str, target_language: str, @@ -1010,8 +1010,8 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[str] + :param body: Defines the content of the request. Required. + :type body: list[str] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1034,7 +1034,7 @@ async def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1112,7 +1112,7 @@ async def lookup_dictionary_entries( @overload async def lookup_dictionary_entries( self, - request_body: List[_models.InputTextItem], + body: List[_models.InputTextItem], *, source_language: str, target_language: str, @@ -1125,8 +1125,8 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: list[~azure.ai.translation.text.models.InputTextItem] + :param body: Defines the content of the request. Required. + :type body: list[~azure.ai.translation.text.models.InputTextItem] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1149,7 +1149,7 @@ async def lookup_dictionary_entries( .. code-block:: python # JSON input template you can fill out and use as your body input. - request_body = [ + body = [ { "text": "str" # Text to translate. Required. } @@ -1227,7 +1227,7 @@ async def lookup_dictionary_entries( @overload async def lookup_dictionary_entries( self, - request_body: IO[bytes], + body: IO[bytes], *, source_language: str, target_language: str, @@ -1240,8 +1240,8 @@ async def lookup_dictionary_entries( Lookup Dictionary Entries. - :param request_body: Defines the content of the request. Required. - :type request_body: IO[bytes] + :param body: Defines the content of the request. Required. + :type body: IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. @@ -1334,7 +1334,7 @@ async def lookup_dictionary_entries( async def lookup_dictionary_entries( self, - request_body: Union[List[str], List[_models.InputTextItem], IO[bytes]], + body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, source_language: str, target_language: str, @@ -1342,16 +1342,16 @@ async def lookup_dictionary_entries( **kwargs: Any ) -> List[_models.DictionaryLookupItem]: body: Union[List[_models.InputTextItem], IO[bytes]] - if isinstance(request_body, list) and all(isinstance(item, str) for item in request_body): + if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] - for text in request_body: + for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], request_body) + body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().lookup_dictionary_entries( - request_body=body, + body=body, source_language=source_language, target_language=target_language, client_trace_id=client_trace_id, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 7bb199a702c0..fbc8565863b7 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -7,13 +7,13 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ -from typing import Union, Optional, Any +from typing import Union, Optional, Any, overload from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy, AzureKeyCredentialPolicy from azure.core.credentials import AzureKeyCredential from azure.core.credentials_async import AsyncTokenCredential -from .._patch import DEFAULT_TOKEN_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy, TranslatorCredential +from .._patch import DEFAULT_TOKEN_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy from ._client import TextTranslationClient as ServiceClientGenerated @@ -27,23 +27,6 @@ def patch_sdk(): """ -class AsyncTranslatorAADCredential: - """Credential for Translator Service when using AAD authentication. - - :param token_credential: An object which can provide an access token for the Translator Resource, - such as a credential from - :mod:`azure.identity` - :type token_credential: ~azure.core.credentials.TokenCredential - :param str resource_id: Azure Resource Id of the Translation Resource. - :param str region: Azure Region of the Translation Resource. - """ - - def __init__(self, token_credential: AsyncTokenCredential, resource_id: str, region: str) -> None: - self.token_credential = token_credential - self.resource_id = resource_id - self.region = region - - class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): """Translator AAD Authentication Policy. Adds headers that are required by Translator Service when global endpoint is used with AAD policy. @@ -51,38 +34,46 @@ class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. :param credential: Translator AAD Credentials used to access Translator Resource for global Translator endpoint. - :type credential: ~azure.ai.translation.text.AsyncTranslatorAADCredential + :type credential: ~azure.core.credentials_async.AsyncTokenCredential """ - def __init__(self, credential: AsyncTranslatorAADCredential, **kwargs: Any) -> None: + def __init__(self, credential: AsyncTokenCredential, resource_id: str, region: str, **kwargs: Any) -> None: super(AsyncTranslatorAADAuthenticationPolicy, self).__init__( credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs ) + self.resource_id = resource_id + self.region = region self.translator_credential = credential async def on_request(self, request: PipelineRequest) -> None: - request.http_request.headers["Ocp-Apim-ResourceId"] = self.translator_credential.resource_id - request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.translator_credential.region + request.http_request.headers["Ocp-Apim-ResourceId"] = self.resource_id + request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.region await super().on_request(request) def set_authentication_policy(credential, kwargs): - if isinstance(credential, TranslatorCredential): + if isinstance(credential, AzureKeyCredential): if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = TranslatorAuthenticationPolicy(credential) - elif isinstance(credential, AsyncTranslatorAADCredential): - if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = AsyncTranslatorAADAuthenticationPolicy(credential) - elif isinstance(credential, AzureKeyCredential): - if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = AzureKeyCredentialPolicy( - name="Ocp-Apim-Subscription-Key", credential=credential - ) + if kwargs.get("region"): + kwargs["authentication_policy"] = TranslatorAuthenticationPolicy(credential, kwargs["region"]) + else: + kwargs["authentication_policy"] = AzureKeyCredentialPolicy( + name="Ocp-Apim-Subscription-Key", credential=credential + ) elif hasattr(credential, "get_token"): if not kwargs.get("authentication_policy"): - kwargs["authentication_policy"] = AsyncBearerTokenCredentialPolicy( - credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs - ) + if kwargs.get("region") and kwargs.get("resource_id"): + kwargs["authentication_policy"] = AsyncTranslatorAADAuthenticationPolicy( + credential, kwargs["resource_id"], kwargs["region"] + ) + else: + if kwargs.get("resource_id") or kwargs.get("region"): + raise ValueError( + "Both 'resource_id' and 'region' must be provided with a TokenCredential for Translator authentication." + ) + kwargs["authentication_policy"] = AsyncBearerTokenCredentialPolicy( + credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs + ) class TextTranslationClient(ServiceClientGenerated): @@ -111,37 +102,49 @@ class TextTranslationClient(ServiceClientGenerated): Combinations of endpoint and credential values: str + AzureKeyCredential - used custom domain translator endpoint - str + TokenCredential - used for regional endpoint with token authentication - str + TranslatorCredential - used for National Clouds + str + AzureKeyCredential + Region - used for global translator endpoint + str + AsyncTokenCredential - used for regional endpoint with token authentication None + AzureKeyCredential - used for global translator endpoint with global Translator resource - None + Token - general translator endpoint with token authentication - None + TranslatorCredential - general translator endpoint with regional Translator resource - - :param endpoint: Supported Text Translation endpoints (protocol and hostname, for example: - https://api.cognitive.microsofttranslator.com). Required. - :type endpoint: str - :param credential: Credential used to authenticate with the Translator service - :type credential: Union[AzureKeyCredential , AsyncTokenCredential , TranslatorCredential, - AsyncTranslatorAADCredential] - :keyword api_version: Default value is "3.0". Note that overriding this default value may + None + AsyncTokenCredential - general translator endpoint with token authentication + None + AsyncTokenCredential + Region - general translator endpoint with regional Translator resource + :keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example: + https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. + :keyword credential: Credential used to authenticate with the Translator service + :paramtype credential: Union[AzureKeyCredential, AsyncTokenCredential] + :keyword str region: Used for National Clouds. + :keyword str resource_id: Used with both a TokenCredential combined with a region. + :keyword str api_version: Default value is "3.0". Note that overriding this default value may result in unsupported behavior. - :paramtype api_version: str """ + @overload def __init__( self, - credential: Union[AzureKeyCredential, AsyncTokenCredential, TranslatorCredential, AsyncTranslatorAADCredential], *, + credential: Optional[Union[AzureKeyCredential]] = None, + region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", **kwargs - ): - - set_authentication_policy(credential, kwargs) + ): ... - translation_endpoint = get_translation_endpoint(endpoint, api_version) + @overload + def __init__( + self, + *, + credential: Optional[Union[AsyncTokenCredential]] = None, + region: Optional[str] = None, + resource_id: Optional[str] = None, + endpoint: Optional[str] = None, + api_version="3.0", + **kwargs + ): ... + def __init__(self, **kwargs): + api_version = kwargs.get("api_version", "3.0") + set_authentication_policy(kwargs.get("credential"), kwargs) + translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint"), api_version) super().__init__(endpoint=translation_endpoint, api_version=api_version, **kwargs) -__all__ = ["TextTranslationClient", "AsyncTranslatorAADCredential"] +__all__ = ["TextTranslationClient"] diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 6994266d65dd..8663d3e625d6 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -48,8 +48,8 @@ The appropriate constructor is invoked in each sample to create a `TextTranslati ```python -credential = TranslatorCredential(apikey, region) -text_translator = TextTranslationClient(credential=credential, endpoint=endpoint) +credential = AzureKeyCredential(apikey) +text_translator = TextTranslationClient(credential=credential, endpoint=endpoint, region=region) ``` @@ -208,7 +208,7 @@ try: input_text_elements = ["This is a test"] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -240,7 +240,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -276,7 +276,7 @@ try: input_text_elements = ["hudha akhtabar."] response = text_translator.translate( - request_body=input_text_elements, + body=input_text_elements, to=target_languages, source_language_script=source_language_script, source_language=from_language, @@ -318,7 +318,7 @@ try: "Dies ist ein Test.", ] - translations = text_translator.translate(request_body=input_text_elements, to=target_languages) + translations = text_translator.translate(body=input_text_elements, to=target_languages) for translation in translations: print( @@ -347,7 +347,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -379,7 +379,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(request_body=input_text_elements, to=target_languages, text_type=text_type) + response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) translation = response[0] if response else None if translation: @@ -415,7 +415,7 @@ try: ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -448,7 +448,7 @@ try: ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -480,7 +480,7 @@ try: input_text_elements = ["This is ***."] response = text_translator.translate( - request_body=input_text_elements, + body=input_text_elements, to=target_languages, profanity_action=profanity_action, profanity_marker=profanity_maker, @@ -517,7 +517,7 @@ try: input_text_elements = ["The answer lies in machine translation."] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, include_alignment=include_alignment + body=input_text_elements, to=target_languages, include_alignment=include_alignment ) translation = response[0] if response else None @@ -553,7 +553,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -595,7 +595,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) translation = response[0] if response else None if translation: @@ -631,7 +631,7 @@ try: input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, + body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -667,7 +667,7 @@ try: input_text_elements = ["zhè shì gè cè shì。"] response = text_translator.find_sentence_boundaries( - request_body=input_text_elements, language=source_language, script=source_script + body=input_text_elements, language=source_language, script=source_script ) sentence_boundaries = response[0] if response else None @@ -700,7 +700,7 @@ You can omit source language of the input text. In this case, API will try to au try: input_text_elements = ["This is a test. This is the second sentence."] - response = text_translator.find_sentence_boundaries(request_body=input_text_elements) + response = text_translator.find_sentence_boundaries(body=input_text_elements) sentence_boundaries = response[0] if response else None if sentence_boundaries: @@ -736,7 +736,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py index f6f892d2a8ff..204cbf8044c6 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py @@ -42,7 +42,7 @@ def get_text_sentence_boundaries(): input_text_elements = ["zhè shì gè cè shì。"] response = text_translator.find_sentence_boundaries( - request_body=input_text_elements, language=source_language, script=source_script + body=input_text_elements, language=source_language, script=source_script ) sentence_boundaries = response[0] if response else None @@ -69,7 +69,7 @@ def get_text_sentence_boundaries_auto(): try: input_text_elements = ["This is a test. This is the second sentence."] - response = text_translator.find_sentence_boundaries(request_body=input_text_elements) + response = text_translator.find_sentence_boundaries(body=input_text_elements) sentence_boundaries = response[0] if response else None if sentence_boundaries: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py index 9983652e60a5..f6c546b70c20 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py @@ -41,13 +41,14 @@ def create_text_translation_client_with_endpoint(): def create_text_translation_client_with_credential(): - from azure.ai.translation.text import TextTranslationClient, TranslatorCredential + from azure.ai.translation.text import TextTranslationClient + from azure.core.credentials import AzureKeyCredential endpoint = os.environ["AZURE_TEXT_TRANSLATION_ENDPOINT"] apikey = os.environ["AZURE_TEXT_TRANSLATION_APIKEY"] region = os.environ["AZURE_TEXT_TRANSLATION_REGION"] # [START create_text_translation_client_with_credential] - credential = TranslatorCredential(apikey, region) - text_translator = TextTranslationClient(credential=credential, endpoint=endpoint) + credential = AzureKeyCredential(apikey) + text_translator = TextTranslationClient(credential=credential, endpoint=endpoint, region=region) # [END create_text_translation_client_with_credential] return text_translator diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py index 19da46c28f8d..4e231bfec525 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py @@ -45,7 +45,7 @@ def get_text_translation_dictionary_lookup(): input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index 173fdd8cde4c..8adbfd87252c 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -46,7 +46,7 @@ def get_text_translation(): input_text_elements = ["This is a test"] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -68,7 +68,7 @@ def get_text_translation_auto(): target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -98,7 +98,7 @@ def get_text_translation_with_transliteration(): input_text_elements = ["hudha akhtabar."] response = text_translator.translate( - request_body=input_text_elements, + body=input_text_elements, to=target_languages, source_language_script=source_language_script, source_language=from_language, @@ -134,7 +134,7 @@ def get_text_translation_multiple_inputs(): "Dies ist ein Test.", ] - translations = text_translator.translate(request_body=input_text_elements, to=target_languages) + translations = text_translator.translate(body=input_text_elements, to=target_languages) for translation in translations: print( @@ -157,7 +157,7 @@ def get_text_translation_multiple_languages(): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -183,7 +183,7 @@ def get_text_translation_type(): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(request_body=input_text_elements, to=target_languages, text_type=text_type) + response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) translation = response[0] if response else None if translation: @@ -213,7 +213,7 @@ def get_text_translation_exclude(): ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -238,7 +238,7 @@ def get_text_translation_entity(): ] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -262,7 +262,7 @@ def get_text_translation_profanity(): input_text_elements = ["This is ***."] response = text_translator.translate( - request_body=input_text_elements, + body=input_text_elements, to=target_languages, profanity_action=profanity_action, profanity_marker=profanity_maker, @@ -293,7 +293,7 @@ def get_text_translation_alignment(): input_text_elements = ["The answer lies in machine translation."] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, include_alignment=include_alignment + body=input_text_elements, to=target_languages, include_alignment=include_alignment ) translation = response[0] if response else None @@ -323,7 +323,7 @@ def get_text_translation_sentence_length(): input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - request_body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -355,7 +355,7 @@ def get_text_translation_custom(): target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(request_body=input_text_elements, to=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) translation = response[0] if response else None if translation: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py index e08aa699c2c2..9e4415e2be63 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py @@ -46,7 +46,7 @@ def get_text_transliteration(): input_text_elements = ["这是个测试。"] response = text_translator.transliterate( - request_body=input_text_elements, + body=input_text_elements, language=language, source_language_script=source_language_script, target_language_script=target_language_script, diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py index c9161392952b..d2ecc9c98ea6 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py @@ -18,7 +18,7 @@ def test_autodetect(self, **kwargs): client = self.create_client(endpoint, apikey, region) input_text_elements = ["Hello world"] - response = client.find_sentence_boundaries(request_body=input_text_elements) + response = client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence > 0.9 @@ -36,7 +36,7 @@ def test_with_language(self, **kwargs): "รวบรวมแผ่นคำตอบ ระยะเวลาของโครงการ วิธีเลือกชายในฝัน หมายเลขซีเรียลของระเบียน วันที่สิ้นสุดของโครงการเมื่อเสร็จสมบูรณ์ ปีที่มีการรวบรวม ทุกคนมีวัฒนธรรมและวิธีคิดเหมือนกัน ได้รับโทษจำคุกตลอดชีวิตใน ฉันลดได้ถึง 55 ปอนด์ได้อย่างไร ฉันคิดว่าใครๆ ก็ต้องการกำหนดเมนูอาหารส่วนบุคคล" ] - response = client.find_sentence_boundaries(request_body=input_text_elements, language="th") + response = client.find_sentence_boundaries(body=input_text_elements, language="th") assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): @@ -52,7 +52,7 @@ def test_with_language_script(self, **kwargs): input_text_elements = ["zhè shì gè cè shì。"] - response = client.find_sentence_boundaries(request_body=input_text_elements, language="zh-Hans", script="Latn") + response = client.find_sentence_boundaries(body=input_text_elements, language="zh-Hans", script="Latn") assert response is not None assert response[0].sentences_lengths[0] == 18 @@ -69,7 +69,7 @@ def test_with_multiple_languages(self, **kwargs): "العالم هو مكان مثير جدا للاهتمام", ] - response = client.find_sentence_boundaries(request_body=input_text_elements) + response = client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py index 0270b54a2797..589d4b25e450 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py @@ -19,7 +19,7 @@ async def test_autodetect(self, **kwargs): input_text_elements = ["Hello world"] async with client: - response = await client.find_sentence_boundaries(request_body=input_text_elements) + response = await client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence > 0.9 @@ -38,7 +38,7 @@ async def test_with_language(self, **kwargs): ] async with client: - response = await client.find_sentence_boundaries(request_body=input_text_elements, language="th") + response = await client.find_sentence_boundaries(body=input_text_elements, language="th") assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): @@ -56,7 +56,7 @@ async def test_with_language_script(self, **kwargs): async with client: response = await client.find_sentence_boundaries( - request_body=input_text_elements, language="zh-Hans", script="Latn" + body=input_text_elements, language="zh-Hans", script="Latn" ) assert response is not None assert response[0].sentences_lengths[0] == 18 @@ -75,7 +75,7 @@ async def test_with_multiple_languages(self, **kwargs): ] async with client: - response = await client.find_sentence_boundaries(request_body=input_text_elements) + response = await client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py index 0ed0801b81a4..e243d2a0da63 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py @@ -23,7 +23,7 @@ def test_single_input_element(self, **kwargs): input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = client.lookup_dictionary_examples( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -45,7 +45,7 @@ def test_multiple_input_elements(self, **kwargs): ] response = client.lookup_dictionary_examples( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py index 845e31e843ed..5bae5ce49a72 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py @@ -24,7 +24,7 @@ async def test_single_input_element(self, **kwargs): async with client: response = await client.lookup_dictionary_examples( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -47,7 +47,7 @@ async def test_multiple_input_elements(self, **kwargs): async with client: response = await client.lookup_dictionary_examples( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py index 0fea3cf99cd5..25b3e02787cc 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py @@ -22,7 +22,7 @@ def test_single_input_element(self, **kwargs): input_text_elements = ["fly"] response = client.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -41,7 +41,7 @@ def test_multiple_input_elements(self, **kwargs): input_text_elements = ["fly", "fox"] response = client.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py index 8614d3066f45..1b7f11bf97d9 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py @@ -23,7 +23,7 @@ async def test_single_input_element(self, **kwargs): async with client: response = await client.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert response[0].normalized_source == "fly" @@ -43,7 +43,7 @@ async def test_multiple_input_elements(self, **kwargs): async with client: response = await client.lookup_dictionary_entries( - request_body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation.py b/sdk/translation/azure-ai-translation-text/tests/test_translation.py index 80884555f3bc..bc0003118927 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation.py @@ -23,7 +23,7 @@ def test_translate(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -41,7 +41,7 @@ def test_autodetect(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -62,7 +62,7 @@ def test_no_translate_tag(self, **kwargs): target_languages = ["en"] input_text_elements = ["今天是怎么回事是非常可怕的"] response = client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=TextType.HTML, @@ -86,7 +86,7 @@ def test_dictionary_tag(self, **kwargs): 'The word < mstrans:dictionary translation ="wordomatic">wordomatic is a dictionary entry.' ] response = client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -106,7 +106,7 @@ def test_transliteration(self, **kwargs): target_languages = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, source_language_script="Latn", @@ -131,7 +131,7 @@ def test_from_to_latin(self, **kwargs): target_languages = ["ta"] input_text_elements = ["ap kaise ho"] response = client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, source_language_script="Latn", @@ -157,7 +157,7 @@ def test_multiple_input(self, **kwargs): "Esto es una prueba.", "Dies ist ein Test.", ] - response = client.translate(request_body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 3 assert response[0].detected_language.language == "en" @@ -181,7 +181,7 @@ def test_multiple_target_languages(self, **kwargs): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 3 @@ -202,7 +202,7 @@ def test_different_texttypes(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] response = client.translate( - request_body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML + body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML ) assert len(response) == 1 @@ -221,7 +221,7 @@ def test_profanity(self, **kwargs): target_languages = ["zh-cn"] input_text_elements = ["shit this is fucking crazy"] response = client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, @@ -243,9 +243,7 @@ def test_alignment(self, **kwargs): target_languages = ["cs"] input_text_elements = ["It is a beautiful morning"] - response = client.translate( - request_body=input_text_elements, target_languages=target_languages, include_alignment=True - ) + response = client.translate(body=input_text_elements, target_languages=target_languages, include_alignment=True) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -266,7 +264,7 @@ def test_sentence_length(self, **kwargs): "La réponse se trouve dans la traduction automatique. La meilleure technologie de traduction automatique ne peut pas toujours fournir des traductions adaptées à un site ou des utilisateurs comme un être humain. Il suffit de copier et coller un extrait de code n'importe où." ] response = client.translate( - request_body=input_text_elements, target_languages=target_languages, include_sentence_length=True + body=input_text_elements, target_languages=target_languages, include_sentence_length=True ) assert len(response) == 1 @@ -286,7 +284,7 @@ def test_custom_endpoint(self, **kwargs): target_languages = ["fr"] input_text_elements = ["It is a beautiful morning"] - response = client.translate(request_body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -304,7 +302,7 @@ def test_token(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(request_body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -324,7 +322,7 @@ def test_translate_aad(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py index 9eb899470d3f..17d0035a4f9e 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py @@ -25,7 +25,7 @@ async def test_translate(self, **kwargs): input_text_elements = ["Hola mundo"] async with client: response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -44,7 +44,7 @@ async def test_autodetect(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -66,7 +66,7 @@ async def test_no_translate_tag(self, **kwargs): input_text_elements = ["今天是怎么回事是非常可怕的"] async with client: response = await client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=TextType.HTML, @@ -91,7 +91,7 @@ async def test_dictionary_tag(self, **kwargs): ] async with client: response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 @@ -112,7 +112,7 @@ async def test_transliteration(self, **kwargs): input_text_elements = ["hudha akhtabar."] async with client: response = await client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, source_language_script="Latn", @@ -138,7 +138,7 @@ async def test_from_to_latin(self, **kwargs): input_text_elements = ["ap kaise ho"] async with client: response = await client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, source_language=source_language, source_language_script="Latn", @@ -165,7 +165,7 @@ async def test_multiple_input(self, **kwargs): "Dies ist ein Test.", ] async with client: - response = await client.translate(request_body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 3 assert response[0].detected_language.language == "en" @@ -190,7 +190,7 @@ async def test_multiple_target_languages(self, **kwargs): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 3 @@ -212,7 +212,7 @@ async def test_different_texttypes(self, **kwargs): input_text_elements = ["This is a test."] async with client: response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML + body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML ) assert len(response) == 1 @@ -232,7 +232,7 @@ async def test_profanity(self, **kwargs): input_text_elements = ["shit this is fucking crazy"] async with client: response = await client.translate( - request_body=input_text_elements, + body=input_text_elements, target_languages=target_languages, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, @@ -256,7 +256,7 @@ async def test_alignment(self, **kwargs): input_text_elements = ["It is a beautiful morning"] async with client: response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, include_alignment=True + body=input_text_elements, target_languages=target_languages, include_alignment=True ) assert len(response) == 1 @@ -279,7 +279,7 @@ async def test_sentence_length(self, **kwargs): ] async with client: response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, include_sentence_length=True + body=input_text_elements, target_languages=target_languages, include_sentence_length=True ) assert len(response) == 1 @@ -300,7 +300,7 @@ async def test_custom_endpoint(self, **kwargs): target_languages = ["fr"] input_text_elements = ["It is a beautiful morning"] async with client: - response = await client.translate(request_body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -319,7 +319,7 @@ async def test_token(self, **kwargs): target_languages = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(request_body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, target_languages=target_languages) assert len(response) == 1 assert len(response[0].translations) == 1 @@ -339,7 +339,7 @@ async def test_translate_aad(self, **kwargs): target_languages = ["cs"] input_text_elements = ["Hola mundo"] response = await client.translate( - request_body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) assert len(response) == 1 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py index 6a21ac382369..980379d88ea4 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py @@ -20,7 +20,7 @@ def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] response = client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn", @@ -39,7 +39,7 @@ def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] response = client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn", @@ -63,7 +63,7 @@ def test_edit_distance(self, **kwargs): "hukkabar", ] response = client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr", diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py index 9c21395b9b0f..1002474126f0 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py @@ -21,7 +21,7 @@ async def test_transliteration(self, **kwargs): input_text_elements = ["这里怎么一回事?"] async with client: response = await client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="zh-Hans", source_language_script="Hans", target_language_script="Latn", @@ -41,7 +41,7 @@ async def test_multiple_inputs(self, **kwargs): input_text_elements = ["यहएककसौटीहैयहएककसौटीहै", "यहएककसौटीहै"] async with client: response = await client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="hi", source_language_script="Deva", target_language_script="Latn", @@ -66,7 +66,7 @@ async def test_edit_distance(self, **kwargs): ] async with client: response = await client.transliterate( - request_body=input_text_elements, + body=input_text_elements, language="gu", source_language_script="Latn", target_language_script="Gujr", diff --git a/sdk/translation/azure-ai-translation-text/tests/testcase.py b/sdk/translation/azure-ai-translation-text/tests/testcase.py index 3e99cfda3f08..fcd987fa1638 100644 --- a/sdk/translation/azure-ai-translation-text/tests/testcase.py +++ b/sdk/translation/azure-ai-translation-text/tests/testcase.py @@ -5,9 +5,9 @@ import os from devtools_testutils.fake_credentials_async import AsyncFakeCredential -from azure.core.credentials import AccessToken +from azure.core.credentials import AzureKeyCredential from devtools_testutils import AzureRecordedTestCase -from azure.ai.translation.text import TextTranslationClient, TranslatorCredential, TranslatorAADCredential +from azure.ai.translation.text import TextTranslationClient from static_access_token_credential import StaticAccessTokenCredential @@ -18,8 +18,8 @@ def create_getlanguage_client(self, endpoint): return client def create_client(self, endpoint, apikey, region): - credential = TranslatorCredential(apikey, region) - client = TextTranslationClient(endpoint=endpoint, credential=credential) + credential = AzureKeyCredential(apikey) + client = TextTranslationClient(endpoint=endpoint, credential=credential, region=region) return client def create_client_token(self, endpoint, apikey, region): @@ -28,8 +28,7 @@ def create_client_token(self, endpoint, apikey, region): return client def create_text_translation_client_with_aad(self, innerCredential, aadRegion, aadResourceId): - credential = TranslatorAADCredential(innerCredential, aadResourceId, aadRegion) - text_translator = TextTranslationClient(credential=credential) + text_translator = TextTranslationClient(credential=innerCredential, resource_id=aadResourceId, region=aadRegion) return text_translator def create_async_getlanguage_client(self, endpoint): @@ -39,10 +38,10 @@ def create_async_getlanguage_client(self, endpoint): return client def create_async_client(self, endpoint, apikey, region): - credential = TranslatorCredential(apikey, region) + credential = AzureKeyCredential(apikey) from azure.ai.translation.text.aio import TextTranslationClient as TextTranslationClientAsync - client = TextTranslationClientAsync(endpoint=endpoint, credential=credential) + client = TextTranslationClientAsync(endpoint=endpoint, credential=credential, region=region) return client def create_async_client_token(self, endpoint, apikey, region): @@ -53,13 +52,11 @@ def create_async_client_token(self, endpoint, apikey, region): return client def create_async_text_translation_client_with_aad(self, innerCredential, aadRegion, aadResourceId): - from azure.ai.translation.text.aio import ( - TextTranslationClient as TextTranslationClientAsync, - AsyncTranslatorAADCredential, - ) + from azure.ai.translation.text.aio import TextTranslationClient as TextTranslationClientAsync - credential = AsyncTranslatorAADCredential(innerCredential, aadResourceId, aadRegion) - text_translator = TextTranslationClientAsync(credential=credential) + text_translator = TextTranslationClientAsync( + credential=innerCredential, resource_id=aadResourceId, region=aadRegion + ) return text_translator def get_mt_credential(self, is_async, **kwargs): From a652885fc1b82b8de4071a93be042d1917807120 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 09:43:29 -0700 Subject: [PATCH 07/32] Using latest typespec --- .../text/_operations/_operations.py | 7 ++-- .../ai/translation/text/_operations/_patch.py | 32 +++++++++---------- .../azure/ai/translation/text/_patch.py | 9 ++++-- .../text/aio/_operations/_operations.py | 7 ++-- .../text/aio/_operations/_patch.py | 32 +++++++++---------- .../azure/ai/translation/text/aio/_patch.py | 10 +++--- .../ai/translation/text/models/_enums.py | 4 ++- .../tsp-location.yaml | 2 +- 8 files changed, 54 insertions(+), 49 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py index 4f73ca2758a0..2adc4f5b9c18 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py @@ -2084,10 +2084,9 @@ def lookup_dictionary_examples( Lookup Dictionary Examples. - :param body: Defines the content of the request. Is either a - [DictionaryExampleTextItem] type or a IO[bytes] type. Required. - :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or - IO[bytes] + :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type + or a IO[bytes] type. Required. + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index a3a3f462ff51..fd335ed4fe76 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -552,17 +552,17 @@ def translate( allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().translate( - body=body, + body=request_body, target_languages=target_languages, client_trace_id=client_trace_id, source_language=source_language, @@ -765,17 +765,17 @@ def transliterate( client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().transliterate( - body=body, + body=request_body, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -980,18 +980,18 @@ def find_sentence_boundaries( script: Optional[str] = None, **kwargs: Any ) -> List[_models.BreakSentenceItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().find_sentence_boundaries( - body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs + body=request_body, language=language, script=script, client_trace_id=client_trace_id, **kwargs ) @overload @@ -1341,17 +1341,17 @@ def lookup_dictionary_entries( client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().lookup_dictionary_entries( - body=body, + body=request_body, source_language=source_language, target_language=target_language, client_trace_id=client_trace_id, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index cfb72717a2f2..9003b029384c 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -12,6 +12,7 @@ from ._client import TextTranslationClient as ServiceClientGenerated DEFAULT_TOKEN_SCOPE = "https://api.microsofttranslator.com/" +DEFAULT_AAD_SCOPE = "https://cognitiveservices.azure.com/.default" def patch_sdk(): @@ -48,9 +49,9 @@ class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): :type credential: ~azure.ai.translation.text.TranslatorAADCredential """ - def __init__(self, credential: TokenCredential, resource_id: str, region: str, **kwargs: Any) -> None: + def __init__(self, credential: TokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: super(TranslatorAADAuthenticationPolicy, self).__init__( - credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs + credential, scopes, **kwargs ) self.resource_id = resource_id self.region = region @@ -88,7 +89,7 @@ def set_authentication_policy(credential, kwargs): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): kwargs["authentication_policy"] = TranslatorAADAuthenticationPolicy( - credential, kwargs["resource_id"], kwargs["region"] + credential, kwargs["resource_id"], kwargs["region"], kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]) ) else: if kwargs.get("resource_id") or kwargs.get("region"): @@ -137,6 +138,7 @@ class TextTranslationClient(ServiceClientGenerated): :paramtype credential: Union[AzureKeyCredential, TokenCredential] :keyword str region: Used for National Clouds. :keyword str resource_id: Used with both a TokenCredential combined with a region. + :keyword str scopes: Scopes of the credentials. :keyword str api_version: Default value is "3.0". Note that overriding this default value may result in unsupported behavior. """ @@ -160,6 +162,7 @@ def __init__( region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, + scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py index f0c1aa4fa5cf..3fe3bdf398ea 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py @@ -1862,10 +1862,9 @@ async def lookup_dictionary_examples( Lookup Dictionary Examples. - :param body: Defines the content of the request. Is either a - [DictionaryExampleTextItem] type or a IO[bytes] type. Required. - :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or - IO[bytes] + :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type + or a IO[bytes] type. Required. + :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] :keyword source_language: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index 79b6c71cf773..31c642070b2c 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -552,17 +552,17 @@ async def translate( allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().translate( - body=body, + body=request_body, target_languages=target_languages, client_trace_id=client_trace_id, source_language=source_language, @@ -765,17 +765,17 @@ async def transliterate( client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().transliterate( - body=body, + body=request_body, language=language, source_language_script=source_language_script, target_language_script=target_language_script, @@ -980,18 +980,18 @@ async def find_sentence_boundaries( script: Optional[str] = None, **kwargs: Any ) -> List[_models.BreakSentenceItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().find_sentence_boundaries( - body=body, language=language, script=script, client_trace_id=client_trace_id, **kwargs + body=request_body, language=language, script=script, client_trace_id=client_trace_id, **kwargs ) @overload @@ -1341,17 +1341,17 @@ async def lookup_dictionary_entries( client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: - body: Union[List[_models.InputTextItem], IO[bytes]] + request_body: Union[List[_models.InputTextItem], IO[bytes]] if isinstance(body, list) and all(isinstance(item, str) for item in body): input_text_items: List[_models.InputTextItem] = [] for text in body: input_text_items.append(_models.InputTextItem(text=cast(str, text))) - body = input_text_items + request_body = input_text_items else: - body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) + request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().lookup_dictionary_entries( - body=body, + body=request_body, source_language=source_language, target_language=target_language, client_trace_id=client_trace_id, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index fbc8565863b7..02d81676b7de 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -13,7 +13,7 @@ from azure.core.credentials import AzureKeyCredential from azure.core.credentials_async import AsyncTokenCredential -from .._patch import DEFAULT_TOKEN_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy +from .._patch import DEFAULT_TOKEN_SCOPE, DEFAULT_AAD_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy from ._client import TextTranslationClient as ServiceClientGenerated @@ -37,9 +37,9 @@ class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): :type credential: ~azure.core.credentials_async.AsyncTokenCredential """ - def __init__(self, credential: AsyncTokenCredential, resource_id: str, region: str, **kwargs: Any) -> None: + def __init__(self, credential: AsyncTokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: super(AsyncTranslatorAADAuthenticationPolicy, self).__init__( - credential.token_credential, "https://cognitiveservices.azure.com/.default", **kwargs + credential, scopes, **kwargs ) self.resource_id = resource_id self.region = region @@ -64,7 +64,7 @@ def set_authentication_policy(credential, kwargs): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): kwargs["authentication_policy"] = AsyncTranslatorAADAuthenticationPolicy( - credential, kwargs["resource_id"], kwargs["region"] + credential, kwargs["resource_id"], kwargs["region"], kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]) ) else: if kwargs.get("resource_id") or kwargs.get("region"): @@ -113,6 +113,7 @@ class TextTranslationClient(ServiceClientGenerated): :paramtype credential: Union[AzureKeyCredential, AsyncTokenCredential] :keyword str region: Used for National Clouds. :keyword str resource_id: Used with both a TokenCredential combined with a region. + :keyword str scopes: Scopes of the credentials. :keyword str api_version: Default value is "3.0". Note that overriding this default value may result in unsupported behavior. """ @@ -136,6 +137,7 @@ def __init__( region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, + scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py index 693b4db76228..e5f1afb9af32 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_enums.py @@ -27,7 +27,7 @@ class ProfanityAction(str, Enum, metaclass=CaseInsensitiveEnumMeta): MARKED = "Marked" """Profanity is marked.""" DELETED = "Deleted" - """Profanity is deteled from the translated text.""" + """Profanity is deleted from the translated text.""" class ProfanityMarker(str, Enum, metaclass=CaseInsensitiveEnumMeta): @@ -43,4 +43,6 @@ class TextType(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Translation text type.""" PLAIN = "Plain" + """Plain text.""" HTML = "Html" + """HTML-encoded text.""" diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index f938c2399b22..fb7595cff124 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 3af1f0b4582e775d1dfefe578781671fc599296f +commit: 3b46c8aaecb9e51e5d5eb5e2aef06fcd2249ff7d repo: MikeyMCZ/azure-rest-api-specs From 8563f6bee6cf4b301187665c62b5b0c85769c3f0 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 10:48:47 -0700 Subject: [PATCH 08/32] Switch to public TypeSpec location --- sdk/translation/azure-ai-translation-text/CHANGELOG.md | 8 +++++++- .../azure/ai/translation/text/_version.py | 2 +- .../azure-ai-translation-text/tsp-location.yaml | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index e30620591eeb..4cc3dea62d95 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0b2 (Unreleased) +## 1.0.0 (Unreleased) ### Features Added - Added support for AAD authentication. @@ -9,6 +9,12 @@ - All calls to the client using parameter 'content' have been changed to use parameter 'body'. - Users can call methods using just a string type instead of complex objects. + - get_languages methods were changed to get_supported_languages. + - sent_len property was renamed to sentences_lengths. + - from_parameter parameter was renamed to source_language. + - score parameter was renamed to confidence. + - from_script parameter was renamed to source_language_script. + - to_script parameter was renamed to _target_langauge_script. ### Bugs Fixed diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py index be71c81bd282..0ec13ea52bbf 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b1" +VERSION = "1.0.0" diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index fb7595cff124..5537465017bc 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 3b46c8aaecb9e51e5d5eb5e2aef06fcd2249ff7d -repo: MikeyMCZ/azure-rest-api-specs +commit: ca3d63391f7b19322159bb0ef705330413829fae +repo: Azure/azure-rest-api-specs From 1713ced32155636f4816ed5f5cd8af7cb19efbfa Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 11:08:50 -0700 Subject: [PATCH 09/32] Format --- .../azure/ai/translation/text/_patch.py | 9 +++++---- .../azure/ai/translation/text/aio/_patch.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 9003b029384c..70a845ad64ad 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -50,9 +50,7 @@ class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): """ def __init__(self, credential: TokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: - super(TranslatorAADAuthenticationPolicy, self).__init__( - credential, scopes, **kwargs - ) + super(TranslatorAADAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) self.resource_id = resource_id self.region = region self.translator_credential = credential @@ -89,7 +87,10 @@ def set_authentication_policy(credential, kwargs): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): kwargs["authentication_policy"] = TranslatorAADAuthenticationPolicy( - credential, kwargs["resource_id"], kwargs["region"], kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]) + credential, + kwargs["resource_id"], + kwargs["region"], + kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]), ) else: if kwargs.get("resource_id") or kwargs.get("region"): diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 02d81676b7de..b99a0181f64b 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -37,10 +37,10 @@ class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): :type credential: ~azure.core.credentials_async.AsyncTokenCredential """ - def __init__(self, credential: AsyncTokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: - super(AsyncTranslatorAADAuthenticationPolicy, self).__init__( - credential, scopes, **kwargs - ) + def __init__( + self, credential: AsyncTokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any + ) -> None: + super(AsyncTranslatorAADAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) self.resource_id = resource_id self.region = region self.translator_credential = credential @@ -64,7 +64,10 @@ def set_authentication_policy(credential, kwargs): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): kwargs["authentication_policy"] = AsyncTranslatorAADAuthenticationPolicy( - credential, kwargs["resource_id"], kwargs["region"], kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]) + credential, + kwargs["resource_id"], + kwargs["region"], + kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]), ) else: if kwargs.get("resource_id") or kwargs.get("region"): From e7b3172542a48e54dcdc414fa4c5a34c24ce9180 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 15:12:06 -0700 Subject: [PATCH 10/32] Fixes --- .../azure-ai-translation-text/README.md | 8 +++--- .../azure/ai/translation/text/_patch.py | 8 +++--- .../azure/ai/translation/text/aio/_patch.py | 8 +++--- .../samples/README.md | 28 +++++++++---------- ...le_text_translation_dictionary_examples.py | 2 +- ...mple_text_translation_dictionary_lookup.py | 2 +- .../sample_text_translation_translate.py | 24 ++++++++-------- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 85a34d88653c..b664d378b5db 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -143,7 +143,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages) translation = response[0] if response else None if translation: @@ -219,7 +219,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -262,7 +262,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) dictionary_entry = response[0] if response else None @@ -298,7 +298,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, to=target_language + content=input_text_elements, source_language=source_language, target_language=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 70a845ad64ad..d64613046353 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722 +# pylint: disable=C4717, C4722, C4748 from typing import Union, Optional, Any, overload from azure.core.pipeline import PipelineRequest @@ -95,7 +95,7 @@ def set_authentication_policy(credential, kwargs): else: if kwargs.get("resource_id") or kwargs.get("region"): raise ValueError( - "Both 'resource_id' and 'region' must be provided with a TokenCredential for Translator authentication." + "Both 'resource_id' and 'region' must be provided with a TokenCredential for authentication." ) kwargs["authentication_policy"] = BearerTokenCredentialPolicy( credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs @@ -148,7 +148,7 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: Optional[Union[AzureKeyCredential]] = None, + credential: Optional[AzureKeyCredential] = None, region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", @@ -159,7 +159,7 @@ def __init__( def __init__( self, *, - credential: Optional[Union[TokenCredential]] = None, + credential: Optional[TokenCredential] = None, region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index b99a0181f64b..4b3a98dc30d0 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722 +# pylint: disable=C4717, C4722, C4748 """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize @@ -72,7 +72,7 @@ def set_authentication_policy(credential, kwargs): else: if kwargs.get("resource_id") or kwargs.get("region"): raise ValueError( - "Both 'resource_id' and 'region' must be provided with a TokenCredential for Translator authentication." + "Both 'resource_id' and 'region' must be provided with a TokenCredential for authentication." ) kwargs["authentication_policy"] = AsyncBearerTokenCredentialPolicy( credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs @@ -125,7 +125,7 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: Optional[Union[AzureKeyCredential]] = None, + credential: Optional[AzureKeyCredential] = None, region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", @@ -136,7 +136,7 @@ def __init__( def __init__( self, *, - credential: Optional[Union[AsyncTokenCredential]] = None, + credential: Optional[AsyncTokenCredential] = None, region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 8663d3e625d6..ab9f0d154f2f 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -208,7 +208,7 @@ try: input_text_elements = ["This is a test"] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -240,7 +240,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages) translation = response[0] if response else None if translation: @@ -277,7 +277,7 @@ try: response = text_translator.translate( body=input_text_elements, - to=target_languages, + target_languages=target_languages, source_language_script=source_language_script, source_language=from_language, target_language_script=target_language_script, @@ -318,7 +318,7 @@ try: "Dies ist ein Test.", ] - translations = text_translator.translate(body=input_text_elements, to=target_languages) + translations = text_translator.translate(body=input_text_elements, target_languages=target_languages) for translation in translations: print( @@ -347,7 +347,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages) translation = response[0] if response else None if translation: @@ -379,7 +379,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages, text_type=text_type) translation = response[0] if response else None if translation: @@ -415,7 +415,7 @@ try: ] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -448,7 +448,7 @@ try: ] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -481,7 +481,7 @@ try: response = text_translator.translate( body=input_text_elements, - to=target_languages, + target_languages=target_languages, profanity_action=profanity_action, profanity_marker=profanity_maker, ) @@ -517,7 +517,7 @@ try: input_text_elements = ["The answer lies in machine translation."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_alignment=include_alignment + body=input_text_elements, target_languages=target_languages, include_alignment=include_alignment ) translation = response[0] if response else None @@ -553,7 +553,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -595,7 +595,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages, category=category) translation = response[0] if response else None if translation: @@ -736,7 +736,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, target_languages=target_language ) dictionary_entry = response[0] if response else None @@ -768,7 +768,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, to=target_language + content=input_text_elements, source_language=source_language, target_languages=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py index 3d4e554b7257..01caae093a96 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py @@ -45,7 +45,7 @@ def get_text_translation_dictionary_examples(): input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, to=target_language + content=input_text_elements, source_language=source_language, target_language=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py index 4e231bfec525..0ad97a927501 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py @@ -45,7 +45,7 @@ def get_text_translation_dictionary_lookup(): input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index 8adbfd87252c..4cd87174cfe7 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -46,7 +46,7 @@ def get_text_translation(): input_text_elements = ["This is a test"] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -68,7 +68,7 @@ def get_text_translation_auto(): target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages) translation = response[0] if response else None if translation: @@ -99,7 +99,7 @@ def get_text_translation_with_transliteration(): response = text_translator.translate( body=input_text_elements, - to=target_languages, + target_languages=target_languages, source_language_script=source_language_script, source_language=from_language, target_language_script=target_language_script, @@ -134,7 +134,7 @@ def get_text_translation_multiple_inputs(): "Dies ist ein Test.", ] - translations = text_translator.translate(body=input_text_elements, to=target_languages) + translations = text_translator.translate(body=input_text_elements, target_languages=target_languages) for translation in translations: print( @@ -157,7 +157,7 @@ def get_text_translation_multiple_languages(): target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages) translation = response[0] if response else None if translation: @@ -183,7 +183,7 @@ def get_text_translation_type(): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages, text_type=text_type) translation = response[0] if response else None if translation: @@ -213,7 +213,7 @@ def get_text_translation_exclude(): ] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -238,7 +238,7 @@ def get_text_translation_entity(): ] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language + body=input_text_elements, target_languages=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -263,7 +263,7 @@ def get_text_translation_profanity(): response = text_translator.translate( body=input_text_elements, - to=target_languages, + target_languages=target_languages, profanity_action=profanity_action, profanity_marker=profanity_maker, ) @@ -293,7 +293,7 @@ def get_text_translation_alignment(): input_text_elements = ["The answer lies in machine translation."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_alignment=include_alignment + body=input_text_elements, target_languages=target_languages, include_alignment=include_alignment ) translation = response[0] if response else None @@ -323,7 +323,7 @@ def get_text_translation_sentence_length(): input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -355,7 +355,7 @@ def get_text_translation_custom(): target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, target_languages=target_languages, category=category) translation = response[0] if response else None if translation: From eaf0bda76e025182f13cbb58cfd6bfb0f30e382f Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 15:18:49 -0700 Subject: [PATCH 11/32] format --- .../azure-ai-translation-text/samples/README.md | 4 +++- .../samples/sample_text_translation_translate.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index ab9f0d154f2f..3f5bac0a5acc 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -379,7 +379,9 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages, text_type=text_type) + response = text_translator.translate( + body=input_text_elements, target_languages=target_languages, text_type=text_type + ) translation = response[0] if response else None if translation: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index 4cd87174cfe7..2e55ff2992c2 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -183,7 +183,9 @@ def get_text_translation_type(): target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages, text_type=text_type) + response = text_translator.translate( + body=input_text_elements, target_languages=target_languages, text_type=text_type + ) translation = response[0] if response else None if translation: @@ -213,7 +215,10 @@ def get_text_translation_exclude(): ] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, + target_languages=target_languages, + source_language=source_language, + text_type=text_type, ) translation = response[0] if response else None @@ -355,7 +360,9 @@ def get_text_translation_custom(): target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages, category=category) + response = text_translator.translate( + body=input_text_elements, target_languages=target_languages, category=category + ) translation = response[0] if response else None if translation: From 55988d19c25e45f6c0df0712c1d6a7405119ea1a Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Thu, 16 May 2024 15:19:22 -0700 Subject: [PATCH 12/32] fix --- .../azure/ai/translation/text/_patch.py | 2 +- .../azure/ai/translation/text/aio/_patch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index d64613046353..cd57c035cbf4 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722, C4748 +# pylint: disable=C4717, C4722 from typing import Union, Optional, Any, overload from azure.core.pipeline import PipelineRequest diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 4b3a98dc30d0..17d35d16792f 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722, C4748 +# pylint: disable=C4717, C4722 """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize From 39490de5026793fcf51d2c894bae299476e109ab Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 08:31:10 -0700 Subject: [PATCH 13/32] Fixes --- .../azure/ai/translation/text/_patch.py | 4 ++-- .../azure/ai/translation/text/aio/_patch.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index cd57c035cbf4..4fa984594852 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -134,14 +134,14 @@ class TextTranslationClient(ServiceClientGenerated): None + TokenCredential - general translator endpoint with token authentication None + TokenCredential + Region - general translator endpoint with regional Translator resource :keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example: - https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. + https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. :keyword credential: Credential used to authenticate with the Translator service :paramtype credential: Union[AzureKeyCredential, TokenCredential] :keyword str region: Used for National Clouds. :keyword str resource_id: Used with both a TokenCredential combined with a region. :keyword str scopes: Scopes of the credentials. :keyword str api_version: Default value is "3.0". Note that overriding this default value may - result in unsupported behavior. + result in unsupported behavior. """ @overload diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 17d35d16792f..3cf424019690 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -111,14 +111,14 @@ class TextTranslationClient(ServiceClientGenerated): None + AsyncTokenCredential - general translator endpoint with token authentication None + AsyncTokenCredential + Region - general translator endpoint with regional Translator resource :keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example: - https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. + https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. :keyword credential: Credential used to authenticate with the Translator service :paramtype credential: Union[AzureKeyCredential, AsyncTokenCredential] :keyword str region: Used for National Clouds. :keyword str resource_id: Used with both a TokenCredential combined with a region. :keyword str scopes: Scopes of the credentials. :keyword str api_version: Default value is "3.0". Note that overriding this default value may - result in unsupported behavior. + result in unsupported behavior. """ @overload From f66591345bcf1230ef6f591141ae3e06e0251dc6 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 08:45:38 -0700 Subject: [PATCH 14/32] Fix documentation --- .../azure/ai/translation/text/aio/_patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 3cf424019690..78c63de7bc80 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -111,14 +111,14 @@ class TextTranslationClient(ServiceClientGenerated): None + AsyncTokenCredential - general translator endpoint with token authentication None + AsyncTokenCredential + Region - general translator endpoint with regional Translator resource :keyword str endpoint: Supported Text Translation endpoints (protocol and hostname, for example: - https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. + https://api.cognitive.microsofttranslator.com). If not provided, global translator endpoint will be used. :keyword credential: Credential used to authenticate with the Translator service :paramtype credential: Union[AzureKeyCredential, AsyncTokenCredential] :keyword str region: Used for National Clouds. :keyword str resource_id: Used with both a TokenCredential combined with a region. :keyword str scopes: Scopes of the credentials. :keyword str api_version: Default value is "3.0". Note that overriding this default value may - result in unsupported behavior. + result in unsupported behavior. """ @overload From e72c060f7049f419ff917d7c3c7b6c42ed79698e Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 11:02:31 -0700 Subject: [PATCH 15/32] Lint fixes --- .../azure-ai-translation-text/README.md | 8 ++--- .../azure/ai/translation/text/_patch.py | 2 +- .../azure/ai/translation/text/aio/_patch.py | 2 +- .../samples/README.md | 30 +++++++++---------- ...le_text_translation_dictionary_examples.py | 2 +- .../sample_text_translation_translate.py | 8 ++--- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index b664d378b5db..85a34d88653c 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -143,7 +143,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -219,7 +219,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -262,7 +262,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None @@ -298,7 +298,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, target_language=target_language + content=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 4fa984594852..5489ad9c8aca 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -4,7 +4,7 @@ # ------------------------------------ # pylint: disable=C4717, C4722 -from typing import Union, Optional, Any, overload +from typing import Optional, Any, overload from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import SansIOHTTPPolicy, BearerTokenCredentialPolicy, AzureKeyCredentialPolicy from azure.core.credentials import TokenCredential, AzureKeyCredential diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 78c63de7bc80..0f0aeb15dd87 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -7,7 +7,7 @@ Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize """ -from typing import Union, Optional, Any, overload +from typing import Optional, Any, overload from azure.core.pipeline import PipelineRequest from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy, AzureKeyCredentialPolicy from azure.core.credentials import AzureKeyCredential diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 3f5bac0a5acc..8663d3e625d6 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -208,7 +208,7 @@ try: input_text_elements = ["This is a test"] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -240,7 +240,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -277,7 +277,7 @@ try: response = text_translator.translate( body=input_text_elements, - target_languages=target_languages, + to=target_languages, source_language_script=source_language_script, source_language=from_language, target_language_script=target_language_script, @@ -318,7 +318,7 @@ try: "Dies ist ein Test.", ] - translations = text_translator.translate(body=input_text_elements, target_languages=target_languages) + translations = text_translator.translate(body=input_text_elements, to=target_languages) for translation in translations: print( @@ -347,7 +347,7 @@ try: target_languages = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages) + response = text_translator.translate(body=input_text_elements, to=target_languages) translation = response[0] if response else None if translation: @@ -379,9 +379,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, text_type=text_type - ) + response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) translation = response[0] if response else None if translation: @@ -417,7 +415,7 @@ try: ] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type ) translation = response[0] if response else None @@ -450,7 +448,7 @@ try: ] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language + body=input_text_elements, to=target_languages, source_language=source_language ) translation = response[0] if response else None @@ -483,7 +481,7 @@ try: response = text_translator.translate( body=input_text_elements, - target_languages=target_languages, + to=target_languages, profanity_action=profanity_action, profanity_marker=profanity_maker, ) @@ -519,7 +517,7 @@ try: input_text_elements = ["The answer lies in machine translation."] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, include_alignment=include_alignment + body=input_text_elements, to=target_languages, include_alignment=include_alignment ) translation = response[0] if response else None @@ -555,7 +553,7 @@ try: input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -597,7 +595,7 @@ try: target_languages = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) translation = response[0] if response else None if translation: @@ -738,7 +736,7 @@ try: input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_languages=target_language + body=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None @@ -770,7 +768,7 @@ try: input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, target_languages=target_language + content=input_text_elements, source_language=source_language, to=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py index 01caae093a96..a717621b2f2b 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py @@ -45,7 +45,7 @@ def get_text_translation_dictionary_examples(): input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, source_language=source_language, target_language=target_language ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index 2e55ff2992c2..dbf0a8845da5 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -311,7 +311,7 @@ def get_text_translation_alignment(): for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") if translated_text.alignment: - print(f"Alignments: {translated_text.alignment.proj}") + print(f"Alignments: {translated_text.alignment.projections}") except HttpResponseError as exception: if exception.error is not None: @@ -340,10 +340,10 @@ def get_text_translation_sentence_length(): ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sentences_lengths: - print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") + if translated_text.sentence_boundaries: + print(f"Source Sentence length: {translated_text.sentence_boundaries.source_sentences_lengths}") print( - f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" + f"Translated Sentence length: {translated_text.sentence_boundaries.translated_sentences_lengths}" ) except HttpResponseError as exception: From 4f9b16863bd5bfafc0f0677e63b0c19002795533 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 11:24:04 -0700 Subject: [PATCH 16/32] Using latest TypeSpec --- .../ai/translation/text/models/_models.py | 17 ++++---- .../sample_text_translation_translate.py | 42 ++++++++++++++----- .../tests/test_get_languages.py | 16 +++---- .../tests/test_get_languages_async.py | 16 +++---- .../tests/test_translation.py | 10 ++--- .../tests/test_translation_async.py | 10 ++--- .../tsp-location.yaml | 2 +- 7 files changed, 67 insertions(+), 46 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py index 7378d83c2c2e..a22e3cf68468 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py @@ -979,8 +979,9 @@ class TranslationText(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar to: A string representing the language code of the target language. Required. - :vartype to: str + :ivar target_language: A string representing the language code of the target language. + Required. + :vartype target_language: str :ivar text: A string giving the translated text. Required. :vartype text: str :ivar transliteration: An object giving the translated text in the script specified by the @@ -992,7 +993,7 @@ class TranslationText(_model_base.Model): :vartype sentence_boundaries: ~azure.ai.translation.text.models.SentenceBoundaries """ - to: str = rest_field() + target_language: str = rest_field(name="to") """A string representing the language code of the target language. Required.""" text: str = rest_field() """A string giving the translated text. Required.""" @@ -1007,7 +1008,7 @@ class TranslationText(_model_base.Model): def __init__( self, *, - to: str, + target_language: str, text: str, transliteration: Optional["_models.TransliteratedText"] = None, alignment: Optional["_models.TranslatedTextAlignment"] = None, @@ -1041,11 +1042,11 @@ class TransliterableScript(LanguageScript): :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. Known values are: "ltr" and "rtl". :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality - :ivar to_scripts: List of scripts available to convert text to. Required. - :vartype to_scripts: list[~azure.ai.translation.text.models.LanguageScript] + :ivar target_language_scripts: List of scripts available to convert text to. Required. + :vartype target_language_scripts: list[~azure.ai.translation.text.models.LanguageScript] """ - to_scripts: List["_models.LanguageScript"] = rest_field(name="toScripts") + target_language_scripts: List["_models.LanguageScript"] = rest_field(name="toScripts") """List of scripts available to convert text to. Required.""" @overload @@ -1056,7 +1057,7 @@ def __init__( name: str, native_name: str, directionality: Union[str, "_models.LanguageDirectionality"], - to_scripts: List["_models.LanguageScript"], + target_language_scripts: List["_models.LanguageScript"], ): ... @overload diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index dbf0a8845da5..d71bf0a63c93 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -52,7 +52,9 @@ def get_text_translation(): if translation: for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -78,7 +80,9 @@ def get_text_translation_auto(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -141,7 +145,7 @@ def get_text_translation_multiple_inputs(): f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.confidence if translation.detected_language else None}." ) print( - f"Text was translated to: '{translation.translations[0].to if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." + f"Text was translated to: '{translation.translations[0].target_language if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." ) except HttpResponseError as exception: @@ -167,7 +171,9 @@ def get_text_translation_multiple_languages(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -195,7 +201,9 @@ def get_text_translation_type(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -224,7 +232,9 @@ def get_text_translation_exclude(): if translation: for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -249,7 +259,9 @@ def get_text_translation_entity(): if translation: for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -281,7 +293,9 @@ def get_text_translation_profanity(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: @@ -309,7 +323,9 @@ def get_text_translation_alignment(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) if translated_text.alignment: print(f"Alignments: {translated_text.alignment.projections}") @@ -339,7 +355,9 @@ def get_text_translation_sentence_length(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) if translated_text.sentence_boundaries: print(f"Source Sentence length: {translated_text.sentence_boundaries.source_sentences_lengths}") print( @@ -372,7 +390,9 @@ def get_text_translation_custom(): f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." ) for translated_text in translation.translations: - print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + print( + f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." + ) except HttpResponseError as exception: if exception.error is not None: diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py index bbff3859a38d..e241f3c61858 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py @@ -51,13 +51,13 @@ def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None assert transliterations.scripts[0].directionality is not None - assert transliterations.scripts[0].to_scripts is not None + assert transliterations.scripts[0].target_language_scripts is not None - assert len(transliterations.scripts[0].to_scripts) > 0 - assert transliterations.scripts[0].to_scripts[0].name is not None - assert transliterations.scripts[0].to_scripts[0].native_name is not None - assert transliterations.scripts[0].to_scripts[0].code is not None - assert transliterations.scripts[0].to_scripts[0].directionality is not None + assert len(transliterations.scripts[0].target_language_scripts) > 0 + assert transliterations.scripts[0].target_language_scripts[0].name is not None + assert transliterations.scripts[0].target_language_scripts[0].native_name is not None + assert transliterations.scripts[0].target_language_scripts[0].code is not None + assert transliterations.scripts[0].target_language_scripts[0].directionality is not None @TextTranslationPreparer() @recorded_by_proxy @@ -73,8 +73,8 @@ def test_transliteration_multiple_scripts(self, **kwargs): assert transliterations.scripts is not None assert len(transliterations.scripts) > 1 - assert len(transliterations.scripts[0].to_scripts) > 1 - assert len(transliterations.scripts[1].to_scripts) > 1 + assert len(transliterations.scripts[0].target_language_scripts) > 1 + assert len(transliterations.scripts[1].target_language_scripts) > 1 @TextTranslationPreparer() @recorded_by_proxy diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py index 93afeab796a5..3d9e1679b472 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py @@ -54,13 +54,13 @@ async def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None assert transliterations.scripts[0].directionality is not None - assert transliterations.scripts[0].to_scripts is not None + assert transliterations.scripts[0].target_language_scripts is not None - assert len(transliterations.scripts[0].to_scripts) > 0 - assert transliterations.scripts[0].to_scripts[0].name is not None - assert transliterations.scripts[0].to_scripts[0].native_name is not None - assert transliterations.scripts[0].to_scripts[0].code is not None - assert transliterations.scripts[0].to_scripts[0].directionality is not None + assert len(transliterations.scripts[0].target_language_scripts) > 0 + assert transliterations.scripts[0].target_language_scripts[0].name is not None + assert transliterations.scripts[0].target_language_scripts[0].native_name is not None + assert transliterations.scripts[0].target_language_scripts[0].code is not None + assert transliterations.scripts[0].target_language_scripts[0].directionality is not None @TextTranslationPreparer() @recorded_by_proxy_async @@ -77,8 +77,8 @@ async def test_transliteration_multiple_scripts(self, **kwargs): assert transliterations.scripts is not None assert len(transliterations.scripts) > 1 - assert len(transliterations.scripts[0].to_scripts) > 1 - assert len(transliterations.scripts[1].to_scripts) > 1 + assert len(transliterations.scripts[0].target_language_scripts) > 1 + assert len(transliterations.scripts[1].target_language_scripts) > 1 @TextTranslationPreparer() @recorded_by_proxy_async diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation.py b/sdk/translation/azure-ai-translation-text/tests/test_translation.py index bc0003118927..30f1e30d2804 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation.py @@ -28,7 +28,7 @@ def test_translate(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -47,7 +47,7 @@ def test_autodetect(self, **kwargs): assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -91,7 +91,7 @@ def test_dictionary_tag(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "es" + assert response[0].translations[0].target_language == "es" assert "wordomatic" in response[0].translations[0].text @TextTranslationPreparer() @@ -116,7 +116,7 @@ def test_transliteration(self, **kwargs): assert len(response) == 1 assert response[0].source_text is not None assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "zh-Hans" + assert response[0].translations[0].target_language == "zh-Hans" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -327,5 +327,5 @@ def test_translate_aad(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py index 17d0035a4f9e..77f1d3454867 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py @@ -30,7 +30,7 @@ async def test_translate(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -50,7 +50,7 @@ async def test_autodetect(self, **kwargs): assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -96,7 +96,7 @@ async def test_dictionary_tag(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "es" + assert response[0].translations[0].target_language == "es" assert "wordomatic" in response[0].translations[0].text @TextTranslationPreparer() @@ -122,7 +122,7 @@ async def test_transliteration(self, **kwargs): assert len(response) == 1 assert response[0].source_text is not None assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "zh-Hans" + assert response[0].translations[0].target_language == "zh-Hans" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -344,5 +344,5 @@ async def test_translate_aad(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].to == "cs" + assert response[0].translations[0].target_language == "cs" assert response[0].translations[0].text is not None diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index 5537465017bc..da41a8211de5 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: ca3d63391f7b19322159bb0ef705330413829fae +commit: cc6917418740a76c0c1b5be595a89f279df73bf6 repo: Azure/azure-rest-api-specs From 154887103a2e9e2b8fa3d54a5d89ec487264bad5 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 13:05:38 -0700 Subject: [PATCH 17/32] Switch to Entra Id name from AAD --- .../azure-ai-translation-text/CHANGELOG.md | 2 +- .../azure/ai/translation/text/_patch.py | 18 +++++++++--------- .../azure/ai/translation/text/aio/_patch.py | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index 4cc3dea62d95..95a3a5eb8b8e 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -3,7 +3,7 @@ ## 1.0.0 (Unreleased) ### Features Added - - Added support for AAD authentication. + - Added support for Entra Id authentication. ### Breaking Changes diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 5489ad9c8aca..3001fdd8b94c 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -12,7 +12,7 @@ from ._client import TextTranslationClient as ServiceClientGenerated DEFAULT_TOKEN_SCOPE = "https://api.microsofttranslator.com/" -DEFAULT_AAD_SCOPE = "https://cognitiveservices.azure.com/.default" +DEFAULT_ENTRA_ID_SCOPE = "https://cognitiveservices.azure.com/.default" def patch_sdk(): @@ -39,18 +39,18 @@ def on_request(self, request: PipelineRequest) -> None: request.http_request.headers["Ocp-Apim-Subscription-Region"] = self.region -class TranslatorAADAuthenticationPolicy(BearerTokenCredentialPolicy): - """Translator AAD Authentication Policy. Adds headers that are required by Translator Service - when global endpoint is used with AAD policy. +class TranslatorEntraIdAuthenticationPolicy(BearerTokenCredentialPolicy): + """Translator EntraId Authentication Policy. Adds headers that are required by Translator Service + when global endpoint is used with Entra Id policy. Ocp-Apim-Subscription-Region header contains region of the Translator resource. Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. - :param credential: Translator AAD Credentials used to access Translator Resource for global Translator endpoint. - :type credential: ~azure.ai.translation.text.TranslatorAADCredential + :param credential: Translator Entra Id Credentials used to access Translator Resource for global Translator endpoint. + :type credential: ~azure.ai.translation.text.TranslatorEntraIdCredential """ def __init__(self, credential: TokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: - super(TranslatorAADAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) + super(TranslatorEntraIdAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) self.resource_id = resource_id self.region = region self.translator_credential = credential @@ -86,11 +86,11 @@ def set_authentication_policy(credential, kwargs): elif hasattr(credential, "get_token"): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): - kwargs["authentication_policy"] = TranslatorAADAuthenticationPolicy( + kwargs["authentication_policy"] = TranslatorEntraIdAuthenticationPolicy( credential, kwargs["resource_id"], kwargs["region"], - kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]), + kwargs.pop("credential_scopes", [DEFAULT_ENTRA_ID_SCOPE]), ) else: if kwargs.get("resource_id") or kwargs.get("region"): diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 0f0aeb15dd87..db0848c2921b 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -13,7 +13,7 @@ from azure.core.credentials import AzureKeyCredential from azure.core.credentials_async import AsyncTokenCredential -from .._patch import DEFAULT_TOKEN_SCOPE, DEFAULT_AAD_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy +from .._patch import DEFAULT_TOKEN_SCOPE, DEFAULT_ENTRA_ID_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy from ._client import TextTranslationClient as ServiceClientGenerated @@ -27,20 +27,20 @@ def patch_sdk(): """ -class AsyncTranslatorAADAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): - """Translator AAD Authentication Policy. Adds headers that are required by Translator Service - when global endpoint is used with AAD policy. +class AsyncTranslatorEntraIdAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): + """Translator Entra Id Authentication Policy. Adds headers that are required by Translator Service + when global endpoint is used with Entra Id policy. Ocp-Apim-Subscription-Region header contains region of the Translator resource. Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. - :param credential: Translator AAD Credentials used to access Translator Resource for global Translator endpoint. + :param credential: Translator Entra Id Credentials used to access Translator Resource for global Translator endpoint. :type credential: ~azure.core.credentials_async.AsyncTokenCredential """ def __init__( self, credential: AsyncTokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any ) -> None: - super(AsyncTranslatorAADAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) + super(AsyncTranslatorEntraIdAuthenticationPolicy, self).__init__(credential, scopes, **kwargs) self.resource_id = resource_id self.region = region self.translator_credential = credential @@ -63,11 +63,11 @@ def set_authentication_policy(credential, kwargs): elif hasattr(credential, "get_token"): if not kwargs.get("authentication_policy"): if kwargs.get("region") and kwargs.get("resource_id"): - kwargs["authentication_policy"] = AsyncTranslatorAADAuthenticationPolicy( + kwargs["authentication_policy"] = AsyncTranslatorEntraIdAuthenticationPolicy( credential, kwargs["resource_id"], kwargs["region"], - kwargs.pop("credential_scopes", [DEFAULT_AAD_SCOPE]), + kwargs.pop("credential_scopes", [DEFAULT_ENTRA_ID_SCOPE]), ) else: if kwargs.get("resource_id") or kwargs.get("region"): From cde274b5bd7f1de752fdb0a71df3b3f1b7fc976e Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 13:10:18 -0700 Subject: [PATCH 18/32] format --- .../azure/ai/translation/text/aio/_patch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index db0848c2921b..db1c4fa5a209 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -13,7 +13,12 @@ from azure.core.credentials import AzureKeyCredential from azure.core.credentials_async import AsyncTokenCredential -from .._patch import DEFAULT_TOKEN_SCOPE, DEFAULT_ENTRA_ID_SCOPE, get_translation_endpoint, TranslatorAuthenticationPolicy +from .._patch import ( + DEFAULT_TOKEN_SCOPE, + DEFAULT_ENTRA_ID_SCOPE, + get_translation_endpoint, + TranslatorAuthenticationPolicy, +) from ._client import TextTranslationClient as ServiceClientGenerated From 9ada29ce884d135e01c6d43cf8d757a8a2071d77 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Fri, 17 May 2024 15:51:50 -0700 Subject: [PATCH 19/32] Fixing tests --- .../azure/ai/translation/text/_patch.py | 6 +++--- .../azure/ai/translation/text/aio/_patch.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 3001fdd8b94c..ca7dbcdcffa7 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -90,7 +90,7 @@ def set_authentication_policy(credential, kwargs): credential, kwargs["resource_id"], kwargs["region"], - kwargs.pop("credential_scopes", [DEFAULT_ENTRA_ID_SCOPE]), + kwargs.pop("scopes", DEFAULT_ENTRA_ID_SCOPE), ) else: if kwargs.get("resource_id") or kwargs.get("region"): @@ -98,7 +98,7 @@ def set_authentication_policy(credential, kwargs): "Both 'resource_id' and 'region' must be provided with a TokenCredential for authentication." ) kwargs["authentication_policy"] = BearerTokenCredentialPolicy( - credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs + credential, *kwargs.pop("scopes", [DEFAULT_TOKEN_SCOPE]), kwargs ) @@ -171,7 +171,7 @@ def __init__( def __init__(self, **kwargs): api_version = kwargs.get("api_version", "3.0") set_authentication_policy(kwargs.get("credential"), kwargs) - translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint"), api_version) + translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint", "https://api.cognitive.microsofttranslator.com"), api_version) super().__init__(endpoint=translation_endpoint, api_version=api_version, **kwargs) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index db1c4fa5a209..f05a06c3f025 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -72,7 +72,7 @@ def set_authentication_policy(credential, kwargs): credential, kwargs["resource_id"], kwargs["region"], - kwargs.pop("credential_scopes", [DEFAULT_ENTRA_ID_SCOPE]), + kwargs.pop("scopes", DEFAULT_ENTRA_ID_SCOPE), ) else: if kwargs.get("resource_id") or kwargs.get("region"): @@ -80,7 +80,7 @@ def set_authentication_policy(credential, kwargs): "Both 'resource_id' and 'region' must be provided with a TokenCredential for authentication." ) kwargs["authentication_policy"] = AsyncBearerTokenCredentialPolicy( - credential, *kwargs.pop("credential_scopes", [DEFAULT_TOKEN_SCOPE]), kwargs + credential, *kwargs.pop("scopes", [DEFAULT_TOKEN_SCOPE]), kwargs ) From 3fd120b5177890bc65f669a52ed049db46f73c06 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 20 May 2024 15:14:18 -0700 Subject: [PATCH 20/32] Fixing PR comment --- .../azure-ai-translation-text/CHANGELOG.md | 6 +- .../text/_operations/_operations.py | 298 +++++++++--------- .../ai/translation/text/_operations/_patch.py | 206 ++++++------ .../azure/ai/translation/text/_patch.py | 4 +- .../text/aio/_operations/_operations.py | 247 +++++++-------- .../text/aio/_operations/_patch.py | 206 ++++++------ .../ai/translation/text/models/_models.py | 130 ++++---- .../sample_text_translation_break_sentence.py | 12 +- ...le_text_translation_dictionary_examples.py | 6 +- ...mple_text_translation_dictionary_lookup.py | 8 +- .../sample_text_translation_translate.py | 144 ++++----- .../sample_text_translation_transliterate.py | 8 +- .../tests/test_break_sentence.py | 12 +- .../tests/test_break_sentence_async.py | 12 +- .../tests/test_dictionary_examples.py | 16 +- .../tests/test_dictionary_examples_async.py | 12 +- .../tests/test_dictionary_lookup.py | 16 +- .../tests/test_dictionary_lookup_async.py | 12 +- .../tests/test_get_languages.py | 26 +- .../tests/test_get_languages_async.py | 26 +- .../tests/test_translation.py | 134 ++++---- .../tests/test_translation_async.py | 136 ++++---- .../tests/test_transliteration.py | 12 +- .../tests/test_transliteration_async.py | 12 +- .../tsp-location.yaml | 4 +- 25 files changed, 812 insertions(+), 893 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index 95a3a5eb8b8e..5f652fd3c187 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -10,10 +10,10 @@ - All calls to the client using parameter 'content' have been changed to use parameter 'body'. - Users can call methods using just a string type instead of complex objects. - get_languages methods were changed to get_supported_languages. - - sent_len property was renamed to sentences_lengths. - - from_parameter parameter was renamed to source_language. + - sent_len property was renamed to sent_len. + - from_parameter parameter was renamed to from_parameter. - score parameter was renamed to confidence. - - from_script parameter was renamed to source_language_script. + - from_script parameter was renamed to from_script. - to_script parameter was renamed to _target_langauge_script. ### Bugs Fixed diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py index 2adc4f5b9c18..968c088aa7aa 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_operations.py @@ -84,18 +84,18 @@ def build_text_translation_get_supported_languages_request( # pylint: disable=n def build_text_translation_translate_request( *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> HttpRequest: @@ -110,9 +110,9 @@ def build_text_translation_translate_request( _url = "/translate" # Construct parameters - _params["to"] = [_SERIALIZER.query("target_languages", q, "str") if q is not None else "" for q in target_languages] - if source_language is not None: - _params["from"] = _SERIALIZER.query("source_language", source_language, "str") + _params["to"] = [_SERIALIZER.query("to", q, "str") if q is not None else "" for q in to] + if from_parameter is not None: + _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") if text_type is not None: _params["textType"] = _SERIALIZER.query("text_type", text_type, "str") if category is not None: @@ -125,12 +125,12 @@ def build_text_translation_translate_request( _params["includeAlignment"] = _SERIALIZER.query("include_alignment", include_alignment, "bool") if include_sentence_length is not None: _params["includeSentenceLength"] = _SERIALIZER.query("include_sentence_length", include_sentence_length, "bool") - if suggested_source_language is not None: - _params["suggestedFrom"] = _SERIALIZER.query("suggested_source_language", suggested_source_language, "str") - if source_language_script is not None: - _params["fromScript"] = _SERIALIZER.query("source_language_script", source_language_script, "str") - if target_language_script is not None: - _params["toScript"] = _SERIALIZER.query("target_language_script", target_language_script, "str") + if suggested_from is not None: + _params["suggestedFrom"] = _SERIALIZER.query("suggested_from", suggested_from, "str") + if from_script is not None: + _params["fromScript"] = _SERIALIZER.query("from_script", from_script, "str") + if to_script is not None: + _params["toScript"] = _SERIALIZER.query("to_script", to_script, "str") if allow_fallback is not None: _params["allowFallback"] = _SERIALIZER.query("allow_fallback", allow_fallback, "bool") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -146,12 +146,7 @@ def build_text_translation_translate_request( def build_text_translation_transliterate_request( # pylint: disable=name-too-long - *, - language: str, - source_language_script: str, - target_language_script: str, - client_trace_id: Optional[str] = None, - **kwargs: Any + *, language: str, from_script: str, to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -165,8 +160,8 @@ def build_text_translation_transliterate_request( # pylint: disable=name-too-lo # Construct parameters _params["language"] = _SERIALIZER.query("language", language, "str") - _params["fromScript"] = _SERIALIZER.query("source_language_script", source_language_script, "str") - _params["toScript"] = _SERIALIZER.query("target_language_script", target_language_script, "str") + _params["fromScript"] = _SERIALIZER.query("from_script", from_script, "str") + _params["toScript"] = _SERIALIZER.query("to_script", to_script, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers @@ -214,7 +209,7 @@ def build_text_translation_find_sentence_boundaries_request( # pylint: disable= def build_text_translation_lookup_dictionary_entries_request( # pylint: disable=name-too-long - *, source_language: str, target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any + *, from_parameter: str, to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -227,8 +222,8 @@ def build_text_translation_lookup_dictionary_entries_request( # pylint: disable _url = "/dictionary/lookup" # Construct parameters - _params["from"] = _SERIALIZER.query("source_language", source_language, "str") - _params["to"] = _SERIALIZER.query("target_language", target_language, "str") + _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") + _params["to"] = _SERIALIZER.query("to", to, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers @@ -242,7 +237,7 @@ def build_text_translation_lookup_dictionary_entries_request( # pylint: disable def build_text_translation_lookup_dictionary_examples_request( # pylint: disable=name-too-long - *, source_language: str, target_language: str, client_trace_id: Optional[str] = None, **kwargs: Any + *, from_parameter: str, to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) @@ -255,8 +250,8 @@ def build_text_translation_lookup_dictionary_examples_request( # pylint: disabl _url = "/dictionary/examples" # Construct parameters - _params["from"] = _SERIALIZER.query("source_language", source_language, "str") - _params["to"] = _SERIALIZER.query("target_language", target_language, "str") + _params["from"] = _SERIALIZER.query("from_parameter", from_parameter, "str") + _params["to"] = _SERIALIZER.query("to", to, "str") _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") # Construct headers @@ -465,18 +460,18 @@ def translate( self, body: List[_models.InputTextItem], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -488,17 +483,17 @@ def translate( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -507,7 +502,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -536,16 +531,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -642,18 +636,18 @@ def translate( self, body: IO[bytes], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -665,17 +659,17 @@ def translate( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -684,7 +678,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -713,16 +707,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -812,18 +805,18 @@ def translate( self, body: Union[List[_models.InputTextItem], IO[bytes]], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -835,17 +828,17 @@ def translate( :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -854,7 +847,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -883,16 +876,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -995,18 +987,18 @@ def translate( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( - target_languages=target_languages, + to=to, client_trace_id=client_trace_id, - source_language=source_language, + from_parameter=from_parameter, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_source_language=suggested_source_language, - source_language_script=source_language_script, - target_language_script=target_language_script, + suggested_from=suggested_from, + from_script=from_script, + to_script=to_script, allow_fallback=allow_fallback, content_type=content_type, api_version=self._config.api_version, @@ -1054,8 +1046,8 @@ def transliterate( body: List[_models.InputTextItem], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1070,14 +1062,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1115,8 +1107,8 @@ def transliterate( body: IO[bytes], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1131,14 +1123,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1169,8 +1161,8 @@ def transliterate( body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -1185,14 +1177,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1236,8 +1228,8 @@ def transliterate( _request = build_text_translation_transliterate_request( language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1522,8 +1514,8 @@ def lookup_dictionary_entries( self, body: List[_models.InputTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1535,14 +1527,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1637,8 +1629,8 @@ def lookup_dictionary_entries( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1650,14 +1642,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1745,8 +1737,8 @@ def lookup_dictionary_entries( self, body: Union[List[_models.InputTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1758,14 +1750,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1866,8 +1858,8 @@ def lookup_dictionary_entries( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( - source_language=source_language, - target_language=target_language, + from_parameter=from_parameter, + to=to, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1912,8 +1904,8 @@ def lookup_dictionary_examples( self, body: List[_models.DictionaryExampleTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1925,14 +1917,14 @@ def lookup_dictionary_examples( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1999,8 +1991,8 @@ def lookup_dictionary_examples( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -2012,14 +2004,14 @@ def lookup_dictionary_examples( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -2074,8 +2066,8 @@ def lookup_dictionary_examples( self, body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryExampleItem]: @@ -2087,14 +2079,14 @@ def lookup_dictionary_examples( :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -2162,8 +2154,8 @@ def lookup_dictionary_examples( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( - source_language=source_language, - target_language=target_language, + from_parameter=from_parameter, + to=to, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index fd335ed4fe76..3975fe42e1c3 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -19,18 +19,18 @@ def translate( self, body: List[str], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -42,17 +42,17 @@ def translate( :param body: Defines the content of the request. Required. :type body: list[str] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -61,7 +61,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -90,15 +90,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -193,18 +193,18 @@ def translate( self, body: List[_models.InputTextItem], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -216,17 +216,17 @@ def translate( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -235,7 +235,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -264,15 +264,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -369,18 +369,18 @@ def translate( self, body: IO[bytes], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -392,17 +392,17 @@ def translate( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -411,7 +411,7 @@ def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -440,15 +440,15 @@ def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -537,18 +537,18 @@ def translate( self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -563,18 +563,18 @@ def translate( return super().translate( body=request_body, - target_languages=target_languages, + to=to, client_trace_id=client_trace_id, - source_language=source_language, + from_parameter=from_parameter, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_source_language=suggested_source_language, - source_language_script=source_language_script, - target_language_script=target_language_script, + suggested_from=suggested_from, + from_script=from_script, + to_script=to_script, allow_fallback=allow_fallback, **kwargs ) @@ -585,8 +585,8 @@ def transliterate( body: List[str], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -601,14 +601,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -646,8 +646,8 @@ def transliterate( body: List[_models.InputTextItem], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -662,14 +662,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -707,8 +707,8 @@ def transliterate( body: IO[bytes], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -723,14 +723,14 @@ def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -760,8 +760,8 @@ def transliterate( body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -777,8 +777,8 @@ def transliterate( return super().transliterate( body=request_body, language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, client_trace_id=client_trace_id, **kwargs ) @@ -999,8 +999,8 @@ def lookup_dictionary_entries( self, body: List[str], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1012,14 +1012,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[str] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1080,7 +1080,7 @@ def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1114,8 +1114,8 @@ def lookup_dictionary_entries( self, body: List[_models.InputTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1127,14 +1127,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1195,7 +1195,7 @@ def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1229,8 +1229,8 @@ def lookup_dictionary_entries( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1242,14 +1242,14 @@ def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1303,7 +1303,7 @@ def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1336,8 +1336,8 @@ def lookup_dictionary_entries( self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1351,11 +1351,7 @@ def lookup_dictionary_entries( request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return super().lookup_dictionary_entries( - body=request_body, - source_language=source_language, - target_language=target_language, - client_trace_id=client_trace_id, - **kwargs + body=request_body, from_parameter=from_parameter, to=to, client_trace_id=client_trace_id, **kwargs ) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index ca7dbcdcffa7..34eaaf318c7d 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -171,7 +171,9 @@ def __init__( def __init__(self, **kwargs): api_version = kwargs.get("api_version", "3.0") set_authentication_policy(kwargs.get("credential"), kwargs) - translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint", "https://api.cognitive.microsofttranslator.com"), api_version) + translation_endpoint = get_translation_endpoint( + kwargs.pop("endpoint", "https://api.cognitive.microsofttranslator.com"), api_version + ) super().__init__(endpoint=translation_endpoint, api_version=api_version, **kwargs) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py index 3fe3bdf398ea..d1560bb354c8 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_operations.py @@ -243,18 +243,18 @@ async def translate( self, body: List[_models.InputTextItem], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -266,17 +266,17 @@ async def translate( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -285,7 +285,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -314,16 +314,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -420,18 +419,18 @@ async def translate( self, body: IO[bytes], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -443,17 +442,17 @@ async def translate( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -462,7 +461,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -491,16 +490,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -590,18 +588,18 @@ async def translate( self, body: Union[List[_models.InputTextItem], IO[bytes]], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -613,17 +611,17 @@ async def translate( :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must - be one of the supported languages included + :keyword to: Specifies the language of the output text. The target language must be one of the + supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -632,7 +630,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -661,16 +659,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input - text can't be identified. + :keyword suggested_from: Specifies a fallback language if the language of the input text can't + be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is - None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -773,18 +770,18 @@ async def translate( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_translate_request( - target_languages=target_languages, + to=to, client_trace_id=client_trace_id, - source_language=source_language, + from_parameter=from_parameter, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_source_language=suggested_source_language, - source_language_script=source_language_script, - target_language_script=target_language_script, + suggested_from=suggested_from, + from_script=from_script, + to_script=to_script, allow_fallback=allow_fallback, content_type=content_type, api_version=self._config.api_version, @@ -832,8 +829,8 @@ async def transliterate( body: List[_models.InputTextItem], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -848,14 +845,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -893,8 +890,8 @@ async def transliterate( body: IO[bytes], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -909,14 +906,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -947,8 +944,8 @@ async def transliterate( body: Union[List[_models.InputTextItem], IO[bytes]], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -963,14 +960,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported - languages using the transliteration scope, + :keyword from_script: Specifies the script used by the input text. Look up supported languages + using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using - the transliteration scope, to find output + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the + transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1014,8 +1011,8 @@ async def transliterate( _request = build_text_translation_transliterate_request( language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1300,8 +1297,8 @@ async def lookup_dictionary_entries( self, body: List[_models.InputTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1313,14 +1310,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1415,8 +1412,8 @@ async def lookup_dictionary_entries( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1428,14 +1425,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1523,8 +1520,8 @@ async def lookup_dictionary_entries( self, body: Union[List[_models.InputTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1536,14 +1533,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Is either a [InputTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] or IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1644,8 +1641,8 @@ async def lookup_dictionary_entries( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_entries_request( - source_language=source_language, - target_language=target_language, + from_parameter=from_parameter, + to=to, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, @@ -1690,8 +1687,8 @@ async def lookup_dictionary_examples( self, body: List[_models.DictionaryExampleTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1703,14 +1700,14 @@ async def lookup_dictionary_examples( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1777,8 +1774,8 @@ async def lookup_dictionary_examples( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1790,14 +1787,14 @@ async def lookup_dictionary_examples( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1852,8 +1849,8 @@ async def lookup_dictionary_examples( self, body: Union[List[_models.DictionaryExampleTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryExampleItem]: @@ -1865,14 +1862,14 @@ async def lookup_dictionary_examples( :param body: Defines the content of the request. Is either a [DictionaryExampleTextItem] type or a IO[bytes] type. Required. :type body: list[~azure.ai.translation.text.models.DictionaryExampleTextItem] or IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1940,8 +1937,8 @@ async def lookup_dictionary_examples( _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore _request = build_text_translation_lookup_dictionary_examples_request( - source_language=source_language, - target_language=target_language, + from_parameter=from_parameter, + to=to, client_trace_id=client_trace_id, content_type=content_type, api_version=self._config.api_version, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index 31c642070b2c..e038458c3929 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -19,18 +19,18 @@ async def translate( self, body: List[str], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -42,17 +42,17 @@ async def translate( :param body: Defines the content of the request. Required. :type body: list[str] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -61,7 +61,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -90,15 +90,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -193,18 +193,18 @@ async def translate( self, body: List[_models.InputTextItem], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -216,17 +216,17 @@ async def translate( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -235,7 +235,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -264,15 +264,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -369,18 +369,18 @@ async def translate( self, body: IO[bytes], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, content_type: str = "application/json", **kwargs: Any @@ -392,17 +392,17 @@ async def translate( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword target_languages: Specifies the language of the output text. The target language must be one of the + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the translation scope. For example, use to=de to translate to German. It's possible to translate to multiple languages simultaneously by repeating the parameter in the query string. For example, use to=de&to=it to translate to German and Italian. Required. - :paramtype target_languages: list[str] + :paramtype to: list[str] :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str - :keyword source_language: Specifies the language of the input text. Find which languages are + :keyword from_parameter: Specifies the language of the input text. Find which languages are available to translate from by looking up supported languages using the translation scope. If the from parameter isn't specified, @@ -411,7 +411,7 @@ async def translate( You must use the from parameter rather than autodetection when using the dynamic dictionary feature. Note: the dynamic dictionary feature is case-sensitive. Default value is None. - :paramtype source_language: str + :paramtype from_parameter: str :keyword text_type: 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. Known values are: "Plain" and @@ -440,15 +440,15 @@ async def translate( input text and the translated text. Possible values are: true or false (default). Default value is None. :paramtype include_sentence_length: bool - :keyword suggested_source_language: Specifies a fallback language if the language of the input text can't + :keyword suggested_from: Specifies a fallback language if the language of the input text can't be identified. Language autodetection is applied when the from parameter is omitted. If detection fails, the suggestedFrom language will be assumed. Default value is None. - :paramtype suggested_source_language: str - :keyword source_language_script: Specifies the script of the input text. Default value is None. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the script of the translated text. Default value is None. - :paramtype target_language_script: str + :paramtype suggested_from: str + :keyword from_script: Specifies the script of the input text. Default value is None. + :paramtype from_script: str + :keyword to_script: Specifies the script of the translated text. Default value is None. + :paramtype to_script: str :keyword allow_fallback: 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. @@ -537,18 +537,18 @@ async def translate( self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - target_languages: List[str], + to: List[str], client_trace_id: Optional[str] = None, - source_language: Optional[str] = None, + from_parameter: Optional[str] = None, text_type: Optional[Union[str, _models.TextType]] = None, category: Optional[str] = None, profanity_action: Optional[Union[str, _models.ProfanityAction]] = None, profanity_marker: Optional[Union[str, _models.ProfanityMarker]] = None, include_alignment: Optional[bool] = None, include_sentence_length: Optional[bool] = None, - suggested_source_language: Optional[str] = None, - source_language_script: Optional[str] = None, - target_language_script: Optional[str] = None, + suggested_from: Optional[str] = None, + from_script: Optional[str] = None, + to_script: Optional[str] = None, allow_fallback: Optional[bool] = None, **kwargs: Any ) -> List[_models.TranslatedTextItem]: @@ -563,18 +563,18 @@ async def translate( return await super().translate( body=request_body, - target_languages=target_languages, + to=to, client_trace_id=client_trace_id, - source_language=source_language, + from_parameter=from_parameter, text_type=text_type, category=category, profanity_action=profanity_action, profanity_marker=profanity_marker, include_alignment=include_alignment, include_sentence_length=include_sentence_length, - suggested_source_language=suggested_source_language, - source_language_script=source_language_script, - target_language_script=target_language_script, + suggested_from=suggested_from, + from_script=from_script, + to_script=to_script, allow_fallback=allow_fallback, **kwargs ) @@ -585,8 +585,8 @@ async def transliterate( body: List[str], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -601,14 +601,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -646,8 +646,8 @@ async def transliterate( body: List[_models.InputTextItem], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -662,14 +662,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -707,8 +707,8 @@ async def transliterate( body: IO[bytes], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -723,14 +723,14 @@ async def transliterate( Possible languages are listed in the transliteration scope obtained by querying the service for its supported languages. Required. :paramtype language: str - :keyword source_language_script: Specifies the script used by the input text. Look up supported languages + :keyword from_script: Specifies the script used by the input text. Look up supported languages using the transliteration scope, to find input scripts available for the selected language. Required. - :paramtype source_language_script: str - :keyword target_language_script: Specifies the output script. Look up supported languages using the + :paramtype from_script: str + :keyword to_script: Specifies the output script. Look up supported languages using the transliteration scope, to find output scripts available for the selected combination of input language and input script. Required. - :paramtype target_language_script: str + :paramtype to_script: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -760,8 +760,8 @@ async def transliterate( body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, language: str, - source_language_script: str, - target_language_script: str, + from_script: str, + to_script: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.TransliteratedText]: @@ -777,8 +777,8 @@ async def transliterate( return await super().transliterate( body=request_body, language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, client_trace_id=client_trace_id, **kwargs ) @@ -999,8 +999,8 @@ async def lookup_dictionary_entries( self, body: List[str], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1012,14 +1012,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[str] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1080,7 +1080,7 @@ async def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1114,8 +1114,8 @@ async def lookup_dictionary_entries( self, body: List[_models.InputTextItem], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1127,14 +1127,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: list[~azure.ai.translation.text.models.InputTextItem] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1195,7 +1195,7 @@ async def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1229,8 +1229,8 @@ async def lookup_dictionary_entries( self, body: IO[bytes], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, content_type: str = "application/json", **kwargs: Any @@ -1242,14 +1242,14 @@ async def lookup_dictionary_entries( :param body: Defines the content of the request. Required. :type body: IO[bytes] - :keyword source_language: Specifies the language of the input text. + :keyword from_parameter: Specifies the language of the input text. The source language must be one of the supported languages included in the dictionary scope. Required. - :paramtype source_language: str - :keyword target_language: Specifies the language of the output text. + :paramtype from_parameter: str + :keyword to: Specifies the language of the output text. The target language must be one of the supported languages included in the dictionary scope. Required. - :paramtype target_language: str + :paramtype to: str :keyword client_trace_id: A client-generated GUID to uniquely identify the request. Default value is None. :paramtype client_trace_id: str @@ -1303,7 +1303,7 @@ async def lookup_dictionary_entries( "bad" examples. Required. } ], - "confidence": 0.0, # A value between 0.0 and 1.0 + "score": 0.0, # 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 @@ -1336,8 +1336,8 @@ async def lookup_dictionary_entries( self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, - source_language: str, - target_language: str, + from_parameter: str, + to: str, client_trace_id: Optional[str] = None, **kwargs: Any ) -> List[_models.DictionaryLookupItem]: @@ -1351,11 +1351,7 @@ async def lookup_dictionary_entries( request_body = cast(Union[List[_models.InputTextItem], IO[bytes]], body) return await super().lookup_dictionary_entries( - body=request_body, - source_language=source_language, - target_language=target_language, - client_trace_id=client_trace_id, - **kwargs + body=request_body, from_parameter=from_parameter, to=to, client_trace_id=client_trace_id, **kwargs ) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py index a22e3cf68468..e636f1f0a345 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/_models.py @@ -30,8 +30,8 @@ class BackTranslation(_model_base.Model): a form best suited for end-user display. Required. :vartype display_text: str - :ivar examples_count: An integer representing the number of examples that are available for - this translation pair. + :ivar num_examples: 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 @@ -40,7 +40,7 @@ class BackTranslation(_model_base.Model): 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. Required. - :vartype examples_count: int + :vartype num_examples: int :ivar frequency_count: 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 @@ -55,7 +55,7 @@ class BackTranslation(_model_base.Model): display_text: str = rest_field(name="displayText") """A string giving the source term that is a back-translation of the target in a form best suited for end-user display. Required.""" - examples_count: int = rest_field(name="numExamples") + num_examples: int = rest_field(name="numExamples") """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 @@ -76,7 +76,7 @@ def __init__( *, normalized_text: str, display_text: str, - examples_count: int, + num_examples: int, frequency_count: int, ): ... @@ -99,17 +99,16 @@ class BreakSentenceItem(_model_base.Model): :ivar detected_language: The detectedLanguage property is only present in the result object when language auto-detection is requested. :vartype detected_language: ~azure.ai.translation.text.models.DetectedLanguage - :ivar sentences_lengths: An integer array representing the lengths of the sentences in the - input text. + :ivar sent_len: 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. Required. - :vartype sentences_lengths: list[int] + :vartype sent_len: list[int] """ detected_language: Optional["_models.DetectedLanguage"] = rest_field(name="detectedLanguage") """The detectedLanguage property is only present in the result object when language auto-detection is requested.""" - sentences_lengths: List[int] = rest_field(name="sentLen") + sent_len: List[int] = rest_field(name="sentLen") """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. Required.""" @@ -118,7 +117,7 @@ class BreakSentenceItem(_model_base.Model): def __init__( self, *, - sentences_lengths: List[int], + sent_len: List[int], detected_language: Optional["_models.DetectedLanguage"] = None, ): ... @@ -140,14 +139,14 @@ class DetectedLanguage(_model_base.Model): :ivar language: A string representing the code of the detected language. Required. :vartype language: str - :ivar confidence: A float value indicating the confidence in the result. + :ivar score: A float value indicating the confidence in the result. The score is between zero and one and a low score indicates a low confidence. Required. - :vartype confidence: float + :vartype score: float """ language: str = rest_field() """A string representing the code of the detected language. Required.""" - confidence: float = rest_field(name="score") + score: float = rest_field() """A float value indicating the confidence in the result. The score is between zero and one and a low score indicates a low confidence. Required.""" @@ -156,7 +155,7 @@ def __init__( self, *, language: str, - confidence: float, + score: float, ): ... @overload @@ -615,9 +614,9 @@ class LanguageScript(_model_base.Model): :ivar native_name: Display name of the language in the locale native for the language. Required. :vartype native_name: str - :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for - left-to-right languages. Required. Known values are: "ltr" and "rtl". - :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right + languages. Required. Known values are: "ltr" and "rtl". + :vartype dir: str or ~azure.ai.translation.text.models.LanguageDirectionality """ code: str = rest_field() @@ -626,7 +625,7 @@ class LanguageScript(_model_base.Model): """Display name of the script in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for the language. Required.""" - directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + dir: Union[str, "_models.LanguageDirectionality"] = rest_field() """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. Known values are: \"ltr\" and \"rtl\".""" @@ -637,7 +636,7 @@ def __init__( code: str, name: str, native_name: str, - directionality: Union[str, "_models.LanguageDirectionality"], + dir: Union[str, "_models.LanguageDirectionality"], ): ... @overload @@ -656,23 +655,23 @@ class SentenceBoundaries(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar source_sentences_lengths: An integer array representing the lengths of the sentences in - the input text. + :ivar src_sent_len: 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. Required. - :vartype source_sentences_lengths: list[int] - :ivar translated_sentences_lengths: An integer array representing the lengths of the sentences - in the translated text. + :vartype src_sent_len: list[int] + :ivar trans_sent_len: 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. Required. - :vartype translated_sentences_lengths: list[int] + :vartype trans_sent_len: list[int] """ - source_sentences_lengths: List[int] = rest_field(name="srcSentLen") + src_sent_len: List[int] = rest_field(name="srcSentLen") """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. Required.""" - translated_sentences_lengths: List[int] = rest_field(name="transSentLen") + trans_sent_len: List[int] = rest_field(name="transSentLen") """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. Required.""" @@ -681,8 +680,8 @@ class SentenceBoundaries(_model_base.Model): def __init__( self, *, - source_sentences_lengths: List[int], - translated_sentences_lengths: List[int], + src_sent_len: List[int], + trans_sent_len: List[int], ): ... @overload @@ -707,9 +706,9 @@ class SourceDictionaryLanguage(_model_base.Model): :ivar native_name: Display name of the language in the locale native for this language. Required. :vartype native_name: str - :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for - left-to-right languages. Required. Known values are: "ltr" and "rtl". - :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right + languages. Required. Known values are: "ltr" and "rtl". + :vartype dir: str or ~azure.ai.translation.text.models.LanguageDirectionality :ivar translations: List of languages with alterative translations and examples for the query expressed in the source language. Required. :vartype translations: list[~azure.ai.translation.text.models.TargetDictionaryLanguage] @@ -719,7 +718,7 @@ class SourceDictionaryLanguage(_model_base.Model): """Display name of the language in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for this language. Required.""" - directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + dir: Union[str, "_models.LanguageDirectionality"] = rest_field() """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. Known values are: \"ltr\" and \"rtl\".""" translations: List["_models.TargetDictionaryLanguage"] = rest_field() @@ -732,7 +731,7 @@ def __init__( *, name: str, native_name: str, - directionality: Union[str, "_models.LanguageDirectionality"], + dir: Union[str, "_models.LanguageDirectionality"], translations: List["_models.TargetDictionaryLanguage"], ): ... @@ -788,9 +787,9 @@ class TargetDictionaryLanguage(_model_base.Model): :ivar native_name: Display name of the language in the locale native for this language. Required. :vartype native_name: str - :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for - left-to-right languages. Required. Known values are: "ltr" and "rtl". - :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right + languages. Required. Known values are: "ltr" and "rtl". + :vartype dir: str or ~azure.ai.translation.text.models.LanguageDirectionality :ivar code: Language code identifying the target language. Required. :vartype code: str """ @@ -799,7 +798,7 @@ class TargetDictionaryLanguage(_model_base.Model): """Display name of the language in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for this language. Required.""" - directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + dir: Union[str, "_models.LanguageDirectionality"] = rest_field() """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. Known values are: \"ltr\" and \"rtl\".""" code: str = rest_field() @@ -811,7 +810,7 @@ def __init__( *, name: str, native_name: str, - directionality: Union[str, "_models.LanguageDirectionality"], + dir: Union[str, "_models.LanguageDirectionality"], code: str, ): ... @@ -831,8 +830,8 @@ class TranslatedTextAlignment(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar projections: Maps input text to translated text. The alignment information is only - provided when the request + :ivar proj: 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 @@ -841,10 +840,10 @@ class TranslatedTextAlignment(_model_base.Model): words may be non-contiguous. When no alignment information is available, the alignment element will be empty. Required. - :vartype projections: str + :vartype proj: str """ - projections: str = rest_field(name="proj") + proj: str = rest_field() """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]]. @@ -859,7 +858,7 @@ class TranslatedTextAlignment(_model_base.Model): def __init__( self, *, - projections: str, + proj: str, ): ... @overload @@ -941,16 +940,16 @@ class TranslationLanguage(_model_base.Model): :ivar native_name: Display name of the language in the locale native for this language. Required. :vartype native_name: str - :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for - left-to-right languages. Required. Known values are: "ltr" and "rtl". - :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality + :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right + languages. Required. Known values are: "ltr" and "rtl". + :vartype dir: str or ~azure.ai.translation.text.models.LanguageDirectionality """ name: str = rest_field() """Display name of the language in the locale requested via Accept-Language header. Required.""" native_name: str = rest_field(name="nativeName") """Display name of the language in the locale native for this language. Required.""" - directionality: Union[str, "_models.LanguageDirectionality"] = rest_field(name="dir") + dir: Union[str, "_models.LanguageDirectionality"] = rest_field() """Directionality, which is rtl for right-to-left languages or ltr for left-to-right languages. Required. Known values are: \"ltr\" and \"rtl\".""" @@ -960,7 +959,7 @@ def __init__( *, name: str, native_name: str, - directionality: Union[str, "_models.LanguageDirectionality"], + dir: Union[str, "_models.LanguageDirectionality"], ): ... @overload @@ -979,9 +978,8 @@ class TranslationText(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar target_language: A string representing the language code of the target language. - Required. - :vartype target_language: str + :ivar to: A string representing the language code of the target language. Required. + :vartype to: str :ivar text: A string giving the translated text. Required. :vartype text: str :ivar transliteration: An object giving the translated text in the script specified by the @@ -989,11 +987,11 @@ class TranslationText(_model_base.Model): :vartype transliteration: ~azure.ai.translation.text.models.TransliteratedText :ivar alignment: Alignment information. :vartype alignment: ~azure.ai.translation.text.models.TranslatedTextAlignment - :ivar sentence_boundaries: Sentence boundaries in the input and output texts. - :vartype sentence_boundaries: ~azure.ai.translation.text.models.SentenceBoundaries + :ivar sent_len: Sentence boundaries in the input and output texts. + :vartype sent_len: ~azure.ai.translation.text.models.SentenceBoundaries """ - target_language: str = rest_field(name="to") + to: str = rest_field() """A string representing the language code of the target language. Required.""" text: str = rest_field() """A string giving the translated text. Required.""" @@ -1001,18 +999,18 @@ class TranslationText(_model_base.Model): """An object giving the translated text in the script specified by the toScript parameter.""" alignment: Optional["_models.TranslatedTextAlignment"] = rest_field() """Alignment information.""" - sentence_boundaries: Optional["_models.SentenceBoundaries"] = rest_field(name="sentLen") + sent_len: Optional["_models.SentenceBoundaries"] = rest_field(name="sentLen") """Sentence boundaries in the input and output texts.""" @overload def __init__( self, *, - target_language: str, + to: str, text: str, transliteration: Optional["_models.TransliteratedText"] = None, alignment: Optional["_models.TranslatedTextAlignment"] = None, - sentence_boundaries: Optional["_models.SentenceBoundaries"] = None, + sent_len: Optional["_models.SentenceBoundaries"] = None, ): ... @overload @@ -1039,14 +1037,14 @@ class TransliterableScript(LanguageScript): :ivar native_name: Display name of the language in the locale native for the language. Required. :vartype native_name: str - :ivar directionality: Directionality, which is rtl for right-to-left languages or ltr for - left-to-right languages. Required. Known values are: "ltr" and "rtl". - :vartype directionality: str or ~azure.ai.translation.text.models.LanguageDirectionality - :ivar target_language_scripts: List of scripts available to convert text to. Required. - :vartype target_language_scripts: list[~azure.ai.translation.text.models.LanguageScript] + :ivar dir: Directionality, which is rtl for right-to-left languages or ltr for left-to-right + languages. Required. Known values are: "ltr" and "rtl". + :vartype dir: str or ~azure.ai.translation.text.models.LanguageDirectionality + :ivar to_scripts: List of scripts available to convert text to. Required. + :vartype to_scripts: list[~azure.ai.translation.text.models.LanguageScript] """ - target_language_scripts: List["_models.LanguageScript"] = rest_field(name="toScripts") + to_scripts: List["_models.LanguageScript"] = rest_field(name="toScripts") """List of scripts available to convert text to. Required.""" @overload @@ -1056,8 +1054,8 @@ def __init__( code: str, name: str, native_name: str, - directionality: Union[str, "_models.LanguageDirectionality"], - target_language_scripts: List["_models.LanguageScript"], + dir: Union[str, "_models.LanguageDirectionality"], + to_scripts: List["_models.LanguageScript"], ): ... @overload diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py index 204cbf8044c6..06a5fdf20e41 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py @@ -37,12 +37,12 @@ def get_text_sentence_boundaries(): # [START get_text_sentence_boundaries] try: - source_language = "zh-Hans" + from_parameter = "zh-Hans" source_script = "Latn" input_text_elements = ["zhè shì gè cè shì。"] response = text_translator.find_sentence_boundaries( - body=input_text_elements, language=source_language, script=source_script + body=input_text_elements, language=from_parameter, script=source_script ) sentence_boundaries = response[0] if response else None @@ -50,10 +50,10 @@ def get_text_sentence_boundaries(): detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sentences_lengths: + for boundary in sentence_boundaries.sent_len: print(boundary) except HttpResponseError as exception: @@ -76,10 +76,10 @@ def get_text_sentence_boundaries_auto(): detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sentences_lengths: + for boundary in sentence_boundaries.sent_len: print(boundary) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py index a717621b2f2b..59b033eb928e 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py @@ -40,12 +40,12 @@ def get_text_translation_dictionary_examples(): # [START get_text_translation_dictionary_examples] try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py index 0ad97a927501..e322843795bf 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py @@ -40,19 +40,19 @@ def get_text_translation_dictionary_lookup(): # [START get_text_translation_dictionary_lookup] try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None if dictionary_entry: print(f"For the given input {len(dictionary_entry.translations)} entries were found in the dictionary.") print( - f"First entry: '{dictionary_entry.translations[0].display_target}', confidence: {dictionary_entry.translations[0].confidence}." + f"First entry: '{dictionary_entry.translations[0].display_target}', score: {dictionary_entry.translations[0].score}." ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py index d71bf0a63c93..027981ab6c0d 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py @@ -41,20 +41,16 @@ def get_text_translation(): # [START get_text_translation] try: - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = text_translator.translate(body=input_text_elements, to=to, from_parameter=from_parameter) translation = response[0] if response else None if translation: for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -67,22 +63,20 @@ def get_text_translation(): def get_text_translation_auto(): # [START get_text_translation_auto] try: - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages) + response = text_translator.translate(body=input_text_elements, to=to) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -95,18 +89,18 @@ def get_text_translation_auto(): def get_text_translation_with_transliteration(): # [START get_text_translation_with_transliteration] try: - source_language_script = "Latn" + from_script = "Latn" from_language = "ar" - target_language_script = "Latn" - target_languages = ["zh-Hans"] + to_script = "Latn" + to = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = text_translator.translate( body=input_text_elements, - target_languages=target_languages, - source_language_script=source_language_script, - source_language=from_language, - target_language_script=target_language_script, + to=to, + from_script=from_script, + from_parameter=from_language, + to_script=to_script, ) translation = response[0] if response else None @@ -131,21 +125,21 @@ def get_text_translation_with_transliteration(): def get_text_translation_multiple_inputs(): # [START get_text_translation_multiple_inputs] try: - target_languages = ["cs"] + to = ["cs"] input_text_elements = [ "This is a test.", "Esto es una prueba.", "Dies ist ein Test.", ] - translations = text_translator.translate(body=input_text_elements, target_languages=target_languages) + translations = text_translator.translate(body=input_text_elements, to=to) for translation in translations: print( - f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.confidence if translation.detected_language else None}." + f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.score if translation.detected_language else None}." ) print( - f"Text was translated to: '{translation.translations[0].target_language if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." + f"Text was translated to: '{translation.translations[0].to if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." ) except HttpResponseError as exception: @@ -158,22 +152,20 @@ def get_text_translation_multiple_inputs(): def get_text_translation_multiple_languages(): # [START get_text_translation_multiple_languages] try: - target_languages = ["cs", "es", "de"] + to = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, target_languages=target_languages) + response = text_translator.translate(body=input_text_elements, to=to) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -186,24 +178,20 @@ def get_text_translation_type(): # [START get_text_translation_type] try: text_type = TextType.HTML - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, text_type=text_type - ) + response = text_translator.translate(body=input_text_elements, to=to, text_type=text_type) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -216,25 +204,23 @@ def get_text_translation_exclude(): # [START get_text_translation_exclude] try: text_type = TextType.HTML - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = [ '
This will not be translated.
This will be translated.
' ] response = text_translator.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, + to=to, + from_parameter=from_parameter, text_type=text_type, ) translation = response[0] if response else None if translation: for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -246,22 +232,18 @@ def get_text_translation_exclude(): def get_text_translation_entity(): # [START get_text_translation_entity] try: - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = [ 'The word wordomatic is a dictionary entry.' ] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = text_translator.translate(body=input_text_elements, to=to, from_parameter=from_parameter) translation = response[0] if response else None if translation: for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -275,12 +257,12 @@ def get_text_translation_profanity(): try: profanity_action = ProfanityAction.MARKED profanity_maker = ProfanityMarker.ASTERISK - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is ***."] response = text_translator.translate( body=input_text_elements, - target_languages=target_languages, + to=to, profanity_action=profanity_action, profanity_marker=profanity_maker, ) @@ -290,12 +272,10 @@ def get_text_translation_profanity(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: @@ -308,26 +288,22 @@ def get_text_translation_alignment(): # [START get_text_translation_alignment] try: include_alignment = True - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["The answer lies in machine translation."] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, include_alignment=include_alignment - ) + response = text_translator.translate(body=input_text_elements, to=to, include_alignment=include_alignment) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") if translated_text.alignment: - print(f"Alignments: {translated_text.alignment.projections}") + print(f"Alignments: {translated_text.alignment.proj}") except HttpResponseError as exception: if exception.error is not None: @@ -340,11 +316,11 @@ def get_text_translation_sentence_length(): # [START get_text_translation_sentence_length] try: include_sentence_length = True - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=to, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -352,17 +328,13 @@ def get_text_translation_sentence_length(): detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) - if translated_text.sentence_boundaries: - print(f"Source Sentence length: {translated_text.sentence_boundaries.source_sentences_lengths}") - print( - f"Translated Sentence length: {translated_text.sentence_boundaries.translated_sentences_lengths}" - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") + if translated_text.sent_len: + print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") + print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") except HttpResponseError as exception: if exception.error is not None: @@ -375,24 +347,20 @@ def get_text_translation_custom(): # [START get_text_translation_custom] try: category = "<>" - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate( - body=input_text_elements, target_languages=target_languages, category=category - ) + response = text_translator.translate(body=input_text_elements, to=to, category=category) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: - print( - f"Text was translated to: '{translated_text.target_language}' and the result is: '{translated_text.text}'." - ) + print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") except HttpResponseError as exception: if exception.error is not None: diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py index 9e4415e2be63..14ea30724109 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py @@ -41,15 +41,15 @@ def get_text_transliteration(): # [START get_text_transliteration] try: language = "zh-Hans" - source_language_script = "Hans" - target_language_script = "Latn" + from_script = "Hans" + to_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( body=input_text_elements, language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, ) transliteration = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py index d2ecc9c98ea6..b0d0489983ff 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py @@ -21,8 +21,8 @@ def test_autodetect(self, **kwargs): response = client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence > 0.9 - assert response[0].sentences_lengths[0] == 11 + assert response[0].detected_language.score > 0.9 + assert response[0].sent_len[0] == 11 @TextTranslationPreparer() @recorded_by_proxy @@ -40,7 +40,7 @@ def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].sentences_lengths[i] + assert expected_length == response[0].sent_len[i] @TextTranslationPreparer() @recorded_by_proxy @@ -54,7 +54,7 @@ def test_with_language_script(self, **kwargs): response = client.find_sentence_boundaries(body=input_text_elements, language="zh-Hans", script="Latn") assert response is not None - assert response[0].sentences_lengths[0] == 18 + assert response[0].sent_len[0] == 18 @TextTranslationPreparer() @recorded_by_proxy @@ -73,5 +73,5 @@ def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].sentences_lengths[0] == 11 - assert response[1].sentences_lengths[0] == 32 + assert response[0].sent_len[0] == 11 + assert response[1].sent_len[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py index 589d4b25e450..6213bc9e431d 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_break_sentence_async.py @@ -22,8 +22,8 @@ async def test_autodetect(self, **kwargs): response = await client.find_sentence_boundaries(body=input_text_elements) assert response is not None assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence > 0.9 - assert response[0].sentences_lengths[0] == 11 + assert response[0].detected_language.score > 0.9 + assert response[0].sent_len[0] == 11 @TextTranslationPreparer() @recorded_by_proxy_async @@ -42,7 +42,7 @@ async def test_with_language(self, **kwargs): assert response is not None expected_lengths = [78, 41, 110, 46] for i, expected_length in enumerate(expected_lengths): - assert expected_length == response[0].sentences_lengths[i] + assert expected_length == response[0].sent_len[i] @TextTranslationPreparer() @recorded_by_proxy_async @@ -59,7 +59,7 @@ async def test_with_language_script(self, **kwargs): body=input_text_elements, language="zh-Hans", script="Latn" ) assert response is not None - assert response[0].sentences_lengths[0] == 18 + assert response[0].sent_len[0] == 18 @TextTranslationPreparer() @recorded_by_proxy_async @@ -79,5 +79,5 @@ async def test_with_multiple_languages(self, **kwargs): assert response is not None assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "ar" - assert response[0].sentences_lengths[0] == 11 - assert response[1].sentences_lengths[0] == 32 + assert response[0].sent_len[0] == 11 + assert response[1].sent_len[0] == 32 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py index e243d2a0da63..bde073049195 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples.py @@ -18,13 +18,11 @@ def test_single_input_element(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] - response = client.lookup_dictionary_examples( - body=input_text_elements, source_language=source_language, target_language=target_language - ) + response = client.lookup_dictionary_examples(body=input_text_elements, from_parameter=from_parameter, to=to) assert response is not None assert response[0].normalized_source == "fly" assert response[0].normalized_target == "volar" @@ -37,16 +35,14 @@ def test_multiple_input_elements(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [ DictionaryExampleTextItem(text="fly", translation="volar"), DictionaryExampleTextItem(text="beef", translation="came"), ] - response = client.lookup_dictionary_examples( - body=input_text_elements, source_language=source_language, target_language=target_language - ) + response = client.lookup_dictionary_examples(body=input_text_elements, from_parameter=from_parameter, to=to) assert response is not None assert len(response) == 2 assert response[0].normalized_source == "fly" diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py index 5bae5ce49a72..014d4e0040a1 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_examples_async.py @@ -18,13 +18,13 @@ async def test_single_input_element(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] async with client: response = await client.lookup_dictionary_examples( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) assert response is not None assert response[0].normalized_source == "fly" @@ -38,8 +38,8 @@ async def test_multiple_input_elements(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [ DictionaryExampleTextItem(text="fly", translation="volar"), DictionaryExampleTextItem(text="beef", translation="came"), @@ -47,7 +47,7 @@ async def test_multiple_input_elements(self, **kwargs): async with client: response = await client.lookup_dictionary_examples( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py index 25b3e02787cc..b1703ec3d45c 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup.py @@ -17,13 +17,11 @@ def test_single_input_element(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly"] - response = client.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language - ) + response = client.lookup_dictionary_entries(body=input_text_elements, from_parameter=from_parameter, to=to) assert response is not None assert response[0].normalized_source == "fly" assert response[0].display_source == "fly" @@ -36,13 +34,11 @@ def test_multiple_input_elements(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly", "fox"] - response = client.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language - ) + response = client.lookup_dictionary_entries(body=input_text_elements, from_parameter=from_parameter, to=to) assert response is not None assert len(response) == 2 assert response[0].normalized_source == "fly" diff --git a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py index 1b7f11bf97d9..aca8fc3a644c 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_dictionary_lookup_async.py @@ -17,13 +17,13 @@ async def test_single_input_element(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly"] async with client: response = await client.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) assert response is not None assert response[0].normalized_source == "fly" @@ -37,13 +37,13 @@ async def test_multiple_input_elements(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly", "fox"] async with client: response = await client.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, target_language=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) assert response is not None assert len(response) == 2 diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py index e241f3c61858..544a85c33006 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages.py @@ -29,7 +29,7 @@ def test_translation_scope(self, **kwargs): assert len(response.translation) > 0 translations = response.translation["af"] - assert translations.directionality is not None + assert translations.dir is not None assert translations.name is not None assert translations.native_name is not None @@ -50,14 +50,14 @@ def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].name is not None assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None - assert transliterations.scripts[0].directionality is not None - assert transliterations.scripts[0].target_language_scripts is not None + assert transliterations.scripts[0].dir is not None + assert transliterations.scripts[0].to_scripts is not None - assert len(transliterations.scripts[0].target_language_scripts) > 0 - assert transliterations.scripts[0].target_language_scripts[0].name is not None - assert transliterations.scripts[0].target_language_scripts[0].native_name is not None - assert transliterations.scripts[0].target_language_scripts[0].code is not None - assert transliterations.scripts[0].target_language_scripts[0].directionality is not None + assert len(transliterations.scripts[0].to_scripts) > 0 + assert transliterations.scripts[0].to_scripts[0].name is not None + assert transliterations.scripts[0].to_scripts[0].native_name is not None + assert transliterations.scripts[0].to_scripts[0].code is not None + assert transliterations.scripts[0].to_scripts[0].dir is not None @TextTranslationPreparer() @recorded_by_proxy @@ -73,8 +73,8 @@ def test_transliteration_multiple_scripts(self, **kwargs): assert transliterations.scripts is not None assert len(transliterations.scripts) > 1 - assert len(transliterations.scripts[0].target_language_scripts) > 1 - assert len(transliterations.scripts[1].target_language_scripts) > 1 + assert len(transliterations.scripts[0].to_scripts) > 1 + assert len(transliterations.scripts[1].to_scripts) > 1 @TextTranslationPreparer() @recorded_by_proxy @@ -90,7 +90,7 @@ def test_dictionary_scope(self, **kwargs): assert len(dictionaries.translations) > 0 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].directionality is not None + assert dictionaries.translations[0].dir is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -108,7 +108,7 @@ def test_dictionary_multiple_translations(self, **kwargs): assert len(dictionaries.translations) > 1 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].directionality is not None + assert dictionaries.translations[0].dir is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -123,6 +123,6 @@ def test_with_culture(self, **kwargs): assert len(response.transliteration.items()) > 0 assert len(response.dictionary.items()) > 0 translations = response.translation["en"] - assert translations.directionality is not None + assert translations.dir is not None assert translations.name is not None assert translations.native_name is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py index 3d9e1679b472..e7818325453d 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_get_languages_async.py @@ -31,7 +31,7 @@ async def test_translation_scope(self, **kwargs): assert len(response.translation) > 0 translations = response.translation["af"] - assert translations.directionality is not None + assert translations.dir is not None assert translations.name is not None assert translations.native_name is not None @@ -53,14 +53,14 @@ async def test_transliteration_scope(self, **kwargs): assert transliterations.scripts[0].name is not None assert transliterations.scripts[0].native_name is not None assert transliterations.scripts[0].code is not None - assert transliterations.scripts[0].directionality is not None - assert transliterations.scripts[0].target_language_scripts is not None + assert transliterations.scripts[0].dir is not None + assert transliterations.scripts[0].to_scripts is not None - assert len(transliterations.scripts[0].target_language_scripts) > 0 - assert transliterations.scripts[0].target_language_scripts[0].name is not None - assert transliterations.scripts[0].target_language_scripts[0].native_name is not None - assert transliterations.scripts[0].target_language_scripts[0].code is not None - assert transliterations.scripts[0].target_language_scripts[0].directionality is not None + assert len(transliterations.scripts[0].to_scripts) > 0 + assert transliterations.scripts[0].to_scripts[0].name is not None + assert transliterations.scripts[0].to_scripts[0].native_name is not None + assert transliterations.scripts[0].to_scripts[0].code is not None + assert transliterations.scripts[0].to_scripts[0].dir is not None @TextTranslationPreparer() @recorded_by_proxy_async @@ -77,8 +77,8 @@ async def test_transliteration_multiple_scripts(self, **kwargs): assert transliterations.scripts is not None assert len(transliterations.scripts) > 1 - assert len(transliterations.scripts[0].target_language_scripts) > 1 - assert len(transliterations.scripts[1].target_language_scripts) > 1 + assert len(transliterations.scripts[0].to_scripts) > 1 + assert len(transliterations.scripts[1].to_scripts) > 1 @TextTranslationPreparer() @recorded_by_proxy_async @@ -95,7 +95,7 @@ async def test_dictionary_scope(self, **kwargs): assert len(dictionaries.translations) > 0 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].directionality is not None + assert dictionaries.translations[0].dir is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -114,7 +114,7 @@ async def test_dictionary_multiple_translations(self, **kwargs): assert len(dictionaries.translations) > 1 assert dictionaries.translations[0].code is not None - assert dictionaries.translations[0].directionality is not None + assert dictionaries.translations[0].dir is not None assert dictionaries.translations[0].name is not None assert dictionaries.translations[0].native_name is not None @@ -130,6 +130,6 @@ async def test_with_culture(self, **kwargs): assert len(response.transliteration.items()) > 0 assert len(response.dictionary.items()) > 0 translations = response.translation["en"] - assert translations.directionality is not None + assert translations.dir is not None assert translations.name is not None assert translations.native_name is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation.py b/sdk/translation/azure-ai-translation-text/tests/test_translation.py index 30f1e30d2804..fe0328337bb4 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation.py @@ -19,16 +19,14 @@ def test_translate(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "es" - target_languages = ["cs"] + from_parameter = "es" + to = ["cs"] input_text_elements = ["Hola mundo"] - response = client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -39,15 +37,15 @@ def test_autodetect(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].detected_language.score == 1 + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -58,13 +56,13 @@ def test_no_translate_tag(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "zh-chs" - target_languages = ["en"] + from_parameter = "zh-chs" + to = ["en"] input_text_elements = ["今天是怎么回事是非常可怕的"] response = client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, + to=to, + from_parameter=from_parameter, text_type=TextType.HTML, ) @@ -80,18 +78,16 @@ def test_dictionary_tag(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "en" - target_languages = ["es"] + from_parameter = "en" + to = ["es"] input_text_elements = [ 'The word < mstrans:dictionary translation ="wordomatic">wordomatic is a dictionary entry.' ] - response = client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "es" + assert response[0].translations[0].to == "es" assert "wordomatic" in response[0].translations[0].text @TextTranslationPreparer() @@ -102,21 +98,21 @@ def test_transliteration(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "ar" - target_languages = ["zh-Hans"] + from_parameter = "ar" + to = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, - source_language_script="Latn", - target_language_script="Latn", + to=to, + from_parameter=from_parameter, + from_script="Latn", + to_script="Latn", ) assert len(response) == 1 assert response[0].source_text is not None assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "zh-Hans" + assert response[0].translations[0].to == "zh-Hans" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -127,15 +123,15 @@ def test_from_to_latin(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - source_language = "hi" - target_languages = ["ta"] + from_parameter = "hi" + to = ["ta"] input_text_elements = ["ap kaise ho"] response = client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, - source_language_script="Latn", - target_language_script="Latn", + to=to, + from_parameter=from_parameter, + from_script="Latn", + to_script="Latn", ) assert len(response) == 1 @@ -151,21 +147,21 @@ def test_multiple_input(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = [ "This is a test.", "Esto es una prueba.", "Dies ist ein Test.", ] - response = client.translate(body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, to=to) assert len(response) == 3 assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "es" assert response[2].detected_language.language == "de" - assert response[0].detected_language.confidence == 1 - assert response[1].detected_language.confidence == 1 - assert response[2].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 + assert response[1].detected_language.score == 1 + assert response[2].detected_language.score == 1 assert response[0].translations[0].text is not None assert response[1].translations[0].text is not None @@ -179,14 +175,14 @@ def test_multiple_target_languages(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["cs", "es", "de"] + to = ["cs", "es", "de"] input_text_elements = ["This is a test."] - response = client.translate(body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 3 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 assert response[0].translations[0].text is not None assert response[0].translations[1].text is not None assert response[0].translations[2].text is not None @@ -199,16 +195,14 @@ def test_different_texttypes(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] - response = client.translate( - body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML - ) + response = client.translate(body=input_text_elements, to=to, text_type=TextType.HTML) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @TextTranslationPreparer() @recorded_by_proxy @@ -218,11 +212,11 @@ def test_profanity(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["zh-cn"] + to = ["zh-cn"] input_text_elements = ["shit this is fucking crazy"] response = client.translate( body=input_text_elements, - target_languages=target_languages, + to=to, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, ) @@ -230,7 +224,7 @@ def test_profanity(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 assert "***" in response[0].translations[0].text @TextTranslationPreparer() @@ -241,15 +235,15 @@ def test_alignment(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["It is a beautiful morning"] - response = client.translate(body=input_text_elements, target_languages=target_languages, include_alignment=True) + response = client.translate(body=input_text_elements, to=to, include_alignment=True) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].alignment.projections is not None + assert response[0].detected_language.score == 1 + assert response[0].translations[0].alignment.proj is not None @TextTranslationPreparer() @recorded_by_proxy @@ -259,20 +253,18 @@ def test_sentence_length(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["fr"] + to = ["fr"] input_text_elements = [ "La réponse se trouve dans la traduction automatique. La meilleure technologie de traduction automatique ne peut pas toujours fournir des traductions adaptées à un site ou des utilisateurs comme un être humain. Il suffit de copier et coller un extrait de code n'importe où." ] - response = client.translate( - body=input_text_elements, target_languages=target_languages, include_sentence_length=True - ) + response = client.translate(body=input_text_elements, to=to, include_sentence_length=True) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "fr" - assert response[0].detected_language.confidence == 1 - assert len(response[0].translations[0].sentence_boundaries.source_sentences_lengths) == 3 - assert len(response[0].translations[0].sentence_boundaries.translated_sentences_lengths) == 3 + assert response[0].detected_language.score == 1 + assert len(response[0].translations[0].sent_len.src_sent_len) == 3 + assert len(response[0].translations[0].sent_len.trans_sent_len) == 3 @TextTranslationPreparer() @recorded_by_proxy @@ -282,14 +274,14 @@ def test_custom_endpoint(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client(endpoint, apikey, region) - target_languages = ["fr"] + to = ["fr"] input_text_elements = ["It is a beautiful morning"] - response = client.translate(body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -300,14 +292,14 @@ def test_token(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_client_token(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] - response = client.translate(body=input_text_elements, target_languages=target_languages) + response = client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -318,14 +310,12 @@ def test_translate_aad(self, **kwargs): token_credential = self.get_mt_credential(False) client = self.create_text_translation_client_with_aad(token_credential, aadRegion, aadResourceId) - source_language = "es" - target_languages = ["cs"] + from_parameter = "es" + to = ["cs"] input_text_elements = ["Hola mundo"] - response = client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py index 77f1d3454867..8f1501f0e203 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_translation_async.py @@ -20,17 +20,15 @@ async def test_translate(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "es" - target_languages = ["cs"] + from_parameter = "es" + to = ["cs"] input_text_elements = ["Hola mundo"] async with client: - response = await client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = await client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -41,16 +39,16 @@ async def test_autodetect(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].detected_language.score == 1 + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -61,14 +59,14 @@ async def test_no_translate_tag(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "zh-chs" - target_languages = ["en"] + from_parameter = "zh-chs" + to = ["en"] input_text_elements = ["今天是怎么回事是非常可怕的"] async with client: response = await client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, + to=to, + from_parameter=from_parameter, text_type=TextType.HTML, ) @@ -84,19 +82,17 @@ async def test_dictionary_tag(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "en" - target_languages = ["es"] + from_parameter = "en" + to = ["es"] input_text_elements = [ 'The word < mstrans:dictionary translation ="wordomatic">wordomatic is a dictionary entry.' ] async with client: - response = await client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = await client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "es" + assert response[0].translations[0].to == "es" assert "wordomatic" in response[0].translations[0].text @TextTranslationPreparer() @@ -107,22 +103,22 @@ async def test_transliteration(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "ar" - target_languages = ["zh-Hans"] + from_parameter = "ar" + to = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] async with client: response = await client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, - source_language_script="Latn", - target_language_script="Latn", + to=to, + from_parameter=from_parameter, + from_script="Latn", + to_script="Latn", ) assert len(response) == 1 assert response[0].source_text is not None assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "zh-Hans" + assert response[0].translations[0].to == "zh-Hans" assert response[0].translations[0].text is not None @TextTranslationPreparer() @@ -133,16 +129,16 @@ async def test_from_to_latin(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - source_language = "hi" - target_languages = ["ta"] + from_parameter = "hi" + to = ["ta"] input_text_elements = ["ap kaise ho"] async with client: response = await client.translate( body=input_text_elements, - target_languages=target_languages, - source_language=source_language, - source_language_script="Latn", - target_language_script="Latn", + to=to, + from_parameter=from_parameter, + from_script="Latn", + to_script="Latn", ) assert len(response) == 1 @@ -158,22 +154,22 @@ async def test_multiple_input(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = [ "This is a test.", "Esto es una prueba.", "Dies ist ein Test.", ] async with client: - response = await client.translate(body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, to=to) assert len(response) == 3 assert response[0].detected_language.language == "en" assert response[1].detected_language.language == "es" assert response[2].detected_language.language == "de" - assert response[0].detected_language.confidence == 1 - assert response[1].detected_language.confidence == 1 - assert response[2].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 + assert response[1].detected_language.score == 1 + assert response[2].detected_language.score == 1 assert response[0].translations[0].text is not None assert response[1].translations[0].text is not None @@ -187,15 +183,15 @@ async def test_multiple_target_languages(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["cs", "es", "de"] + to = ["cs", "es", "de"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 3 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 assert response[0].translations[0].text is not None assert response[0].translations[1].text is not None assert response[0].translations[2].text is not None @@ -208,17 +204,15 @@ async def test_different_texttypes(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate( - body=input_text_elements, target_languages=target_languages, text_type=TextType.HTML - ) + response = await client.translate(body=input_text_elements, to=to, text_type=TextType.HTML) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @TextTranslationPreparer() @recorded_by_proxy_async @@ -228,12 +222,12 @@ async def test_profanity(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["zh-cn"] + to = ["zh-cn"] input_text_elements = ["shit this is fucking crazy"] async with client: response = await client.translate( body=input_text_elements, - target_languages=target_languages, + to=to, profanity_action=ProfanityAction.MARKED, profanity_marker=ProfanityMarker.ASTERISK, ) @@ -241,7 +235,7 @@ async def test_profanity(self, **kwargs): assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 assert "***" in response[0].translations[0].text @TextTranslationPreparer() @@ -252,18 +246,16 @@ async def test_alignment(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["It is a beautiful morning"] async with client: - response = await client.translate( - body=input_text_elements, target_languages=target_languages, include_alignment=True - ) + response = await client.translate(body=input_text_elements, to=to, include_alignment=True) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 - assert response[0].translations[0].alignment.projections is not None + assert response[0].detected_language.score == 1 + assert response[0].translations[0].alignment.proj is not None @TextTranslationPreparer() @recorded_by_proxy_async @@ -273,21 +265,19 @@ async def test_sentence_length(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["fr"] + to = ["fr"] input_text_elements = [ "La réponse se trouve dans la traduction automatique. La meilleure technologie de traduction automatique ne peut pas toujours fournir des traductions adaptées à un site ou des utilisateurs comme un être humain. Il suffit de copier et coller un extrait de code n'importe où." ] async with client: - response = await client.translate( - body=input_text_elements, target_languages=target_languages, include_sentence_length=True - ) + response = await client.translate(body=input_text_elements, to=to, include_sentence_length=True) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "fr" - assert response[0].detected_language.confidence == 1 - assert len(response[0].translations[0].sentence_boundaries.source_sentences_lengths) == 3 - assert len(response[0].translations[0].sentence_boundaries.translated_sentences_lengths) == 3 + assert response[0].detected_language.score == 1 + assert len(response[0].translations[0].sent_len.src_sent_len) == 3 + assert len(response[0].translations[0].sent_len.trans_sent_len) == 3 @TextTranslationPreparer() @recorded_by_proxy_async @@ -297,15 +287,15 @@ async def test_custom_endpoint(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client(endpoint, apikey, region) - target_languages = ["fr"] + to = ["fr"] input_text_elements = ["It is a beautiful morning"] async with client: - response = await client.translate(body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -316,15 +306,15 @@ async def test_token(self, **kwargs): region = kwargs.get("text_translation_region") client = self.create_async_client_token(endpoint, apikey, region) - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] async with client: - response = await client.translate(body=input_text_elements, target_languages=target_languages) + response = await client.translate(body=input_text_elements, to=to) assert len(response) == 1 assert len(response[0].translations) == 1 assert response[0].detected_language.language == "en" - assert response[0].detected_language.confidence == 1 + assert response[0].detected_language.score == 1 @pytest.mark.live_test_only @TextTranslationPreparer() @@ -335,14 +325,12 @@ async def test_translate_aad(self, **kwargs): token_credential = self.get_mt_credential(True) client = self.create_async_text_translation_client_with_aad(token_credential, aadRegion, aadResourceId) - source_language = "es" - target_languages = ["cs"] + from_parameter = "es" + to = ["cs"] input_text_elements = ["Hola mundo"] - response = await client.translate( - body=input_text_elements, target_languages=target_languages, source_language=source_language - ) + response = await client.translate(body=input_text_elements, to=to, from_parameter=from_parameter) assert len(response) == 1 assert len(response[0].translations) == 1 - assert response[0].translations[0].target_language == "cs" + assert response[0].translations[0].to == "cs" assert response[0].translations[0].text is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py index 980379d88ea4..dca33ad14409 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration.py @@ -22,8 +22,8 @@ def test_transliteration(self, **kwargs): response = client.transliterate( body=input_text_elements, language="zh-Hans", - source_language_script="Hans", - target_language_script="Latn", + from_script="Hans", + to_script="Latn", ) assert response is not None @@ -41,8 +41,8 @@ def test_multiple_inputs(self, **kwargs): response = client.transliterate( body=input_text_elements, language="hi", - source_language_script="Deva", - target_language_script="Latn", + from_script="Deva", + to_script="Latn", ) assert response is not None @@ -65,8 +65,8 @@ def test_edit_distance(self, **kwargs): response = client.transliterate( body=input_text_elements, language="gu", - source_language_script="Latn", - target_language_script="Gujr", + from_script="Latn", + to_script="Gujr", ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py index 1002474126f0..b8fa9e72837c 100644 --- a/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py +++ b/sdk/translation/azure-ai-translation-text/tests/test_transliteration_async.py @@ -23,8 +23,8 @@ async def test_transliteration(self, **kwargs): response = await client.transliterate( body=input_text_elements, language="zh-Hans", - source_language_script="Hans", - target_language_script="Latn", + from_script="Hans", + to_script="Latn", ) assert response is not None @@ -43,8 +43,8 @@ async def test_multiple_inputs(self, **kwargs): response = await client.transliterate( body=input_text_elements, language="hi", - source_language_script="Deva", - target_language_script="Latn", + from_script="Deva", + to_script="Latn", ) assert response is not None @@ -68,8 +68,8 @@ async def test_edit_distance(self, **kwargs): response = await client.transliterate( body=input_text_elements, language="gu", - source_language_script="Latn", - target_language_script="Gujr", + from_script="Latn", + to_script="Gujr", ) assert response is not None diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index da41a8211de5..31cb1bc2981d 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: cc6917418740a76c0c1b5be595a89f279df73bf6 -repo: Azure/azure-rest-api-specs +commit: 6b2192458cb1fd7df296402f8c4b068e41475562 +repo: MikeyMCZ/azure-rest-api-specs From e7982e58c2268c7b10dd94c9169b321976306957 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 20 May 2024 16:11:13 -0700 Subject: [PATCH 21/32] Fixes --- .../azure/ai/translation/text/_operations/_patch.py | 8 ++++---- .../azure/ai/translation/text/_patch.py | 4 ++-- .../azure/ai/translation/text/aio/_operations/_patch.py | 8 ++++---- .../azure/ai/translation/text/aio/_patch.py | 6 +++--- .../samples/sample_text_translation_dictionary_lookup.py | 2 +- .../azure-ai-translation-text/tsp-location.yaml | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py index 3975fe42e1c3..ec03767f5bac 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_operations/_patch.py @@ -533,7 +533,7 @@ def translate( ] """ - def translate( + def translate( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -755,7 +755,7 @@ def transliterate( ] """ - def transliterate( + def transliterate( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -971,7 +971,7 @@ def find_sentence_boundaries( ] """ - def find_sentence_boundaries( + def find_sentence_boundaries( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -1332,7 +1332,7 @@ def lookup_dictionary_entries( ] """ - def lookup_dictionary_entries( + def lookup_dictionary_entries( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 34eaaf318c7d..ed06b002c4c0 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722 +# pylint: disable=C4717, C4722, C4748 from typing import Optional, Any, overload from azure.core.pipeline import PipelineRequest @@ -45,7 +45,7 @@ class TranslatorEntraIdAuthenticationPolicy(BearerTokenCredentialPolicy): Ocp-Apim-Subscription-Region header contains region of the Translator resource. Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. - :param credential: Translator Entra Id Credentials used to access Translator Resource for global Translator endpoint. + :param credential: Translator Entra Id Credentials used to access Translator Resource for global endpoint. :type credential: ~azure.ai.translation.text.TranslatorEntraIdCredential """ diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py index e038458c3929..ca87b48dee97 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_operations/_patch.py @@ -533,7 +533,7 @@ async def translate( ] """ - async def translate( + async def translate( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -755,7 +755,7 @@ async def transliterate( ] """ - async def transliterate( + async def transliterate( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -971,7 +971,7 @@ async def find_sentence_boundaries( ] """ - async def find_sentence_boundaries( + async def find_sentence_boundaries( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, @@ -1332,7 +1332,7 @@ async def lookup_dictionary_entries( ] """ - async def lookup_dictionary_entries( + async def lookup_dictionary_entries( # pyright: ignore[reportIncompatibleMethodOverride] self, body: Union[List[str], List[_models.InputTextItem], IO[bytes]], *, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index f05a06c3f025..cc9f3f8e52ae 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -# pylint: disable=C4717, C4722 +# pylint: disable=C4717, C4722, C4748 """Customize generated code here. Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize @@ -32,13 +32,13 @@ def patch_sdk(): """ -class AsyncTranslatorEntraIdAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): +class AsyncTranslatorEntraIdAuthenticationPolicy(AsyncBearerTokenCredentialPolicy): # pylint: disable=name-too-long """Translator Entra Id Authentication Policy. Adds headers that are required by Translator Service when global endpoint is used with Entra Id policy. Ocp-Apim-Subscription-Region header contains region of the Translator resource. Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. - :param credential: Translator Entra Id Credentials used to access Translator Resource for global Translator endpoint. + :param credential: Translator Entra Id Credentials used to access Translator Resource for global endpoint. :type credential: ~azure.core.credentials_async.AsyncTokenCredential """ diff --git a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py index e322843795bf..875985d624d8 100644 --- a/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py +++ b/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py @@ -52,7 +52,7 @@ def get_text_translation_dictionary_lookup(): if dictionary_entry: print(f"For the given input {len(dictionary_entry.translations)} entries were found in the dictionary.") print( - f"First entry: '{dictionary_entry.translations[0].display_target}', score: {dictionary_entry.translations[0].score}." + f"First entry: '{dictionary_entry.translations[0].display_target}', confidence: {dictionary_entry.translations[0].confidence}." ) except HttpResponseError as exception: diff --git a/sdk/translation/azure-ai-translation-text/tsp-location.yaml b/sdk/translation/azure-ai-translation-text/tsp-location.yaml index 31cb1bc2981d..151e72c1cf9d 100644 --- a/sdk/translation/azure-ai-translation-text/tsp-location.yaml +++ b/sdk/translation/azure-ai-translation-text/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/translation/Azure.AI.TextTranslation -commit: 6b2192458cb1fd7df296402f8c4b068e41475562 -repo: MikeyMCZ/azure-rest-api-specs +commit: 9583ed6c26ce1f10bbea92346e28a46394a784b4 +repo: Azure/azure-rest-api-specs From 00768cfd00d1a2ca5db28e381e9633d8185ba7ee Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 20 May 2024 16:41:51 -0700 Subject: [PATCH 22/32] pyright rules --- .../azure/ai/translation/text/_patch.py | 2 +- .../azure/ai/translation/text/aio/_patch.py | 2 +- .../azure/ai/translation/text/models/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index ed06b002c4c0..0e77ee0f1c51 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -156,7 +156,7 @@ def __init__( ): ... @overload - def __init__( + def __init__( # pyright: ignore[reportOverlappingOverload] self, *, credential: Optional[TokenCredential] = None, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index cc9f3f8e52ae..37ef04de4e32 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -138,7 +138,7 @@ def __init__( ): ... @overload - def __init__( + def __init__( # pyright: ignore[reportOverlappingOverload] self, *, credential: Optional[AsyncTokenCredential] = None, diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py index da99621bc1e2..9aae62f6f103 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/models/__init__.py @@ -69,5 +69,5 @@ "ProfanityMarker", "TextType", ] -__all__.extend([p for p in _patch_all if p not in __all__]) +__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore[reportUnsupportedDunderAll] _patch_sdk() From 0126813516d80b36656f2f47bd8dd29e5431ae05 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 20 May 2024 16:50:01 -0700 Subject: [PATCH 23/32] Fix PR comment --- .../azure/ai/translation/text/_patch.py | 1 + .../azure/ai/translation/text/aio/_patch.py | 1 + 2 files changed, 2 insertions(+) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 0e77ee0f1c51..4079a557b734 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -130,6 +130,7 @@ class TextTranslationClient(ServiceClientGenerated): str + AzureKeyCredential - used custom domain translator endpoint str + AzureKeyCredential + Region - used for global translator endpoint str + TokenCredential - used for regional endpoint with token authentication + str + None - used with text translation on-prem container None + AzureKeyCredential - used for global translator endpoint with global Translator resource None + TokenCredential - general translator endpoint with token authentication None + TokenCredential + Region - general translator endpoint with regional Translator resource diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 37ef04de4e32..fe68c45fb2b8 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -112,6 +112,7 @@ class TextTranslationClient(ServiceClientGenerated): str + AzureKeyCredential - used custom domain translator endpoint str + AzureKeyCredential + Region - used for global translator endpoint str + AsyncTokenCredential - used for regional endpoint with token authentication + str + None - used with text translation on-prem container None + AzureKeyCredential - used for global translator endpoint with global Translator resource None + AsyncTokenCredential - general translator endpoint with token authentication None + AsyncTokenCredential + Region - general translator endpoint with regional Translator resource From 0ac6f85c7b85a02157e1e80d6ec944319fc73c01 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Mon, 20 May 2024 17:52:15 -0700 Subject: [PATCH 24/32] Fixing docs --- .../azure-ai-translation-text/README.md | 40 +++--- .../samples/README.md | 129 +++++++++--------- 2 files changed, 81 insertions(+), 88 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/README.md b/sdk/translation/azure-ai-translation-text/README.md index 85a34d88653c..796c6bc8b137 100644 --- a/sdk/translation/azure-ai-translation-text/README.md +++ b/sdk/translation/azure-ai-translation-text/README.md @@ -140,17 +140,17 @@ Renders single source-language text to multiple target-language texts with a sin ```python try: - target_languages = ["cs", "es", "de"] + to = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=to) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -177,15 +177,15 @@ Converts characters or letters of a source language to the corresponding charact ```python try: language = "zh-Hans" - source_language_script = "Hans" - target_language_script = "Latn" + from_script = "Hans" + to_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( body=input_text_elements, language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, ) transliteration = response[0] if response else None @@ -215,11 +215,11 @@ Identifies the positioning of sentence boundaries in a piece of text. ```python try: include_sentence_length = True - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=to, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -227,15 +227,13 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sentences_lengths: - print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") - print( - f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" - ) + if translated_text.sent_len: + print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") + print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") except HttpResponseError as exception: if exception.error is not None: @@ -257,12 +255,12 @@ Returns equivalent words for the source term in the target language. ```python try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None @@ -293,12 +291,12 @@ Returns grammatical structure and context examples for the source term and targe ```python try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None diff --git a/sdk/translation/azure-ai-translation-text/samples/README.md b/sdk/translation/azure-ai-translation-text/samples/README.md index 8663d3e625d6..4807efaa63aa 100644 --- a/sdk/translation/azure-ai-translation-text/samples/README.md +++ b/sdk/translation/azure-ai-translation-text/samples/README.md @@ -203,13 +203,11 @@ Translate text from known source language to target language. ```python try: - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language - ) + response = text_translator.translate(body=input_text_elements, to=to, from_parameter=from_parameter) translation = response[0] if response else None if translation: @@ -237,17 +235,17 @@ You can omit source language of the input text. In this case, API will try to au ```python try: - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=to) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -269,18 +267,18 @@ You can combine both Translation and Transliteration in one Translate call. Your ```python try: - source_language_script = "Latn" + from_script = "Latn" from_language = "ar" - target_language_script = "Latn" - target_languages = ["zh-Hans"] + to_script = "Latn" + to = ["zh-Hans"] input_text_elements = ["hudha akhtabar."] response = text_translator.translate( body=input_text_elements, - to=target_languages, - source_language_script=source_language_script, - source_language=from_language, - target_language_script=target_language_script, + to=to, + from_script=from_script, + from_parameter=from_language, + to_script=to_script, ) translation = response[0] if response else None @@ -311,18 +309,18 @@ You can translate multiple text elements with a various length. Each input eleme ```python try: - target_languages = ["cs"] + to = ["cs"] input_text_elements = [ "This is a test.", "Esto es una prueba.", "Dies ist ein Test.", ] - translations = text_translator.translate(body=input_text_elements, to=target_languages) + translations = text_translator.translate(body=input_text_elements, to=to) for translation in translations: print( - f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.confidence if translation.detected_language else None}." + f"Detected languages of the input text: {translation.detected_language.language if translation.detected_language else None} with score: {translation.detected_language.score if translation.detected_language else None}." ) print( f"Text was translated to: '{translation.translations[0].to if translation.translations else None}' and the result is: '{translation.translations[0].text if translation.translations else None}'." @@ -344,17 +342,17 @@ You can provide multiple target languages which results to each input element be ```python try: - target_languages = ["cs", "es", "de"] + to = ["cs", "es", "de"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages) + response = text_translator.translate(body=input_text_elements, to=to) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -376,17 +374,17 @@ You can select whether the translated text is plain text or HTML text. Any HTML ```python try: text_type = TextType.HTML - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test."] - response = text_translator.translate(body=input_text_elements, to=target_languages, text_type=text_type) + response = text_translator.translate(body=input_text_elements, to=to, text_type=text_type) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -408,14 +406,17 @@ It's sometimes useful to exclude specific content from translation. You can use ```python try: text_type = TextType.HTML - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = [ '
This will not be translated.
This will be translated.
' ] response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language, text_type=text_type + body=input_text_elements, + to=to, + from_parameter=from_parameter, + text_type=text_type, ) translation = response[0] if response else None @@ -441,15 +442,13 @@ If you already know the translation you want to apply to a word or a phrase, you ```python try: - source_language = "en" - target_languages = ["cs"] + from_parameter = "en" + to = ["cs"] input_text_elements = [ 'The word wordomatic is a dictionary entry.' ] - response = text_translator.translate( - body=input_text_elements, to=target_languages, source_language=source_language - ) + response = text_translator.translate(body=input_text_elements, to=to, from_parameter=from_parameter) translation = response[0] if response else None if translation: @@ -476,12 +475,12 @@ If you want to avoid getting profanity in the translation, regardless of the pre try: profanity_action = ProfanityAction.MARKED profanity_maker = ProfanityMarker.ASTERISK - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is ***."] response = text_translator.translate( body=input_text_elements, - to=target_languages, + to=to, profanity_action=profanity_action, profanity_marker=profanity_maker, ) @@ -491,7 +490,7 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -513,19 +512,17 @@ You can ask translation service to include alignment projection from source text ```python try: include_alignment = True - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["The answer lies in machine translation."] - response = text_translator.translate( - body=input_text_elements, to=target_languages, include_alignment=include_alignment - ) + response = text_translator.translate(body=input_text_elements, to=to, include_alignment=include_alignment) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -549,11 +546,11 @@ You can ask translator service to include sentence boundaries for the input text ```python try: include_sentence_length = True - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["The answer lies in machine translation. This is a test."] response = text_translator.translate( - body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length + body=input_text_elements, to=to, include_sentence_length=include_sentence_length ) translation = response[0] if response else None @@ -561,15 +558,13 @@ try: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") - if translated_text.sentences_lengths: - print(f"Source Sentence length: {translated_text.sentences_lengths.src_sentences_lengths}") - print( - f"Translated Sentence length: {translated_text.sentences_lengths.translated_sentences_lengths}" - ) + if translated_text.sent_len: + print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}") + print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}") except HttpResponseError as exception: if exception.error is not None: @@ -592,17 +587,17 @@ It is possible to set `allow_fallback` parameter. It specifies that the service ```python try: category = "<>" - target_languages = ["cs"] + to = ["cs"] input_text_elements = ["This is a test"] - response = text_translator.translate(body=input_text_elements, to=target_languages, category=category) + response = text_translator.translate(body=input_text_elements, to=to, category=category) translation = response[0] if response else None if translation: detected_language = translation.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) for translated_text in translation.translations: print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.") @@ -626,15 +621,15 @@ Converts characters or letters of a source language to the corresponding charact ```python try: language = "zh-Hans" - source_language_script = "Hans" - target_language_script = "Latn" + from_script = "Hans" + to_script = "Latn" input_text_elements = ["这是个测试。"] response = text_translator.transliterate( body=input_text_elements, language=language, - source_language_script=source_language_script, - target_language_script=target_language_script, + from_script=from_script, + to_script=to_script, ) transliteration = response[0] if response else None @@ -662,12 +657,12 @@ When the input language is known, you can provide those to the service call. ```python try: - source_language = "zh-Hans" + from_parameter = "zh-Hans" source_script = "Latn" input_text_elements = ["zhè shì gè cè shì。"] response = text_translator.find_sentence_boundaries( - body=input_text_elements, language=source_language, script=source_script + body=input_text_elements, language=from_parameter, script=source_script ) sentence_boundaries = response[0] if response else None @@ -675,10 +670,10 @@ try: detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sentences_lengths: + for boundary in sentence_boundaries.sent_len: print(boundary) except HttpResponseError as exception: @@ -707,10 +702,10 @@ try: detected_language = sentence_boundaries.detected_language if detected_language: print( - f"Detected languages of the input text: {detected_language.language} with score: {detected_language.confidence}." + f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}." ) print(f"The detected sentence boundaries:") - for boundary in sentence_boundaries.sentences_lengths: + for boundary in sentence_boundaries.sent_len: print(boundary) except HttpResponseError as exception: @@ -731,12 +726,12 @@ Returns equivalent words for the source term in the target language. ```python try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = ["fly"] response = text_translator.lookup_dictionary_entries( - body=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None @@ -763,12 +758,12 @@ Returns grammatical structure and context examples for the source term and targe ```python try: - source_language = "en" - target_language = "es" + from_parameter = "en" + to = "es" input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")] response = text_translator.lookup_dictionary_examples( - content=input_text_elements, source_language=source_language, to=target_language + body=input_text_elements, from_parameter=from_parameter, to=to ) dictionary_entry = response[0] if response else None From 34bc5df0ae0ddf027b43fc35f30476dbaf009dd9 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 07:35:24 -0700 Subject: [PATCH 25/32] Preparing for a release --- sdk/translation/azure-ai-translation-text/CHANGELOG.md | 6 +----- sdk/translation/azure-ai-translation-text/setup.py | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index 5f652fd3c187..8c11d797d371 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0 (Unreleased) +## 1.0.0 (2024-05-21) ### Features Added - Added support for Entra Id authentication. @@ -16,10 +16,6 @@ - from_script parameter was renamed to from_script. - to_script parameter was renamed to _target_langauge_script. -### Bugs Fixed - -### Other Changes - ## 1.0.0b1 (2023-04-19) - Initial Release diff --git a/sdk/translation/azure-ai-translation-text/setup.py b/sdk/translation/azure-ai-translation-text/setup.py index 0188bfb2d400..fd168a300310 100644 --- a/sdk/translation/azure-ai-translation-text/setup.py +++ b/sdk/translation/azure-ai-translation-text/setup.py @@ -38,7 +38,7 @@ url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk", keywords="azure, azure sdk", classifiers=[ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3", From 7c4015c599e35170e917497385ea3923ba562a8e Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 09:16:31 -0700 Subject: [PATCH 26/32] Fixing PR comment --- .../azure/ai/translation/text/_patch.py | 13 +++++++++++-- .../azure/ai/translation/text/aio/_patch.py | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 4079a557b734..037af7ebbacb 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -149,7 +149,7 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: Optional[AzureKeyCredential] = None, + credential: AzureKeyCredential, region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", @@ -160,7 +160,7 @@ def __init__( def __init__( # pyright: ignore[reportOverlappingOverload] self, *, - credential: Optional[TokenCredential] = None, + credential: TokenCredential, region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, @@ -169,6 +169,15 @@ def __init__( # pyright: ignore[reportOverlappingOverload] **kwargs ): ... + @overload + def __init__( + self, + *, + endpoint: str, + api_version="3.0", + **kwargs + ): ... + def __init__(self, **kwargs): api_version = kwargs.get("api_version", "3.0") set_authentication_policy(kwargs.get("credential"), kwargs) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index fe68c45fb2b8..f287815ef7c2 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -131,7 +131,7 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: Optional[AzureKeyCredential] = None, + credential: AzureKeyCredential = None, region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", @@ -142,7 +142,7 @@ def __init__( def __init__( # pyright: ignore[reportOverlappingOverload] self, *, - credential: Optional[AsyncTokenCredential] = None, + credential: AsyncTokenCredential = None, region: Optional[str] = None, resource_id: Optional[str] = None, endpoint: Optional[str] = None, @@ -151,6 +151,15 @@ def __init__( # pyright: ignore[reportOverlappingOverload] **kwargs ): ... + @overload + def __init__( + self, + *, + endpoint: str, + api_version="3.0", + **kwargs + ): ... + def __init__(self, **kwargs): api_version = kwargs.get("api_version", "3.0") set_authentication_policy(kwargs.get("credential"), kwargs) From 756f25641db0251304571fbe0691ff8531bff1ea Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 09:23:49 -0700 Subject: [PATCH 27/32] Fixing PR comments --- .../azure/ai/translation/text/_patch.py | 10 +++++----- .../azure/ai/translation/text/aio/_patch.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index 037af7ebbacb..b4d4eba6ad2a 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -149,22 +149,22 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: AzureKeyCredential, + credential: TokenCredential, region: Optional[str] = None, endpoint: Optional[str] = None, + resource_id: Optional[str] = None, + scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... @overload - def __init__( # pyright: ignore[reportOverlappingOverload] + def __init__( self, *, - credential: TokenCredential, + credential: AzureKeyCredential, region: Optional[str] = None, - resource_id: Optional[str] = None, endpoint: Optional[str] = None, - scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index f287815ef7c2..484909f6a9c7 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -131,22 +131,22 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: AzureKeyCredential = None, + credential: AsyncTokenCredential = None, region: Optional[str] = None, endpoint: Optional[str] = None, + resource_id: Optional[str] = None, + scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... @overload - def __init__( # pyright: ignore[reportOverlappingOverload] + def __init__( self, *, - credential: AsyncTokenCredential = None, + credential: AzureKeyCredential = None, region: Optional[str] = None, - resource_id: Optional[str] = None, endpoint: Optional[str] = None, - scopes: Optional[str] = None, api_version="3.0", **kwargs ): ... From c2780cde78a8fd0c4b7682501f0b379853badb95 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 09:53:23 -0700 Subject: [PATCH 28/32] Fix mypy --- .../azure/ai/translation/text/aio/_patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 484909f6a9c7..1e4b79983c50 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -131,7 +131,7 @@ class TextTranslationClient(ServiceClientGenerated): def __init__( self, *, - credential: AsyncTokenCredential = None, + credential: AsyncTokenCredential, region: Optional[str] = None, endpoint: Optional[str] = None, resource_id: Optional[str] = None, @@ -144,7 +144,7 @@ def __init__( def __init__( self, *, - credential: AzureKeyCredential = None, + credential: AzureKeyCredential, region: Optional[str] = None, endpoint: Optional[str] = None, api_version="3.0", From 890a8bcc2026638ca4a5daf73df7d55828f297c6 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 10:36:13 -0700 Subject: [PATCH 29/32] Fix the optional endpoint for async tests --- .../azure/ai/translation/text/aio/_patch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py index 1e4b79983c50..f08ab3618209 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py @@ -163,7 +163,9 @@ def __init__( def __init__(self, **kwargs): api_version = kwargs.get("api_version", "3.0") set_authentication_policy(kwargs.get("credential"), kwargs) - translation_endpoint = get_translation_endpoint(kwargs.pop("endpoint"), api_version) + translation_endpoint = get_translation_endpoint( + kwargs.pop("endpoint", "https://api.cognitive.microsofttranslator.com"), api_version + ) super().__init__(endpoint=translation_endpoint, api_version=api_version, **kwargs) From 94d9640f191f2df0b195180ce40ef1ec28e8dbb4 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 10:46:14 -0700 Subject: [PATCH 30/32] Update sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py Co-authored-by: Krista Pratico --- .../azure/ai/translation/text/_patch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py index b4d4eba6ad2a..a487ff800650 100644 --- a/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py +++ b/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_patch.py @@ -46,7 +46,7 @@ class TranslatorEntraIdAuthenticationPolicy(BearerTokenCredentialPolicy): Ocp-Apim-ResourceId header contains Azure resource Id - Translator resource. :param credential: Translator Entra Id Credentials used to access Translator Resource for global endpoint. - :type credential: ~azure.ai.translation.text.TranslatorEntraIdCredential + :type credential: ~azure.core.credentials.TokenCredential """ def __init__(self, credential: TokenCredential, resource_id: str, region: str, scopes: str, **kwargs: Any) -> None: From 8bf125562ab5ae2398216e8ed4fb2d76f77f1363 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 10:48:51 -0700 Subject: [PATCH 31/32] Updated Changelog --- sdk/translation/azure-ai-translation-text/CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index 8c11d797d371..5790a672878d 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -9,12 +9,6 @@ - All calls to the client using parameter 'content' have been changed to use parameter 'body'. - Users can call methods using just a string type instead of complex objects. - - get_languages methods were changed to get_supported_languages. - - sent_len property was renamed to sent_len. - - from_parameter parameter was renamed to from_parameter. - - score parameter was renamed to confidence. - - from_script parameter was renamed to from_script. - - to_script parameter was renamed to _target_langauge_script. ## 1.0.0b1 (2023-04-19) From b2bc8aa28c93598ebed7dd21de71e7f5f10ccdd1 Mon Sep 17 00:00:00 2001 From: Michal Materna Date: Tue, 21 May 2024 10:52:56 -0700 Subject: [PATCH 32/32] Fix the changelog --- sdk/translation/azure-ai-translation-text/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/translation/azure-ai-translation-text/CHANGELOG.md b/sdk/translation/azure-ai-translation-text/CHANGELOG.md index 5790a672878d..2d6a9700cfad 100644 --- a/sdk/translation/azure-ai-translation-text/CHANGELOG.md +++ b/sdk/translation/azure-ai-translation-text/CHANGELOG.md @@ -7,8 +7,9 @@ ### Breaking Changes - - All calls to the client using parameter 'content' have been changed to use parameter 'body'. + - All calls to the client using parameter `content` have been changed to use parameter `body`. - Users can call methods using just a string type instead of complex objects. + - `get_languages` methods were changed to `get_supported_languages`. ## 1.0.0b1 (2023-04-19)