-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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) <v-hmunibyrai@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/samples/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/setup.py Co-authored-by: Krista Pratico <krpratic@microsoft.com> * 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 <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/README.md Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Update sdk/translation/azure-ai-translation-text/azure/ai/translation/text/aio/_patch.py Co-authored-by: Krista Pratico <krpratic@microsoft.com> * Fixing PR comments * PR fixes * Passing default scope to the token policy * Fixing PR comments * Fixing the PR comments --------- Co-authored-by: Michal Materna <mimat@microsoft.com> Co-authored-by: Hamshavathi Munibyraiah (Murphy V-hmunibyrai Associates Inc) <v-hmunibyrai@microsoft.com> Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com> Co-authored-by: hamshavathimunibyraiah <125092972+hamshavathimunibyraiah@users.noreply.github.com> Co-authored-by: Krista Pratico <krpratic@microsoft.com>
- Loading branch information
1 parent
8a20de4
commit dafceb2
Showing
88 changed files
with
20,851 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Release History | ||
|
||
## 1.0.0b1 (Unreleased) | ||
|
||
- Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) Microsoft Corporation. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
recursive-include tests *.py | ||
recursive-include samples *.py *.md | ||
include *.md | ||
include LICENSE | ||
include azure/__init__.py | ||
include azure/ai/__init__.py | ||
include azure/ai/translation/__init__.py | ||
include azure/ai/translation/text/py.typed |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore |
1 change: 1 addition & 0 deletions
1
sdk/translation/azure-ai-translation-text/azure/ai/translation/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore |
26 changes: 26 additions & 0 deletions
26
sdk/translation/azure-ai-translation-text/azure/ai/translation/text/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._patch import TextTranslationClient | ||
from ._version import VERSION | ||
|
||
__version__ = VERSION | ||
|
||
try: | ||
from ._patch import __all__ as _patch_all | ||
from ._patch import * # pylint: disable=unused-wildcard-import | ||
except ImportError: | ||
_patch_all = [] | ||
from ._patch import patch_sdk as _patch_sdk | ||
|
||
__all__ = [ | ||
"TextTranslationClient", | ||
] | ||
__all__.extend([p for p in _patch_all if p not in __all__]) | ||
|
||
_patch_sdk() |
97 changes: 97 additions & 0 deletions
97
sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from copy import deepcopy | ||
from typing import Any | ||
|
||
from azure.core import PipelineClient | ||
from azure.core.rest import HttpRequest, HttpResponse | ||
|
||
from ._configuration import TextTranslationClientConfiguration | ||
from ._operations import TextTranslationClientOperationsMixin | ||
from ._serialization import Deserializer, Serializer | ||
|
||
|
||
class TextTranslationClient(TextTranslationClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
"""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. | ||
The following methods are supported by the Text Translation feature: | ||
Languages. Returns a list of languages supported by Translate, Transliterate, and Dictionary | ||
Lookup operations. | ||
Translate. Renders single source-language text to multiple target-language texts with a single | ||
request. | ||
Transliterate. Converts characters or letters of a source language to the corresponding | ||
characters or letters of a target language. | ||
Detect. Returns the source code language code and a boolean variable denoting whether the | ||
detected language is supported for text translation and transliteration. | ||
Dictionary lookup. Returns equivalent words for the source term in the target language. | ||
Dictionary example Returns grammatical structure and context examples for the source term and | ||
target term pair. | ||
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example: | ||
https://api.cognitive.microsofttranslator.com). Required. | ||
:type endpoint: str | ||
:keyword api_version: Default value is "3.0". Note that overriding this default value may | ||
result in unsupported behavior. | ||
:paramtype api_version: str | ||
""" | ||
|
||
def __init__( # pylint: disable=missing-client-constructor-parameter-credential | ||
self, endpoint: str, **kwargs: Any | ||
) -> None: | ||
_endpoint = "{Endpoint}" | ||
self._config = TextTranslationClientConfiguration(endpoint=endpoint, **kwargs) | ||
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) | ||
|
||
self._serialize = Serializer() | ||
self._deserialize = Deserializer() | ||
self._serialize.client_side_validation = False | ||
|
||
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: | ||
"""Runs the network request through the client's chained policies. | ||
>>> from azure.core.rest import HttpRequest | ||
>>> request = HttpRequest("GET", "https://www.example.org/") | ||
<HttpRequest [GET], url: 'https://www.example.org/'> | ||
>>> response = client.send_request(request) | ||
<HttpResponse: 200 OK> | ||
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request | ||
:param request: The network request you want to make. Required. | ||
:type request: ~azure.core.rest.HttpRequest | ||
:keyword bool stream: Whether the response payload will be streamed. Defaults to False. | ||
:return: The response of your network call. Does not do error handling on your response. | ||
:rtype: ~azure.core.rest.HttpResponse | ||
""" | ||
|
||
request_copy = deepcopy(request) | ||
path_format_arguments = { | ||
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), | ||
} | ||
|
||
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) | ||
return self._client.send_request(request_copy, **kwargs) | ||
|
||
def close(self) -> None: | ||
self._client.close() | ||
|
||
def __enter__(self) -> "TextTranslationClient": | ||
self._client.__enter__() | ||
return self | ||
|
||
def __exit__(self, *exc_details: Any) -> None: | ||
self._client.__exit__(*exc_details) |
58 changes: 58 additions & 0 deletions
58
sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
import sys | ||
from typing import Any | ||
|
||
from azure.core.configuration import Configuration | ||
from azure.core.pipeline import policies | ||
|
||
from ._version import VERSION | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports | ||
else: | ||
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports | ||
|
||
|
||
class TextTranslationClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes | ||
"""Configuration for TextTranslationClient. | ||
Note that all parameters used to create this instance are saved as instance | ||
attributes. | ||
:param endpoint: Supported Text Translation endpoints (protocol and hostname, for example: | ||
https://api.cognitive.microsofttranslator.com). Required. | ||
:type endpoint: str | ||
:keyword api_version: Default value is "3.0". Note that overriding this default value may | ||
result in unsupported behavior. | ||
:paramtype api_version: str | ||
""" | ||
|
||
def __init__(self, endpoint: str, **kwargs: Any) -> None: | ||
super(TextTranslationClientConfiguration, self).__init__(**kwargs) | ||
api_version: Literal["3.0"] = kwargs.pop("api_version", "3.0") | ||
|
||
if endpoint is None: | ||
raise ValueError("Parameter 'endpoint' must not be None.") | ||
|
||
self.endpoint = endpoint | ||
self.api_version = api_version | ||
kwargs.setdefault("sdk_moniker", "ai-translation-text/{}".format(VERSION)) | ||
self._configure(**kwargs) | ||
|
||
def _configure(self, **kwargs: Any) -> None: | ||
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) | ||
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) | ||
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) | ||
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) | ||
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) | ||
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) | ||
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) | ||
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) | ||
self.authentication_policy = kwargs.get("authentication_policy") |
Oops, something went wrong.