Skip to content

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 73 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
3b5fb54
Initial commit
Feb 16, 2023
d4887e5
Merge pull request #1 from MikeyMCZ/mimat/adding_translator
MikeyMCZ Feb 22, 2023
02106ff
Updates for async operations
Feb 23, 2023
0425d35
Removing Detect, Fixing BreakSentence
Feb 27, 2023
26291e9
Moving to correct location
Mar 1, 2023
8907967
Adding samples
Mar 7, 2023
e3c2bb2
Updating samples
Mar 8, 2023
8d161fb
Update names
Mar 14, 2023
74c5f75
Remove custom endpoint file
Mar 14, 2023
b561114
Update names according to APIView review
Mar 17, 2023
007a7b1
Trying to investigate failing tests
HamshavathiM Mar 23, 2023
56842d2
Investigation translate call failure
HamshavathiM Mar 23, 2023
3d279b0
Merge branch 'Azure:main' into main
MikeyMCZ Mar 24, 2023
5ddce40
Fixing spelling issues
Mar 24, 2023
37fb5db
Merge
Mar 24, 2023
851cebe
Spelling fixes
Mar 24, 2023
c00979b
Links in MD files updated
Mar 24, 2023
956c2c5
Updating samples
Mar 24, 2023
1f07a0a
Spelling fix
Mar 24, 2023
0180713
Readme file fix
Mar 24, 2023
96a3a58
Adding missing chapters to README
Mar 24, 2023
15e9c3d
Commiting before syncing to main
HamshavathiM Mar 24, 2023
1b1a5b3
Merge remote-tracking branch 'origin/main' into Hamsha/GettingStarted…
HamshavathiM Mar 24, 2023
fc9ee6b
Update version in the changelog
Mar 24, 2023
f20a3aa
Merge pull request #3 from MikeyMCZ/mimat/fix-pipeline
MikeyMCZ Mar 24, 2023
89d1ae6
Add package_data to setup
Mar 24, 2023
bce652f
exclude packages that would be excluded by pep420.
scbedd Mar 24, 2023
39399a9
Adding description content type
Mar 24, 2023
221de72
Update setup.py
Mar 24, 2023
93b6a3d
Removing license
Mar 24, 2023
473e706
Fixing setup file
Mar 24, 2023
7a61a64
Adding all test cases and recordings
HamshavathiM Mar 27, 2023
f254f56
Updated test-resources.json
HamshavathiM Mar 27, 2023
4a63705
Updated endpoint value for token test
HamshavathiM Mar 28, 2023
ed05f0d
Fixing mypy
Mar 28, 2023
3856dcb
Adding pyproject.toml
Mar 28, 2023
5e5cc07
Testing translate with token test
HamshavathiM Mar 31, 2023
73f5086
Fixed translate token test and updated all recordings
HamshavathiM Mar 31, 2023
c77b249
Fixing linting
HamshavathiM Apr 3, 2023
6ef0cf7
Merge pull request #2 from MikeyMCZ/Hamsha/GettingStartedWithTests
hamshavathimunibyraiah Apr 3, 2023
d96c9bc
Fixing spelling in the test files
Apr 3, 2023
eaba407
Fixing test errors found in pipeline (#4)
hamshavathimunibyraiah Apr 3, 2023
87329ac
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
5e29811
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
088a5b4
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
4342c5b
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
e9ab6cf
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
f285f64
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 4, 2023
dd3f154
Update sdk/translation/azure-ai-translation-text/samples/README.md
MikeyMCZ Apr 4, 2023
a76cb46
Update sdk/translation/azure-ai-translation-text/setup.py
MikeyMCZ Apr 4, 2023
1abf440
Fixing PR comments
Apr 4, 2023
f08de36
Fixing PR comments
Apr 5, 2023
c7873aa
Fixing PR comments
Apr 5, 2023
13c31d6
Fixing the links
Apr 5, 2023
55f61f2
Reference shared implementations
Apr 5, 2023
3ab92f5
Sharing more implementation
Apr 5, 2023
e016d9a
Removing unused imports
Apr 5, 2023
c084473
Using hasattr instead of isinstance
Apr 5, 2023
868bdfb
Merge branch 'Azure:main' into main
MikeyMCZ Apr 5, 2023
ce54e14
Fix build
Apr 5, 2023
2e97833
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
Apr 5, 2023
1471ed4
Merge branch 'Azure:main' into main
MikeyMCZ Apr 5, 2023
4e7e7d2
Sample update
Apr 5, 2023
8ac5ba8
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
Apr 5, 2023
4311686
Update sdk/translation/azure-ai-translation-text/setup.py
MikeyMCZ Apr 6, 2023
dc60fd7
Update sdk/translation/azure-ai-translation-text/README.md
MikeyMCZ Apr 6, 2023
50ea95b
Update sdk/translation/azure-ai-translation-text/azure/ai/translation…
MikeyMCZ Apr 6, 2023
3d83cd1
Fixing PR comments
Apr 6, 2023
30557fd
Merge branch 'main' of https://github.com/MikeyMCZ/azure-sdk-for-python
Apr 6, 2023
413642a
PR fixes
Apr 6, 2023
eeb0f91
Passing default scope to the token policy
Apr 6, 2023
cc6d38f
Fixing PR comments
Apr 6, 2023
94b6821
Fixing the PR comments
Apr 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
"sdk/ml/azure-ai-ml/NOTICE.txt",
"sdk/loadtestservice/azure-developer-loadtesting/**",
"sdk/monitor/azure-monitor-ingestion/**",
"sdk/translation/azure-ai-translation-text/azure/ai/translation/text/_serialization.py",
"sdk/translation/azure-ai-translation-text/tests/test_break_sentence.py",
"sdk/translation/azure-ai-translation-text/tests/test_translation.py",
"sdk/translation/azure-ai-translation-text/tests/test_transliteration.py",
"sdk/translation/test-resources.json",
"eng/**/*.json",
"eng/*.txt",
"eng/tox/tox.ini",
Expand Down Expand Up @@ -483,6 +488,20 @@
"myfoldername"
]
},
{
"filename": "sdk/translation/azure-ai-translation-text/**",
"words": [
"akhtabar",
"deserializers",
"Esto",
"hudha",
"mosca",
"mros",
"NOACTION",
"prueba",
"wordomatic"
]
},
{
"filename": "sdk/textanalytics/azure-ai-textanalytics/**",
"words": [
Expand Down
5 changes: 5 additions & 0 deletions sdk/translation/azure-ai-translation-text/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 1.0.0b1 (Unreleased)

- Initial Release
21 changes: 21 additions & 0 deletions sdk/translation/azure-ai-translation-text/LICENSE
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.
8 changes: 8 additions & 0 deletions sdk/translation/azure-ai-translation-text/MANIFEST.in
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
319 changes: 319 additions & 0 deletions sdk/translation/azure-ai-translation-text/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
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()
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)
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")
Loading