Skip to content

Commit dafceb2

Browse files
MikeyMCZMichal MaternaHamshavathiMscbeddhamshavathimunibyraiah
authored
Adding Translation Text Service SDK (#29569)
* Initial commit * Updates for async operations * Removing Detect, Fixing BreakSentence * Moving to correct location * Adding samples * Updating samples * Update names * Remove custom endpoint file * Update names according to APIView review * Trying to investigate failing tests * Investigation translate call failure * Fixing spelling issues * Spelling fixes * Links in MD files updated * Updating samples * Spelling fix * Readme file fix * Adding missing chapters to README * Commiting before syncing to main * Update version in the changelog * Add package_data to setup * exclude packages that would be excluded by pep420. * Adding description content type * Update setup.py * Removing license * Fixing setup file * Adding all test cases and recordings * Updated test-resources.json * Updated endpoint value for token test * Fixing mypy * Adding pyproject.toml * Testing translate with token test * Fixed translate token test and updated all recordings * Fixing linting * Fixing spelling in the test files * Fixing test errors found in pipeline (#4) Co-authored-by: Hamshavathi Munibyraiah (Murphy V-hmunibyrai Associates Inc) <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/samples/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/setup.py Co-authored-by: Krista Pratico <[email protected]> * Fixing PR comments * Fixing PR comments * Fixing PR comments * Fixing the links * Reference shared implementations * Sharing more implementation * Removing unused imports * Using hasattr instead of isinstance * Fix build * Sample update * Update sdk/translation/azure-ai-translation-text/setup.py Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <[email protected]> * Update sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py Co-authored-by: Krista Pratico <[email protected]> * Fixing PR comments * PR fixes * Passing default scope to the token policy * Fixing PR comments * Fixing the PR comments --------- Co-authored-by: Michal Materna <[email protected]> Co-authored-by: Hamshavathi Munibyraiah (Murphy V-hmunibyrai Associates Inc) <[email protected]> Co-authored-by: scbedd <[email protected]> Co-authored-by: hamshavathimunibyraiah <[email protected]> Co-authored-by: Krista Pratico <[email protected]>
1 parent 8a20de4 commit dafceb2

File tree

88 files changed

+20851
-0
lines changed

Some content is hidden

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

88 files changed

+20851
-0
lines changed

.vscode/cspell.json

+19
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
"sdk/ml/azure-ai-ml/NOTICE.txt",
9292
"sdk/loadtestservice/azure-developer-loadtesting/**",
9393
"sdk/monitor/azure-monitor-ingestion/**",
94+
"sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_serialization.py",
95+
"sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py",
96+
"sdk/translation/azure-ai-translation-text/tests/test_translation.py",
97+
"sdk/translation/azure-ai-translation-text/tests/test_transliteration.py",
98+
"sdk/translation/test-resources.json",
9499
"eng/**/*.json",
95100
"eng/*.txt",
96101
"eng/tox/tox.ini",
@@ -483,6 +488,20 @@
483488
"myfoldername"
484489
]
485490
},
491+
{
492+
"filename": "sdk/translation/azure-ai-translation-text/**",
493+
"words": [
494+
"akhtabar",
495+
"deserializers",
496+
"Esto",
497+
"hudha",
498+
"mosca",
499+
"mros",
500+
"NOACTION",
501+
"prueba",
502+
"wordomatic"
503+
]
504+
},
486505
{
487506
"filename": "sdk/textanalytics/azure-ai-textanalytics/**",
488507
"words": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release History
2+
3+
## 1.0.0b1 (Unreleased)
4+
5+
- Initial Release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
recursive-include tests *.py
2+
recursive-include samples *.py *.md
3+
include *.md
4+
include LICENSE
5+
include azure/__init__.py
6+
include azure/ai/__init__.py
7+
include azure/ai/translation/__init__.py
8+
include azure/ai/translation/text/py.typed

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

+319
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._patch import TextTranslationClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = [
22+
"TextTranslationClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any
11+
12+
from azure.core import PipelineClient
13+
from azure.core.rest import HttpRequest, HttpResponse
14+
15+
from ._configuration import TextTranslationClientConfiguration
16+
from ._operations import TextTranslationClientOperationsMixin
17+
from ._serialization import Deserializer, Serializer
18+
19+
20+
class TextTranslationClient(TextTranslationClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
21+
"""Text translation is a cloud-based REST API feature of the Translator service that uses neural
22+
machine translation technology to enable quick and accurate source-to-target text translation
23+
in real time across all supported languages.
24+
25+
The following methods are supported by the Text Translation feature:
26+
27+
Languages. Returns a list of languages supported by Translate, Transliterate, and Dictionary
28+
Lookup operations.
29+
30+
Translate. Renders single source-language text to multiple target-language texts with a single
31+
request.
32+
33+
Transliterate. Converts characters or letters of a source language to the corresponding
34+
characters or letters of a target language.
35+
36+
Detect. Returns the source code language code and a boolean variable denoting whether the
37+
detected language is supported for text translation and transliteration.
38+
39+
Dictionary lookup. Returns equivalent words for the source term in the target language.
40+
41+
Dictionary example Returns grammatical structure and context examples for the source term and
42+
target term pair.
43+
44+
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example:
45+
https://api.cognitive.microsofttranslator.com). Required.
46+
:type endpoint: str
47+
:keyword api_version: Default value is "3.0". Note that overriding this default value may
48+
result in unsupported behavior.
49+
:paramtype api_version: str
50+
"""
51+
52+
def __init__( # pylint: disable=missing-client-constructor-parameter-credential
53+
self, endpoint: str, **kwargs: Any
54+
) -> None:
55+
_endpoint = "{Endpoint}"
56+
self._config = TextTranslationClientConfiguration(endpoint=endpoint, **kwargs)
57+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
58+
59+
self._serialize = Serializer()
60+
self._deserialize = Deserializer()
61+
self._serialize.client_side_validation = False
62+
63+
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
64+
"""Runs the network request through the client's chained policies.
65+
66+
>>> from azure.core.rest import HttpRequest
67+
>>> request = HttpRequest("GET", "https://www.example.org/")
68+
<HttpRequest [GET], url: 'https://www.example.org/'>
69+
>>> response = client.send_request(request)
70+
<HttpResponse: 200 OK>
71+
72+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
73+
74+
:param request: The network request you want to make. Required.
75+
:type request: ~azure.core.rest.HttpRequest
76+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
77+
:return: The response of your network call. Does not do error handling on your response.
78+
:rtype: ~azure.core.rest.HttpResponse
79+
"""
80+
81+
request_copy = deepcopy(request)
82+
path_format_arguments = {
83+
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
84+
}
85+
86+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
87+
return self._client.send_request(request_copy, **kwargs)
88+
89+
def close(self) -> None:
90+
self._client.close()
91+
92+
def __enter__(self) -> "TextTranslationClient":
93+
self._client.__enter__()
94+
return self
95+
96+
def __exit__(self, *exc_details: Any) -> None:
97+
self._client.__exit__(*exc_details)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
import sys
10+
from typing import Any
11+
12+
from azure.core.configuration import Configuration
13+
from azure.core.pipeline import policies
14+
15+
from ._version import VERSION
16+
17+
if sys.version_info >= (3, 8):
18+
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
19+
else:
20+
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
21+
22+
23+
class TextTranslationClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
24+
"""Configuration for TextTranslationClient.
25+
26+
Note that all parameters used to create this instance are saved as instance
27+
attributes.
28+
29+
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example:
30+
https://api.cognitive.microsofttranslator.com). Required.
31+
:type endpoint: str
32+
:keyword api_version: Default value is "3.0". Note that overriding this default value may
33+
result in unsupported behavior.
34+
:paramtype api_version: str
35+
"""
36+
37+
def __init__(self, endpoint: str, **kwargs: Any) -> None:
38+
super(TextTranslationClientConfiguration, self).__init__(**kwargs)
39+
api_version: Literal["3.0"] = kwargs.pop("api_version", "3.0")
40+
41+
if endpoint is None:
42+
raise ValueError("Parameter 'endpoint' must not be None.")
43+
44+
self.endpoint = endpoint
45+
self.api_version = api_version
46+
kwargs.setdefault("sdk_moniker", "ai-translation-text/{}".format(VERSION))
47+
self._configure(**kwargs)
48+
49+
def _configure(self, **kwargs: Any) -> None:
50+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
51+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
52+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
53+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
54+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
55+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
56+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
57+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
58+
self.authentication_policy = kwargs.get("authentication_policy")

0 commit comments

Comments
 (0)