Skip to content

Commit ffdee53

Browse files
[textanalytics] feature/ta-language-beta (Azure#24195)
* [textanalytics] regenerate ta 2022-03-01-preview (Azure#23758) * regenerate ta 2022-03-01-preview * add back v3.2-preview.2 to uncomplicate things for now * [textanalytics] use language API for analyze text operations (Azure#23814) * language api compat code changes * use language api for sync/async detect_language * use language api for sync/async recognize_entities * use language api for sync/async recognize_pii_entities * use language api for sync/async recognize_linked_entities * use language api for sync/async extract_key_phrases * use language api for sync/async analyze_sentiment * add recordings * [textanalytics] map language API to actions (Azure#24149) * initial work, not all tests passing * fixes for tests and recordings * fix import * fix pylint * skip missed tests affected by modelVersion service bug * add healthcare entities mapping to language + tests/recordings * lint
1 parent 3bd0bc3 commit ffdee53

File tree

719 files changed

+211526
-41173
lines changed

Some content is hidden

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

719 files changed

+211526
-41173
lines changed

scripts/devops_tasks/test_run_samples.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@
136136
"sample_copy_model_async.py",
137137
],
138138
"azure-ai-language-questionanswering": ["sample_chat.py"],
139+
"azure-ai-textanalytics": [
140+
"sample_authentication.py",
141+
"sample_authentication_async.py",
142+
"sample_analyze_healthcare_entities_with_cancellation.py",
143+
"sample_analyze_healthcare_entities_with_cancellation_async.py",
144+
]
139145
}
140146

