Skip to content

Commit b2b490c

Browse files
jrjrguoJiarui Guo
andauthored
Update azure-ai-translation-text 2.0.0b1 (API Version: 2025-10-01-preview) (#43962)
* first codegen from 10-01 spec * update the patches * version, changelog, remove obsolete samples & tests * update from typespec * update get languages tests & samples * fix patch, transliterate & translate tests * fix tests per copilot commnts * update test resources to use foundry & add llm tests * cleanup genrated tests & samples * update samples * update docstrings in patch * link remove en-us * resolve overload methods * pyright fixes * fix snippets extra line error? * fix docstring per pylint * from_language docstring * document translation pylint * update test recording assets tag * switch to composition * pull tsp changes and update tests * update readme * mypy and snippets updates * fix pylint * addressing more linting checks --------- Co-authored-by: Jiarui Guo <[email protected]>
1 parent 908d293 commit b2b490c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5213
-8052
lines changed

sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_model_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def _deserialize(cls, data, exist_discriminators):
633633
discriminator_value = data.find(xml_name).text # pyright: ignore
634634
else:
635635
discriminator_value = data.get(discriminator._rest_name)
636-
mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore
636+
mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore # pylint: disable=no-member
637637
return mapped_cls._deserialize(data, exist_discriminators)
638638

639639
def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing.Any]:

sdk/translation/azure-ai-translation-text/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# Release History
22

3-
## 1.0.2 (Unreleased)
3+
## 2.0.0b1 (Unreleased)
44

55
### Features Added
66

7+
- Added support for the latest Azure AI Translator API, including translations using LLM models, adaptive custom translations, tone variant translations, and gender-specific language translations.
8+
79
### Breaking Changes
810

11+
- Dictionary, sentence boundaries and text alignments features have been removed, and relevant models and properties have been removed.
12+
-
13+
914
### Bugs Fixed
1015

1116
### Other Changes

sdk/translation/azure-ai-translation-text/MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ recursive-include tests *.py
55
recursive-include samples *.py *.md
66
include azure/__init__.py
77
include azure/ai/__init__.py
8-
include azure/ai/translation/__init__.py
8+
include azure/ai/translation/__init__.py

sdk/translation/azure-ai-translation-text/README.md

Lines changed: 17 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
# Azure Text Translation client library for Python
22

3-
Text Translation is a cloud-based REST API feature of the Translator service that uses neural machine translation technology to enable quick and accurate source-to-target text translation in real time across all supported languages.
3+
Azure text translation is a cloud-based REST API provided by the Azure Translator service. It utilizes neural machine translation technology to deliver precise, contextually relevant, and semantically accurate real-time text translations across all supported languages.
44

55
Use the Text Translation client library for Python to:
66

7-
* Return a list of languages supported by Translate, Transliterate, and Dictionary operations.
7+
- Retrieve the list of languages supported for translation and transliteration operations, as well as LLM models available for translations.
88

9-
* Render single source-language text to multiple target-language texts with a single request.
9+
- Perform deterministic text translation from a specified source language to a target language, with configurable parameters to ensure precision and maintain contextual integrity.
1010

11-
* Convert text of a source language in letters of a different script.
11+
- Execute transliteration by converting text from the original script to an alternative script representation.
1212

13-
* Return equivalent words for the source term in the target language.
14-
15-
* Return grammatical structure and context examples for the source term and target term pair.
13+
- Use LLM models to produce translation output variants that are tone-specific and gender-aware.
1614

1715
[Source code][python-dt-src]
1816
| [Package (PyPI)][python-dt-pypi]
@@ -101,7 +99,7 @@ try:
10199
f"Number of supported languages for transliterate operation: {len(response.transliteration) if response.transliteration is not None else 0}"
102100
)
103101
print(
104-
f"Number of supported languages for dictionary operations: {len(response.dictionary) if response.dictionary is not None else 0}"
102+
f"Number of supported models for translation: {len(response.models) if response.models is not None else 0}"
105103
)
106104

