-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Python client for Model-as-a-Service (MaaS) / Model-as-a-Platform (MaaP) endpoints #34937
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
Changes from 124 commits
Commits
Show all changes
126 commits
Select commit
Hold shift + click to select a range
18b5021
auto-gen files
dargilco b8ea0cd
first pass at writing tests
dargilco ee78c9c
Re-emit client library with fixed variable name
dargilco 25b5c6b
Fix test
dargilco 5072f00
First test working!
dargilco 62c476a
Re-emit after adding tools. Add async test
dargilco 2bdb446
Add basic samples
dargilco ad9992c
Ignore spelling errors
dargilco 59bf4f3
fix `tox run -e sphinx` errors
dargilco 1613b37
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 8d3948c
Update SDK to support embeddings. Add sample. Add root README.md
dargilco fff460e
Fix typo
dargilco 9d171a7
After re-emit using flat input arguments
dargilco 7efa800
Update README.md code snippets
dargilco 8008505
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 61b62ac
Re-emit
dargilco 675ba6d
Samples for image generation
dargilco c5ea2fc
Add dictionary of extra parameters
dargilco 45c7ca1
Re-emit
dargilco 8ee88aa
Example of setting extra parameters
dargilco bad14c9
Fix README.md title
dargilco b49acb6
Placeholder patch for streaming chat method
dargilco 708e4c4
Re-emit, to get two new streaming 'Delta' classes
dargilco da8a678
first go at streaming
dargilco ed2b227
Latest re-emit, removing 'extra_parameters'
dargilco 0428d95
async streaming support
dargilco 9d98958
A few quality gates fixes
dargilco 37c3599
Use aclose() for async interator
dargilco 58b3669
Update env-variable names
dargilco 0f79e70
First set of updates following SDK review meeting
dargilco e70da4b
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 8e274b6
New client names. Other minor model name changes
dargilco 159d82f
Minor fixes to root README.md
dargilco 5326bba
Update tests
dargilco 27b555f
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 1e42647
Minor test updates
dargilco 65b2bf1
Add assets.json
dargilco 32368f2
Fix test name
dargilco 18d6baa
First round of Pylint fixes
dargilco 1243048
Fix pyright errors
dargilco 3c84d22
Fix all pyright errors
dargilco c951405
Fix more quality gates
dargilco e18d79c
Add streaming tests
dargilco 51f30d3
Fix streaming to work with small HTTP buffers (tested down to 64 bytes)
dargilco 2578c8d
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 3090bae
Update ci.yml
dargilco 84ad0b5
Add samples for chat history, JSON input, IO[bytes] input
dargilco 6b87862
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 6aaa1c4
Draft sample for chat completion with tools
dargilco 11a1c78
Grab latest TypeSpec changes
dargilco 6a6cbc5
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 5864275
Re-emit SDK to pick up TypeSpec tools changes. Fix result.id check to…
dargilco 9e18146
New test for tool, new recordings
dargilco 2c97356
use logger for detailed SSE streaming debug spew
dargilco 37d1e35
Don't build azure-ai-generative and azure-ai-resources packages, as t…
dargilco e79c4b5
Split streaming response class to two, one for sync, one for async
dargilco 06e11f7
Update test timeout. Rename /templates/stages/platform-matrix-ai.json…
dargilco 610b4eb
Mark azure-ai-generative and azure-ai-resources as in-active
dargilco 9def3bb
Fix mypy and pylint errors
dargilco fb7612b
Sample for getting model info
dargilco cd30a48
Remove image generation
dargilco a6ae407
Re-emit from TypeSpec without Image Generation
dargilco 78331f7
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 943faa9
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco a1ebd6b
Update auth
dargilco f0b773c
Add get_model_info tests
dargilco e4f3089
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco deb3d16
Add sample for ClientGenerator
dargilco c6b3bc2
Remove /v1
dargilco 042c06a
Use new test recording assests without /v1
dargilco 56450c9
Pick up TypeSpec with /v1 removed from route
dargilco a36fbee
Support Image Embeddings and version 2024-05
dargilco 82168b5
Update test recordings
dargilco e788873
Fix quality some quality gates
dargilco 2c18488
Fix broken link ('link verification check')
dargilco 2ac893f
Use 'response' instead of 'result' in samples, as this is what I see …
dargilco b56ca82
Implement load_client and load_async_client
dargilco aafcc37
Make three BaseStreamingChatCompletions variables (constants) private)
dargilco b5484ee
sync and async versions of load_client
dargilco 0a82fe2
Remove wait loop in async samples. Simplify tool sample. Other minor …
dargilco 3dbca9e
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco bf93525
Re-emit with new operator names
dargilco ca2f4ff
Minor change to sample
dargilco 9db8bce
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco 673f27b
Add support for hyper_parameters
dargilco 0ed9d7b
Update root README.md
dargilco 7c5424f
Save work - unknown_params header, hyper_params input, cached model_info
dargilco 1faf123
Some test changes
dargilco 71bd71d
Many changes
dargilco 712dfcc
New test recordings
dargilco d6012b7
Minor samples and README.md changes
dargilco 3f52d6f
Update names of streaming response classes
dargilco 62c5d8a
Update Entra ID sample, document Entra ID in README, use ttps://ml.az…
dargilco 8a3a167
use model_extras instead of hyper_params. Update client __str__ to no…
dargilco 092f91b
Fix all pylint errors. Minor updates to root README.md
dargilco 8e610c2
Example of JSON messages in the root README.md
dargilco 6d1e7ce
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco a738ff5
Some MyPy fixes. Also fix wrong package name in root README.md
dargilco 44e94d0
Same work before re-emitting SDK
dargilco 27ac7b0
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco a825db4
Use `embed` instead of `embedding`. Update Entra ID and AOAI samples
dargilco c4814d8
Fix some mypy errors. Use different terms for MaaS/MaaP
dargilco 2df88dc
Re-emit, now with pyproject.toml
dargilco 89d92d3
Fix/supress mypy & pyright errors
dargilco e20d003
Fix missing Etra ID auth in load_client
dargilco d7ef3b7
Use vanity link for samples folder
dargilco 63fefdf
Revert "Use vanity link for samples folder"
dargilco ab6973f
Fix mypy and pyright errors
dargilco efbcf5c
Update root README.md. Update operator ref doc comments
dargilco 6f69018
Re-emit
dargilco aed30bf
Fix mypy error in sample
dargilco c327403
Fix missing ranges in ref-doc comments
dargilco 27f2ed6
Remove unneeded cast
dargilco 2c92e9d
Fix pylint error
dargilco 98cd4fd
Fix typos & method names. Thanks Jarno!
dargilco a44df4e
Address Johan's code review comments. Thanks Johan!
dargilco c0958e3
Fix mypy errors
dargilco 2cbb1cf
Minor update to root README.md
dargilco 73c836e
Remove capacity_type
dargilco 0883400
Fix public patched methods not showing up in intellisense, when using…
dargilco d0930a8
Import 'Self' from Typing package starting from Python 3.11
dargilco 13e8ed6
Fix pylint error, line too long
dargilco 223238c
More AOAI samples. Update package README with regards to AOAI support
dargilco 0d03ad2
Add overloads with `stream: Literal[..]` to fix mypy and pyright erro…
dargilco 8647964
Override all client __init__ methods so you can define and initialize…
dargilco 3715766
Cleanup: delete now unused platform-matrix-ai.json.old
dargilco 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
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
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
File renamed without changes.
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
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 (2024-06-11) | ||
|
|
||
| - Initial beta 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,7 @@ | ||
| include *.md | ||
| include LICENSE | ||
| include azure/ai/inference/py.typed | ||
| recursive-include tests *.py | ||
| recursive-include samples *.py *.md | ||
| include azure/__init__.py | ||
| include azure/ai/__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,6 @@ | ||
| { | ||
| "AssetsRepo": "Azure/azure-sdk-assets", | ||
| "AssetsRepoPrefixPath": "python", | ||
| "TagPrefix": "python/ai/azure-ai-inference", | ||
| "Tag": "python/ai/azure-ai-inference_a50981dab0" | ||
| } |
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,28 @@ | ||
| # 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 ChatCompletionsClient | ||
| from ._patch import EmbeddingsClient | ||
| from ._patch import ImageEmbeddingsClient | ||
| from ._version import VERSION | ||
|
|
||
| __version__ = VERSION | ||
|
|
||
|
|
||
| from ._patch import load_client | ||
| from ._patch import patch_sdk as _patch_sdk | ||
|
|
||
| __all__ = [ | ||
| "load_client", | ||
| "ChatCompletionsClient", | ||
| "EmbeddingsClient", | ||
| "ImageEmbeddingsClient", | ||
| ] | ||
|
|
||
|
|
||
| _patch_sdk() |
265 changes: 265 additions & 0 deletions
265
sdk/ai/azure-ai-inference/azure/ai/inference/_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,265 @@ | ||
| # 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 ( | ||
| ChatCompletionsClientConfiguration, | ||
| EmbeddingsClientConfiguration, | ||
| ImageEmbeddingsClientConfiguration, | ||
| ) | ||
| from ._operations import ( | ||
| ChatCompletionsClientOperationsMixin, | ||
| EmbeddingsClientOperationsMixin, | ||
| ImageEmbeddingsClientOperationsMixin, | ||
| ) | ||
| from ._serialization import Deserializer, Serializer | ||
|
|
||
| if TYPE_CHECKING: | ||
| # pylint: disable=unused-import,ungrouped-imports | ||
| from azure.core.credentials import TokenCredential | ||
|
|
||
|
|
||
| class ChatCompletionsClient(ChatCompletionsClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
| """ChatCompletionsClient. | ||
|
|
||
| :param endpoint: Service host. 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: The API version to use for this operation. Default value is | ||
| "2024-05-01-preview". Note that overriding this default value may result in unsupported | ||
| behavior. | ||
| :paramtype api_version: str | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}" | ||
| self._config = ChatCompletionsClientConfiguration(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), | ||
| } | ||
|
|
||
| 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) -> "ChatCompletionsClient": | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *exc_details: Any) -> None: | ||
| self._client.__exit__(*exc_details) | ||
|
|
||
|
|
||
| class EmbeddingsClient(EmbeddingsClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
| """EmbeddingsClient. | ||
|
|
||
| :param endpoint: Service host. 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: The API version to use for this operation. Default value is | ||
| "2024-05-01-preview". Note that overriding this default value may result in unsupported | ||
| behavior. | ||
| :paramtype api_version: str | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}" | ||
| self._config = EmbeddingsClientConfiguration(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), | ||
| } | ||
|
|
||
| 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) -> "EmbeddingsClient": | ||
| self._client.__enter__() | ||
| return self | ||
|
|
||
| def __exit__(self, *exc_details: Any) -> None: | ||
| self._client.__exit__(*exc_details) | ||
|
|
||
|
|
||
| class ImageEmbeddingsClient(ImageEmbeddingsClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword | ||
| """ImageEmbeddingsClient. | ||
|
|
||
| :param endpoint: Service host. 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: The API version to use for this operation. Default value is | ||
| "2024-05-01-preview". Note that overriding this default value may result in unsupported | ||
| behavior. | ||
| :paramtype api_version: str | ||
| """ | ||
|
|
||
| def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: | ||
| _endpoint = "{endpoint}" | ||
| self._config = ImageEmbeddingsClientConfiguration(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), | ||
| } | ||
|
|
||
| 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) -> "ImageEmbeddingsClient": | ||
| 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.