141147
def run_check_call_with_timeout(

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_base_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class TextAnalyticsApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
2020
"""Text Analytics API versions supported by this package"""
2121

2222
#: this is the default version
23+
V2022_03_01_PREVIEW = "2022-03-01-preview"
2324
V3_2_PREVIEW = "v3.2-preview.2"
2425
V3_1 = "v3.1"
2526
V3_0 = "v3.0"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pylint: disable=too-many-lines
2+
# ------------------------------------
3+
# Copyright (c) Microsoft Corporation.
4+
# Licensed under the MIT License.
5+
# ------------------------------------
6+
7+
import re
8+
9+
10+
def is_language_api(api_version):
11+
"""Language API is date-based
12+
"""
13+
return re.search(r'\d{4}-\d{2}-\d{2}', api_version)

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_generated/_operations_mixin.py

Lines changed: 179 additions & 26 deletions
Large diffs are not rendered by default.

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_generated/_text_analytics_client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
from typing import TYPE_CHECKING
1313

14+
from msrest import Deserializer, Serializer
15+
1416
from azure.core import PipelineClient
1517
from azure.profiles import KnownProfiles, ProfileDefinition
1618
from azure.profiles.multiapiclient import MultiApiClientMixin
17-
from msrest import Deserializer, Serializer
1819

1920
from ._configuration import TextAnalyticsClientConfiguration
2021
from ._operations_mixin import TextAnalyticsClientOperationsMixin
@@ -54,11 +55,15 @@ class TextAnalyticsClient(TextAnalyticsClientOperationsMixin, MultiApiClientMixi
5455
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
5556
"""
5657

57-
DEFAULT_API_VERSION = 'v3.2-preview.2'
58+
DEFAULT_API_VERSION = 'v3.1'
5859
_PROFILE_TAG = "azure.ai.textanalytics.TextAnalyticsClient"
5960
LATEST_PROFILE = ProfileDefinition({
6061
_PROFILE_TAG: {
6162
None: DEFAULT_API_VERSION,
63+
'analyze_text': '2022-03-01-preview',
64+
'analyze_text_job_status': '2022-03-01-preview',
65+
'begin_analyze_text_cancel_job': '2022-03-01-preview',
66+
'begin_analyze_text_submit_job': '2022-03-01-preview',
6267
}},
6368
_PROFILE_TAG + " latest"
6469
)
@@ -71,7 +76,9 @@ def __init__(
7176
profile=KnownProfiles.default, # type: KnownProfiles
7277
**kwargs # type: Any
7378
):
74-
if api_version == 'v3.0':
79+
if api_version == '2022-03-01-preview':
80+
base_url = '{Endpoint}/language'
81+
elif api_version == 'v3.0':
7582
base_url = '{Endpoint}/text/analytics/v3.0'
7683
elif api_version == 'v3.1':
7784
base_url = '{Endpoint}/text/analytics/v3.1'
@@ -94,11 +101,15 @@ def _models_dict(cls, api_version):
94101
def models(cls, api_version=DEFAULT_API_VERSION):
95102
"""Module depends on the API version:
96103
104+
* 2022-03-01-preview: :mod:`v2022_03_01_preview.models<azure.ai.textanalytics.v2022_03_01_preview.models>`
97105
* v3.0: :mod:`v3_0.models<azure.ai.textanalytics.v3_0.models>`
98106
* v3.1: :mod:`v3_1.models<azure.ai.textanalytics.v3_1.models>`
99107
* v3.2-preview.2: :mod:`v3_2_preview_2.models<azure.ai.textanalytics.v3_2_preview_2.models>`
100108
"""
101-
if api_version == 'v3.0':
109+
if api_version == '2022-03-01-preview':
110+
from .v2022_03_01_preview import models
111+
return models
112+
elif api_version == 'v3.0':
102113
from .v3_0 import models
103114
return models
104115
elif api_version == 'v3.1':

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_generated/aio/_operations_mixin.py

Lines changed: 175 additions & 25 deletions
Large diffs are not rendered by default.

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_generated/aio/_text_analytics_client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
from typing import Any, Optional, TYPE_CHECKING
1313

14+
from msrest import Deserializer, Serializer
15+
1416
from azure.core import AsyncPipelineClient
1517
from azure.profiles import KnownProfiles, ProfileDefinition
1618
from azure.profiles.multiapiclient import MultiApiClientMixin
17-
from msrest import Deserializer, Serializer
1819

1920
from ._configuration import TextAnalyticsClientConfiguration
2021
from ._operations_mixin import TextAnalyticsClientOperationsMixin
@@ -53,11 +54,15 @@ class TextAnalyticsClient(TextAnalyticsClientOperationsMixin, MultiApiClientMixi
5354
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
5455
"""
5556

56-
DEFAULT_API_VERSION = 'v3.2-preview.2'
57+
DEFAULT_API_VERSION = 'v3.1'
5758
_PROFILE_TAG = "azure.ai.textanalytics.TextAnalyticsClient"
5859
LATEST_PROFILE = ProfileDefinition({
5960
_PROFILE_TAG: {
6061
None: DEFAULT_API_VERSION,
62+
'analyze_text': '2022-03-01-preview',
63+
'analyze_text_job_status': '2022-03-01-preview',
64+
'begin_analyze_text_cancel_job': '2022-03-01-preview',
65+
'begin_analyze_text_submit_job': '2022-03-01-preview',
6166
}},
6267
_PROFILE_TAG + " latest"
6368
)
@@ -70,7 +75,9 @@ def __init__(
7075
profile: KnownProfiles = KnownProfiles.default,
7176
**kwargs # type: Any
7277
) -> None:
73-
if api_version == 'v3.0':
78+
if api_version == '2022-03-01-preview':
79+
base_url = '{Endpoint}/language'
80+
elif api_version == 'v3.0':
7481
base_url = '{Endpoint}/text/analytics/v3.0'
7582
elif api_version == 'v3.1':
7683
base_url = '{Endpoint}/text/analytics/v3.1'
@@ -93,11 +100,15 @@ def _models_dict(cls, api_version):
93100
def models(cls, api_version=DEFAULT_API_VERSION):
94101
"""Module depends on the API version:
95102
103+
* 2022-03-01-preview: :mod:`v2022_03_01_preview.models<azure.ai.textanalytics.v2022_03_01_preview.models>`
96104
* v3.0: :mod:`v3_0.models<azure.ai.textanalytics.v3_0.models>`
97105
* v3.1: :mod:`v3_1.models<azure.ai.textanalytics.v3_1.models>`
98106
* v3.2-preview.2: :mod:`v3_2_preview_2.models<azure.ai.textanalytics.v3_2_preview_2.models>`
99107
"""
100-
if api_version == 'v3.0':
108+
if api_version == '2022-03-01-preview':
109+
from ..v2022_03_01_preview import models
110+
return models
111+
elif api_version == 'v3.0':
101112
from ..v3_0 import models
102113
return models
103114
elif api_version == 'v3.1':

sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_generated/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# Licensed under the MIT License. See License.txt in the project root for
55
# license information.
66
# --------------------------------------------------------------------------
7-
from .v3_2_preview_2.models import *
7+
from .v2022_03_01_preview.models import *
8+
from .v3_1.models import *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._text_analytics_client import TextAnalyticsClient
10+
__all__ = ['TextAnalyticsClient']
11+
12+
# `._patch.py` is used for handwritten extensions to the generated code
13+
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
14+
from ._patch import patch_sdk
15+
patch_sdk()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
14+
if TYPE_CHECKING:
15+
# pylint: disable=unused-import,ungrouped-imports
16+
from typing import Any
17+
18+
from azure.core.credentials import TokenCredential
19+
20+
VERSION = "unknown"
21+
22+
class TextAnalyticsClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
23+
"""Configuration for TextAnalyticsClient.
24+
25+
Note that all parameters used to create this instance are saved as instance
26+
attributes.
27+
28+
:param credential: Credential needed for the client to connect to Azure.
29+
:type credential: ~azure.core.credentials.TokenCredential
30+
:param endpoint: Supported Cognitive Services endpoint (e.g.,
31+
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
32+
:type endpoint: str
33+
:keyword api_version: Api Version. The default value is "2022-03-01-preview". Note that
34+
overriding this default value may result in unsupported behavior.
35+
:paramtype api_version: str
36+
"""
37+
38+
def __init__(
39+
self,
40+
credential, # type: "TokenCredential"
41+
endpoint, # type: str
42+
**kwargs # type: Any
43+
):
44+
# type: (...) -> None
45+
super(TextAnalyticsClientConfiguration, self).__init__(**kwargs)
46+
api_version = kwargs.pop('api_version', "2022-03-01-preview") # type: str
47+
48+
if credential is None:
49+
raise ValueError("Parameter 'credential' must not be None.")
50+
if endpoint is None:
51+
raise ValueError("Parameter 'endpoint' must not be None.")
52+
53+
self.credential = credential
54+
self.endpoint = endpoint
55+
self.api_version = api_version
56+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://cognitiveservices.azure.com/.default'])
57+
kwargs.setdefault('sdk_moniker', 'ai-textanalytics/{}'.format(VERSION))
58+
self._configure(**kwargs)
59+
60+
def _configure(
61+
self,
62+
**kwargs # type: Any
63+
):
64+
# type: (...) -> None
65+
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
66+
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
67+
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
68+
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
69+
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs)
70+
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
71+
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
72+
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
73+
self.authentication_policy = kwargs.get('authentication_policy')
74+
if self.credential and not self.authentication_policy:
75+
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)

0 commit comments

Comments
 (0)