azure-ai-evaluation 1.5.0__py3-none-any.whl → 1.7.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.

Files changed (144) hide show
  1. azure/ai/evaluation/__init__.py +10 -0
  2. azure/ai/evaluation/_aoai/__init__.py +10 -0
  3. azure/ai/evaluation/_aoai/aoai_grader.py +89 -0
  4. azure/ai/evaluation/_aoai/label_grader.py +66 -0
  5. azure/ai/evaluation/_aoai/string_check_grader.py +65 -0
  6. azure/ai/evaluation/_aoai/text_similarity_grader.py +88 -0
  7. azure/ai/evaluation/_azure/_clients.py +4 -4
  8. azure/ai/evaluation/_azure/_envs.py +208 -0
  9. azure/ai/evaluation/_azure/_token_manager.py +12 -7
  10. azure/ai/evaluation/_common/__init__.py +7 -0
  11. azure/ai/evaluation/_common/evaluation_onedp_client.py +163 -0
  12. azure/ai/evaluation/_common/onedp/__init__.py +32 -0
  13. azure/ai/evaluation/_common/onedp/_client.py +139 -0
  14. azure/ai/evaluation/_common/onedp/_configuration.py +73 -0
  15. azure/ai/evaluation/_common/onedp/_model_base.py +1232 -0
  16. azure/ai/evaluation/_common/onedp/_patch.py +21 -0
  17. azure/ai/evaluation/_common/onedp/_serialization.py +2032 -0
  18. azure/ai/evaluation/_common/onedp/_types.py +21 -0
  19. azure/ai/evaluation/_common/onedp/_validation.py +50 -0
  20. azure/ai/evaluation/_common/onedp/_vendor.py +50 -0
  21. azure/ai/evaluation/_common/onedp/_version.py +9 -0
  22. azure/ai/evaluation/_common/onedp/aio/__init__.py +29 -0
  23. azure/ai/evaluation/_common/onedp/aio/_client.py +143 -0
  24. azure/ai/evaluation/_common/onedp/aio/_configuration.py +75 -0
  25. azure/ai/evaluation/_common/onedp/aio/_patch.py +21 -0
  26. azure/ai/evaluation/_common/onedp/aio/_vendor.py +40 -0
  27. azure/ai/evaluation/_common/onedp/aio/operations/__init__.py +39 -0
  28. azure/ai/evaluation/_common/onedp/aio/operations/_operations.py +4494 -0
  29. azure/ai/evaluation/_common/onedp/aio/operations/_patch.py +21 -0
  30. azure/ai/evaluation/_common/onedp/models/__init__.py +142 -0
  31. azure/ai/evaluation/_common/onedp/models/_enums.py +162 -0
  32. azure/ai/evaluation/_common/onedp/models/_models.py +2228 -0
  33. azure/ai/evaluation/_common/onedp/models/_patch.py +21 -0
  34. azure/ai/evaluation/_common/onedp/operations/__init__.py +39 -0
  35. azure/ai/evaluation/_common/onedp/operations/_operations.py +5655 -0
  36. azure/ai/evaluation/_common/onedp/operations/_patch.py +21 -0
  37. azure/ai/evaluation/_common/onedp/py.typed +1 -0
  38. azure/ai/evaluation/_common/onedp/servicepatterns/__init__.py +1 -0
  39. azure/ai/evaluation/_common/onedp/servicepatterns/aio/__init__.py +1 -0
  40. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/__init__.py +25 -0
  41. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_operations.py +34 -0
  42. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_patch.py +20 -0
  43. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/__init__.py +1 -0
  44. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/__init__.py +1 -0
  45. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/__init__.py +22 -0
  46. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_operations.py +29 -0
  47. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_patch.py +20 -0
  48. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/__init__.py +22 -0
  49. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_operations.py +29 -0
  50. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_patch.py +20 -0
  51. azure/ai/evaluation/_common/onedp/servicepatterns/operations/__init__.py +25 -0
  52. azure/ai/evaluation/_common/onedp/servicepatterns/operations/_operations.py +34 -0
  53. azure/ai/evaluation/_common/onedp/servicepatterns/operations/_patch.py +20 -0
  54. azure/ai/evaluation/_common/rai_service.py +165 -34
  55. azure/ai/evaluation/_common/raiclient/_version.py +1 -1
  56. azure/ai/evaluation/_common/utils.py +79 -1
  57. azure/ai/evaluation/_constants.py +16 -0
  58. azure/ai/evaluation/_converters/_ai_services.py +162 -118
  59. azure/ai/evaluation/_converters/_models.py +76 -6
  60. azure/ai/evaluation/_eval_mapping.py +73 -0
  61. azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +30 -16
  62. azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +8 -0
  63. azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +5 -0
  64. azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +17 -1
  65. azure/ai/evaluation/_evaluate/_eval_run.py +1 -1
  66. azure/ai/evaluation/_evaluate/_evaluate.py +325 -76
  67. azure/ai/evaluation/_evaluate/_evaluate_aoai.py +553 -0
  68. azure/ai/evaluation/_evaluate/_utils.py +117 -4
  69. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +11 -1
  70. azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.py +9 -1
  71. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +12 -2
  72. azure/ai/evaluation/_evaluators/_common/_base_eval.py +12 -3
  73. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +12 -3
  74. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +2 -2
  75. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +12 -2
  76. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +14 -4
  77. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +9 -8
  78. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +10 -0
  79. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +10 -0
  80. azure/ai/evaluation/_evaluators/_document_retrieval/__init__.py +11 -0
  81. azure/ai/evaluation/_evaluators/_document_retrieval/_document_retrieval.py +469 -0
  82. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +10 -0
  83. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +11 -1
  84. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +10 -0
  85. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +11 -1
  86. azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +16 -2
  87. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +10 -0
  88. azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +11 -0
  89. azure/ai/evaluation/_evaluators/_qa/_qa.py +10 -0
  90. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +11 -1
  91. azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +20 -2
  92. azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +31 -46
  93. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +10 -0
  94. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +10 -0
  95. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +10 -0
  96. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +11 -1
  97. azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +16 -2
  98. azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +86 -12
  99. azure/ai/evaluation/_evaluators/_ungrounded_attributes/_ungrounded_attributes.py +10 -0
  100. azure/ai/evaluation/_evaluators/_xpia/xpia.py +11 -0
  101. azure/ai/evaluation/_exceptions.py +2 -0
  102. azure/ai/evaluation/_legacy/_adapters/__init__.py +0 -14
  103. azure/ai/evaluation/_legacy/_adapters/_check.py +17 -0
  104. azure/ai/evaluation/_legacy/_adapters/_flows.py +1 -1
  105. azure/ai/evaluation/_legacy/_batch_engine/_engine.py +51 -32
  106. azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +114 -8
  107. azure/ai/evaluation/_legacy/_batch_engine/_result.py +6 -0
  108. azure/ai/evaluation/_legacy/_batch_engine/_run.py +6 -0
  109. azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +69 -29
  110. azure/ai/evaluation/_legacy/_batch_engine/_trace.py +54 -62
  111. azure/ai/evaluation/_legacy/_batch_engine/_utils.py +19 -1
  112. azure/ai/evaluation/_legacy/_common/__init__.py +3 -0
  113. azure/ai/evaluation/_legacy/_common/_async_token_provider.py +124 -0
  114. azure/ai/evaluation/_legacy/_common/_thread_pool_executor_with_context.py +15 -0
  115. azure/ai/evaluation/_legacy/prompty/_connection.py +11 -74
  116. azure/ai/evaluation/_legacy/prompty/_exceptions.py +80 -0
  117. azure/ai/evaluation/_legacy/prompty/_prompty.py +119 -9
  118. azure/ai/evaluation/_legacy/prompty/_utils.py +72 -2
  119. azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +114 -22
  120. azure/ai/evaluation/_version.py +1 -1
  121. azure/ai/evaluation/red_team/_attack_strategy.py +1 -1
  122. azure/ai/evaluation/red_team/_red_team.py +976 -546
  123. azure/ai/evaluation/red_team/_utils/metric_mapping.py +23 -0
  124. azure/ai/evaluation/red_team/_utils/strategy_utils.py +1 -1
  125. azure/ai/evaluation/simulator/_adversarial_simulator.py +63 -39
  126. azure/ai/evaluation/simulator/_constants.py +1 -0
  127. azure/ai/evaluation/simulator/_conversation/__init__.py +13 -6
  128. azure/ai/evaluation/simulator/_conversation/_conversation.py +2 -1
  129. azure/ai/evaluation/simulator/_conversation/constants.py +1 -1
  130. azure/ai/evaluation/simulator/_direct_attack_simulator.py +38 -25
  131. azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +1 -0
  132. azure/ai/evaluation/simulator/_indirect_attack_simulator.py +43 -28
  133. azure/ai/evaluation/simulator/_model_tools/__init__.py +2 -1
  134. azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +26 -18
  135. azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +5 -10
  136. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +65 -41
  137. azure/ai/evaluation/simulator/_model_tools/_template_handler.py +15 -10
  138. azure/ai/evaluation/simulator/_model_tools/models.py +20 -17
  139. {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.7.0.dist-info}/METADATA +49 -3
  140. {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.7.0.dist-info}/RECORD +144 -86
  141. /azure/ai/evaluation/_legacy/{_batch_engine → _common}/_logging.py +0 -0
  142. {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.7.0.dist-info}/NOTICE.txt +0 -0
  143. {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.7.0.dist-info}/WHEEL +0 -0
  144. {azure_ai_evaluation-1.5.0.dist-info → azure_ai_evaluation-1.7.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,163 @@
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, RedTeamUpload)
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(
26
+ self, *, name: str, path: str, version=1, metrics: Dict[str, int]=None, result_type: ResultType=ResultType.EVALUATION, **kwargs) -> EvaluationResult:
27
+ """Create and upload evaluation results to Azure evaluation service.
28
+
29
+ This method uploads evaluation results from a local path to Azure Blob Storage
30
+ and registers them with the evaluation service. The process involves:
31
+ 1. Starting a pending upload with the evaluation service
32
+ 2. Getting a SAS token for the blob container
33
+ 3. Uploading the local evaluation results to the blob container
34
+ 4. Creating a version record for the evaluation results
35
+
36
+ :param name: The name to identify the evaluation results
37
+ :type name: str
38
+ :param path: The local path to the evaluation results file or directory
39
+ :type path: str
40
+ :param version: The version number for the evaluation results, defaults to 1
41
+ :type version: int, optional
42
+ :param metrics: Metrics to be added to evaluation result
43
+ :type metrics: Dict[str, int], optional
44
+ :param result_type: Evaluation Result Type to create
45
+ :type result_type: ResultType, optional
46
+ :param kwargs: Additional keyword arguments to pass to the underlying API calls
47
+ :return: The response from creating the evaluation result version
48
+ :rtype: EvaluationResult
49
+ :raises: Various exceptions from the underlying API calls or upload process
50
+ """
51
+
52
+ LOGGER.debug(f"Creating evaluation result for {name} with version {version} type {result_type} from path {path}")
53
+ start_pending_upload_response = self.rest_client.evaluation_results.start_pending_upload(
54
+ name=name,
55
+ version=version,
56
+ body=PendingUploadRequest(pending_upload_type=PendingUploadType.TEMPORARY_BLOB_REFERENCE),
57
+ **kwargs
58
+ )
59
+
60
+ LOGGER.debug(f"Uploading {path} to {start_pending_upload_response.blob_reference_for_consumption.blob_uri}")
61
+ with ContainerClient.from_container_url(
62
+ start_pending_upload_response.blob_reference_for_consumption.credential.sas_uri) as container_client:
63
+ upload(path=path, container_client=container_client, logger=LOGGER)
64
+
65
+ LOGGER.debug(f"Creating evaluation result version for {name} with version {version}")
66
+ create_version_response = self.rest_client.evaluation_results.create_or_update_version(
67
+ body=EvaluationResult(
68
+ blob_uri=start_pending_upload_response.blob_reference_for_consumption.blob_uri,
69
+ result_type=result_type,
70
+ name=name,
71
+ version=version,
72
+ metrics=metrics,
73
+ ),
74
+ name=name,
75
+ version=version,
76
+ **kwargs
77
+ )
78
+
79
+ return create_version_response
80
+
81
+ def start_evaluation_run(self, *, evaluation: EvaluationUpload, **kwargs) -> EvaluationUpload:
82
+ """Start a new evaluation run in the Azure evaluation service.
83
+
84
+ This method creates a new evaluation run with the provided configuration details.
85
+
86
+ :param evaluation: The evaluation configuration to upload
87
+ :type evaluation: EvaluationUpload
88
+ :param kwargs: Additional keyword arguments to pass to the underlying API calls
89
+ :return: The created evaluation run object
90
+ :rtype: EvaluationUpload
91
+ :raises: Various exceptions from the underlying API calls
92
+ """
93
+ upload_run_response = self.rest_client.evaluations.upload_run(
94
+ evaluation=evaluation,
95
+ **kwargs
96
+ )
97
+
98
+ return upload_run_response
99
+
100
+ def update_evaluation_run(self, *, name: str, evaluation: EvaluationUpload, **kwargs) -> EvaluationUpload:
101
+ """Update an existing evaluation run in the Azure evaluation service.
102
+
103
+ This method updates an evaluation run with new information such as status changes,
104
+ result references, or other metadata.
105
+
106
+ :param name: The identifier of the evaluation run to update
107
+ :type name: str
108
+ :param evaluation: The updated evaluation configuration
109
+ :type evaluation: EvaluationUpload
110
+ :param kwargs: Additional keyword arguments to pass to the underlying API calls
111
+ :return: The updated evaluation run object
112
+ :rtype: EvaluationUpload
113
+ :raises: Various exceptions from the underlying API calls
114
+ """
115
+ update_run_response = self.rest_client.evaluations.upload_update_run(
116
+ name=name,
117
+ evaluation=evaluation,
118
+ **kwargs
119
+ )
120
+
121
+ return update_run_response
122
+
123
+ def start_red_team_run(self, *, red_team: RedTeamUpload, **kwargs):
124
+ """Start a new red team run in the Azure evaluation service.
125
+
126
+ This method creates a new red team run with the provided configuration details.
127
+
128
+ :param red_team: The red team configuration to upload
129
+ :type red_team: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
130
+ :param kwargs: Additional keyword arguments to pass to the underlying API calls
131
+ :return: The created red team run object
132
+ :rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
133
+ :raises: Various exceptions from the underlying API calls
134
+ """
135
+ upload_run_response = self.rest_client.red_teams.upload_run(
136
+ redteam=red_team,
137
+ **kwargs
138
+ )
139
+
140
+ return upload_run_response
141
+
142
+ def update_red_team_run(self, *, name: str, red_team: RedTeamUpload, **kwargs):
143
+ """Update an existing red team run in the Azure evaluation service.
144
+
145
+ This method updates a red team run with new information such as status changes,
146
+ result references, or other metadata.
147
+
148
+ :param name: The identifier of the red team run to update
149
+ :type name: str
150
+ :param red_team: The updated red team configuration
151
+ :type red_team: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
152
+ :param kwargs: Additional keyword arguments to pass to the underlying API calls
153
+ :return: The updated red team run object
154
+ :rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
155
+ :raises: Various exceptions from the underlying API calls
156
+ """
157
+ update_run_response = self.rest_client.red_teams.upload_update_run(
158
+ name=name,
159
+ redteam=red_team,
160
+ **kwargs
161
+ )
162
+
163
+ 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)