azure-ai-evaluation 1.3.0__py3-none-any.whl → 1.4.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 (123) hide show
  1. azure/ai/evaluation/__init__.py +43 -1
  2. azure/ai/evaluation/_azure/_models.py +6 -6
  3. azure/ai/evaluation/_common/constants.py +6 -2
  4. azure/ai/evaluation/_common/rai_service.py +38 -4
  5. azure/ai/evaluation/_common/raiclient/__init__.py +34 -0
  6. azure/ai/evaluation/_common/raiclient/_client.py +128 -0
  7. azure/ai/evaluation/_common/raiclient/_configuration.py +87 -0
  8. azure/ai/evaluation/_common/raiclient/_model_base.py +1235 -0
  9. azure/ai/evaluation/_common/raiclient/_patch.py +20 -0
  10. azure/ai/evaluation/_common/raiclient/_serialization.py +2050 -0
  11. azure/ai/evaluation/_common/raiclient/_version.py +9 -0
  12. azure/ai/evaluation/_common/raiclient/aio/__init__.py +29 -0
  13. azure/ai/evaluation/_common/raiclient/aio/_client.py +130 -0
  14. azure/ai/evaluation/_common/raiclient/aio/_configuration.py +87 -0
  15. azure/ai/evaluation/_common/raiclient/aio/_patch.py +20 -0
  16. azure/ai/evaluation/_common/raiclient/aio/operations/__init__.py +25 -0
  17. azure/ai/evaluation/_common/raiclient/aio/operations/_operations.py +981 -0
  18. azure/ai/evaluation/_common/raiclient/aio/operations/_patch.py +20 -0
  19. azure/ai/evaluation/_common/raiclient/models/__init__.py +60 -0
  20. azure/ai/evaluation/_common/raiclient/models/_enums.py +18 -0
  21. azure/ai/evaluation/_common/raiclient/models/_models.py +651 -0
  22. azure/ai/evaluation/_common/raiclient/models/_patch.py +20 -0
  23. azure/ai/evaluation/_common/raiclient/operations/__init__.py +25 -0
  24. azure/ai/evaluation/_common/raiclient/operations/_operations.py +1225 -0
  25. azure/ai/evaluation/_common/raiclient/operations/_patch.py +20 -0
  26. azure/ai/evaluation/_common/raiclient/py.typed +1 -0
  27. azure/ai/evaluation/_common/utils.py +22 -2
  28. azure/ai/evaluation/_constants.py +7 -0
  29. azure/ai/evaluation/_converters/__init__.py +3 -0
  30. azure/ai/evaluation/_converters/_ai_services.py +804 -0
  31. azure/ai/evaluation/_converters/_models.py +302 -0
  32. azure/ai/evaluation/_evaluate/_batch_run/__init__.py +10 -3
  33. azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +104 -0
  34. azure/ai/evaluation/_evaluate/_batch_run/batch_clients.py +82 -0
  35. azure/ai/evaluation/_evaluate/_eval_run.py +1 -1
  36. azure/ai/evaluation/_evaluate/_evaluate.py +31 -2
  37. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +23 -3
  38. azure/ai/evaluation/_evaluators/_code_vulnerability/__init__.py +5 -0
  39. azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.py +120 -0
  40. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +21 -2
  41. azure/ai/evaluation/_evaluators/_common/_base_eval.py +43 -3
  42. azure/ai/evaluation/_evaluators/_common/_base_multi_eval.py +3 -1
  43. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +43 -4
  44. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +16 -4
  45. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +42 -5
  46. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +15 -0
  47. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +15 -0
  48. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +15 -0
  49. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +15 -0
  50. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +28 -4
  51. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +21 -2
  52. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +26 -3
  53. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +21 -3
  54. azure/ai/evaluation/_evaluators/_intent_resolution/__init__.py +7 -0
  55. azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +152 -0
  56. azure/ai/evaluation/_evaluators/_intent_resolution/intent_resolution.prompty +161 -0
  57. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +26 -3
  58. azure/ai/evaluation/_evaluators/_qa/_qa.py +51 -7
  59. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +26 -2
  60. azure/ai/evaluation/_evaluators/_response_completeness/__init__.py +7 -0
  61. azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +157 -0
  62. azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +99 -0
  63. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +21 -2
  64. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +113 -4
  65. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +23 -3
  66. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +24 -5
  67. azure/ai/evaluation/_evaluators/_task_adherence/__init__.py +7 -0
  68. azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +148 -0
  69. azure/ai/evaluation/_evaluators/_task_adherence/task_adherence.prompty +117 -0
  70. azure/ai/evaluation/_evaluators/_tool_call_accuracy/__init__.py +9 -0
  71. azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +292 -0
  72. azure/ai/evaluation/_evaluators/_tool_call_accuracy/tool_call_accuracy.prompty +71 -0
  73. azure/ai/evaluation/_evaluators/_ungrounded_attributes/__init__.py +5 -0
  74. azure/ai/evaluation/_evaluators/_ungrounded_attributes/_ungrounded_attributes.py +103 -0
  75. azure/ai/evaluation/_evaluators/_xpia/xpia.py +2 -0
  76. azure/ai/evaluation/_exceptions.py +5 -0
  77. azure/ai/evaluation/_legacy/__init__.py +3 -0
  78. azure/ai/evaluation/_legacy/_batch_engine/__init__.py +9 -0
  79. azure/ai/evaluation/_legacy/_batch_engine/_config.py +45 -0
  80. azure/ai/evaluation/_legacy/_batch_engine/_engine.py +368 -0
  81. azure/ai/evaluation/_legacy/_batch_engine/_exceptions.py +88 -0
  82. azure/ai/evaluation/_legacy/_batch_engine/_logging.py +292 -0
  83. azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +23 -0
  84. azure/ai/evaluation/_legacy/_batch_engine/_result.py +99 -0
  85. azure/ai/evaluation/_legacy/_batch_engine/_run.py +121 -0
  86. azure/ai/evaluation/_legacy/_batch_engine/_run_storage.py +128 -0
  87. azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +217 -0
  88. azure/ai/evaluation/_legacy/_batch_engine/_status.py +25 -0
  89. azure/ai/evaluation/_legacy/_batch_engine/_trace.py +105 -0
  90. azure/ai/evaluation/_legacy/_batch_engine/_utils.py +82 -0
  91. azure/ai/evaluation/_legacy/_batch_engine/_utils_deprecated.py +131 -0
  92. azure/ai/evaluation/_legacy/prompty/__init__.py +36 -0
  93. azure/ai/evaluation/_legacy/prompty/_connection.py +182 -0
  94. azure/ai/evaluation/_legacy/prompty/_exceptions.py +59 -0
  95. azure/ai/evaluation/_legacy/prompty/_prompty.py +313 -0
  96. azure/ai/evaluation/_legacy/prompty/_utils.py +545 -0
  97. azure/ai/evaluation/_legacy/prompty/_yaml_utils.py +99 -0
  98. azure/ai/evaluation/_red_team/__init__.py +3 -0
  99. azure/ai/evaluation/_red_team/_attack_objective_generator.py +192 -0
  100. azure/ai/evaluation/_red_team/_attack_strategy.py +42 -0
  101. azure/ai/evaluation/_red_team/_callback_chat_target.py +74 -0
  102. azure/ai/evaluation/_red_team/_default_converter.py +21 -0
  103. azure/ai/evaluation/_red_team/_red_team.py +1858 -0
  104. azure/ai/evaluation/_red_team/_red_team_result.py +246 -0
  105. azure/ai/evaluation/_red_team/_utils/__init__.py +3 -0
  106. azure/ai/evaluation/_red_team/_utils/constants.py +64 -0
  107. azure/ai/evaluation/_red_team/_utils/formatting_utils.py +164 -0
  108. azure/ai/evaluation/_red_team/_utils/logging_utils.py +139 -0
  109. azure/ai/evaluation/_red_team/_utils/strategy_utils.py +188 -0
  110. azure/ai/evaluation/_safety_evaluation/__init__.py +1 -1
  111. azure/ai/evaluation/_safety_evaluation/_generated_rai_client.py +0 -0
  112. azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +251 -150
  113. azure/ai/evaluation/_version.py +1 -1
  114. azure/ai/evaluation/simulator/_adversarial_scenario.py +3 -1
  115. azure/ai/evaluation/simulator/_adversarial_simulator.py +54 -27
  116. azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +145 -0
  117. azure/ai/evaluation/simulator/_model_tools/_rai_client.py +71 -1
  118. {azure_ai_evaluation-1.3.0.dist-info → azure_ai_evaluation-1.4.0.dist-info}/METADATA +69 -15
  119. azure_ai_evaluation-1.4.0.dist-info/RECORD +197 -0
  120. {azure_ai_evaluation-1.3.0.dist-info → azure_ai_evaluation-1.4.0.dist-info}/WHEEL +1 -1
  121. azure_ai_evaluation-1.3.0.dist-info/RECORD +0 -119
  122. {azure_ai_evaluation-1.3.0.dist-info → azure_ai_evaluation-1.4.0.dist-info}/NOTICE.txt +0 -0
  123. {azure_ai_evaluation-1.3.0.dist-info → azure_ai_evaluation-1.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1225 @@
1
+ # pylint: disable=too-many-lines
2
+ # coding=utf-8
3
+ # --------------------------------------------------------------------------
4
+ # Copyright (c) Microsoft Corporation. All rights reserved.
5
+ # Licensed under the MIT License. See License.txt in the project root for license information.
6
+ # Code generated by Microsoft (R) Python Code Generator.
7
+ # Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
+ # --------------------------------------------------------------------------
9
+ from io import IOBase
10
+ import json
11
+ import sys
12
+ from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload
13
+
14
+ from azure.core import PipelineClient
15
+ from azure.core.exceptions import (
16
+ ClientAuthenticationError,
17
+ HttpResponseError,
18
+ ResourceExistsError,
19
+ ResourceNotFoundError,
20
+ ResourceNotModifiedError,
21
+ StreamClosedError,
22
+ StreamConsumedError,
23
+ map_error,
24
+ )
25
+ from azure.core.pipeline import PipelineResponse
26
+ from azure.core.rest import HttpRequest, HttpResponse
27
+ from azure.core.tracing.decorator import distributed_trace
28
+ from azure.core.utils import case_insensitive_dict
29
+
30
+ from .. import models as _models
31
+ from .._configuration import MachineLearningServicesClientConfiguration
32
+ from .._model_base import SdkJSONEncoder, _deserialize
33
+ from .._serialization import Deserializer, Serializer
34
+
35
+ if sys.version_info >= (3, 9):
36
+ from collections.abc import MutableMapping
37
+ else:
38
+ from typing import MutableMapping # type: ignore
39
+ JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
40
+ T = TypeVar("T")
41
+ ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
42
+
43
+ _SERIALIZER = Serializer()
44
+ _SERIALIZER.client_side_validation = False
45
+
46
+
47
+ def build_rai_svc_get_annotation_request(**kwargs: Any) -> HttpRequest:
48
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
49
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
50
+
51
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
52
+ accept = _headers.pop("Accept", "application/json")
53
+
54
+ # Construct URL
55
+ _url = "/checkannotation"
56
+
57
+ # Construct parameters
58
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
59
+
60
+ # Construct headers
61
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
62
+
63
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
64
+
65
+
66
+ def build_rai_svc_submit_annotation_request(**kwargs: Any) -> HttpRequest:
67
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
68
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
69
+
70
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
71
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
72
+ accept = _headers.pop("Accept", "application/json")
73
+
74
+ # Construct URL
75
+ _url = "/submitannotation"
76
+
77
+ # Construct parameters
78
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
79
+
80
+ # Construct headers
81
+ if content_type is not None:
82
+ _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
83
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
84
+
85
+ return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
86
+
87
+
88
+ def build_rai_svc_get_jail_break_dataset_with_type_request( # pylint: disable=name-too-long
89
+ type: str, **kwargs: Any
90
+ ) -> HttpRequest:
91
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
92
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
93
+
94
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
95
+ accept = _headers.pop("Accept", "application/json")
96
+
97
+ # Construct URL
98
+ _url = "/simulation/jailbreak/{type}"
99
+ path_format_arguments = {
100
+ "type": _SERIALIZER.url("type", type, "str"),
101
+ }
102
+
103
+ _url: str = _url.format(**path_format_arguments) # type: ignore
104
+
105
+ # Construct parameters
106
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
107
+
108
+ # Construct headers
109
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
110
+
111
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
112
+
113
+
114
+ def build_rai_svc_get_attack_objectives_request( # pylint: disable=name-too-long
115
+ *, risk_types: Optional[List[str]] = None, lang: Optional[str] = None, strategy: Optional[str] = None, **kwargs: Any
116
+ ) -> HttpRequest:
117
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
118
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
119
+
120
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
121
+ accept = _headers.pop("Accept", "application/json")
122
+
123
+ # Construct URL
124
+ _url = "/simulation/attackobjectives"
125
+
126
+ # Construct parameters
127
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
128
+ if risk_types is not None:
129
+ _params["riskTypes"] = [_SERIALIZER.query("risk_types", q, "str") if q is not None else "" for q in risk_types]
130
+ if lang is not None:
131
+ _params["lang"] = _SERIALIZER.query("lang", lang, "str")
132
+ if strategy is not None:
133
+ _params["strategy"] = _SERIALIZER.query("strategy", strategy, "str")
134
+
135
+ # Construct headers
136
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
137
+
138
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
139
+
140
+
141
+ def build_rai_svc_get_jail_break_dataset_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long
142
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
143
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
144
+
145
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
146
+ accept = _headers.pop("Accept", "application/json")
147
+
148
+ # Construct URL
149
+ _url = "/simulation/jailbreak/"
150
+
151
+ # Construct parameters
152
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
153
+
154
+ # Construct headers
155
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
156
+
157
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
158
+
159
+
160
+ def build_rai_svc_get_template_parameters_with_type_request( # pylint: disable=name-too-long
161
+ type: str, **kwargs: Any
162
+ ) -> HttpRequest:
163
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
164
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
165
+
166
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
167
+ accept = _headers.pop("Accept", "application/json")
168
+
169
+ # Construct URL
170
+ _url = "/simulation/template/parameters/{type}"
171
+ path_format_arguments = {
172
+ "type": _SERIALIZER.url("type", type, "str"),
173
+ }
174
+
175
+ _url: str = _url.format(**path_format_arguments) # type: ignore
176
+
177
+ # Construct parameters
178
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
179
+
180
+ # Construct headers
181
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
182
+
183
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
184
+
185
+
186
+ def build_rai_svc_get_template_parameters_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long
187
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
188
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
189
+
190
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
191
+ accept = _headers.pop("Accept", "application/json")
192
+
193
+ # Construct URL
194
+ _url = "/simulation/template/parameters/"
195
+
196
+ # Construct parameters
197
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
198
+
199
+ # Construct headers
200
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
201
+
202
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
203
+
204
+
205
+ def build_rai_svc_get_template_parameters_image_request( # pylint: disable=name-too-long
206
+ *, path: str, **kwargs: Any
207
+ ) -> HttpRequest:
208
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
209
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
210
+
211
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
212
+ accept = _headers.pop("Accept", "application/json")
213
+
214
+ # Construct URL
215
+ _url = "/simulation/template/parameters/image"
216
+
217
+ # Construct parameters
218
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
219
+ _params["path"] = _SERIALIZER.query("path", path, "str")
220
+
221
+ # Construct headers
222
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
223
+
224
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
225
+
226
+
227
+ def build_rai_svc_submit_simulation_request(**kwargs: Any) -> HttpRequest:
228
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
229
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
230
+
231
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
232
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
233
+ accept = _headers.pop("Accept", "application/json")
234
+
235
+ # Construct URL
236
+ _url = "/simulation/chat/completions/submit"
237
+
238
+ # Construct parameters
239
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
240
+
241
+ # Construct headers
242
+ if content_type is not None:
243
+ _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
244
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
245
+
246
+ return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
247
+
248
+
249
+ def build_rai_svc_submit_aoai_evaluation_request(**kwargs: Any) -> HttpRequest: # pylint: disable=name-too-long
250
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
251
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
252
+
253
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
254
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
255
+ accept = _headers.pop("Accept", "application/json")
256
+
257
+ # Construct URL
258
+ _url = "/submitaoaievaluation"
259
+
260
+ # Construct parameters
261
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
262
+
263
+ # Construct headers
264
+ if content_type is not None:
265
+ _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
266
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
267
+
268
+ return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)
269
+
270
+
271
+ def build_rai_svc_get_operation_result_request( # pylint: disable=name-too-long
272
+ operation_id: str, *, api_key: Optional[str] = None, model_endpoint: Optional[str] = None, **kwargs: Any
273
+ ) -> HttpRequest:
274
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
275
+ _params = case_insensitive_dict(kwargs.pop("params", {}) or {})
276
+
277
+ api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2022-11-01-preview"))
278
+ accept = _headers.pop("Accept", "application/json")
279
+
280
+ # Construct URL
281
+ _url = "/operations/{operationId}"
282
+ path_format_arguments = {
283
+ "operationId": _SERIALIZER.url("operation_id", operation_id, "str"),
284
+ }
285
+
286
+ _url: str = _url.format(**path_format_arguments) # type: ignore
287
+
288
+ # Construct parameters
289
+ _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
290
+
291
+ # Construct headers
292
+ if api_key is not None:
293
+ _headers["api-key"] = _SERIALIZER.header("api_key", api_key, "str")
294
+ if model_endpoint is not None:
295
+ _headers["model-endpoint"] = _SERIALIZER.header("model_endpoint", model_endpoint, "str")
296
+ _headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
297
+
298
+ return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
299
+
300
+
301
+ class RAISvcOperations:
302
+ """
303
+ .. warning::
304
+ **DO NOT** instantiate this class directly.
305
+
306
+ Instead, you should access the following operations through
307
+ :class:`~raiclient.MachineLearningServicesClient`'s
308
+ :attr:`rai_svc` attribute.
309
+ """
310
+
311
+ def __init__(self, *args, **kwargs):
312
+ input_args = list(args)
313
+ self._client: PipelineClient = input_args.pop(0) if input_args else kwargs.pop("client")
314
+ self._config: MachineLearningServicesClientConfiguration = (
315
+ input_args.pop(0) if input_args else kwargs.pop("config")
316
+ )
317
+ self._serialize: Serializer = input_args.pop(0) if input_args else kwargs.pop("serializer")
318
+ self._deserialize: Deserializer = input_args.pop(0) if input_args else kwargs.pop("deserializer")
319
+
320
+ @distributed_trace
321
+ def get_annotation(self, **kwargs: Any) -> List[str]:
322
+ """Get the supported annotation tasks.
323
+
324
+ :return: list of str
325
+ :rtype: list[str]
326
+ :raises ~azure.core.exceptions.HttpResponseError:
327
+ """
328
+ error_map: MutableMapping = {
329
+ 401: ClientAuthenticationError,
330
+ 404: ResourceNotFoundError,
331
+ 409: ResourceExistsError,
332
+ 304: ResourceNotModifiedError,
333
+ }
334
+ error_map.update(kwargs.pop("error_map", {}) or {})
335
+
336
+ _headers = kwargs.pop("headers", {}) or {}
337
+ _params = kwargs.pop("params", {}) or {}
338
+
339
+ cls: ClsType[List[str]] = kwargs.pop("cls", None)
340
+
341
+ _request = build_rai_svc_get_annotation_request(
342
+ api_version=self._config.api_version,
343
+ headers=_headers,
344
+ params=_params,
345
+ )
346
+ path_format_arguments = {
347
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
348
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
349
+ "resourceGroupName": self._serialize.url(
350
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
351
+ ),
352
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
353
+ }
354
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
355
+
356
+ _stream = kwargs.pop("stream", False)
357
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
358
+ _request, stream=_stream, **kwargs
359
+ )
360
+
361
+ response = pipeline_response.http_response
362
+
363
+ if response.status_code not in [200]:
364
+ if _stream:
365
+ try:
366
+ response.read() # Load the body in memory and close the socket
367
+ except (StreamConsumedError, StreamClosedError):
368
+ pass
369
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
370
+ raise HttpResponseError(response=response)
371
+
372
+ if _stream:
373
+ deserialized = response.iter_bytes()
374
+ else:
375
+ deserialized = _deserialize(List[str], response.json())
376
+
377
+ if cls:
378
+ return cls(pipeline_response, deserialized, {}) # type: ignore
379
+
380
+ return deserialized # type: ignore
381
+
382
+ @overload
383
+ def submit_annotation(
384
+ self, body: _models.AnnotationDTO, *, content_type: str = "application/json", **kwargs: Any
385
+ ) -> _models.LongRunningResponse:
386
+ """Submit a request for annotation.
387
+
388
+ :param body: Properties of a Prompt Version. Required.
389
+ :type body: ~raiclient.models.AnnotationDTO
390
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
391
+ Default value is "application/json".
392
+ :paramtype content_type: str
393
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
394
+ :rtype: ~raiclient.models.LongRunningResponse
395
+ :raises ~azure.core.exceptions.HttpResponseError:
396
+ """
397
+
398
+ @overload
399
+ def submit_annotation(
400
+ self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
401
+ ) -> _models.LongRunningResponse:
402
+ """Submit a request for annotation.
403
+
404
+ :param body: Properties of a Prompt Version. Required.
405
+ :type body: JSON
406
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
407
+ Default value is "application/json".
408
+ :paramtype content_type: str
409
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
410
+ :rtype: ~raiclient.models.LongRunningResponse
411
+ :raises ~azure.core.exceptions.HttpResponseError:
412
+ """
413
+
414
+ @overload
415
+ def submit_annotation(
416
+ self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
417
+ ) -> _models.LongRunningResponse:
418
+ """Submit a request for annotation.
419
+
420
+ :param body: Properties of a Prompt Version. Required.
421
+ :type body: IO[bytes]
422
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
423
+ Default value is "application/json".
424
+ :paramtype content_type: str
425
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
426
+ :rtype: ~raiclient.models.LongRunningResponse
427
+ :raises ~azure.core.exceptions.HttpResponseError:
428
+ """
429
+
430
+ @distributed_trace
431
+ def submit_annotation(
432
+ self, body: Union[_models.AnnotationDTO, JSON, IO[bytes]], **kwargs: Any
433
+ ) -> _models.LongRunningResponse:
434
+ """Submit a request for annotation.
435
+
436
+ :param body: Properties of a Prompt Version. Is one of the following types: AnnotationDTO,
437
+ JSON, IO[bytes] Required.
438
+ :type body: ~raiclient.models.AnnotationDTO or JSON or IO[bytes]
439
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
440
+ :rtype: ~raiclient.models.LongRunningResponse
441
+ :raises ~azure.core.exceptions.HttpResponseError:
442
+ """
443
+ error_map: MutableMapping = {
444
+ 401: ClientAuthenticationError,
445
+ 404: ResourceNotFoundError,
446
+ 409: ResourceExistsError,
447
+ 304: ResourceNotModifiedError,
448
+ }
449
+ error_map.update(kwargs.pop("error_map", {}) or {})
450
+
451
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
452
+ _params = kwargs.pop("params", {}) or {}
453
+
454
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
455
+ cls: ClsType[_models.LongRunningResponse] = kwargs.pop("cls", None)
456
+
457
+ content_type = content_type or "application/json"
458
+ _content = None
459
+ if isinstance(body, (IOBase, bytes)):
460
+ _content = body
461
+ else:
462
+ _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
463
+
464
+ _request = build_rai_svc_submit_annotation_request(
465
+ content_type=content_type,
466
+ api_version=self._config.api_version,
467
+ content=_content,
468
+ headers=_headers,
469
+ params=_params,
470
+ )
471
+ path_format_arguments = {
472
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
473
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
474
+ "resourceGroupName": self._serialize.url(
475
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
476
+ ),
477
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
478
+ }
479
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
480
+
481
+ _stream = kwargs.pop("stream", False)
482
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
483
+ _request, stream=_stream, **kwargs
484
+ )
485
+
486
+ response = pipeline_response.http_response
487
+
488
+ if response.status_code not in [202]:
489
+ if _stream:
490
+ try:
491
+ response.read() # Load the body in memory and close the socket
492
+ except (StreamConsumedError, StreamClosedError):
493
+ pass
494
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
495
+ raise HttpResponseError(response=response)
496
+
497
+ if _stream:
498
+ deserialized = response.iter_bytes()
499
+ else:
500
+ deserialized = _deserialize(_models.LongRunningResponse, response.json())
501
+
502
+ if cls:
503
+ return cls(pipeline_response, deserialized, {}) # type: ignore
504
+
505
+ return deserialized # type: ignore
506
+
507
+ @distributed_trace
508
+ def get_jail_break_dataset_with_type(self, type: str, **kwargs: Any) -> List[str]:
509
+ """Get the jailbreak dataset with type.
510
+
511
+ :param type: Type of jailbreak dataset. Required.
512
+ :type type: str
513
+ :return: list of str
514
+ :rtype: list[str]
515
+ :raises ~azure.core.exceptions.HttpResponseError:
516
+ """
517
+ error_map: MutableMapping = {
518
+ 401: ClientAuthenticationError,
519
+ 404: ResourceNotFoundError,
520
+ 409: ResourceExistsError,
521
+ 304: ResourceNotModifiedError,
522
+ }
523
+ error_map.update(kwargs.pop("error_map", {}) or {})
524
+
525
+ _headers = kwargs.pop("headers", {}) or {}
526
+ _params = kwargs.pop("params", {}) or {}
527
+
528
+ cls: ClsType[List[str]] = kwargs.pop("cls", None)
529
+
530
+ _request = build_rai_svc_get_jail_break_dataset_with_type_request(
531
+ type=type,
532
+ api_version=self._config.api_version,
533
+ headers=_headers,
534
+ params=_params,
535
+ )
536
+ path_format_arguments = {
537
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
538
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
539
+ "resourceGroupName": self._serialize.url(
540
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
541
+ ),
542
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
543
+ }
544
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
545
+
546
+ _stream = kwargs.pop("stream", False)
547
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
548
+ _request, stream=_stream, **kwargs
549
+ )
550
+
551
+ response = pipeline_response.http_response
552
+
553
+ if response.status_code not in [200]:
554
+ if _stream:
555
+ try:
556
+ response.read() # Load the body in memory and close the socket
557
+ except (StreamConsumedError, StreamClosedError):
558
+ pass
559
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
560
+ raise HttpResponseError(response=response)
561
+
562
+ if _stream:
563
+ deserialized = response.iter_bytes()
564
+ else:
565
+ deserialized = _deserialize(List[str], response.json())
566
+
567
+ if cls:
568
+ return cls(pipeline_response, deserialized, {}) # type: ignore
569
+
570
+ return deserialized # type: ignore
571
+
572
+ @distributed_trace
573
+ def get_attack_objectives(
574
+ self,
575
+ *,
576
+ risk_types: Optional[List[str]] = None,
577
+ lang: Optional[str] = None,
578
+ strategy: Optional[str] = None,
579
+ **kwargs: Any
580
+ ) -> List[_models.AttackObjective]:
581
+ """Get the attack objectives.
582
+
583
+ :keyword risk_types: Risk types for the attack objectives dataset. Default value is None.
584
+ :paramtype risk_types: list[str]
585
+ :keyword lang: The language for the attack objectives dataset, defaults to 'en'. Default value
586
+ is None.
587
+ :paramtype lang: str
588
+ :keyword strategy: The strategy. Default value is None.
589
+ :paramtype strategy: str
590
+ :return: list of AttackObjective
591
+ :rtype: list[~raiclient.models.AttackObjective]
592
+ :raises ~azure.core.exceptions.HttpResponseError:
593
+ """
594
+ error_map: MutableMapping = {
595
+ 401: ClientAuthenticationError,
596
+ 404: ResourceNotFoundError,
597
+ 409: ResourceExistsError,
598
+ 304: ResourceNotModifiedError,
599
+ }
600
+ error_map.update(kwargs.pop("error_map", {}) or {})
601
+
602
+ _headers = kwargs.pop("headers", {}) or {}
603
+ _params = kwargs.pop("params", {}) or {}
604
+
605
+ cls: ClsType[List[_models.AttackObjective]] = kwargs.pop("cls", None)
606
+
607
+ _request = build_rai_svc_get_attack_objectives_request(
608
+ risk_types=risk_types,
609
+ lang=lang,
610
+ strategy=strategy,
611
+ api_version=self._config.api_version,
612
+ headers=_headers,
613
+ params=_params,
614
+ )
615
+ path_format_arguments = {
616
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
617
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
618
+ "resourceGroupName": self._serialize.url(
619
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
620
+ ),
621
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
622
+ }
623
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
624
+ _stream = kwargs.pop("stream", False)
625
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
626
+ _request, stream=_stream, **kwargs
627
+ )
628
+
629
+ response = pipeline_response.http_response
630
+
631
+ if response.status_code not in [200]:
632
+ if _stream:
633
+ try:
634
+ response.read() # Load the body in memory and close the socket
635
+ except (StreamConsumedError, StreamClosedError):
636
+ pass
637
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
638
+ raise HttpResponseError(response=response)
639
+
640
+ if _stream:
641
+ deserialized = response.iter_bytes()
642
+ else:
643
+ deserialized = _deserialize(List[_models.AttackObjective], response.json())
644
+
645
+ if cls:
646
+ return cls(pipeline_response, deserialized, {}) # type: ignore
647
+
648
+ return deserialized # type: ignore
649
+
650
+ @distributed_trace
651
+ def get_jail_break_dataset(self, **kwargs: Any) -> List[str]:
652
+ """Get the jailbreak dataset.
653
+
654
+ :return: list of str
655
+ :rtype: list[str]
656
+ :raises ~azure.core.exceptions.HttpResponseError:
657
+ """
658
+ error_map: MutableMapping = {
659
+ 401: ClientAuthenticationError,
660
+ 404: ResourceNotFoundError,
661
+ 409: ResourceExistsError,
662
+ 304: ResourceNotModifiedError,
663
+ }
664
+ error_map.update(kwargs.pop("error_map", {}) or {})
665
+
666
+ _headers = kwargs.pop("headers", {}) or {}
667
+ _params = kwargs.pop("params", {}) or {}
668
+
669
+ cls: ClsType[List[str]] = kwargs.pop("cls", None)
670
+
671
+ _request = build_rai_svc_get_jail_break_dataset_request(
672
+ api_version=self._config.api_version,
673
+ headers=_headers,
674
+ params=_params,
675
+ )
676
+ path_format_arguments = {
677
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
678
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
679
+ "resourceGroupName": self._serialize.url(
680
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
681
+ ),
682
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
683
+ }
684
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
685
+
686
+ _stream = kwargs.pop("stream", False)
687
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
688
+ _request, stream=_stream, **kwargs
689
+ )
690
+
691
+ response = pipeline_response.http_response
692
+
693
+ if response.status_code not in [200]:
694
+ if _stream:
695
+ try:
696
+ response.read() # Load the body in memory and close the socket
697
+ except (StreamConsumedError, StreamClosedError):
698
+ pass
699
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
700
+ raise HttpResponseError(response=response)
701
+
702
+ if _stream:
703
+ deserialized = response.iter_bytes()
704
+ else:
705
+ deserialized = _deserialize(List[str], response.json())
706
+
707
+ if cls:
708
+ return cls(pipeline_response, deserialized, {}) # type: ignore
709
+
710
+ return deserialized # type: ignore
711
+
712
+ @distributed_trace
713
+ def get_template_parameters_with_type(self, type: str, **kwargs: Any) -> str:
714
+ """Get template parameters with type.
715
+
716
+ :param type: Type for the template parameters. Required.
717
+ :type type: str
718
+ :return: str
719
+ :rtype: str
720
+ :raises ~azure.core.exceptions.HttpResponseError:
721
+ """
722
+ error_map: MutableMapping = {
723
+ 401: ClientAuthenticationError,
724
+ 404: ResourceNotFoundError,
725
+ 409: ResourceExistsError,
726
+ 304: ResourceNotModifiedError,
727
+ }
728
+ error_map.update(kwargs.pop("error_map", {}) or {})
729
+
730
+ _headers = kwargs.pop("headers", {}) or {}
731
+ _params = kwargs.pop("params", {}) or {}
732
+
733
+ cls: ClsType[str] = kwargs.pop("cls", None)
734
+
735
+ _request = build_rai_svc_get_template_parameters_with_type_request(
736
+ type=type,
737
+ api_version=self._config.api_version,
738
+ headers=_headers,
739
+ params=_params,
740
+ )
741
+ path_format_arguments = {
742
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
743
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
744
+ "resourceGroupName": self._serialize.url(
745
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
746
+ ),
747
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
748
+ }
749
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
750
+
751
+ _stream = kwargs.pop("stream", False)
752
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
753
+ _request, stream=_stream, **kwargs
754
+ )
755
+
756
+ response = pipeline_response.http_response
757
+
758
+ if response.status_code not in [200]:
759
+ if _stream:
760
+ try:
761
+ response.read() # Load the body in memory and close the socket
762
+ except (StreamConsumedError, StreamClosedError):
763
+ pass
764
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
765
+ raise HttpResponseError(response=response)
766
+
767
+ if _stream:
768
+ deserialized = response.iter_bytes()
769
+ else:
770
+ deserialized = _deserialize(str, response.json())
771
+
772
+ if cls:
773
+ return cls(pipeline_response, deserialized, {}) # type: ignore
774
+
775
+ return deserialized # type: ignore
776
+
777
+ @distributed_trace
778
+ def get_template_parameters(self, **kwargs: Any) -> str:
779
+ """Get template parameters.
780
+
781
+ :return: str
782
+ :rtype: str
783
+ :raises ~azure.core.exceptions.HttpResponseError:
784
+ """
785
+ error_map: MutableMapping = {
786
+ 401: ClientAuthenticationError,
787
+ 404: ResourceNotFoundError,
788
+ 409: ResourceExistsError,
789
+ 304: ResourceNotModifiedError,
790
+ }
791
+ error_map.update(kwargs.pop("error_map", {}) or {})
792
+
793
+ _headers = kwargs.pop("headers", {}) or {}
794
+ _params = kwargs.pop("params", {}) or {}
795
+
796
+ cls: ClsType[str] = kwargs.pop("cls", None)
797
+
798
+ _request = build_rai_svc_get_template_parameters_request(
799
+ api_version=self._config.api_version,
800
+ headers=_headers,
801
+ params=_params,
802
+ )
803
+ path_format_arguments = {
804
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
805
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
806
+ "resourceGroupName": self._serialize.url(
807
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
808
+ ),
809
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
810
+ }
811
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
812
+
813
+ _stream = kwargs.pop("stream", False)
814
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
815
+ _request, stream=_stream, **kwargs
816
+ )
817
+
818
+ response = pipeline_response.http_response
819
+
820
+ if response.status_code not in [200]:
821
+ if _stream:
822
+ try:
823
+ response.read() # Load the body in memory and close the socket
824
+ except (StreamConsumedError, StreamClosedError):
825
+ pass
826
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
827
+ raise HttpResponseError(response=response)
828
+
829
+ if _stream:
830
+ deserialized = response.iter_bytes()
831
+ else:
832
+ deserialized = _deserialize(str, response.json())
833
+
834
+ if cls:
835
+ return cls(pipeline_response, deserialized, {}) # type: ignore
836
+
837
+ return deserialized # type: ignore
838
+
839
+ @distributed_trace
840
+ def get_template_parameters_image(self, *, path: str, **kwargs: Any) -> str:
841
+ """Get the template parameters image.
842
+
843
+ :keyword path: Image path. Required.
844
+ :paramtype path: str
845
+ :return: str
846
+ :rtype: str
847
+ :raises ~azure.core.exceptions.HttpResponseError:
848
+ """
849
+ error_map: MutableMapping = {
850
+ 401: ClientAuthenticationError,
851
+ 404: ResourceNotFoundError,
852
+ 409: ResourceExistsError,
853
+ 304: ResourceNotModifiedError,
854
+ }
855
+ error_map.update(kwargs.pop("error_map", {}) or {})
856
+
857
+ _headers = kwargs.pop("headers", {}) or {}
858
+ _params = kwargs.pop("params", {}) or {}
859
+
860
+ cls: ClsType[str] = kwargs.pop("cls", None)
861
+
862
+ _request = build_rai_svc_get_template_parameters_image_request(
863
+ path=path,
864
+ api_version=self._config.api_version,
865
+ headers=_headers,
866
+ params=_params,
867
+ )
868
+ path_format_arguments = {
869
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
870
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
871
+ "resourceGroupName": self._serialize.url(
872
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
873
+ ),
874
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
875
+ }
876
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
877
+
878
+ _stream = kwargs.pop("stream", False)
879
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
880
+ _request, stream=_stream, **kwargs
881
+ )
882
+
883
+ response = pipeline_response.http_response
884
+
885
+ if response.status_code not in [200]:
886
+ if _stream:
887
+ try:
888
+ response.read() # Load the body in memory and close the socket
889
+ except (StreamConsumedError, StreamClosedError):
890
+ pass
891
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
892
+ raise HttpResponseError(response=response)
893
+
894
+ if _stream:
895
+ deserialized = response.iter_bytes()
896
+ else:
897
+ deserialized = _deserialize(str, response.json())
898
+
899
+ if cls:
900
+ return cls(pipeline_response, deserialized, {}) # type: ignore
901
+
902
+ return deserialized # type: ignore
903
+
904
+ @overload
905
+ def submit_simulation(
906
+ self, body: _models.SimulationDTO, *, content_type: str = "application/json", **kwargs: Any
907
+ ) -> _models.LongRunningResponse:
908
+ """Submit a request for simulation.
909
+
910
+ :param body: Properties of a Prompt Version. Required.
911
+ :type body: ~raiclient.models.SimulationDTO
912
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
913
+ Default value is "application/json".
914
+ :paramtype content_type: str
915
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
916
+ :rtype: ~raiclient.models.LongRunningResponse
917
+ :raises ~azure.core.exceptions.HttpResponseError:
918
+ """
919
+
920
+ @overload
921
+ def submit_simulation(
922
+ self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
923
+ ) -> _models.LongRunningResponse:
924
+ """Submit a request for simulation.
925
+
926
+ :param body: Properties of a Prompt Version. Required.
927
+ :type body: JSON
928
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
929
+ Default value is "application/json".
930
+ :paramtype content_type: str
931
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
932
+ :rtype: ~raiclient.models.LongRunningResponse
933
+ :raises ~azure.core.exceptions.HttpResponseError:
934
+ """
935
+
936
+ @overload
937
+ def submit_simulation(
938
+ self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
939
+ ) -> _models.LongRunningResponse:
940
+ """Submit a request for simulation.
941
+
942
+ :param body: Properties of a Prompt Version. Required.
943
+ :type body: IO[bytes]
944
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
945
+ Default value is "application/json".
946
+ :paramtype content_type: str
947
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
948
+ :rtype: ~raiclient.models.LongRunningResponse
949
+ :raises ~azure.core.exceptions.HttpResponseError:
950
+ """
951
+
952
+ @distributed_trace
953
+ def submit_simulation(
954
+ self, body: Union[_models.SimulationDTO, JSON, IO[bytes]], **kwargs: Any
955
+ ) -> _models.LongRunningResponse:
956
+ """Submit a request for simulation.
957
+
958
+ :param body: Properties of a Prompt Version. Is one of the following types: SimulationDTO,
959
+ JSON, IO[bytes] Required.
960
+ :type body: ~raiclient.models.SimulationDTO or JSON or IO[bytes]
961
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
962
+ :rtype: ~raiclient.models.LongRunningResponse
963
+ :raises ~azure.core.exceptions.HttpResponseError:
964
+ """
965
+ error_map: MutableMapping = {
966
+ 401: ClientAuthenticationError,
967
+ 404: ResourceNotFoundError,
968
+ 409: ResourceExistsError,
969
+ 304: ResourceNotModifiedError,
970
+ }
971
+ error_map.update(kwargs.pop("error_map", {}) or {})
972
+
973
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
974
+ _params = kwargs.pop("params", {}) or {}
975
+
976
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
977
+ cls: ClsType[_models.LongRunningResponse] = kwargs.pop("cls", None)
978
+
979
+ content_type = content_type or "application/json"
980
+ _content = None
981
+ if isinstance(body, (IOBase, bytes)):
982
+ _content = body
983
+ else:
984
+ _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
985
+
986
+ _request = build_rai_svc_submit_simulation_request(
987
+ content_type=content_type,
988
+ api_version=self._config.api_version,
989
+ content=_content,
990
+ headers=_headers,
991
+ params=_params,
992
+ )
993
+ path_format_arguments = {
994
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
995
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
996
+ "resourceGroupName": self._serialize.url(
997
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
998
+ ),
999
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
1000
+ }
1001
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
1002
+
1003
+ _stream = kwargs.pop("stream", False)
1004
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1005
+ _request, stream=_stream, **kwargs
1006
+ )
1007
+
1008
+ response = pipeline_response.http_response
1009
+
1010
+ if response.status_code not in [202]:
1011
+ if _stream:
1012
+ try:
1013
+ response.read() # Load the body in memory and close the socket
1014
+ except (StreamConsumedError, StreamClosedError):
1015
+ pass
1016
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
1017
+ raise HttpResponseError(response=response)
1018
+
1019
+ if _stream:
1020
+ deserialized = response.iter_bytes()
1021
+ else:
1022
+ deserialized = _deserialize(_models.LongRunningResponse, response.json())
1023
+
1024
+ if cls:
1025
+ return cls(pipeline_response, deserialized, {}) # type: ignore
1026
+
1027
+ return deserialized # type: ignore
1028
+
1029
+ @overload
1030
+ def submit_aoai_evaluation(
1031
+ self, body: _models.GradersDTO, *, content_type: str = "application/json", **kwargs: Any
1032
+ ) -> _models.LongRunningResponse:
1033
+ """Submit a request for graders.
1034
+
1035
+ :param body: Properties of a Prompt Version. Required.
1036
+ :type body: ~raiclient.models.GradersDTO
1037
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1038
+ Default value is "application/json".
1039
+ :paramtype content_type: str
1040
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
1041
+ :rtype: ~raiclient.models.LongRunningResponse
1042
+ :raises ~azure.core.exceptions.HttpResponseError:
1043
+ """
1044
+
1045
+ @overload
1046
+ def submit_aoai_evaluation(
1047
+ self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
1048
+ ) -> _models.LongRunningResponse:
1049
+ """Submit a request for graders.
1050
+
1051
+ :param body: Properties of a Prompt Version. Required.
1052
+ :type body: JSON
1053
+ :keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1054
+ Default value is "application/json".
1055
+ :paramtype content_type: str
1056
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
1057
+ :rtype: ~raiclient.models.LongRunningResponse
1058
+ :raises ~azure.core.exceptions.HttpResponseError:
1059
+ """
1060
+
1061
+ @overload
1062
+ def submit_aoai_evaluation(
1063
+ self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
1064
+ ) -> _models.LongRunningResponse:
1065
+ """Submit a request for graders.
1066
+
1067
+ :param body: Properties of a Prompt Version. Required.
1068
+ :type body: IO[bytes]
1069
+ :keyword content_type: Body Parameter content-type. Content type parameter for binary body.
1070
+ Default value is "application/json".
1071
+ :paramtype content_type: str
1072
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
1073
+ :rtype: ~raiclient.models.LongRunningResponse
1074
+ :raises ~azure.core.exceptions.HttpResponseError:
1075
+ """
1076
+
1077
+ @distributed_trace
1078
+ def submit_aoai_evaluation(
1079
+ self, body: Union[_models.GradersDTO, JSON, IO[bytes]], **kwargs: Any
1080
+ ) -> _models.LongRunningResponse:
1081
+ """Submit a request for graders.
1082
+
1083
+ :param body: Properties of a Prompt Version. Is one of the following types: GradersDTO, JSON,
1084
+ IO[bytes] Required.
1085
+ :type body: ~raiclient.models.GradersDTO or JSON or IO[bytes]
1086
+ :return: LongRunningResponse. The LongRunningResponse is compatible with MutableMapping
1087
+ :rtype: ~raiclient.models.LongRunningResponse
1088
+ :raises ~azure.core.exceptions.HttpResponseError:
1089
+ """
1090
+ error_map: MutableMapping = {
1091
+ 401: ClientAuthenticationError,
1092
+ 404: ResourceNotFoundError,
1093
+ 409: ResourceExistsError,
1094
+ 304: ResourceNotModifiedError,
1095
+ }
1096
+ error_map.update(kwargs.pop("error_map", {}) or {})
1097
+
1098
+ _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1099
+ _params = kwargs.pop("params", {}) or {}
1100
+
1101
+ content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1102
+ cls: ClsType[_models.LongRunningResponse] = kwargs.pop("cls", None)
1103
+
1104
+ content_type = content_type or "application/json"
1105
+ _content = None
1106
+ if isinstance(body, (IOBase, bytes)):
1107
+ _content = body
1108
+ else:
1109
+ _content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
1110
+
1111
+ _request = build_rai_svc_submit_aoai_evaluation_request(
1112
+ content_type=content_type,
1113
+ api_version=self._config.api_version,
1114
+ content=_content,
1115
+ headers=_headers,
1116
+ params=_params,
1117
+ )
1118
+ path_format_arguments = {
1119
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
1120
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
1121
+ "resourceGroupName": self._serialize.url(
1122
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
1123
+ ),
1124
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
1125
+ }
1126
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
1127
+
1128
+ _stream = kwargs.pop("stream", False)
1129
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1130
+ _request, stream=_stream, **kwargs
1131
+ )
1132
+
1133
+ response = pipeline_response.http_response
1134
+
1135
+ if response.status_code not in [202]:
1136
+ if _stream:
1137
+ try:
1138
+ response.read() # Load the body in memory and close the socket
1139
+ except (StreamConsumedError, StreamClosedError):
1140
+ pass
1141
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
1142
+ raise HttpResponseError(response=response)
1143
+
1144
+ if _stream:
1145
+ deserialized = response.iter_bytes()
1146
+ else:
1147
+ deserialized = _deserialize(_models.LongRunningResponse, response.json())
1148
+
1149
+ if cls:
1150
+ return cls(pipeline_response, deserialized, {}) # type: ignore
1151
+
1152
+ return deserialized # type: ignore
1153
+
1154
+ @distributed_trace
1155
+ def get_operation_result(
1156
+ self, operation_id: str, *, api_key: Optional[str] = None, model_endpoint: Optional[str] = None, **kwargs: Any
1157
+ ) -> str:
1158
+ """Get the operation result.
1159
+
1160
+ :param operation_id: Operation id. Required.
1161
+ :type operation_id: str
1162
+ :keyword api_key: Api key. Default value is None.
1163
+ :paramtype api_key: str
1164
+ :keyword model_endpoint: Model Endpoint. Default value is None.
1165
+ :paramtype model_endpoint: str
1166
+ :return: str
1167
+ :rtype: str
1168
+ :raises ~azure.core.exceptions.HttpResponseError:
1169
+ """
1170
+ error_map: MutableMapping = {
1171
+ 401: ClientAuthenticationError,
1172
+ 404: ResourceNotFoundError,
1173
+ 409: ResourceExistsError,
1174
+ 304: ResourceNotModifiedError,
1175
+ }
1176
+ error_map.update(kwargs.pop("error_map", {}) or {})
1177
+
1178
+ _headers = kwargs.pop("headers", {}) or {}
1179
+ _params = kwargs.pop("params", {}) or {}
1180
+
1181
+ cls: ClsType[str] = kwargs.pop("cls", None)
1182
+
1183
+ _request = build_rai_svc_get_operation_result_request(
1184
+ operation_id=operation_id,
1185
+ api_key=api_key,
1186
+ model_endpoint=model_endpoint,
1187
+ api_version=self._config.api_version,
1188
+ headers=_headers,
1189
+ params=_params,
1190
+ )
1191
+ path_format_arguments = {
1192
+ "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
1193
+ "subscriptionId": self._serialize.url("self._config.subscription_id", self._config.subscription_id, "str"),
1194
+ "resourceGroupName": self._serialize.url(
1195
+ "self._config.resource_group_name", self._config.resource_group_name, "str"
1196
+ ),
1197
+ "workspaceName": self._serialize.url("self._config.workspace_name", self._config.workspace_name, "str"),
1198
+ }
1199
+ _request.url = self._client.format_url(_request.url, **path_format_arguments)
1200
+
1201
+ _stream = kwargs.pop("stream", False)
1202
+ pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
1203
+ _request, stream=_stream, **kwargs
1204
+ )
1205
+
1206
+ response = pipeline_response.http_response
1207
+
1208
+ if response.status_code not in [200]:
1209
+ if _stream:
1210
+ try:
1211
+ response.read() # Load the body in memory and close the socket
1212
+ except (StreamConsumedError, StreamClosedError):
1213
+ pass
1214
+ map_error(status_code=response.status_code, response=response, error_map=error_map)
1215
+ raise HttpResponseError(response=response)
1216
+
1217
+ if _stream:
1218
+ deserialized = response.iter_bytes()
1219
+ else:
1220
+ deserialized = _deserialize(str, response.json())
1221
+
1222
+ if cls:
1223
+ return cls(pipeline_response, deserialized, {}) # type: ignore
1224
+
1225
+ return deserialized # type: ignore