Skip to content

Commit b40c8b5

Browse files
authored
Adding 1 RP Client to evaluation package. (#40479)
* Add files via upload * Add files via upload * Delete sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/onedp/__pycache__ directory * Delete sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/onedp/models/__pycache__ directory * Delete sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/onedp/operations/__pycache__ directory * Update cspell.json * Update cspell.json
1 parent ce204aa commit b40c8b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+17418
-0
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,8 @@
14111411
"Inadherent",
14121412
"nbformat",
14131413
"nbconvert",
1414+
"onedp",
1415+
"azureai",
14141416
]
14151417
},
14161418
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
# pylint: disable=wrong-import-position
9+
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import AIProjectClient # type: ignore
16+
from ._version import VERSION
17+
18+
__version__ = VERSION
19+
20+
try:
21+
from ._patch import __all__ as _patch_all
22+
from ._patch import *
23+
except ImportError:
24+
_patch_all = []
25+
from ._patch import patch_sdk as _patch_sdk
26+
27+
__all__ = [
28+
"AIProjectClient",
29+
]
30+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
31+
32+
_patch_sdk()
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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, Union
11+
from typing_extensions import Self
12+
13+
from azure.core import PipelineClient
14+
from azure.core.credentials import AzureKeyCredential
15+
from azure.core.pipeline import policies
16+
from azure.core.rest import HttpRequest, HttpResponse
17+
18+
from ._configuration import AIProjectClientConfiguration
19+
from ._serialization import Deserializer, Serializer
20+
from .operations import (
21+
ConnectionsOperations,
22+
DatasetsOperations,
23+
DeploymentsOperations,
24+
EvaluationResultsOperations,
25+
EvaluationsOperations,
26+
IndexesOperations,
27+
RedTeamsOperations,
28+
ServicePatternsOperations,
29+
)
30+
31+
if TYPE_CHECKING:
32+
from azure.core.credentials import TokenCredential
33+
34+
35+
class AIProjectClient: # pylint: disable=too-many-instance-attributes
36+
"""AIProjectClient.
37+
38+
:ivar service_patterns: ServicePatternsOperations operations
39+
:vartype service_patterns: azure.ai.projects.onedp.operations.ServicePatternsOperations
40+
:ivar connections: ConnectionsOperations operations
41+
:vartype connections: azure.ai.projects.onedp.operations.ConnectionsOperations
42+
:ivar evaluations: EvaluationsOperations operations
43+
:vartype evaluations: azure.ai.projects.onedp.operations.EvaluationsOperations
44+
:ivar datasets: DatasetsOperations operations
45+
:vartype datasets: azure.ai.projects.onedp.operations.DatasetsOperations
46+
:ivar indexes: IndexesOperations operations
47+
:vartype indexes: azure.ai.projects.onedp.operations.IndexesOperations
48+
:ivar deployments: DeploymentsOperations operations
49+
:vartype deployments: azure.ai.projects.onedp.operations.DeploymentsOperations
50+
:ivar red_teams: RedTeamsOperations operations
51+
:vartype red_teams: azure.ai.projects.onedp.operations.RedTeamsOperations
52+
:ivar evaluation_results: EvaluationResultsOperations operations
53+
:vartype evaluation_results: azure.ai.projects.onedp.operations.EvaluationResultsOperations
54+
:param endpoint: Project endpoint in the form of:
55+
https://<aiservices-id>.services.ai.azure.com/api/projects/<project-name>. Required.
56+
:type endpoint: str
57+
:param credential: Credential used to authenticate requests to the service. Is either a key
58+
credential type or a token credential type. Required.
59+
:type credential: ~azure.core.credentials.AzureKeyCredential or
60+
~azure.core.credentials.TokenCredential
61+
:keyword api_version: The API version to use for this operation. Default value is
62+
"2025-05-15-preview". Note that overriding this default value may result in unsupported
63+
behavior.
64+
:paramtype api_version: str
65+
"""
66+
67+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
68+
_endpoint = "{endpoint}"
69+
self._config = AIProjectClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
70+
_policies = kwargs.pop("policies", None)
71+
if _policies is None:
72+
_policies = [
73+
policies.RequestIdPolicy(**kwargs),
74+
self._config.headers_policy,
75+
self._config.user_agent_policy,
76+
self._config.proxy_policy,
77+
policies.ContentDecodePolicy(**kwargs),
78+
self._config.redirect_policy,
79+
self._config.retry_policy,
80+
self._config.authentication_policy,
81+
self._config.custom_hook_policy,
82+
self._config.logging_policy,
83+
policies.DistributedTracingPolicy(**kwargs),
84+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
85+
self._config.http_logging_policy,
86+
]
87+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
88+
89+
self._serialize = Serializer()
90+
self._deserialize = Deserializer()
91+
self._serialize.client_side_validation = False
92+
self.service_patterns = ServicePatternsOperations(
93+
self._client, self._config, self._serialize, self._deserialize
94+
)
95+
self.connections = ConnectionsOperations(self._client, self._config, self._serialize, self._deserialize)
96+
self.evaluations = EvaluationsOperations(self._client, self._config, self._serialize, self._deserialize)
97+
self.datasets = DatasetsOperations(self._client, self._config, self._serialize, self._deserialize)
98+
self.indexes = IndexesOperations(self._client, self._config, self._serialize, self._deserialize)
99+
self.deployments = DeploymentsOperations(self._client, self._config, self._serialize, self._deserialize)
100+
self.red_teams = RedTeamsOperations(self._client, self._config, self._serialize, self._deserialize)
101+
self.evaluation_results = EvaluationResultsOperations(
102+
self._client, self._config, self._serialize, self._deserialize
103+
)
104+
105+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
106+
"""Runs the network request through the client's chained policies.
107+
108+
>>> from azure.core.rest import HttpRequest
109+
>>> request = HttpRequest("GET", "https://www.example.org/")
110+
<HttpRequest [GET], url: 'https://www.example.org/'>
111+
>>> response = client.send_request(request)
112+
<HttpResponse: 200 OK>
113+
114+
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
115+
116+
:param request: The network request you want to make. Required.
117+
:type request: ~azure.core.rest.HttpRequest
118+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
119+
:return: The response of your network call. Does not do error handling on your response.
120+
:rtype: ~azure.core.rest.HttpResponse
121+
"""
122+
123+
request_copy = deepcopy(request)
124+
path_format_arguments = {
125+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
126+
}
127+
128+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
129+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
130+
131+
def close(self) -> None:
132+
self._client.close()
133+
134+
def __enter__(self) -> Self:
135+
self._client.__enter__()
136+
return self
137+
138+
def __exit__(self, *exc_details: Any) -> None:
139+
self._client.__exit__(*exc_details)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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, Union
10+
11+
from azure.core.credentials import AzureKeyCredential
12+
from azure.core.pipeline import policies
13+
14+
from ._version import VERSION
15+
16+
if TYPE_CHECKING:
17+
from azure.core.credentials import TokenCredential
18+
19+
20+
class AIProjectClientConfiguration: # pylint: disable=too-many-instance-attributes
21+
"""Configuration for AIProjectClient.
22+
23+
Note that all parameters used to create this instance are saved as instance
24+
attributes.
25+
26+
:param endpoint: Project endpoint in the form of:
27+
https://<aiservices-id>.services.ai.azure.com/api/projects/<project-name>. Required.
28+
:type endpoint: str
29+
:param credential: Credential used to authenticate requests to the service. Is either a key
30+
credential type or a token credential type. Required.
31+
:type credential: ~azure.core.credentials.AzureKeyCredential or
32+
~azure.core.credentials.TokenCredential
33+
:keyword api_version: The API version to use for this operation. Default value is
34+
"2025-05-15-preview". Note that overriding this default value may result in unsupported
35+
behavior.
36+
:paramtype api_version: str
37+
"""
38+
39+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
40+
api_version: str = kwargs.pop("api_version", "2025-05-15-preview")
41+
42+
if endpoint is None:
43+
raise ValueError("Parameter 'endpoint' must not be None.")
44+
if credential is None:
45+
raise ValueError("Parameter 'credential' must not be None.")
46+
47+
self.endpoint = endpoint
48+
self.credential = credential
49+
self.api_version = api_version
50+
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
51+
kwargs.setdefault("sdk_moniker", "ai-projects-onedp/{}".format(VERSION))
52+
self.polling_interval = kwargs.get("polling_interval", 30)
53+
self._configure(**kwargs)
54+
55+
def _infer_policy(self, **kwargs):
56+
if isinstance(self.credential, AzureKeyCredential):
57+
return policies.AzureKeyCredentialPolicy(self.credential, "Authorization", prefix="Bearer", **kwargs)
58+
if hasattr(self.credential, "get_token"):
59+
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
60+
raise TypeError(f"Unsupported credential: {self.credential}")
61+
62+
def _configure(self, **kwargs: Any) -> None:
63+
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
64+
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
65+
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
66+
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
67+
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
68+
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
69+
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
70+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
71+
self.authentication_policy = kwargs.get("authentication_policy")
72+
if self.credential and not self.authentication_policy:
73+
self.authentication_policy = self._infer_policy(**kwargs)

0 commit comments

Comments
 (0)