-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Adding Translation Text Service SDK #29569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 42 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
3b5fb54
Initial commit
d4887e5
Merge pull request #1 from MikeyMCZ/mimat/adding_translator
MikeyMCZ 02106ff
Updates for async operations
0425d35
Removing Detect, Fixing BreakSentence
26291e9
Moving to correct location
8907967
Adding samples
e3c2bb2
Updating samples
8d161fb
Update names
74c5f75
Remove custom endpoint file
b561114
Update names according to APIView review
007a7b1
Trying to investigate failing tests
HamshavathiM 56842d2
Investigation translate call failure
HamshavathiM 3d279b0
Merge branch 'Azure:main' into main
MikeyMCZ 5ddce40
Fixing spelling issues
37fb5db
Merge
851cebe
Spelling fixes
c00979b
Links in MD files updated
956c2c5
Updating samples
1f07a0a
Spelling fix
0180713
Readme file fix
96a3a58
Adding missing chapters to README
15e9c3d
Commiting before syncing to main
HamshavathiM 1b1a5b3
Merge remote-tracking branch 'origin/main' into Hamsha/GettingStarted…
HamshavathiM fc9ee6b
Update version in the changelog
f20a3aa
Merge pull request #3 from MikeyMCZ/mimat/fix-pipeline
MikeyMCZ 89d1ae6
Add package_data to setup
bce652f
exclude packages that would be excluded by pep420.
scbedd 39399a9
Adding description content type
221de72
Update setup.py
93b6a3d
Removing license
473e706
Fixing setup file
7a61a64
Adding all test cases and recordings
HamshavathiM f254f56
Updated test-resources.json
HamshavathiM 4a63705
Updated endpoint value for token test
HamshavathiM ed05f0d
Fixing mypy
3856dcb
Adding pyproject.toml
5e5cc07
Testing translate with token test
HamshavathiM 73f5086
Fixed translate token test and updated all recordings
HamshavathiM c77b249
Fixing linting
HamshavathiM 6ef0cf7
Merge pull request #2 from MikeyMCZ/Hamsha/GettingStartedWithTests
hamshavathimunibyraiah d96c9bc
Fixing spelling in the test files
eaba407
Fixing test errors found in pipeline (#4)
hamshavathimunibyraiah 87329ac
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ 5e29811
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ 088a5b4
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ 4342c5b
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ e9ab6cf
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ f285f64
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ dd3f154
Update sdk/translation/azure-ai-translation-text/samples/README.md
MikeyMCZ a76cb46
Update sdk/translation/azure-ai-translation-text/setup.py
MikeyMCZ 1abf440
Fixing PR comments
f08de36
Fixing PR comments
c7873aa
Fixing PR comments
13c31d6
Fixing the links
55f61f2
Reference shared implementations
3ab92f5
Sharing more implementation
e016d9a
Removing unused imports
c084473
Using hasattr instead of isinstance
868bdfb
Merge branch 'Azure:main' into main
MikeyMCZ ce54e14
Fix build
2e97833
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
1471ed4
Merge branch 'Azure:main' into main
MikeyMCZ 4e7e7d2
Sample update
8ac5ba8
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
4311686
Update sdk/translation/azure-ai-translation-text/setup.py
MikeyMCZ dc60fd7
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ 50ea95b
Update sdk/translation/azure-ai-translation-text/azure/ai/translation…
MikeyMCZ 3d83cd1
Fixing PR comments
30557fd
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
413642a
PR fixes
eeb0f91
Passing default scope to the token policy
cc6d38f
Fixing PR comments
94b6821
Fixing the PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 (2023-03-24) | ||
|
|
||
| - Initial Release | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.