Skip to content

Commit c18f7ec

Browse files
authored
[AI] Azure OpenAI Deployment CRUD (#34358)
* skeleton code for new deployment types * AOAI deployment creation * endpoints operations placeholder, remove dead files * remove begin_update * try sending request as bytes * fix cspell
1 parent b5c5845 commit c18f7ec

29 files changed

+5794
-27
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"sdk/ai/**/index/**",
3535
"sdk/ai/azure-ai-generative/tests/**",
3636
"sdk/ai/azure-ai-resources/azure/ai/resources/_index/_langchain/vendor/**",
37+
"sdk/ai/azure-ai-resources/azure/ai/resources/_restclient/**",
3738
"sdk/cognitiveservices/azure-cognitiveservices-search-autosuggest/**",
3839
"sdk/cognitiveservices/azure-cognitiveservices-search-customimagesearch/**",
3940
"sdk/cognitiveservices/azure-cognitiveservices-search-customsearch/**",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._client import MachineLearningServicesClient
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
14+
try:
15+
from ._patch import __all__ as _patch_all
16+
from ._patch import * # pylint: disable=unused-wildcard-import
17+
except ImportError:
18+
_patch_all = []
19+
from ._patch import patch_sdk as _patch_sdk
20+
21+
__all__ = [
22+
"MachineLearningServicesClient",
23+
]
24+
__all__.extend([p for p in _patch_all if p not in __all__])
25+
26+
_patch_sdk()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import Any, TYPE_CHECKING
11+
12+
from azure.core.pipeline import policies
13+
from azure.core.rest import HttpRequest, HttpResponse
14+
from azure.mgmt.core import ARMPipelineClient
15+
from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy
16+
17+
from . import models as _models
18+
from ._configuration import MachineLearningServicesClientConfiguration
19+
from ._serialization import Deserializer, Serializer
20+
from .operations import AzureOpenAIDeploymentsOperations
21+
22+
if TYPE_CHECKING:
23+
# pylint: disable=unused-import,ungrouped-imports
24+
from azure.core.credentials import TokenCredential
25+
26+
27+
class MachineLearningServicesClient: # pylint: disable=client-accepts-api-version-keyword
28+
"""MachineLearningServicesClient.
29+
30+
:ivar azure_open_ai_deployments: AzureOpenAIDeploymentsOperations operations
31+
:vartype azure_open_ai_deployments:
32+
azure.ai.resources.autogen.operations.AzureOpenAIDeploymentsOperations
33+
:param credential: Credential needed for the client to connect to Azure. Required.
34+
:type credential: ~azure.core.credentials.TokenCredential
35+
:param api_version: The API version to use for this operation. Required.
36+
:type api_version: str
37+
:param subscription_id: The ID of the target subscription. Required.
38+
:type subscription_id: str
39+
:param base_url: Service host. Default value is "https://management.azure.com".
40+
:type base_url: str
41+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
42+
Retry-After header is present.
43+
"""
44+
45+
def __init__(
46+
self,
47+
credential: "TokenCredential",
48+
api_version: str,
49+
subscription_id: str,
50+
base_url: str = "https://management.azure.com",
51+
**kwargs: Any
52+
) -> None:
53+
self._config = MachineLearningServicesClientConfiguration(
54+
credential=credential, api_version=api_version, subscription_id=subscription_id, **kwargs
55+
)
56+
_policies = kwargs.pop("policies", None)
57+
if _policies is None:
58+
_policies = [
59+
policies.RequestIdPolicy(**kwargs),
60+
self._config.headers_policy,
61+
self._config.user_agent_policy,
62+
self._config.proxy_policy,
63+
policies.ContentDecodePolicy(**kwargs),
64+
ARMAutoResourceProviderRegistrationPolicy(),
65+
self._config.redirect_policy,
66+
self._config.retry_policy,
67+
self._config.authentication_policy,
68+
self._config.custom_hook_policy,
69+
self._config.logging_policy,
70+
policies.DistributedTracingPolicy(**kwargs),
71+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
72+
self._config.http_logging_policy,
73+
]
74+
self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, policies=_policies, **kwargs)
75+
76+
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
77+
self._serialize = Serializer(client_models)
78+
self._deserialize = Deserializer(client_models)
79+
self._serialize.client_side_validation = False
80+
self.azure_open_ai_deployments = AzureOpenAIDeploymentsOperations(
81+
self._client, self._config, self._serialize, self._deserialize
82+
)
83+
84+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
85+
"""Runs the network request through the client's chained policies.
86+
87+
>>> from azure.core.rest import HttpRequest
88+
>>> request = HttpRequest("GET", "https://www.example.org/")
89+
<HttpRequest [GET], url: 'https://www.example.org/'>
90+
>>> response = client.send_request(request)
91+
<HttpResponse: 200 OK>
92+
93+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
94+
95+
:param request: The network request you want to make. Required.
96+
:type request: ~azure.core.rest.HttpRequest
97+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
98+
:return: The response of your network call. Does not do error handling on your response.
99+
:rtype: ~azure.core.rest.HttpResponse
100+
"""
101+
102+
request_copy = deepcopy(request)
103+
request_copy.url = self._client.format_url(request_copy.url)
104+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
105+
106+
def close(self) -> None:
107+
self._client.close()
108+
109+
def __enter__(self) -> "MachineLearningServicesClient":
110+
self._client.__enter__()
111+
return self
112+
113+
def __exit__(self, *exc_details: Any) -> None:
114+
self._client.__exit__(*exc_details)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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) Python Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import Any, TYPE_CHECKING
10+
11+
from azure.core.pipeline import policies
12+
from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy
13+
14+
from ._version import VERSION
15+
16+
if TYPE_CHECKING:
17+
# pylint: disable=unused-import,ungrouped-imports
18+
from azure.core.credentials import TokenCredential
19+
20+
21+
class MachineLearningServicesClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
22+
"""Configuration for MachineLearningServicesClient.
23+
24+
Note that all parameters used to create this instance are saved as instance
25+
attributes.
26+
27+
:param credential: Credential needed for the client to connect to Azure. Required.
28+
:type credential: ~azure.core.credentials.TokenCredential
29+
:param api_version: The API version to use for this operation. Required.
30+
:type api_version: str
31+
:param subscription_id: The ID of the target subscription. Required.
32+
:type subscription_id: str
33+
"""
34+
35+
def __init__(self, credential: "TokenCredential", api_version: str, subscription_id: str, **kwargs: Any) -> None:
36+
if credential is None:
37+
raise ValueError("Parameter 'credential' must not be None.")
38+
if api_version is None:
39+
raise ValueError("Parameter 'api_version' must not be None.")
40+
if subscription_id is None:
41+
raise ValueError("Parameter 'subscription_id' must not be None.")
42+
43+
self.credential = credential
44+
self.api_version = api_version
45+
self.subscription_id = subscription_id
46+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"])
47+
kwargs.setdefault("sdk_moniker", "ai-resources-autogen/{}".format(VERSION))
48+
self.polling_interval = kwargs.get("polling_interval", 30)
49+
self._configure(**kwargs)
50+
51+
def _configure(self, **kwargs: Any) -> None:
52+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
53+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
54+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
55+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
56+
self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs)
57+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
58+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
59+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
60+
self.authentication_policy = kwargs.get("authentication_policy")
61+
if self.credential and not self.authentication_policy:
62+
self.authentication_policy = ARMChallengeAuthenticationPolicy(
63+
self.credential, *self.credential_scopes, **kwargs
64+
)

0 commit comments

Comments
 (0)