azure-ai-evaluation 1.5.0__py3-none-any.whl → 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of azure-ai-evaluation might be problematic. Click here for more details.
- azure/ai/evaluation/__init__.py +9 -0
- azure/ai/evaluation/_aoai/__init__.py +10 -0
- azure/ai/evaluation/_aoai/aoai_grader.py +89 -0
- azure/ai/evaluation/_aoai/label_grader.py +66 -0
- azure/ai/evaluation/_aoai/string_check_grader.py +65 -0
- azure/ai/evaluation/_aoai/text_similarity_grader.py +88 -0
- azure/ai/evaluation/_azure/_clients.py +4 -4
- azure/ai/evaluation/_azure/_envs.py +208 -0
- azure/ai/evaluation/_azure/_token_manager.py +12 -7
- azure/ai/evaluation/_common/__init__.py +5 -0
- azure/ai/evaluation/_common/evaluation_onedp_client.py +118 -0
- azure/ai/evaluation/_common/onedp/__init__.py +32 -0
- azure/ai/evaluation/_common/onedp/_client.py +139 -0
- azure/ai/evaluation/_common/onedp/_configuration.py +73 -0
- azure/ai/evaluation/_common/onedp/_model_base.py +1232 -0
- azure/ai/evaluation/_common/onedp/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/_serialization.py +2032 -0
- azure/ai/evaluation/_common/onedp/_types.py +21 -0
- azure/ai/evaluation/_common/onedp/_validation.py +50 -0
- azure/ai/evaluation/_common/onedp/_vendor.py +50 -0
- azure/ai/evaluation/_common/onedp/_version.py +9 -0
- azure/ai/evaluation/_common/onedp/aio/__init__.py +29 -0
- azure/ai/evaluation/_common/onedp/aio/_client.py +143 -0
- azure/ai/evaluation/_common/onedp/aio/_configuration.py +75 -0
- azure/ai/evaluation/_common/onedp/aio/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/aio/_vendor.py +40 -0
- azure/ai/evaluation/_common/onedp/aio/operations/__init__.py +39 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_operations.py +4494 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/models/__init__.py +142 -0
- azure/ai/evaluation/_common/onedp/models/_enums.py +162 -0
- azure/ai/evaluation/_common/onedp/models/_models.py +2228 -0
- azure/ai/evaluation/_common/onedp/models/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/operations/__init__.py +39 -0
- azure/ai/evaluation/_common/onedp/operations/_operations.py +5655 -0
- azure/ai/evaluation/_common/onedp/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/py.typed +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/rai_service.py +158 -28
- azure/ai/evaluation/_common/raiclient/_version.py +1 -1
- azure/ai/evaluation/_common/utils.py +79 -1
- azure/ai/evaluation/_constants.py +16 -0
- azure/ai/evaluation/_eval_mapping.py +71 -0
- azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +30 -16
- azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +8 -0
- azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +5 -0
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +17 -1
- azure/ai/evaluation/_evaluate/_eval_run.py +1 -1
- azure/ai/evaluation/_evaluate/_evaluate.py +325 -74
- azure/ai/evaluation/_evaluate/_evaluate_aoai.py +534 -0
- azure/ai/evaluation/_evaluate/_utils.py +117 -4
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +8 -3
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +12 -3
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +2 -2
- azure/ai/evaluation/_evaluators/_document_retrieval/__init__.py +11 -0
- azure/ai/evaluation/_evaluators/_document_retrieval/_document_retrieval.py +467 -0
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +1 -1
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +1 -1
- azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +6 -2
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +1 -1
- azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +7 -2
- azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +31 -46
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +1 -1
- azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +5 -2
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +6 -2
- azure/ai/evaluation/_exceptions.py +2 -0
- azure/ai/evaluation/_legacy/_adapters/__init__.py +0 -14
- azure/ai/evaluation/_legacy/_adapters/_check.py +17 -0
- azure/ai/evaluation/_legacy/_adapters/_flows.py +1 -1
- azure/ai/evaluation/_legacy/_batch_engine/_engine.py +51 -32
- azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +114 -8
- azure/ai/evaluation/_legacy/_batch_engine/_result.py +6 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run.py +6 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +69 -29
- azure/ai/evaluation/_legacy/_batch_engine/_trace.py +54 -62
- azure/ai/evaluation/_legacy/_batch_engine/_utils.py +19 -1
- azure/ai/evaluation/_legacy/_common/__init__.py +3 -0
- azure/ai/evaluation/_legacy/_common/_async_token_provider.py +124 -0
- azure/ai/evaluation/_legacy/_common/_thread_pool_executor_with_context.py +15 -0
- azure/ai/evaluation/_legacy/prompty/_connection.py +11 -74
- azure/ai/evaluation/_legacy/prompty/_exceptions.py +80 -0
- azure/ai/evaluation/_legacy/prompty/_prompty.py +119 -9
- azure/ai/evaluation/_legacy/prompty/_utils.py +72 -2
- azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +90 -17
- azure/ai/evaluation/_version.py +1 -1
- azure/ai/evaluation/red_team/_attack_strategy.py +1 -1
- azure/ai/evaluation/red_team/_red_team.py +825 -450
- azure/ai/evaluation/red_team/_utils/metric_mapping.py +23 -0
- azure/ai/evaluation/red_team/_utils/strategy_utils.py +1 -1
- azure/ai/evaluation/simulator/_adversarial_simulator.py +63 -39
- azure/ai/evaluation/simulator/_constants.py +1 -0
- azure/ai/evaluation/simulator/_conversation/__init__.py +13 -6
- azure/ai/evaluation/simulator/_conversation/_conversation.py +2 -1
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +35 -22
- azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +1 -0
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +40 -25
- azure/ai/evaluation/simulator/_model_tools/__init__.py +2 -1
- azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +24 -18
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +5 -10
- azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +65 -41
- azure/ai/evaluation/simulator/_model_tools/_template_handler.py +9 -5
- azure/ai/evaluation/simulator/_model_tools/models.py +20 -17
- {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.6.0.dist-info}/METADATA +25 -2
- {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.6.0.dist-info}/RECORD +123 -65
- /azure/ai/evaluation/_legacy/{_batch_engine → _common}/_logging.py +0 -0
- {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.6.0.dist-info}/NOTICE.txt +0 -0
- {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.6.0.dist-info}/WHEEL +0 -0
- {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# ---------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# ---------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Union, Any, Dict
|
|
7
|
+
from azure.core.credentials import AzureKeyCredential, TokenCredential
|
|
8
|
+
from azure.ai.evaluation._common.onedp import AIProjectClient as RestEvaluationServiceClient
|
|
9
|
+
from azure.ai.evaluation._common.onedp.models import (PendingUploadRequest, PendingUploadType, EvaluationResult,
|
|
10
|
+
ResultType, AssetCredentialRequest, EvaluationUpload, InputDataset)
|
|
11
|
+
from azure.storage.blob import ContainerClient
|
|
12
|
+
from .utils import upload
|
|
13
|
+
|
|
14
|
+
LOGGER = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
class EvaluationServiceOneDPClient:
|
|
17
|
+
|
|
18
|
+
def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
|
|
19
|
+
self.rest_client = RestEvaluationServiceClient(
|
|
20
|
+
endpoint=endpoint,
|
|
21
|
+
credential=credential,
|
|
22
|
+
**kwargs,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def create_evaluation_result(self, *, name: str, path: str, version=1, metrics: Dict[str, int]=None, **kwargs) -> EvaluationResult:
|
|
26
|
+
"""Create and upload evaluation results to Azure evaluation service.
|
|
27
|
+
|
|
28
|
+
This method uploads evaluation results from a local path to Azure Blob Storage
|
|
29
|
+
and registers them with the evaluation service. The process involves:
|
|
30
|
+
1. Starting a pending upload with the evaluation service
|
|
31
|
+
2. Getting a SAS token for the blob container
|
|
32
|
+
3. Uploading the local evaluation results to the blob container
|
|
33
|
+
4. Creating a version record for the evaluation results
|
|
34
|
+
|
|
35
|
+
:param name: The name to identify the evaluation results
|
|
36
|
+
:type name: str
|
|
37
|
+
:param path: The local path to the evaluation results file or directory
|
|
38
|
+
:type path: str
|
|
39
|
+
:param version: The version number for the evaluation results, defaults to 1
|
|
40
|
+
:type version: int, optional
|
|
41
|
+
:param metrics: Metrics to be added to evaluation result
|
|
42
|
+
:type version: Dict[str, int], optional
|
|
43
|
+
:param kwargs: Additional keyword arguments to pass to the underlying API calls
|
|
44
|
+
:return: The response from creating the evaluation result version
|
|
45
|
+
:rtype: EvaluationResult
|
|
46
|
+
:raises: Various exceptions from the underlying API calls or upload process
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
LOGGER.debug(f"Creating evaluation result for {name} with version {version} from path {path}")
|
|
50
|
+
start_pending_upload_response = self.rest_client.evaluation_results.start_pending_upload(
|
|
51
|
+
name=name,
|
|
52
|
+
version=version,
|
|
53
|
+
body=PendingUploadRequest(pending_upload_type=PendingUploadType.TEMPORARY_BLOB_REFERENCE),
|
|
54
|
+
**kwargs
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
LOGGER.debug(f"Uploading {path} to {start_pending_upload_response.blob_reference_for_consumption.blob_uri}")
|
|
58
|
+
with ContainerClient.from_container_url(
|
|
59
|
+
start_pending_upload_response.blob_reference_for_consumption.credential.sas_uri) as container_client:
|
|
60
|
+
upload(path=path, container_client=container_client, logger=LOGGER)
|
|
61
|
+
|
|
62
|
+
LOGGER.debug(f"Creating evaluation result version for {name} with version {version}")
|
|
63
|
+
create_version_response = self.rest_client.evaluation_results.create_or_update_version(
|
|
64
|
+
body=EvaluationResult(
|
|
65
|
+
blob_uri=start_pending_upload_response.blob_reference_for_consumption.blob_uri,
|
|
66
|
+
result_type=ResultType.EVALUATION,
|
|
67
|
+
name=name,
|
|
68
|
+
version=version,
|
|
69
|
+
metrics=metrics,
|
|
70
|
+
),
|
|
71
|
+
name=name,
|
|
72
|
+
version=version,
|
|
73
|
+
**kwargs
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return create_version_response
|
|
77
|
+
|
|
78
|
+
def start_evaluation_run(self, *, evaluation: EvaluationUpload, **kwargs) -> EvaluationUpload:
|
|
79
|
+
"""Start a new evaluation run in the Azure evaluation service.
|
|
80
|
+
|
|
81
|
+
This method creates a new evaluation run with the provided configuration details.
|
|
82
|
+
|
|
83
|
+
:param evaluation: The evaluation configuration to upload
|
|
84
|
+
:type evaluation: EvaluationUpload
|
|
85
|
+
:param kwargs: Additional keyword arguments to pass to the underlying API calls
|
|
86
|
+
:return: The created evaluation run object
|
|
87
|
+
:rtype: EvaluationUpload
|
|
88
|
+
:raises: Various exceptions from the underlying API calls
|
|
89
|
+
"""
|
|
90
|
+
upload_run_response = self.rest_client.evaluations.upload_run(
|
|
91
|
+
evaluation=evaluation,
|
|
92
|
+
**kwargs
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return upload_run_response
|
|
96
|
+
|
|
97
|
+
def update_evaluation_run(self, *, name: str, evaluation: EvaluationUpload, **kwargs) -> EvaluationUpload:
|
|
98
|
+
"""Update an existing evaluation run in the Azure evaluation service.
|
|
99
|
+
|
|
100
|
+
This method updates an evaluation run with new information such as status changes,
|
|
101
|
+
result references, or other metadata.
|
|
102
|
+
|
|
103
|
+
:param name: The identifier of the evaluation run to update
|
|
104
|
+
:type name: str
|
|
105
|
+
:param evaluation: The updated evaluation configuration
|
|
106
|
+
:type evaluation: EvaluationUpload
|
|
107
|
+
:param kwargs: Additional keyword arguments to pass to the underlying API calls
|
|
108
|
+
:return: The updated evaluation run object
|
|
109
|
+
:rtype: EvaluationUpload
|
|
110
|
+
:raises: Various exceptions from the underlying API calls
|
|
111
|
+
"""
|
|
112
|
+
update_run_response = self.rest_client.evaluations.upload_update_run(
|
|
113
|
+
name=name,
|
|
114
|
+
evaluation=evaluation,
|
|
115
|
+
**kwargs
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return update_run_response
|
|
@@ -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()
|
|
@@ -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)
|
|
@@ -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://ai.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)
|