Skip to content

Commit 11e1ecd

Browse files
MikeyMCZMichal Materna
andauthored
[Text Translation] Allow users to pass in just string instead of complex object (Azure#34516)
* Allow users to pass in just string instead of complex object * Update change log * Fix spelling error * Update changelog * Fix changelog * Update version number * Fix the build * Fix build * Fix the mypy issues * Fixing PR comments --------- Co-authored-by: Michal Materna <[email protected]>
1 parent b930399 commit 11e1ecd

34 files changed

+4665
-522
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Release History
22

33
## 1.0.0b2 (Unreleased)
4-
5-
- All calls to the client using parameter 'content' have been changed to use parameter 'request_body'.
6-
4+
75
### Features Added
86

97
### Breaking Changes
108

9+
- All calls to the client using parameter 'content' have been changed to use parameter 'request_body'.
10+
- Users can call methods using just a string type instead of complex objects.
11+
1112
### Bugs Fixed
1213

1314
### Other Changes

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ With the value of the `endpoint`, `credential` and a `region`, you can create th
6464

6565
```python
6666
credential = TranslatorCredential(apikey, region)
67-
text_translator = TextTranslationClient(credential, endpoint=endpoint)
67+
text_translator = TextTranslationClient(credential=credential, endpoint=endpoint)
6868
```
6969

7070
<!-- END SNIPPET -->
@@ -141,7 +141,7 @@ Renders single source-language text to multiple target-language texts with a sin
141141
```python
142142
try:
143143
target_languages = ["cs", "es", "de"]
144-
input_text_elements = [InputTextItem(text="This is a test")]
144+
input_text_elements = ["This is a test"]
145145

146146
response = text_translator.translate(request_body=input_text_elements, to=target_languages)
147147
translation = response[0] if response else None
@@ -156,8 +156,9 @@ try:
156156
print(f"Text was translated to: '{translated_text.to}' and the result is: '{translated_text.text}'.")
157157

158158
except HttpResponseError as exception:
159-
print(f"Error Code: {exception.error.code}")
160-
print(f"Message: {exception.error.message}")
159+
if exception.error is not None:
160+
print(f"Error Code: {exception.error.code}")
161+
print(f"Message: {exception.error.message}")
161162
```
162163

163164
<!-- END SNIPPET -->
@@ -178,7 +179,7 @@ try:
178179
language = "zh-Hans"
179180
from_script = "Hans"
180181
to_script = "Latn"
181-
input_text_elements = [InputTextItem(text="这是个测试。")]
182+
input_text_elements = ["这是个测试。"]
182183

183184
response = text_translator.transliterate(
184185
request_body=input_text_elements, language=language, from_script=from_script, to_script=to_script
@@ -212,7 +213,7 @@ Identifies the positioning of sentence boundaries in a piece of text.
212213
try:
213214
include_sentence_length = True
214215
target_languages = ["cs"]
215-
input_text_elements = [InputTextItem(text="The answer lies in machine translation. This is a test.")]
216+
input_text_elements = ["The answer lies in machine translation. This is a test."]
216217

217218
response = text_translator.translate(
218219
request_body=input_text_elements, to=target_languages, include_sentence_length=include_sentence_length
@@ -232,8 +233,9 @@ try:
232233
print(f"Translated Sentence length: {translated_text.sent_len.trans_sent_len}")
233234

234235
except HttpResponseError as exception:
235-
print(f"Error Code: {exception.error.code}")
236-
print(f"Message: {exception.error.message}")
236+
if exception.error is not None:
237+
print(f"Error Code: {exception.error.code}")
238+
print(f"Message: {exception.error.message}")
237239
```
238240

239241
<!-- END SNIPPET -->
@@ -252,7 +254,7 @@ Returns equivalent words for the source term in the target language.
252254
try:
253255
source_language = "en"
254256
target_language = "es"
255-
input_text_elements = [InputTextItem(text="fly")]
257+
input_text_elements = ["fly"]
256258

257259
response = text_translator.lookup_dictionary_entries(
258260
request_body=input_text_elements, from_parameter=source_language, to=target_language

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
7878
self._deserialize = Deserializer()
7979
self._serialize.client_side_validation = False
8080

81-
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
81+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
8282
"""Runs the network request through the client's chained policies.
8383
8484
>>> from azure.core.rest import HttpRequest
@@ -102,7 +102,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
102102
}
103103

104104
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
105-
return self._client.send_request(request_copy, **kwargs) # type: ignore
105+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
106106

107107
def close(self) -> None:
108108
self._client.close()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _configure(self, **kwargs: Any) -> None:
4545
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
4646
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
4747
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
48-
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
4948
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
5049
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
50+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
5151
self.authentication_policy = kwargs.get("authentication_policy")

0 commit comments

Comments
 (0)