Skip to content
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

Python client for Model-as-a-Service (MaaS) / Model-as-a-Platform (MaaP) endpoints #34937

Merged
merged 126 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 124 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
18b5021
auto-gen files
dargilco Mar 26, 2024
b8ea0cd
first pass at writing tests
dargilco Mar 27, 2024
ee78c9c
Re-emit client library with fixed variable name
dargilco Mar 27, 2024
25b5c6b
Fix test
dargilco Mar 27, 2024
5072f00
First test working!
dargilco Mar 28, 2024
62c476a
Re-emit after adding tools. Add async test
dargilco Mar 29, 2024
2bdb446
Add basic samples
dargilco Mar 29, 2024
ad9992c
Ignore spelling errors
dargilco Mar 29, 2024
59bf4f3
fix `tox run -e sphinx` errors
dargilco Mar 29, 2024
1613b37
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco Mar 29, 2024
8d3948c
Update SDK to support embeddings. Add sample. Add root README.md
dargilco Mar 30, 2024
fff460e
Fix typo
dargilco Apr 2, 2024
9d171a7
After re-emit using flat input arguments
dargilco Apr 2, 2024
7efa800
Update README.md code snippets
dargilco Apr 2, 2024
8008505
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco Apr 4, 2024
61b62ac
Re-emit
dargilco Apr 4, 2024
675ba6d
Samples for image generation
dargilco Apr 4, 2024
c5ea2fc
Add dictionary of extra parameters
dargilco Apr 4, 2024
45c7ca1
Re-emit
dargilco Apr 4, 2024
8ee88aa
Example of setting extra parameters
dargilco Apr 4, 2024
bad14c9
Fix README.md title
dargilco Apr 5, 2024
b49acb6
Placeholder patch for streaming chat method
dargilco Apr 5, 2024
708e4c4
Re-emit, to get two new streaming 'Delta' classes
dargilco Apr 5, 2024
da8a678
first go at streaming
dargilco Apr 10, 2024
ed2b227
Latest re-emit, removing 'extra_parameters'
dargilco Apr 10, 2024
0428d95
async streaming support
dargilco Apr 11, 2024
9d98958
A few quality gates fixes
dargilco Apr 11, 2024
37c3599
Use aclose() for async interator
dargilco Apr 11, 2024
58b3669
Update env-variable names
dargilco Apr 11, 2024
0f79e70
First set of updates following SDK review meeting
dargilco Apr 12, 2024
e70da4b
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco Apr 12, 2024
8e274b6
New client names. Other minor model name changes
dargilco Apr 12, 2024
159d82f
Minor fixes to root README.md
dargilco Apr 12, 2024
5326bba
Update tests
dargilco Apr 15, 2024
27b555f
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco Apr 15, 2024
1e42647
Minor test updates
dargilco Apr 16, 2024
65b2bf1
Add assets.json
dargilco Apr 16, 2024
32368f2
Fix test name
dargilco Apr 16, 2024
18d6baa
First round of Pylint fixes
dargilco Apr 16, 2024
1243048
Fix pyright errors
dargilco Apr 16, 2024
3c84d22
Fix all pyright errors
dargilco Apr 16, 2024
c951405
Fix more quality gates
dargilco Apr 17, 2024
e18d79c
Add streaming tests
dargilco Apr 17, 2024
51f30d3
Fix streaming to work with small HTTP buffers (tested down to 64 bytes)
dargilco Apr 18, 2024
2578c8d
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco Apr 18, 2024
3090bae
Update ci.yml
dargilco Apr 18, 2024
84ad0b5
Add samples for chat history, JSON input, IO[bytes] input
dargilco Apr 19, 2024
6b87862
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 6, 2024
6aaa1c4
Draft sample for chat completion with tools
dargilco May 8, 2024
11a1c78
Grab latest TypeSpec changes
dargilco May 8, 2024
6a6cbc5
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 8, 2024
5864275
Re-emit SDK to pick up TypeSpec tools changes. Fix result.id check to…
dargilco May 8, 2024
9e18146
New test for tool, new recordings
dargilco May 8, 2024
2c97356
use logger for detailed SSE streaming debug spew
dargilco May 9, 2024
37d1e35
Don't build azure-ai-generative and azure-ai-resources packages, as t…
dargilco May 9, 2024
e79c4b5
Split streaming response class to two, one for sync, one for async
dargilco May 9, 2024
06e11f7
Update test timeout. Rename /templates/stages/platform-matrix-ai.json…
dargilco May 9, 2024
610b4eb
Mark azure-ai-generative and azure-ai-resources as in-active
dargilco May 9, 2024
9def3bb
Fix mypy and pylint errors
dargilco May 10, 2024
fb7612b
Sample for getting model info
dargilco May 10, 2024
cd30a48
Remove image generation
dargilco May 10, 2024
a6ae407
Re-emit from TypeSpec without Image Generation
dargilco May 10, 2024
78331f7
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 10, 2024
943faa9
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 13, 2024
a1ebd6b
Update auth
dargilco May 13, 2024
f0b773c
Add get_model_info tests
dargilco May 14, 2024
e4f3089
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 14, 2024
deb3d16
Add sample for ClientGenerator
dargilco May 14, 2024
c6b3bc2
Remove /v1
dargilco May 14, 2024
042c06a
Use new test recording assests without /v1
dargilco May 14, 2024
56450c9
Pick up TypeSpec with /v1 removed from route
dargilco May 14, 2024
a36fbee
Support Image Embeddings and version 2024-05
dargilco May 14, 2024
82168b5
Update test recordings
dargilco May 14, 2024
e788873
Fix quality some quality gates
dargilco May 15, 2024
2c18488
Fix broken link ('link verification check')
dargilco May 15, 2024
2ac893f
Use 'response' instead of 'result' in samples, as this is what I see …
dargilco May 15, 2024
b56ca82
Implement load_client and load_async_client
dargilco May 16, 2024
aafcc37
Make three BaseStreamingChatCompletions variables (constants) private)
dargilco May 16, 2024
b5484ee
sync and async versions of load_client
dargilco May 17, 2024
0a82fe2
Remove wait loop in async samples. Simplify tool sample. Other minor …
dargilco May 17, 2024
3dbca9e
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 17, 2024
bf93525
Re-emit with new operator names
dargilco May 17, 2024
ca2f4ff
Minor change to sample
dargilco May 20, 2024
9db8bce
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 20, 2024
673f27b
Add support for hyper_parameters
dargilco May 21, 2024
0ed9d7b
Update root README.md
dargilco May 21, 2024
7c5424f
Save work - unknown_params header, hyper_params input, cached model_info
dargilco May 22, 2024
1faf123
Some test changes
dargilco May 22, 2024
71bd71d
Many changes
dargilco May 23, 2024
712dfcc
New test recordings
dargilco May 23, 2024
d6012b7
Minor samples and README.md changes
dargilco May 23, 2024
3f52d6f
Update names of streaming response classes
dargilco May 23, 2024
62c5d8a
Update Entra ID sample, document Entra ID in README, use ttps://ml.az…
dargilco May 23, 2024
8a3a167
use model_extras instead of hyper_params. Update client __str__ to no…
dargilco May 24, 2024
092f91b
Fix all pylint errors. Minor updates to root README.md
dargilco May 28, 2024
8e610c2
Example of JSON messages in the root README.md
dargilco May 28, 2024
6d1e7ce
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 28, 2024
a738ff5
Some MyPy fixes. Also fix wrong package name in root README.md
dargilco May 28, 2024
44e94d0
Same work before re-emitting SDK
dargilco May 29, 2024
27ac7b0
Merge remote-tracking branch 'origin/main' into dargilco/azure-ai-inf…
dargilco May 30, 2024
a825db4
Use `embed` instead of `embedding`. Update Entra ID and AOAI samples
dargilco May 30, 2024
c4814d8
Fix some mypy errors. Use different terms for MaaS/MaaP
dargilco May 31, 2024
2df88dc
Re-emit, now with pyproject.toml
dargilco May 31, 2024
89d92d3
Fix/supress mypy & pyright errors
dargilco May 31, 2024
e20d003
Fix missing Etra ID auth in load_client
dargilco May 31, 2024
d7ef3b7
Use vanity link for samples folder
dargilco Jun 3, 2024
63fefdf
Revert "Use vanity link for samples folder"
dargilco Jun 3, 2024
ab6973f
Fix mypy and pyright errors
dargilco Jun 3, 2024
efbcf5c
Update root README.md. Update operator ref doc comments
dargilco Jun 3, 2024
6f69018
Re-emit
dargilco Jun 3, 2024
aed30bf
Fix mypy error in sample
dargilco Jun 3, 2024
c327403
Fix missing ranges in ref-doc comments
dargilco Jun 3, 2024
27f2ed6
Remove unneeded cast
dargilco Jun 3, 2024
2c92e9d
Fix pylint error
dargilco Jun 3, 2024
98cd4fd
Fix typos & method names. Thanks Jarno!
dargilco Jun 4, 2024
a44df4e
Address Johan's code review comments. Thanks Johan!
dargilco Jun 5, 2024
c0958e3
Fix mypy errors
dargilco Jun 5, 2024
2cbb1cf
Minor update to root README.md
dargilco Jun 5, 2024
73c836e
Remove capacity_type
dargilco Jun 6, 2024
0883400
Fix public patched methods not showing up in intellisense, when using…
dargilco Jun 6, 2024
d0930a8
Import 'Self' from Typing package starting from Python 3.11
dargilco Jun 6, 2024
13e8ed6
Fix pylint error, line too long
dargilco Jun 6, 2024
223238c
More AOAI samples. Update package README with regards to AOAI support
dargilco Jun 6, 2024
0d03ad2
Add overloads with `stream: Literal[..]` to fix mypy and pyright erro…
dargilco Jun 6, 2024
8647964
Override all client __init__ methods so you can define and initialize…
dargilco Jun 6, 2024
3715766
Cleanup: delete now unused platform-matrix-ai.json.old
dargilco Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@
# ServiceLabel: %Image Analysis %Service Attention
/sdk/vision/azure-ai-vision-imageanalysis/ @dargilco @rhurey

