Skip to content

Commit

Permalink
[textanalytics] feature/ta-language-beta (Azure#24195)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
kristapratico authored Apr 26, 2022
1 parent 3bd0bc3 commit ffdee53
Show file tree
Hide file tree
Showing 719 changed files with 211,526 additions and 41,173 deletions.
6 changes: 6 additions & 0 deletions scripts/devops_tasks/test_run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
"sample_copy_model_async.py",
],
"azure-ai-language-questionanswering": ["sample_chat.py"],
"azure-ai-textanalytics": [
"sample_authentication.py",
"sample_authentication_async.py",
"sample_analyze_healthcare_entities_with_cancellation.py",
"sample_analyze_healthcare_entities_with_cancellation_async.py",
]
}

def run_check_call_with_timeout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TextAnalyticsApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""Text Analytics API versions supported by this package"""

#: this is the default version
V2022_03_01_PREVIEW = "2022-03-01-preview"
V3_2_PREVIEW = "v3.2-preview.2"
V3_1 = "v3.1"
V3_0 = "v3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pylint: disable=too-many-lines
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

import re


def is_language_api(api_version):
"""Language API is date-based
"""
return re.search(r'\d{4}-\d{2}-\d{2}', api_version)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

from typing import TYPE_CHECKING

from msrest import Deserializer, Serializer

from azure.core import PipelineClient
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from msrest import Deserializer, Serializer

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

DEFAULT_API_VERSION = 'v3.2-preview.2'
DEFAULT_API_VERSION = 'v3.1'
_PROFILE_TAG = "azure.ai.textanalytics.TextAnalyticsClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'analyze_text': '2022-03-01-preview',
'analyze_text_job_status': '2022-03-01-preview',
'begin_analyze_text_cancel_job': '2022-03-01-preview',
'begin_analyze_text_submit_job': '2022-03-01-preview',
}},
_PROFILE_TAG + " latest"
)
Expand All @@ -71,7 +76,9 @@ def __init__(
profile=KnownProfiles.default, # type: KnownProfiles
**kwargs # type: Any
):
if api_version == 'v3.0':
if api_version == '2022-03-01-preview':
base_url = '{Endpoint}/language'
elif api_version == 'v3.0':
base_url = '{Endpoint}/text/analytics/v3.0'
elif api_version == 'v3.1':
base_url = '{Endpoint}/text/analytics/v3.1'
Expand All @@ -94,11 +101,15 @@ def _models_dict(cls, api_version):
def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2022-03-01-preview: :mod:`v2022_03_01_preview.models<azure.ai.textanalytics.v2022_03_01_preview.models>`
* v3.0: :mod:`v3_0.models<azure.ai.textanalytics.v3_0.models>`
* v3.1: :mod:`v3_1.models<azure.ai.textanalytics.v3_1.models>`
* v3.2-preview.2: :mod:`v3_2_preview_2.models<azure.ai.textanalytics.v3_2_preview_2.models>`
"""
if api_version == 'v3.0':
if api_version == '2022-03-01-preview':
from .v2022_03_01_preview import models
return models
elif api_version == 'v3.0':
from .v3_0 import models
return models
elif api_version == 'v3.1':
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

from typing import Any, Optional, TYPE_CHECKING

from msrest import Deserializer, Serializer

from azure.core import AsyncPipelineClient
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from msrest import Deserializer, Serializer

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

DEFAULT_API_VERSION = 'v3.2-preview.2'
DEFAULT_API_VERSION = 'v3.1'
_PROFILE_TAG = "azure.ai.textanalytics.TextAnalyticsClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
'analyze_text': '2022-03-01-preview',
'analyze_text_job_status': '2022-03-01-preview',
'begin_analyze_text_cancel_job': '2022-03-01-preview',
'begin_analyze_text_submit_job': '2022-03-01-preview',
}},
_PROFILE_TAG + " latest"
)
Expand All @@ -70,7 +75,9 @@ def __init__(
profile: KnownProfiles = KnownProfiles.default,
**kwargs # type: Any
) -> None:
if api_version == 'v3.0':
if api_version == '2022-03-01-preview':
base_url = '{Endpoint}/language'
elif api_version == 'v3.0':
base_url = '{Endpoint}/text/analytics/v3.0'
elif api_version == 'v3.1':
base_url = '{Endpoint}/text/analytics/v3.1'
Expand All @@ -93,11 +100,15 @@ def _models_dict(cls, api_version):
def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
* 2022-03-01-preview: :mod:`v2022_03_01_preview.models<azure.ai.textanalytics.v2022_03_01_preview.models>`
* v3.0: :mod:`v3_0.models<azure.ai.textanalytics.v3_0.models>`
* v3.1: :mod:`v3_1.models<azure.ai.textanalytics.v3_1.models>`
* v3.2-preview.2: :mod:`v3_2_preview_2.models<azure.ai.textanalytics.v3_2_preview_2.models>`
"""
if api_version == 'v3.0':
if api_version == '2022-03-01-preview':
from ..v2022_03_01_preview import models
return models
elif api_version == 'v3.0':
from ..v3_0 import models
return models
elif api_version == 'v3.1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from .v3_2_preview_2.models import *
from .v2022_03_01_preview.models import *
from .v3_1.models import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._text_analytics_client import TextAnalyticsClient
__all__ = ['TextAnalyticsClient']

# `._patch.py` is used for handwritten extensions to the generated code
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
from ._patch import patch_sdk
patch_sdk()
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

from azure.core.credentials import TokenCredential

VERSION = "unknown"

class TextAnalyticsClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
"""Configuration for TextAnalyticsClient.
Note that all parameters used to create this instance are saved as instance
attributes.
:param credential: Credential needed for the client to connect to Azure.
:type credential: ~azure.core.credentials.TokenCredential
:param endpoint: Supported Cognitive Services endpoint (e.g.,
https://:code:`<resource-name>`.api.cognitiveservices.azure.com).
:type endpoint: str
:keyword api_version: Api Version. The default value is "2022-03-01-preview". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
self,
credential, # type: "TokenCredential"
endpoint, # type: str
**kwargs # type: Any
):
# type: (...) -> None
super(TextAnalyticsClientConfiguration, self).__init__(**kwargs)
api_version = kwargs.pop('api_version', "2022-03-01-preview") # type: str

if credential is None:
raise ValueError("Parameter 'credential' must not be None.")
if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")

self.credential = credential
self.endpoint = endpoint
self.api_version = api_version
self.credential_scopes = kwargs.pop('credential_scopes', ['https://cognitiveservices.azure.com/.default'])
kwargs.setdefault('sdk_moniker', 'ai-textanalytics/{}'.format(VERSION))
self._configure(**kwargs)

def _configure(
self,
**kwargs # type: Any
):
# type: (...) -> 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')
if self.credential and not self.authentication_policy:
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
Loading

0 comments on commit ffdee53

Please sign in to comment.