107105
if response.translation is not None:
@@ -114,10 +112,8 @@ try:
114112
for key, value in response.transliteration.items():
115113
print(f"{key} -- name: {value.name}, supported script count: {len(value.scripts)}")
116114

117-
if response.dictionary is not None:
118-
print("Dictionary Languages:")
119-
for key, value in response.dictionary.items():
120-
print(f"{key} -- name: {value.name}, supported target languages count: {len(value.translations)}")
115+
if response.models is not None:
116+
print(f"Models: {', '.join(response.models)}")
121117

122118
except HttpResponseError as exception:
123119
if exception.error is not None:
@@ -153,7 +149,9 @@ try:
153149
f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}."
154150
)
155151
for translated_text in translation.translations:
156-
print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.")
152+
print(
153+
f"Text was translated to: '{translated_text.language}' and the result is: '{translated_text.text}'."
154+
)
157155

158156
except HttpResponseError as exception:
159157
if exception.error is not None:
@@ -163,7 +161,6 @@ except HttpResponseError as exception:
163161

164162
<!-- END SNIPPET -->
165163

166-
167164
For samples on using the `translate` endpoint refer to more samples [here][translate_sample].
168165

169166
Please refer to the service documentation for a conceptual discussion of [translate][translate_doc].
@@ -202,131 +199,18 @@ except HttpResponseError as exception:
202199
```
203200

204201
<!-- END SNIPPET -->
202+
205203
For samples on using the `transliterate` endpoint refer to more samples [here][transliterate_sample].
206204

207205
Please refer to the service documentation for a conceptual discussion of [transliterate][transliterate_doc].
208206

209-
### Break Sentence
210-
211-
Identifies the positioning of sentence boundaries in a piece of text.
212-
213-
<!-- SNIPPET: sample_text_translation_translate.get_text_translation_sentence_length -->
214-
215-
```python
216-
try:
217-
include_sentence_length = True
218-
to_language = ["cs"]
219-
input_text_elements = ["The answer lies in machine translation. This is a test."]
220-
221-
response = text_translator.translate(
222-
body=input_text_elements, to_language=to_language, include_sentence_length=include_sentence_length
223-
)
224-
translation = response[0] if response else None
225-
226-
if translation:
227-
detected_language = translation.detected_language
228-
if detected_language:
229-
print(
230-
f"Detected languages of the input text: {detected_language.language} with score: {detected_language.score}."
231-
)
232-
for translated_text in translation.translations:
233-
print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.")
234-
if translated_text.sent_len:
235-
print(f"Source Sentence length: {translated_text.sent_len.src_sent_len}")
236-
print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}")
237-
238-
except HttpResponseError as exception:
239-
if exception.error is not None:
240-
print(f"Error Code: {exception.error.code}")
241-
print(f"Message: {exception.error.message}")
242-
```
243-
244-
<!-- END SNIPPET -->
245-
246-
For samples on using the `break sentence` endpoint refer to more samples [here][breaksentence_sample].
247-
248-
Please refer to the service documentation for a conceptual discussion of [break sentence][breaksentence_doc].
249-
250-
### Dictionary Lookup
251-
252-
Returns equivalent words for the source term in the target language.
253-
254-
<!-- SNIPPET: sample_text_translation_dictionary_lookup.get_text_translation_dictionary_lookup -->
255-
256-
```python
257-
try:
258-
from_language = "en"
259-
to_language = "es"
260-
input_text_elements = ["fly"]
261-
262-
response = text_translator.lookup_dictionary_entries(
263-
body=input_text_elements, from_language=from_language, to_language=to_language
264-
)
265-
dictionary_entry = response[0] if response else None
266-
267-
if dictionary_entry:
268-
print(f"For the given input {len(dictionary_entry.translations)} entries were found in the dictionary.")
269-
print(
270-
f"First entry: '{dictionary_entry.translations[0].display_target}', confidence: {dictionary_entry.translations[0].confidence}."
271-
)
272-
273-
except HttpResponseError as exception:
274-
if exception.error is not None:
275-
print(f"Error Code: {exception.error.code}")
276-
print(f"Message: {exception.error.message}")
277-
raise
278-
```
279-
280-
<!-- END SNIPPET -->
281-
282-
For samples on using the `dictionary lookup` endpoint refer to more samples [here][dictionarylookup_sample].
283-
284-
Please refer to the service documentation for a conceptual discussion of [dictionary lookup][dictionarylookup_doc].
285-
286-
### Dictionary Examples
287-
288-
Returns grammatical structure and context examples for the source term and target term pair.
289-
290-
<!-- SNIPPET: sample_text_translation_dictionary_examples.get_text_translation_dictionary_examples -->
291-
292-
```python
293-
try:
294-
from_language = "en"
295-
to_language = "es"
296-
input_text_elements = [DictionaryExampleTextItem(text="fly", translation="volar")]
297-
298-
response = text_translator.lookup_dictionary_examples(
299-
body=input_text_elements, from_language=from_language, to_language=to_language
300-
)
301-
dictionary_entry = response[0] if response else None
302-
303-
if dictionary_entry:
304-
print(f"For the given input {len(dictionary_entry.examples)} entries were found in the dictionary.")
305-
print(
306-
f"First example: '{dictionary_entry.examples[0].target_prefix}{dictionary_entry.examples[0].target_term}{dictionary_entry.examples[0].target_suffix}'."
307-
)
308-
309-
except HttpResponseError as exception:
310-
if exception.error is not None:
311-
print(f"Error Code: {exception.error.code}")
312-
print(f"Message: {exception.error.message}")
313-
raise
314-
```
315-
316-
<!-- END SNIPPET -->
317-
318-
For samples on using the `dictionary examples` endpoint refer to more samples [here][dictionaryexamples_sample].
319-
320-
Please refer to the service documentation for a conceptual discussion of [dictionary examples][dictionaryexamples_doc].
321207

322208
## Troubleshooting
323209

324210
When you interact with the Translator Service using the TextTranslator client library, errors returned by the Translator service correspond to the same HTTP status codes returned for REST API requests.
325211

326212
For example, if you submit a translation request without a target translate language, a `400` error is returned, indicating "Bad Request".
327213

328-
You can find the different error codes returned by the service in the [Service Documentation][service_errors].
329-
330214
## Provide Feedback
331215

332216
If you encounter any bugs or have suggestions, please file an issue in the
@@ -350,7 +234,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
350234
[python-dt-src]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/azure/ai/translation/text
351235
[python-dt-pypi]: https://aka.ms/azsdk/python/texttranslation/pypi
352236
[python-dt-product-docs]: https://learn.microsoft.com/azure/cognitive-services/translator/
353-
[python-dt-ref-docs]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference
237+
[python-dt-ref-docs]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/rest-api-guide
354238
[python-dt-samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples
355239

356240
[pip]: https://pypi.org/project/pip/
@@ -361,24 +245,17 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
361245

362246
[translator_client_class]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_client.py
363247

364-
[translator_auth]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#authentication
248+
[translator_auth]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/reference/authentication
365249
[translator_limits]: https://learn.microsoft.com/azure/cognitive-services/translator/request-limits
366-
[service_errors]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#errors
367250

368-
[languages_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-languages
369-
[translate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-translate
370-
[transliterate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-transliterate
371-
[breaksentence_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-break-sentence
372-
[dictionarylookup_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-lookup
373-
[dictionaryexamples_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-dictionary-examples
251+
[languages_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/get-languages
252+
[translate_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/translate-api
253+
[transliterate_doc]: https://learn.microsoft.com/azure/ai-services/translator/text-translation/preview/transliterate-api
374254

375255
[client_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_client.py
376256
[languages_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_languages.py
377257
[translate_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_translate.py
378258
[transliterate_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_transliterate.py
379-
[breaksentence_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_break_sentence.py
380-
[dictionarylookup_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_lookup.py
381-
[dictionaryexamples_sample]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples/sample_text_translation_dictionary_examples.py
382259

383260
[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/translation/azure-ai-translation-text/samples
384261

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"apiVersion": "2025-10-01-preview"
3+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"CrossLanguagePackageId": "TextTranslation",
3+
"CrossLanguageDefinitionId": {
4+
"azure.ai.translation.text.models.DetectedLanguage": "TextTranslation.DetectedLanguage",
5+
"azure.ai.translation.text.models.ErrorDetails": "TextTranslation.ErrorDetails",
6+
"azure.ai.translation.text.models.ErrorResponse": "TextTranslation.ErrorResponse",
7+
"azure.ai.translation.text.models.GetSupportedLanguagesResult": "TextTranslation.GetSupportedLanguagesResult",
8+
"azure.ai.translation.text.models.InputTextItem": "TextTranslation.InputTextItem",
9+
"azure.ai.translation.text.models.LanguageScript": "TextTranslation.LanguageScript",
10+
"azure.ai.translation.text.models.ReferenceTextPair": "TextTranslation.ReferenceTextPair",
11+
"azure.ai.translation.text.models.TranslateBody": "TextTranslation.TranslateBody",
12+
"azure.ai.translation.text.models.TranslatedTextItem": "TextTranslation.TranslatedTextItem",
13+
"azure.ai.translation.text.models.TranslateInputItem": "TextTranslation.TranslateInputItem",
14+
"azure.ai.translation.text.models.TranslationLanguage": "TextTranslation.TranslationLanguage",
15+
"azure.ai.translation.text.models.TranslationResult": "TextTranslation.TranslationResult",
16+
"azure.ai.translation.text.models.TranslationTarget": "TextTranslation.TranslationTarget",
17+
"azure.ai.translation.text.models.TranslationText": "TextTranslation.TranslationText",
18+
"azure.ai.translation.text.models.TransliterableScript": "TextTranslation.TransliterableScript",
19+
"azure.ai.translation.text.models.TransliterateBody": "TextTranslation.TransliterateBody",
20+
"azure.ai.translation.text.models.TransliteratedText": "TextTranslation.TransliteratedText",
21+
"azure.ai.translation.text.models.TransliterateResult": "TextTranslation.TransliterateResult",
22+
"azure.ai.translation.text.models.TransliterationLanguage": "TextTranslation.TransliterationLanguage",
23+
"azure.ai.translation.text.models.LanguageDirectionality": "TextTranslation.LanguageDirectionality",
24+
"azure.ai.translation.text.models.TextType": "TextTranslation.TextType",
25+
"azure.ai.translation.text.models.ProfanityAction": "TextTranslation.ProfanityAction",
26+
"azure.ai.translation.text.models.ProfanityMarker": "TextTranslation.ProfanityMarker",
27+
"azure.ai.translation.text.TextTranslationClient.get_supported_languages": "TextTranslation.getSupportedLanguages",
28+
"azure.ai.translation.text.aio.TextTranslationClient.get_supported_languages": "TextTranslation.getSupportedLanguages",
29+
"azure.ai.translation.text.TextTranslationClient.translate": "TextTranslation.translate",
30+
"azure.ai.translation.text.aio.TextTranslationClient.translate": "TextTranslation.translate",
31+
"azure.ai.translation.text.TextTranslationClient.transliterate": "TextTranslation.transliterate",
32+
"azure.ai.translation.text.aio.TextTranslationClient.transliterate": "TextTranslation.transliterate"
33+
}
34+
}

sdk/translation/azure-ai-translation-text/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/translation/azure-ai-translation-text",
5-
"Tag": "python/translation/azure-ai-translation-text_35ab9367d7"
5+
"Tag": "python/translation/azure-ai-translation-text_0fb3c1db32"
66
}

sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@
55
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
8+
# pylint: disable=wrong-import-position
89

9-
from ._patch import TextTranslationClient
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import TextTranslationClient # type: ignore
1016
from ._version import VERSION
1117

1218
__version__ = VERSION
1319

14-
20+
try:
21+
from ._patch import __all__ as _patch_all
22+
from ._patch import *
23+
except ImportError:
24+
_patch_all = []
1525
from ._patch import patch_sdk as _patch_sdk
1626

1727
__all__ = [
1828
"TextTranslationClient",
1929
]
20-
30+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2131

2232
_patch_sdk()

0 commit comments

Comments
 (0)