# PRLabel: %AI Model Inference
# ServiceLabel: %AI Model Inference %Service Attention
/sdk/ai/azure-ai-inference/ @dargilco

# PRLabel: %HDInsight
/sdk/hdinsight/ @idear1203

Expand Down
10 changes: 10 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,16 @@
"smirnov"
]
},
{
"filename": "sdk/ai/azure-ai-inference/**",
"words": [
"ubinary",
"mros",
"Nify",
"ctxt",
"wday"
]
},
{
"filename": "sdk/ai/azure-ai-generative/**",
"words": [
Expand Down
1 change: 1 addition & 0 deletions eng/.docsettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ omitted_paths:
- sdk/**/swagger/*
- sdk/ml/azure-ai-ml/tests/*
- sdk/vision/azure-ai-vision-imageanalysis/tests/*
- sdk/ai/azure-ai-inference/tests/*
- sdk/storage/azure-storage-extensions/*

language: python
Expand Down
dargilco marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-generative/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
url="https://github.com/Azure/azure-sdk-for-python",
keywords="azure, azuresdk, azure sdk",
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 7 - Inactive",
dargilco marked this conversation as resolved.
Show resolved Hide resolved
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
Expand Down
5 changes: 5 additions & 0 deletions sdk/ai/azure-ai-inference/CHANGELOG.md
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
21 changes: 21 additions & 0 deletions sdk/ai/azure-ai-inference/LICENSE
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.
7 changes: 7 additions & 0 deletions sdk/ai/azure-ai-inference/MANIFEST.in
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
482 changes: 482 additions & 0 deletions sdk/ai/azure-ai-inference/README.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions sdk/ai/azure-ai-inference/assets.json
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"
}
1 change: 1 addition & 0 deletions sdk/ai/azure-ai-inference/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
1 change: 1 addition & 0 deletions sdk/ai/azure-ai-inference/azure/ai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
28 changes: 28 additions & 0 deletions sdk/ai/azure-ai-inference/azure/ai/inference/__init__.py
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 sdk/ai/azure-ai-inference/azure/ai/inference/_client.py
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)
Loading
Loading