Skip to content

Commit e19309c

Browse files
author
SDKAuto
committed
CodeGen from PR 31603 in Azure/azure-rest-api-specs
Merge bd451f87456c94d528ec198c0cc845b031ada94a into 0d2ca01a170641d8b1f5dace38b8995bb7563be8
1 parent 66db96d commit e19309c

File tree

19 files changed

+54
-9450
lines changed

19 files changed

+54
-9450
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"commit": "f030c09f439d5347ab57548ade9cd0abb60dd457",
3+
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
4+
"typespec_src": "specification/ai/Azure.AI.Projects",
5+
"@azure-tools/typespec-python": "0.36.4"
6+
}

sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py

Lines changed: 2 additions & 285 deletions
Original file line numberDiff line numberDiff line change
@@ -6,292 +6,9 @@
66
77
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
88
"""
9-
import uuid
10-
from os import PathLike
11-
from pathlib import Path
12-
from typing import Any, Dict, List, Tuple, Union
13-
from typing_extensions import Self
9+
from typing import List
1410

15-
from azure.core import PipelineClient
16-
from azure.core.credentials import TokenCredential
17-
from azure.core.pipeline import policies
18-
19-
from ._client import AIProjectClient as ClientGenerated
20-
from ._configuration import AIProjectClientConfiguration
21-
from ._serialization import Deserializer, Serializer
22-
from .operations import AgentsOperations, ConnectionsOperations, EvaluationsOperations, TelemetryOperations
23-
from .operations._patch import InferenceOperations
24-
25-
26-
class AIProjectClient(
27-
ClientGenerated
28-
): # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes
29-
def __init__( # pylint: disable=super-init-not-called,too-many-statements
30-
self,
31-
endpoint: str,
32-
subscription_id: str,
33-
resource_group_name: str,
34-
project_name: str,
35-
credential: "TokenCredential",
36-
**kwargs: Any,
37-
) -> None:
38-
# TODO: Validate input formats with regex match (e.g. subscription ID)
39-
if not endpoint:
40-
raise ValueError("endpoint is required")
41-
if not subscription_id:
42-
raise ValueError("subscription_id ID is required")
43-
if not resource_group_name:
44-
raise ValueError("resource_group_name is required")
45-
if not project_name:
46-
raise ValueError("project_name is required")
47-
if not credential:
48-
raise ValueError("credential is required")
49-
if "api_version" in kwargs:
50-
raise ValueError("No support for overriding the API version")
51-
if "credential_scopes" in kwargs:
52-
raise ValueError("No support for overriding the credential scopes")
53-
54-
kwargs0 = kwargs.copy()
55-
kwargs1 = kwargs.copy()
56-
kwargs2 = kwargs.copy()
57-
kwargs3 = kwargs.copy()
58-
59-
# For getting AppInsights connection string from the AppInsights resource.
60-
# The AppInsights resource URL is not known at this point. We need to get it from the
61-
# AzureML "Workspace - Get" REST API call. It will have the form:
62-
# https://management.azure.com/subscriptions/{appinsights_subscription_id}/resourceGroups/{appinsights_resource_group_name}/providers/microsoft.insights/components/{appinsights_resource_name}
63-
_endpoint0 = "https://management.azure.com"
64-
self._config0: AIProjectClientConfiguration = AIProjectClientConfiguration(
65-
endpoint=endpoint,
66-
subscription_id=subscription_id,
67-
resource_group_name=resource_group_name,
68-
project_name=project_name,
69-
credential=credential,
70-
api_version="2020-02-02",
71-
credential_scopes=["https://management.azure.com/.default"],
72-
**kwargs0,
73-
)
74-
75-
_policies0 = kwargs0.pop("policies", None)
76-
if _policies0 is None:
77-
_policies0 = [
78-
policies.RequestIdPolicy(**kwargs0),
79-
self._config0.headers_policy,
80-
self._config0.user_agent_policy,
81-
self._config0.proxy_policy,
82-
policies.ContentDecodePolicy(**kwargs0),
83-
self._config0.redirect_policy,
84-
self._config0.retry_policy,
85-
self._config0.authentication_policy,
86-
self._config0.custom_hook_policy,
87-
self._config0.logging_policy,
88-
policies.DistributedTracingPolicy(**kwargs0),
89-
policies.SensitiveHeaderCleanupPolicy(**kwargs0) if self._config0.redirect_policy else None,
90-
self._config0.http_logging_policy,
91-
]
92-
self._client0: PipelineClient = PipelineClient(base_url=_endpoint0, policies=_policies0, **kwargs0)
93-
94-
# For Endpoints operations (listing connections, getting connection properties, getting project properties)
95-
_endpoint1 = (
96-
"https://management.azure.com/"
97-
+ f"subscriptions/{subscription_id}/"
98-
+ f"resourceGroups/{resource_group_name}/"
99-
+ "providers/Microsoft.MachineLearningServices/"
100-
+ f"workspaces/{project_name}"
101-
)
102-
self._config1: AIProjectClientConfiguration = AIProjectClientConfiguration(
103-
endpoint=endpoint,
104-
subscription_id=subscription_id,
105-
resource_group_name=resource_group_name,
106-
project_name=project_name,
107-
credential=credential,
108-
api_version="2024-07-01-preview",
109-
credential_scopes=["https://management.azure.com/.default"],
110-
**kwargs1,
111-
)
112-
_policies1 = kwargs1.pop("policies", None)
113-
if _policies1 is None:
114-
_policies1 = [
115-
policies.RequestIdPolicy(**kwargs1),
116-
self._config1.headers_policy,
117-
self._config1.user_agent_policy,
118-
self._config1.proxy_policy,
119-
policies.ContentDecodePolicy(**kwargs1),
120-
self._config1.redirect_policy,
121-
self._config1.retry_policy,
122-
self._config1.authentication_policy,
123-
self._config1.custom_hook_policy,
124-
self._config1.logging_policy,
125-
policies.DistributedTracingPolicy(**kwargs1),
126-
policies.SensitiveHeaderCleanupPolicy(**kwargs1) if self._config1.redirect_policy else None,
127-
self._config1.http_logging_policy,
128-
]
129-
self._client1: PipelineClient = PipelineClient(base_url=_endpoint1, policies=_policies1, **kwargs1)
130-
131-
# For Agents operations
132-
_endpoint2 = f"{endpoint}/agents/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
133-
self._config2 = AIProjectClientConfiguration(
134-
endpoint=endpoint,
135-
subscription_id=subscription_id,
136-
resource_group_name=resource_group_name,
137-
project_name=project_name,
138-
credential=credential,
139-
api_version="2024-07-01-preview", # TODO: Update me
140-
credential_scopes=["https://ml.azure.com/.default"],
141-
**kwargs2,
142-
)
143-
_policies2 = kwargs2.pop("policies", None)
144-
if _policies2 is None:
145-
_policies2 = [
146-
policies.RequestIdPolicy(**kwargs2),
147-
self._config2.headers_policy,
148-
self._config2.user_agent_policy,
149-
self._config2.proxy_policy,
150-
policies.ContentDecodePolicy(**kwargs2),
151-
self._config2.redirect_policy,
152-
self._config2.retry_policy,
153-
self._config2.authentication_policy,
154-
self._config2.custom_hook_policy,
155-
self._config2.logging_policy,
156-
policies.DistributedTracingPolicy(**kwargs2),
157-
policies.SensitiveHeaderCleanupPolicy(**kwargs2) if self._config2.redirect_policy else None,
158-
self._config2.http_logging_policy,
159-
]
160-
self._client2: PipelineClient = PipelineClient(base_url=_endpoint2, policies=_policies2, **kwargs2)
161-
162-
# For Cloud Evaluations operations
163-
# cSpell:disable-next-line
164-
_endpoint3 = f"{endpoint}/raisvc/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{project_name}" # pylint: disable=line-too-long
165-
self._config3 = AIProjectClientConfiguration(
166-
endpoint=endpoint,
167-
subscription_id=subscription_id,
168-
resource_group_name=resource_group_name,
169-
project_name=project_name,
170-
credential=credential,
171-
api_version="2024-07-01-preview", # TODO: Update me
172-
credential_scopes=["https://ml.azure.com/.default"], # TODO: Update once service changes are ready
173-
**kwargs3,
174-
)
175-
_policies3 = kwargs3.pop("policies", None)
176-
if _policies3 is None:
177-
_policies3 = [
178-
policies.RequestIdPolicy(**kwargs3),
179-
self._config3.headers_policy,
180-
self._config3.user_agent_policy,
181-
self._config3.proxy_policy,
182-
policies.ContentDecodePolicy(**kwargs3),
183-
self._config3.redirect_policy,
184-
self._config3.retry_policy,
185-
self._config3.authentication_policy,
186-
self._config3.custom_hook_policy,
187-
self._config3.logging_policy,
188-
policies.DistributedTracingPolicy(**kwargs3),
189-
policies.SensitiveHeaderCleanupPolicy(**kwargs3) if self._config3.redirect_policy else None,
190-
self._config3.http_logging_policy,
191-
]
192-
self._client3: PipelineClient = PipelineClient(base_url=_endpoint3, policies=_policies3, **kwargs3)
193-
194-
self._serialize = Serializer()
195-
self._deserialize = Deserializer()
196-
self._serialize.client_side_validation = False
197-
198-
self.telemetry = TelemetryOperations(
199-
self._client0, self._config0, self._serialize, self._deserialize, outer_instance=self
200-
)
201-
self.connections = ConnectionsOperations(self._client1, self._config1, self._serialize, self._deserialize)
202-
self.agents = AgentsOperations(self._client2, self._config2, self._serialize, self._deserialize)
203-
self.evaluations = EvaluationsOperations(self._client3, self._config3, self._serialize, self._deserialize)
204-
self.inference = InferenceOperations(self)
205-
206-
def close(self) -> None:
207-
self._client0.close()
208-
self._client1.close()
209-
self._client2.close()
210-
self._client3.close()
211-
212-
def __enter__(self) -> Self:
213-
self._client0.__enter__()
214-
self._client1.__enter__()
215-
self._client2.__enter__()
216-
self._client3.__enter__()
217-
return self
218-
219-
def __exit__(self, *exc_details: Any) -> None:
220-
self._client0.__exit__(*exc_details)
221-
self._client1.__exit__(*exc_details)
222-
self._client2.__exit__(*exc_details)
223-
self._client3.__exit__(*exc_details)
224-
225-
@classmethod
226-
def from_connection_string(cls, conn_str: str, credential: "TokenCredential", **kwargs) -> Self:
227-
"""
228-
Create an AIProjectClient from a connection string.
229-
230-
:param str conn_str: The connection string, copied from your AI Studio project.
231-
:param TokenCredential credential: Credential used to authenticate requests to the service.
232-
:return: An AIProjectClient instance.
233-
:rtype: AIProjectClient
234-
"""
235-
if not conn_str:
236-
raise ValueError("Connection string is required")
237-
parts = conn_str.split(";")
238-
if len(parts) != 4:
239-
raise ValueError("Invalid connection string format")
240-
endpoint = "https://" + parts[0]
241-
subscription_id = parts[1]
242-
resource_group_name = parts[2]
243-
project_name = parts[3]
244-
return cls(endpoint, subscription_id, resource_group_name, project_name, credential, **kwargs)
245-
246-
def upload_file(self, file_path: Union[Path, str, PathLike]) -> Tuple[str, str]:
247-
"""Upload a file to the Azure AI Studio project.
248-
This method required *azure-ai-ml* to be installed.
249-
250-
:param file_path: The path to the file to upload.
251-
:type file_path: Union[str, Path, PathLike]
252-
:return: The tuple, containing asset id and asset URI of uploaded file.
253-
:rtype: Tuple[str]
254-
"""
255-
try:
256-
from azure.ai.ml import MLClient # type: ignore
257-
from azure.ai.ml.constants import AssetTypes # type: ignore
258-
from azure.ai.ml.entities import Data # type: ignore
259-
except ImportError as e:
260-
raise ImportError(
261-
"azure-ai-ml must be installed to use this function. Please install it using `pip install azure-ai-ml`"
262-
) from e
263-
264-
data = Data(
265-
path=str(file_path),
266-
type=AssetTypes.URI_FILE,
267-
name=str(uuid.uuid4()), # generating random name
268-
is_anonymous=True,
269-
version="1",
270-
)
271-
272-
ml_client = MLClient(
273-
self._config3.credential,
274-
self._config3.subscription_id,
275-
self._config3.resource_group_name,
276-
self._config3.project_name,
277-
)
278-
279-
data_asset = ml_client.data.create_or_update(data)
280-
281-
return data_asset.id, data_asset.path
282-
283-
@property
284-
def scope(self) -> Dict[str, str]:
285-
return {
286-
"subscription_id": self._config3.subscription_id,
287-
"resource_group_name": self._config3.resource_group_name,
288-
"project_name": self._config3.project_name,
289-
}
290-
291-
292-
__all__: List[str] = [
293-
"AIProjectClient",
294-
] # Add all objects you want publicly available to users at this package level
11+
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
29512

29613

29714
def patch_sdk():

sdk/ai/azure-ai-projects/azure/ai/projects/_types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
if TYPE_CHECKING:
1212
from . import models as _models
13-
AgentsApiResponseFormatOption = Union[str, "_models.AgentsApiResponseFormatMode", "_models.AgentsApiResponseFormat"]
13+
from .. import models as _models
14+
AgentsApiResponseFormatOption = Union[
15+
str, str, "_models.AgentsApiResponseFormatMode", "_models.AgentsApiResponseFormat"
16+
]
1417
MessageAttachmentToolDefinition = Union["_models.CodeInterpreterToolDefinition", "_models.FileSearchToolDefinition"]
15-
AgentsApiToolChoiceOption = Union[str, "_models.AgentsApiToolChoiceOptionMode", "_models.AgentsNamedToolChoice"]
18+
AgentsApiToolChoiceOption = Union[str, str, "_models.AgentsApiToolChoiceOptionMode", "_models.AgentsNamedToolChoice"]

0 commit comments

Comments
 (0)