-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Generate and implement Face SDK via TypeSpec #35384
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
kristapratico
merged 42 commits into
Azure:main
from
zihyunting:azure-ai-vision-face-test-cases-and-samples
May 16, 2024
Merged
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f0b87e2
CodeGen from PR 27576 in Azure/azure-rest-api-specs
dae9679
Fix SDK error
zihyunting 2673dbd
SDK Customization
zihyunting de6d3d9
test-resources.json
zihyunting dfc57f5
Samples
zihyunting a4016dd
Testcases
zihyunting 931b3a6
Add SDK README.md
zihyunting d591f32
Rename the folder from samples/_shared to samples/shared
zihyunting 5ee2b8b
Update the detection interface
zihyunting d71585f
Correct the comments in sample codes
zihyunting 92a2fbf
Update the README.md
zihyunting 0623a38
Update the interface of detect_from_url()
zihyunting 9dc2109
Removed TODO tag
zihyunting 8bd89ff
Update README.md
zihyunting 91699a7
Correct the path of the model object
zihyunting 66492d1
Refine liveness samples
zihyunting 8d869d1
Reorganize samples and tests folder
zihyunting 48920a7
Add assets.json
zihyunting 0309e20
Update CHANGELOG and README
zihyunting 05291d8
Fix errors reported by CI pipeline
zihyunting b27ccd2
Fix typo
zihyunting 559c065
Fix tests error
zihyunting c2d6fa7
Update CHANGELOG and README
zihyunting 6895791
Update customized operations
zihyunting 8106b40
Update tests to fix test errors
zihyunting e7c81b7
Not support live tests for this preview release
zihyunting 85554ab
Use `black` to reformat all samples and tests
zihyunting fba1d72
Merge branch 'main' into azure-ai-vision-face-test-cases-and-samples
zihyunting 94c082f
Remove all ignore flag from samples
zihyunting d305e5b
Add pyproject.toml
zihyunting 0bfae97
Regenerated code
zihyunting bd1f697
update patches
zihyunting 22dbb02
fix samples
zihyunting f02131f
Update CHANGELOG
zihyunting 29ab198
Regenerate SDK based on the latest TypeSpec
zihyunting 8aae3af
Update customized method to address the TypeSpec changes
zihyunting d49f740
Update customized Enum classes definition and remove ignore flags fro…
zihyunting aeb6ee5
Update README.md
zihyunting 26264e7
Fix pylint error
zihyunting 6d4edec
Use the new name of AAD: 'Microsoft Entra ID'
zihyunting 0f6d75e
Change the order of overload functions of
zihyunting 168c21a
Re-format the code snippet in README.md
zihyunting 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Release History | ||
|
|
||
| ## 1.0.0b1 (1970-01-01) | ||
|
|
||
| - Initial version | ||
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 @@ | ||
| include *.md | ||
| include LICENSE | ||
| include azure/ai/vision/face/py.typed | ||
| recursive-include tests *.py | ||
| recursive-include samples *.py *.md | ||
| include azure/__init__.py | ||
| include azure/ai/__init__.py | ||
| include azure/ai/vision/__init__.py |
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,7 @@ | ||
| { | ||
| "commit": "37acfe2967e5e1be1169146ac461eb1875c9476e", | ||
| "repository_url": "https://github.com/Azure/azure-rest-api-specs", | ||
| "typespec_src": "specification/ai/Face", | ||
| "@azure-tools/typespec-python": "0.23.8", | ||
| "@autorest/python": "6.13.15" | ||
| } |
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 |
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 |
30 changes: 30 additions & 0 deletions
30
sdk/face/azure-ai-vision-face/azure/ai/vision/face/__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,30 @@ | ||
| # 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 ._client import FaceClient | ||
| from ._client import FaceAdministrationClient | ||
| from ._client import FaceSessionClient | ||
| 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__ = [ | ||
| "FaceClient", | ||
| "FaceAdministrationClient", | ||
| "FaceSessionClient", | ||
| ] | ||
| __all__.extend([p for p in _patch_all if p not in __all__]) | ||
|
|
||
| _patch_sdk() |
272 changes: 272 additions & 0 deletions
272
sdk/face/azure-ai-vision-face/azure/ai/vision/face/_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,272 @@ | ||
| # 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, TYPE_CHECKING, Union | ||
|
|
||
| from azure.core import PipelineClient | ||
| from azure.core.credentials import AzureKeyCredential | ||
| from azure.core.pipeline import policies | ||
| from azure.core.rest import HttpRequest, HttpResponse | ||
|
|
||
| from ._configuration import ( | ||
| FaceAdministrationClientConfiguration, | ||
| FaceClientConfiguration, | ||
| FaceSessionClientConfiguration, | ||
| ) | ||
| from ._operations import ( | ||
| FaceAdministrationClientOperationsMixin, | ||
| FaceClientOperationsMixin, | ||
| FaceSessionClientOperationsMixin, | ||
| ) | ||
| from ._serialization import Deserializer, Serializer | ||
|
|
||
| if TYPE_CHECKING: | ||
| # pylint: disable=unused-import,ungrouped-imports | ||
| from azure.core.credentials import TokenCredential | ||
|
|
||
|
|
||
| class FaceClient(FaceClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
| """FaceClient. | ||
|
|
||
| :param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: | ||
| https://{resource-name}.cognitiveservices.azure.com). Required. | ||
| :type endpoint: str | ||
| :param credential: Credential used to authenticate requests to the service. Is either a | ||
| AzureKeyCredential type or a TokenCredential type. Required. | ||
| :type credential: ~azure.core.credentials.AzureKeyCredential or | ||
| ~azure.core.credentials.TokenCredential | ||
| :keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this | ||
| default value may result in unsupported behavior. | ||
| :paramtype api_version: str or ~azure.ai.vision.face.models.Versions | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}/face/{apiVersion}" | ||
| self._config = FaceClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) | ||
| _policies = kwargs.pop("policies", None) | ||
| if _policies is None: | ||
| _policies = [ | ||
| policies.RequestIdPolicy(**kwargs), | ||
| self._config.headers_policy, | ||
| self._config.user_agent_policy, | ||
| self._config.proxy_policy, | ||
| policies.ContentDecodePolicy(**kwargs), | ||
| self._config.redirect_policy, | ||
| self._config.retry_policy, | ||
| self._config.authentication_policy, | ||
| self._config.custom_hook_policy, | ||
| self._config.logging_policy, | ||
| policies.DistributedTracingPolicy(**kwargs), | ||
| policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, | ||
| self._config.http_logging_policy, | ||
| ] | ||
| self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) | ||
|
|
||
| self._serialize = Serializer() | ||
| self._deserialize = Deserializer() | ||
| self._serialize.client_side_validation = False | ||
|
|
||
| def send_request(self, request: HttpRequest, *, stream: bool = False, **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), | ||
| "apiVersion": self._serialize.url("self._config.api_version", self._config.api_version, "str"), | ||
| } | ||
|
|
||
| request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) | ||
| return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore | ||
|
|
||
| def close(self) -> None: | ||
| self._client.close() | ||
|
|
||
| def __enter__(self) -> "FaceClient": | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *exc_details: Any) -> None: | ||
| self._client.__exit__(*exc_details) | ||
|
|
||
|
|
||
| class FaceAdministrationClient( | ||
| FaceAdministrationClientOperationsMixin | ||
| ): # pylint: disable=client-accepts-api-version-keyword | ||
| """FaceAdministrationClient. | ||
|
|
||
| :param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: | ||
| https://{resource-name}.cognitiveservices.azure.com). Required. | ||
| :type endpoint: str | ||
| :param credential: Credential used to authenticate requests to the service. Is either a | ||
| AzureKeyCredential type or a TokenCredential type. Required. | ||
| :type credential: ~azure.core.credentials.AzureKeyCredential or | ||
| ~azure.core.credentials.TokenCredential | ||
| :keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this | ||
| default value may result in unsupported behavior. | ||
| :paramtype api_version: str or ~azure.ai.vision.face.models.Versions | ||
| :keyword int polling_interval: Default waiting time between two polls for LRO operations if no | ||
| Retry-After header is present. | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}/face/{apiVersion}" | ||
| self._config = FaceAdministrationClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) | ||
| _policies = kwargs.pop("policies", None) | ||
| if _policies is None: | ||
| _policies = [ | ||
| policies.RequestIdPolicy(**kwargs), | ||
| self._config.headers_policy, | ||
| self._config.user_agent_policy, | ||
| self._config.proxy_policy, | ||
| policies.ContentDecodePolicy(**kwargs), | ||
| self._config.redirect_policy, | ||
| self._config.retry_policy, | ||
| self._config.authentication_policy, | ||
| self._config.custom_hook_policy, | ||
| self._config.logging_policy, | ||
| policies.DistributedTracingPolicy(**kwargs), | ||
| policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, | ||
| self._config.http_logging_policy, | ||
| ] | ||
| self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) | ||
|
|
||
| self._serialize = Serializer() | ||
| self._deserialize = Deserializer() | ||
| self._serialize.client_side_validation = False | ||
|
|
||
| def send_request(self, request: HttpRequest, *, stream: bool = False, **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), | ||
| "apiVersion": self._serialize.url("self._config.api_version", self._config.api_version, "str"), | ||
| } | ||
|
|
||
| request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) | ||
| return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore | ||
|
|
||
| def close(self) -> None: | ||
| self._client.close() | ||
|
|
||
| def __enter__(self) -> "FaceAdministrationClient": | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *exc_details: Any) -> None: | ||
| self._client.__exit__(*exc_details) | ||
|
|
||
|
|
||
| class FaceSessionClient(FaceSessionClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
| """FaceSessionClient. | ||
|
|
||
| :param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example: | ||
| https://{resource-name}.cognitiveservices.azure.com). Required. | ||
| :type endpoint: str | ||
| :param credential: Credential used to authenticate requests to the service. Is either a | ||
| AzureKeyCredential type or a TokenCredential type. Required. | ||
| :type credential: ~azure.core.credentials.AzureKeyCredential or | ||
| ~azure.core.credentials.TokenCredential | ||
| :keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this | ||
| default value may result in unsupported behavior. | ||
| :paramtype api_version: str or ~azure.ai.vision.face.models.Versions | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}/face/{apiVersion}" | ||
| self._config = FaceSessionClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) | ||
| _policies = kwargs.pop("policies", None) | ||
| if _policies is None: | ||
| _policies = [ | ||
| policies.RequestIdPolicy(**kwargs), | ||
| self._config.headers_policy, | ||
| self._config.user_agent_policy, | ||
| self._config.proxy_policy, | ||
| policies.ContentDecodePolicy(**kwargs), | ||
| self._config.redirect_policy, | ||
| self._config.retry_policy, | ||
| self._config.authentication_policy, | ||
| self._config.custom_hook_policy, | ||
| self._config.logging_policy, | ||
| policies.DistributedTracingPolicy(**kwargs), | ||
| policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, | ||
| self._config.http_logging_policy, | ||
| ] | ||
| self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) | ||
|
|
||
| self._serialize = Serializer() | ||
| self._deserialize = Deserializer() | ||
| self._serialize.client_side_validation = False | ||
|
|
||
| def send_request(self, request: HttpRequest, *, stream: bool = False, **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), | ||
| "apiVersion": self._serialize.url("self._config.api_version", self._config.api_version, "str"), | ||
| } | ||
|
|
||
| request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) | ||
| return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore | ||
|
|
||
| def close(self) -> None: | ||
| self._client.close() | ||
|
|
||
| def __enter__(self) -> "FaceSessionClient": | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *exc_details: Any) -> None: | ||
| self._client.__exit__(*exc_details) |
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.