azure-ai-evaluation 1.0.1__py3-none-any.whl → 1.13.5__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 (277) hide show
  1. azure/ai/evaluation/__init__.py +85 -14
  2. azure/ai/evaluation/_aoai/__init__.py +10 -0
  3. azure/ai/evaluation/_aoai/aoai_grader.py +140 -0
  4. azure/ai/evaluation/_aoai/label_grader.py +68 -0
  5. azure/ai/evaluation/_aoai/python_grader.py +86 -0
  6. azure/ai/evaluation/_aoai/score_model_grader.py +94 -0
  7. azure/ai/evaluation/_aoai/string_check_grader.py +66 -0
  8. azure/ai/evaluation/_aoai/text_similarity_grader.py +80 -0
  9. azure/ai/evaluation/_azure/__init__.py +3 -0
  10. azure/ai/evaluation/_azure/_clients.py +204 -0
  11. azure/ai/evaluation/_azure/_envs.py +207 -0
  12. azure/ai/evaluation/_azure/_models.py +227 -0
  13. azure/ai/evaluation/_azure/_token_manager.py +129 -0
  14. azure/ai/evaluation/_common/__init__.py +9 -1
  15. azure/ai/evaluation/_common/constants.py +124 -2
  16. azure/ai/evaluation/_common/evaluation_onedp_client.py +169 -0
  17. azure/ai/evaluation/_common/onedp/__init__.py +32 -0
  18. azure/ai/evaluation/_common/onedp/_client.py +166 -0
  19. azure/ai/evaluation/_common/onedp/_configuration.py +72 -0
  20. azure/ai/evaluation/_common/onedp/_model_base.py +1232 -0
  21. azure/ai/evaluation/_common/onedp/_patch.py +21 -0
  22. azure/ai/evaluation/_common/onedp/_serialization.py +2032 -0
  23. azure/ai/evaluation/_common/onedp/_types.py +21 -0
  24. azure/ai/evaluation/_common/onedp/_utils/__init__.py +6 -0
  25. azure/ai/evaluation/_common/onedp/_utils/model_base.py +1232 -0
  26. azure/ai/evaluation/_common/onedp/_utils/serialization.py +2032 -0
  27. azure/ai/evaluation/_common/onedp/_validation.py +66 -0
  28. azure/ai/evaluation/_common/onedp/_vendor.py +50 -0
  29. azure/ai/evaluation/_common/onedp/_version.py +9 -0
  30. azure/ai/evaluation/_common/onedp/aio/__init__.py +29 -0
  31. azure/ai/evaluation/_common/onedp/aio/_client.py +168 -0
  32. azure/ai/evaluation/_common/onedp/aio/_configuration.py +72 -0
  33. azure/ai/evaluation/_common/onedp/aio/_patch.py +21 -0
  34. azure/ai/evaluation/_common/onedp/aio/operations/__init__.py +49 -0
  35. azure/ai/evaluation/_common/onedp/aio/operations/_operations.py +7143 -0
  36. azure/ai/evaluation/_common/onedp/aio/operations/_patch.py +21 -0
  37. azure/ai/evaluation/_common/onedp/models/__init__.py +358 -0
  38. azure/ai/evaluation/_common/onedp/models/_enums.py +447 -0
  39. azure/ai/evaluation/_common/onedp/models/_models.py +5963 -0
  40. azure/ai/evaluation/_common/onedp/models/_patch.py +21 -0
  41. azure/ai/evaluation/_common/onedp/operations/__init__.py +49 -0
  42. azure/ai/evaluation/_common/onedp/operations/_operations.py +8951 -0
  43. azure/ai/evaluation/_common/onedp/operations/_patch.py +21 -0
  44. azure/ai/evaluation/_common/onedp/py.typed +1 -0
  45. azure/ai/evaluation/_common/onedp/servicepatterns/__init__.py +1 -0
  46. azure/ai/evaluation/_common/onedp/servicepatterns/aio/__init__.py +1 -0
  47. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/__init__.py +25 -0
  48. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_operations.py +34 -0
  49. azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_patch.py +20 -0
  50. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/__init__.py +1 -0
  51. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/__init__.py +1 -0
  52. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/__init__.py +22 -0
  53. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_operations.py +29 -0
  54. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_patch.py +20 -0
  55. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/__init__.py +22 -0
  56. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_operations.py +29 -0
  57. azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_patch.py +20 -0
  58. azure/ai/evaluation/_common/onedp/servicepatterns/operations/__init__.py +25 -0
  59. azure/ai/evaluation/_common/onedp/servicepatterns/operations/_operations.py +34 -0
  60. azure/ai/evaluation/_common/onedp/servicepatterns/operations/_patch.py +20 -0
  61. azure/ai/evaluation/_common/rai_service.py +578 -69
  62. azure/ai/evaluation/_common/raiclient/__init__.py +34 -0
  63. azure/ai/evaluation/_common/raiclient/_client.py +128 -0
  64. azure/ai/evaluation/_common/raiclient/_configuration.py +87 -0
  65. azure/ai/evaluation/_common/raiclient/_model_base.py +1235 -0
  66. azure/ai/evaluation/_common/raiclient/_patch.py +20 -0
  67. azure/ai/evaluation/_common/raiclient/_serialization.py +2050 -0
  68. azure/ai/evaluation/_common/raiclient/_version.py +9 -0
  69. azure/ai/evaluation/_common/raiclient/aio/__init__.py +29 -0
  70. azure/ai/evaluation/_common/raiclient/aio/_client.py +130 -0
  71. azure/ai/evaluation/_common/raiclient/aio/_configuration.py +87 -0
  72. azure/ai/evaluation/_common/raiclient/aio/_patch.py +20 -0
  73. azure/ai/evaluation/_common/raiclient/aio/operations/__init__.py +25 -0
  74. azure/ai/evaluation/_common/raiclient/aio/operations/_operations.py +981 -0
  75. azure/ai/evaluation/_common/raiclient/aio/operations/_patch.py +20 -0
  76. azure/ai/evaluation/_common/raiclient/models/__init__.py +60 -0
  77. azure/ai/evaluation/_common/raiclient/models/_enums.py +18 -0
  78. azure/ai/evaluation/_common/raiclient/models/_models.py +651 -0
  79. azure/ai/evaluation/_common/raiclient/models/_patch.py +20 -0
  80. azure/ai/evaluation/_common/raiclient/operations/__init__.py +25 -0
  81. azure/ai/evaluation/_common/raiclient/operations/_operations.py +1238 -0
  82. azure/ai/evaluation/_common/raiclient/operations/_patch.py +20 -0
  83. azure/ai/evaluation/_common/raiclient/py.typed +1 -0
  84. azure/ai/evaluation/_common/utils.py +505 -27
  85. azure/ai/evaluation/_constants.py +147 -0
  86. azure/ai/evaluation/_converters/__init__.py +3 -0
  87. azure/ai/evaluation/_converters/_ai_services.py +899 -0
  88. azure/ai/evaluation/_converters/_models.py +467 -0
  89. azure/ai/evaluation/_converters/_sk_services.py +495 -0
  90. azure/ai/evaluation/_eval_mapping.py +87 -0
  91. azure/ai/evaluation/_evaluate/_batch_run/__init__.py +10 -2
  92. azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +176 -0
  93. azure/ai/evaluation/_evaluate/_batch_run/batch_clients.py +82 -0
  94. azure/ai/evaluation/_evaluate/_batch_run/code_client.py +18 -12
  95. azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +19 -6
  96. azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +47 -22
  97. azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +18 -2
  98. azure/ai/evaluation/_evaluate/_eval_run.py +32 -46
  99. azure/ai/evaluation/_evaluate/_evaluate.py +1809 -142
  100. azure/ai/evaluation/_evaluate/_evaluate_aoai.py +992 -0
  101. azure/ai/evaluation/_evaluate/_telemetry/__init__.py +5 -90
  102. azure/ai/evaluation/_evaluate/_utils.py +237 -42
  103. azure/ai/evaluation/_evaluator_definition.py +76 -0
  104. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +80 -28
  105. azure/ai/evaluation/_evaluators/_code_vulnerability/__init__.py +5 -0
  106. azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.py +119 -0
  107. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +40 -4
  108. azure/ai/evaluation/_evaluators/_common/__init__.py +2 -0
  109. azure/ai/evaluation/_evaluators/_common/_base_eval.py +430 -29
  110. azure/ai/evaluation/_evaluators/_common/_base_multi_eval.py +63 -0
  111. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +269 -12
  112. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +74 -9
  113. azure/ai/evaluation/_evaluators/_common/_conversation_aggregators.py +49 -0
  114. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +73 -53
  115. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +35 -5
  116. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +26 -5
  117. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +35 -5
  118. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +34 -4
  119. azure/ai/evaluation/_evaluators/_document_retrieval/__init__.py +7 -0
  120. azure/ai/evaluation/_evaluators/_document_retrieval/_document_retrieval.py +442 -0
  121. azure/ai/evaluation/_evaluators/_eci/_eci.py +6 -3
  122. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +97 -70
  123. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +39 -3
  124. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +80 -25
  125. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +230 -20
  126. azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +30 -29
  127. azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +19 -14
  128. azure/ai/evaluation/_evaluators/_intent_resolution/__init__.py +7 -0
  129. azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +196 -0
  130. azure/ai/evaluation/_evaluators/_intent_resolution/intent_resolution.prompty +275 -0
  131. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +89 -36
  132. azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +22 -4
  133. azure/ai/evaluation/_evaluators/_qa/_qa.py +94 -35
  134. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +100 -4
  135. azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +154 -56
  136. azure/ai/evaluation/_evaluators/_response_completeness/__init__.py +7 -0
  137. azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +202 -0
  138. azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +84 -0
  139. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +39 -3
  140. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +166 -26
  141. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +38 -7
  142. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +81 -85
  143. azure/ai/evaluation/_evaluators/_task_adherence/__init__.py +7 -0
  144. azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +226 -0
  145. azure/ai/evaluation/_evaluators/_task_adherence/task_adherence.prompty +101 -0
  146. azure/ai/evaluation/_evaluators/_task_completion/__init__.py +7 -0
  147. azure/ai/evaluation/_evaluators/_task_completion/_task_completion.py +177 -0
  148. azure/ai/evaluation/_evaluators/_task_completion/task_completion.prompty +220 -0
  149. azure/ai/evaluation/_evaluators/_task_navigation_efficiency/__init__.py +7 -0
  150. azure/ai/evaluation/_evaluators/_task_navigation_efficiency/_task_navigation_efficiency.py +384 -0
  151. azure/ai/evaluation/_evaluators/_tool_call_accuracy/__init__.py +9 -0
  152. azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +298 -0
  153. azure/ai/evaluation/_evaluators/_tool_call_accuracy/tool_call_accuracy.prompty +166 -0
  154. azure/ai/evaluation/_evaluators/_tool_call_success/__init__.py +7 -0
  155. azure/ai/evaluation/_evaluators/_tool_call_success/_tool_call_success.py +306 -0
  156. azure/ai/evaluation/_evaluators/_tool_call_success/tool_call_success.prompty +321 -0
  157. azure/ai/evaluation/_evaluators/_tool_input_accuracy/__init__.py +9 -0
  158. azure/ai/evaluation/_evaluators/_tool_input_accuracy/_tool_input_accuracy.py +263 -0
  159. azure/ai/evaluation/_evaluators/_tool_input_accuracy/tool_input_accuracy.prompty +76 -0
  160. azure/ai/evaluation/_evaluators/_tool_output_utilization/__init__.py +7 -0
  161. azure/ai/evaluation/_evaluators/_tool_output_utilization/_tool_output_utilization.py +225 -0
  162. azure/ai/evaluation/_evaluators/_tool_output_utilization/tool_output_utilization.prompty +221 -0
  163. azure/ai/evaluation/_evaluators/_tool_selection/__init__.py +9 -0
  164. azure/ai/evaluation/_evaluators/_tool_selection/_tool_selection.py +266 -0
  165. azure/ai/evaluation/_evaluators/_tool_selection/tool_selection.prompty +104 -0
  166. azure/ai/evaluation/_evaluators/_ungrounded_attributes/__init__.py +5 -0
  167. azure/ai/evaluation/_evaluators/_ungrounded_attributes/_ungrounded_attributes.py +102 -0
  168. azure/ai/evaluation/_evaluators/_xpia/xpia.py +20 -4
  169. azure/ai/evaluation/_exceptions.py +24 -1
  170. azure/ai/evaluation/_http_utils.py +7 -5
  171. azure/ai/evaluation/_legacy/__init__.py +3 -0
  172. azure/ai/evaluation/_legacy/_adapters/__init__.py +7 -0
  173. azure/ai/evaluation/_legacy/_adapters/_check.py +17 -0
  174. azure/ai/evaluation/_legacy/_adapters/_configuration.py +45 -0
  175. azure/ai/evaluation/_legacy/_adapters/_constants.py +10 -0
  176. azure/ai/evaluation/_legacy/_adapters/_errors.py +29 -0
  177. azure/ai/evaluation/_legacy/_adapters/_flows.py +28 -0
  178. azure/ai/evaluation/_legacy/_adapters/_service.py +16 -0
  179. azure/ai/evaluation/_legacy/_adapters/client.py +51 -0
  180. azure/ai/evaluation/_legacy/_adapters/entities.py +26 -0
  181. azure/ai/evaluation/_legacy/_adapters/tracing.py +28 -0
  182. azure/ai/evaluation/_legacy/_adapters/types.py +15 -0
  183. azure/ai/evaluation/_legacy/_adapters/utils.py +31 -0
  184. azure/ai/evaluation/_legacy/_batch_engine/__init__.py +9 -0
  185. azure/ai/evaluation/_legacy/_batch_engine/_config.py +48 -0
  186. azure/ai/evaluation/_legacy/_batch_engine/_engine.py +477 -0
  187. azure/ai/evaluation/_legacy/_batch_engine/_exceptions.py +88 -0
  188. azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +132 -0
  189. azure/ai/evaluation/_legacy/_batch_engine/_result.py +107 -0
  190. azure/ai/evaluation/_legacy/_batch_engine/_run.py +127 -0
  191. azure/ai/evaluation/_legacy/_batch_engine/_run_storage.py +128 -0
  192. azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +262 -0
  193. azure/ai/evaluation/_legacy/_batch_engine/_status.py +25 -0
  194. azure/ai/evaluation/_legacy/_batch_engine/_trace.py +97 -0
  195. azure/ai/evaluation/_legacy/_batch_engine/_utils.py +97 -0
  196. azure/ai/evaluation/_legacy/_batch_engine/_utils_deprecated.py +131 -0
  197. azure/ai/evaluation/_legacy/_common/__init__.py +3 -0
  198. azure/ai/evaluation/_legacy/_common/_async_token_provider.py +117 -0
  199. azure/ai/evaluation/_legacy/_common/_logging.py +292 -0
  200. azure/ai/evaluation/_legacy/_common/_thread_pool_executor_with_context.py +17 -0
  201. azure/ai/evaluation/_legacy/prompty/__init__.py +36 -0
  202. azure/ai/evaluation/_legacy/prompty/_connection.py +119 -0
  203. azure/ai/evaluation/_legacy/prompty/_exceptions.py +139 -0
  204. azure/ai/evaluation/_legacy/prompty/_prompty.py +430 -0
  205. azure/ai/evaluation/_legacy/prompty/_utils.py +663 -0
  206. azure/ai/evaluation/_legacy/prompty/_yaml_utils.py +99 -0
  207. azure/ai/evaluation/_model_configurations.py +26 -0
  208. azure/ai/evaluation/_safety_evaluation/__init__.py +3 -0
  209. azure/ai/evaluation/_safety_evaluation/_generated_rai_client.py +0 -0
  210. azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +917 -0
  211. azure/ai/evaluation/_user_agent.py +32 -1
  212. azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -4
  213. azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -4
  214. azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -4
  215. azure/ai/evaluation/_version.py +2 -1
  216. azure/ai/evaluation/red_team/__init__.py +22 -0
  217. azure/ai/evaluation/red_team/_agent/__init__.py +3 -0
  218. azure/ai/evaluation/red_team/_agent/_agent_functions.py +261 -0
  219. azure/ai/evaluation/red_team/_agent/_agent_tools.py +461 -0
  220. azure/ai/evaluation/red_team/_agent/_agent_utils.py +89 -0
  221. azure/ai/evaluation/red_team/_agent/_semantic_kernel_plugin.py +228 -0
  222. azure/ai/evaluation/red_team/_attack_objective_generator.py +268 -0
  223. azure/ai/evaluation/red_team/_attack_strategy.py +49 -0
  224. azure/ai/evaluation/red_team/_callback_chat_target.py +115 -0
  225. azure/ai/evaluation/red_team/_default_converter.py +21 -0
  226. azure/ai/evaluation/red_team/_evaluation_processor.py +505 -0
  227. azure/ai/evaluation/red_team/_mlflow_integration.py +430 -0
  228. azure/ai/evaluation/red_team/_orchestrator_manager.py +803 -0
  229. azure/ai/evaluation/red_team/_red_team.py +1717 -0
  230. azure/ai/evaluation/red_team/_red_team_result.py +661 -0
  231. azure/ai/evaluation/red_team/_result_processor.py +1708 -0
  232. azure/ai/evaluation/red_team/_utils/__init__.py +37 -0
  233. azure/ai/evaluation/red_team/_utils/_rai_service_eval_chat_target.py +128 -0
  234. azure/ai/evaluation/red_team/_utils/_rai_service_target.py +601 -0
  235. azure/ai/evaluation/red_team/_utils/_rai_service_true_false_scorer.py +114 -0
  236. azure/ai/evaluation/red_team/_utils/constants.py +72 -0
  237. azure/ai/evaluation/red_team/_utils/exception_utils.py +345 -0
  238. azure/ai/evaluation/red_team/_utils/file_utils.py +266 -0
  239. azure/ai/evaluation/red_team/_utils/formatting_utils.py +365 -0
  240. azure/ai/evaluation/red_team/_utils/logging_utils.py +139 -0
  241. azure/ai/evaluation/red_team/_utils/metric_mapping.py +73 -0
  242. azure/ai/evaluation/red_team/_utils/objective_utils.py +46 -0
  243. azure/ai/evaluation/red_team/_utils/progress_utils.py +252 -0
  244. azure/ai/evaluation/red_team/_utils/retry_utils.py +218 -0
  245. azure/ai/evaluation/red_team/_utils/strategy_utils.py +218 -0
  246. azure/ai/evaluation/simulator/_adversarial_scenario.py +6 -0
  247. azure/ai/evaluation/simulator/_adversarial_simulator.py +187 -80
  248. azure/ai/evaluation/simulator/_constants.py +1 -0
  249. azure/ai/evaluation/simulator/_conversation/__init__.py +138 -11
  250. azure/ai/evaluation/simulator/_conversation/_conversation.py +6 -2
  251. azure/ai/evaluation/simulator/_conversation/constants.py +1 -1
  252. azure/ai/evaluation/simulator/_direct_attack_simulator.py +37 -24
  253. azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +1 -0
  254. azure/ai/evaluation/simulator/_indirect_attack_simulator.py +56 -28
  255. azure/ai/evaluation/simulator/_model_tools/__init__.py +2 -1
  256. azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +225 -0
  257. azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +12 -10
  258. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +100 -45
  259. azure/ai/evaluation/simulator/_model_tools/_rai_client.py +101 -3
  260. azure/ai/evaluation/simulator/_model_tools/_template_handler.py +31 -11
  261. azure/ai/evaluation/simulator/_model_tools/models.py +20 -17
  262. azure/ai/evaluation/simulator/_simulator.py +43 -19
  263. {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/METADATA +378 -27
  264. azure_ai_evaluation-1.13.5.dist-info/RECORD +305 -0
  265. {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/WHEEL +1 -1
  266. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
  267. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
  268. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -55
  269. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
  270. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
  271. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
  272. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
  273. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
  274. azure/ai/evaluation/simulator/_tracing.py +0 -89
  275. azure_ai_evaluation-1.0.1.dist-info/RECORD +0 -119
  276. {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info/licenses}/NOTICE.txt +0 -0
  277. {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/top_level.txt +0 -0
@@ -6,12 +6,15 @@ import copy
6
6
  import json
7
7
  import time
8
8
  import uuid
9
- from typing import Any, Dict, List, Optional, cast
9
+ from typing import Any, Dict, List, Optional, cast, Union
10
10
 
11
11
  from azure.ai.evaluation._http_utils import AsyncHttpPipeline, get_async_http_client
12
- from azure.ai.evaluation._user_agent import USER_AGENT
13
- from azure.core.exceptions import HttpResponseError
12
+ from azure.ai.evaluation._user_agent import UserAgentSingleton
13
+ from azure.core.exceptions import HttpResponseError, ServiceResponseError
14
14
  from azure.core.pipeline.policies import AsyncRetryPolicy, RetryMode
15
+ from azure.ai.evaluation._common.onedp._client import ProjectsClient as AIProjectClient
16
+ from azure.ai.evaluation._common.onedp.models import SimulationDTO
17
+ from azure.ai.evaluation._common.constants import RAIService
15
18
 
16
19
  from .._model_tools._template_handler import TemplateParameters
17
20
  from .models import OpenAIChatCompletionsModel
@@ -40,15 +43,15 @@ class SimulationRequestDTO:
40
43
  headers: Dict[str, str],
41
44
  payload: Dict[str, Any],
42
45
  params: Dict[str, str],
43
- templatekey: str,
44
- template_parameters: Optional[TemplateParameters],
46
+ templateKey: str,
47
+ templateParameters: Optional[TemplateParameters],
45
48
  ):
46
49
  self.url = url
47
50
  self.headers = headers
48
51
  self.json = json.dumps(payload)
49
52
  self.params = params
50
- self.templatekey = templatekey
51
- self.templateParameters = template_parameters
53
+ self.templateKey = templateKey
54
+ self.templateParameters = templateParameters
52
55
 
53
56
  def to_dict(self) -> Dict:
54
57
  """Convert the DTO to a dictionary.
@@ -89,6 +92,7 @@ class ProxyChatCompletionsModel(OpenAIChatCompletionsModel):
89
92
  self.tkey = template_key
90
93
  self.tparam = template_parameters
91
94
  self.result_url: Optional[str] = None
95
+ self.simulation_id: Optional[str] = kwargs.pop("simulation_id", "")
92
96
 
93
97
  super().__init__(name=name, **kwargs)
94
98
 
@@ -110,7 +114,7 @@ class ProxyChatCompletionsModel(OpenAIChatCompletionsModel):
110
114
  async def get_conversation_completion(
111
115
  self,
112
116
  messages: List[Dict],
113
- session: AsyncHttpPipeline,
117
+ session: Union[AsyncHttpPipeline, AIProjectClient],
114
118
  role: str = "assistant", # pylint: disable=unused-argument
115
119
  **request_params,
116
120
  ) -> dict:
@@ -141,7 +145,7 @@ class ProxyChatCompletionsModel(OpenAIChatCompletionsModel):
141
145
 
142
146
  async def request_api(
143
147
  self,
144
- session: AsyncHttpPipeline,
148
+ session: Union[AsyncHttpPipeline, AIProjectClient],
145
149
  request_data: dict,
146
150
  ) -> dict:
147
151
  """
@@ -162,13 +166,14 @@ class ProxyChatCompletionsModel(OpenAIChatCompletionsModel):
162
166
  proxy_headers = {
163
167
  "Authorization": f"Bearer {token}",
164
168
  "Content-Type": "application/json",
165
- "User-Agent": USER_AGENT,
169
+ "User-Agent": UserAgentSingleton().value,
166
170
  }
167
171
 
168
172
  headers = {
169
173
  "Content-Type": "application/json",
170
174
  "X-CV": f"{uuid.uuid4()}",
171
175
  "X-ModelType": self.model or "",
176
+ "x-ms-client-request-id": self.simulation_id,
172
177
  }
173
178
  # add all additional headers
174
179
  headers.update(self.additional_headers) # type: ignore[arg-type]
@@ -181,51 +186,101 @@ class ProxyChatCompletionsModel(OpenAIChatCompletionsModel):
181
186
  headers=headers,
182
187
  payload=request_data,
183
188
  params=params,
184
- templatekey=self.tkey,
185
- template_parameters=self.tparam,
189
+ templateKey=self.tkey,
190
+ templateParameters=self.tparam,
186
191
  )
187
192
 
188
193
  time_start = time.time()
189
194
  full_response = None
190
195
 
191
- response = await session.post(url=self.endpoint_url, headers=proxy_headers, json=sim_request_dto.to_dict())
192
-
193
- if response.status_code != 202:
194
- raise HttpResponseError(
195
- message=f"Received unexpected HTTP status: {response.status_code} {response.text()}", response=response
196
+ if isinstance(session, AIProjectClient):
197
+ sim_request_dto = SimulationDTO(
198
+ headers=headers,
199
+ params=params,
200
+ json=json.dumps(request_data),
201
+ template_key=self.tkey,
202
+ template_parameters=self.tparam,
203
+ )
204
+ response_data = session.red_teams.submit_simulation(sim_request_dto, headers=headers, params=params)
205
+ operation_id = response_data["location"].split("/")[-1]
206
+
207
+ request_count = 0
208
+ flag = True
209
+ while flag:
210
+ try:
211
+ response = session.red_teams.operation_results(operation_id, headers=headers)
212
+ except Exception as e:
213
+ from types import SimpleNamespace # pylint: disable=forgotten-debug-statement
214
+
215
+ response = SimpleNamespace(status_code=202, text=str(e), json=lambda: {"error": str(e)})
216
+ if isinstance(response, dict):
217
+ response_data = response
218
+ flag = False
219
+ break
220
+ if not isinstance(response, SimpleNamespace) and response.get("object") == "chat.completion":
221
+ response_data = response
222
+ flag = False
223
+ break
224
+ else:
225
+ request_count += 1
226
+ sleep_time = RAIService.SLEEP_TIME**request_count
227
+ await asyncio.sleep(sleep_time)
228
+ else:
229
+ # Retry policy for POST request to RAI service
230
+ service_call_retry_policy = AsyncRetryPolicy(
231
+ retry_on_exceptions=[ServiceResponseError],
232
+ retry_total=7,
233
+ retry_backoff_factor=10.0,
234
+ retry_backoff_max=180,
235
+ retry_mode=RetryMode.Exponential,
196
236
  )
197
237
 
198
- response_data = response.json()
199
- self.result_url = cast(str, response_data["location"])
200
-
201
- retry_policy = AsyncRetryPolicy( # set up retry configuration
202
- retry_on_status_codes=[202], # on which statuses to retry
203
- retry_total=7,
204
- retry_backoff_factor=10.0,
205
- retry_backoff_max=180,
206
- retry_mode=RetryMode.Exponential,
207
- )
208
-
209
- # initial 15 seconds wait before attempting to fetch result
210
- # Need to wait both in this thread and in the async thread for some reason?
211
- # Someone not under a crunch and with better async understandings should dig into this more.
212
- await asyncio.sleep(15)
213
- time.sleep(15)
214
-
215
- async with get_async_http_client().with_policies(retry_policy=retry_policy) as exp_retry_client:
216
- token = await self.token_manager.get_token_async()
217
- proxy_headers = {
218
- "Authorization": f"Bearer {token}",
219
- "Content-Type": "application/json",
220
- "User-Agent": USER_AGENT,
221
- }
222
- response = await exp_retry_client.get( # pylint: disable=too-many-function-args,unexpected-keyword-arg
223
- self.result_url, headers=proxy_headers
238
+ response = None
239
+ async with get_async_http_client().with_policies(retry_policy=service_call_retry_policy) as retry_client:
240
+ try:
241
+ response = await retry_client.post(
242
+ url=self.endpoint_url, headers=proxy_headers, json=sim_request_dto.to_dict()
243
+ )
244
+ except ServiceResponseError as e:
245
+ self.logger.error("ServiceResponseError during POST request to rai svc after retries: %s", str(e))
246
+ raise
247
+
248
+ # response.raise_for_status()
249
+ if response.status_code != 202:
250
+ raise HttpResponseError(
251
+ message=f"Received unexpected HTTP status: {response.status_code} {response.text()}",
252
+ response=response,
253
+ )
254
+ response_data = response.json()
255
+
256
+ self.result_url = cast(str, response_data["location"])
257
+ retry_policy = AsyncRetryPolicy( # set up retry configuration
258
+ retry_on_status_codes=[202], # on which statuses to retry
259
+ retry_total=7,
260
+ retry_backoff_factor=10.0,
261
+ retry_backoff_max=180,
262
+ retry_mode=RetryMode.Exponential,
224
263
  )
225
264
 
226
- response.raise_for_status()
265
+ # initial 15 seconds wait before attempting to fetch result
266
+ # Need to wait both in this thread and in the async thread for some reason?
267
+ # Someone not under a crunch and with better async understandings should dig into this more.
268
+ await asyncio.sleep(15)
269
+ time.sleep(15)
270
+
271
+ async with get_async_http_client().with_policies(retry_policy=retry_policy) as exp_retry_client:
272
+ token = await self.token_manager.get_token_async()
273
+ proxy_headers = {
274
+ "Authorization": f"Bearer {token}",
275
+ "Content-Type": "application/json",
276
+ "User-Agent": UserAgentSingleton().value,
277
+ }
278
+ response = await exp_retry_client.get( # pylint: disable=too-many-function-args,unexpected-keyword-arg
279
+ self.result_url, headers=proxy_headers
280
+ )
281
+ response.raise_for_status()
282
+ response_data = response.json()
227
283
 
228
- response_data = response.json()
229
284
  self.logger.info("Response: %s", response_data)
230
285
 
231
286
  # Copy the full response and return it to be saved in jsonl.
@@ -2,13 +2,15 @@
2
2
  # Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  # ---------------------------------------------------------
4
4
  import os
5
- from typing import Any
5
+ from typing import Any, Dict, List
6
6
  from urllib.parse import urljoin, urlparse
7
+ import base64
8
+ import json
7
9
 
8
10
  from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException
9
11
  from azure.ai.evaluation._http_utils import AsyncHttpPipeline, get_async_http_client, get_http_client
10
12
  from azure.ai.evaluation._model_configurations import AzureAIProject
11
- from azure.ai.evaluation._user_agent import USER_AGENT
13
+ from azure.ai.evaluation._user_agent import UserAgentSingleton
12
14
  from azure.core.pipeline.policies import AsyncRetryPolicy, RetryMode
13
15
 
14
16
  from ._identity_manager import APITokenManager
@@ -57,9 +59,11 @@ class RAIClient: # pylint: disable=client-accepts-api-version-keyword
57
59
  # add a "/" at the end of the url
58
60
  self.api_url = self.api_url.rstrip("/") + "/"
59
61
  self.parameter_json_endpoint = urljoin(self.api_url, "simulation/template/parameters")
62
+ self.parameter_image_endpoint = urljoin(self.api_url, "simulation/template/parameters/image")
60
63
  self.jailbreaks_json_endpoint = urljoin(self.api_url, "simulation/jailbreak")
61
64
  self.simulation_submit_endpoint = urljoin(self.api_url, "simulation/chat/completions/submit")
62
65
  self.xpia_jailbreaks_json_endpoint = urljoin(self.api_url, "simulation/jailbreak/xpia")
66
+ self.attack_objectives_endpoint = urljoin(self.api_url, "simulation/attackobjectives")
63
67
 
64
68
  def _get_service_discovery_url(self):
65
69
  bearer_token = self.token_manager.get_token()
@@ -144,7 +148,7 @@ class RAIClient: # pylint: disable=client-accepts-api-version-keyword
144
148
  headers = {
145
149
  "Authorization": f"Bearer {token}",
146
150
  "Content-Type": "application/json",
147
- "User-Agent": USER_AGENT,
151
+ "User-Agent": UserAgentSingleton().value,
148
152
  }
149
153
 
150
154
  session = self._create_async_client()
@@ -166,3 +170,97 @@ class RAIClient: # pylint: disable=client-accepts-api-version-keyword
166
170
  category=ErrorCategory.UNKNOWN,
167
171
  blame=ErrorBlame.USER_ERROR,
168
172
  )
173
+
174
+ async def get_image_data(self, path: str) -> Any:
175
+ """Make a GET Image request to the given url
176
+
177
+ :param path: The url of the image
178
+ :type path: str
179
+ :raises EvaluationException: If the Azure safety evaluation service is not available in the current region
180
+ :return: The response
181
+ :rtype: Any
182
+ """
183
+ token = self.token_manager.get_token()
184
+ headers = {
185
+ "Authorization": f"Bearer {token}",
186
+ "Content-Type": "application/json",
187
+ "User-Agent": UserAgentSingleton().value,
188
+ }
189
+
190
+ session = self._create_async_client()
191
+ params = {"path": path}
192
+ async with session:
193
+ response = await session.get(
194
+ url=self.parameter_image_endpoint, params=params, headers=headers
195
+ ) # pylint: disable=unexpected-keyword-arg
196
+
197
+ if response.status_code == 200:
198
+ return base64.b64encode(response.content).decode("utf-8")
199
+
200
+ msg = (
201
+ "Azure safety evaluation service is not available in your current region, "
202
+ + "please go to https://aka.ms/azureaistudiosafetyeval to see which regions are supported"
203
+ )
204
+ raise EvaluationException(
205
+ message=msg,
206
+ internal_message=msg,
207
+ target=ErrorTarget.RAI_CLIENT,
208
+ category=ErrorCategory.UNKNOWN,
209
+ blame=ErrorBlame.USER_ERROR,
210
+ )
211
+
212
+ async def get_attack_objectives(
213
+ self, risk_categories: List[str], application_scenario: str = None, strategy: str = None
214
+ ) -> Any:
215
+ """Get the attack objectives based on risk categories and application scenario
216
+
217
+ :param risk_categories: List of risk categories to generate attack objectives for
218
+ :type risk_categories: List[str]
219
+ :param application_scenario: Optional description of the application scenario for context
220
+ :type application_scenario: str
221
+ :param strategy: Optional attack strategy to get specific objectives for
222
+ :type strategy: str
223
+ :return: The attack objectives
224
+ :rtype: Any
225
+ """
226
+ # Create query parameters for the request
227
+ if application_scenario:
228
+ raise NotImplementedError("Application scenario is not supported yet")
229
+
230
+ params = {
231
+ "api-version": "2022-11-01-preview",
232
+ "riskTypes": ",".join(risk_categories),
233
+ "lang": "en", # Default to English
234
+ }
235
+
236
+ # Add strategy parameter if provided
237
+ if strategy:
238
+ params["strategy"] = strategy
239
+
240
+ try:
241
+ # Make the request using the existing get method
242
+ result = await self.get(self.attack_objectives_endpoint)
243
+ # from collections import defaultdict
244
+ # counts_by_risk = defaultdict(int)
245
+ # for item in result:
246
+ # target_harms = item.get("Metadata", {}).get("TargetHarms", [])
247
+ # if not target_harms:
248
+ # # No risk type specified
249
+ # counts_by_risk["empty"] += 1
250
+ # else:
251
+ # for harm in target_harms:
252
+ # # Use "empty" if the risk type field is missing
253
+ # risk_type = harm.get("RiskType", "") or "empty"
254
+ # counts_by_risk[risk_type] += 1
255
+ return result
256
+ except Exception:
257
+ # If the API fails or isn't implemented yet, return a mock response
258
+ # This is temporary until the API endpoint is fully implemented
259
+ return [
260
+ {
261
+ "metadata": {"lang": "en", "target_harms": [{"risk-type": "violence", "risk-subtype": ""}]},
262
+ "messages": [{"role": "user", "content": "Risky content"}],
263
+ "modality": "text",
264
+ "source": ["source"],
265
+ }
266
+ ]
@@ -2,11 +2,13 @@
2
2
  # Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  # ---------------------------------------------------------
4
4
 
5
- from typing import Dict, List, Optional, TypedDict, cast
6
-
5
+ from typing import Dict, List, Optional, TypedDict, cast, Union
6
+ from ast import literal_eval
7
7
  from typing_extensions import NotRequired
8
8
 
9
9
  from azure.ai.evaluation._model_configurations import AzureAIProject
10
+ from azure.ai.evaluation._common.onedp._client import ProjectsClient as AIProjectClient
11
+ from azure.ai.evaluation.simulator._adversarial_scenario import AdversarialScenario
10
12
 
11
13
  from ._rai_client import RAIClient
12
14
 
@@ -56,6 +58,7 @@ class TemplateParameters(TypedDict):
56
58
  category: NotRequired[str]
57
59
  target_population: NotRequired[str]
58
60
  topic: NotRequired[str]
61
+ jailbreak_string: NotRequired[str]
59
62
 
60
63
 
61
64
  class _CategorizedParameter(TypedDict):
@@ -144,15 +147,18 @@ class AdversarialTemplate:
144
147
 
145
148
  class AdversarialTemplateHandler:
146
149
  """
147
- Adversarial template handler constructor.
150
+ Initialize the AdversarialTemplateHandler.
148
151
 
149
- :param azure_ai_project: The Azure AI project.
150
- :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
151
- :param rai_client: The RAI client.
152
- :type rai_client: ~azure.ai.evaluation.simulator._model_tools.RAIClient
152
+ :param azure_ai_project: The Azure AI project, which can either be a string representing the project endpoint
153
+ or an instance of AzureAIProject. It contains subscription id, resource group, and project name.
154
+ :type azure_ai_project: Union[str, AzureAIProject]
155
+ :param rai_client: The RAI client or AI Project client used for fetching parameters.
156
+ :type rai_client: Union[~azure.ai.evaluation.simulator._model_tools.RAIClient, ~azure.ai.evaluation._common.onedp._client.AIProjectClient]
153
157
  """
154
158
 
155
- def __init__(self, azure_ai_project: AzureAIProject, rai_client: RAIClient) -> None:
159
+ def __init__(
160
+ self, azure_ai_project: Union[str, AzureAIProject], rai_client: Union[RAIClient, AIProjectClient]
161
+ ) -> None:
156
162
  self.azure_ai_project = azure_ai_project
157
163
  self.categorized_ch_parameters: Optional[Dict[str, _CategorizedParameter]] = None
158
164
  self.rai_client = rai_client
@@ -161,8 +167,10 @@ class AdversarialTemplateHandler:
161
167
  if self.categorized_ch_parameters is None:
162
168
  categorized_parameters: Dict[str, _CategorizedParameter] = {}
163
169
  util = ContentHarmTemplatesUtils
164
-
165
- parameters = await self.rai_client.get_contentharm_parameters()
170
+ if isinstance(self.rai_client, RAIClient):
171
+ parameters = await self.rai_client.get_contentharm_parameters()
172
+ elif isinstance(self.rai_client, AIProjectClient):
173
+ parameters = literal_eval(self.rai_client.red_teams.get_template_parameters())
166
174
 
167
175
  for k in parameters.keys():
168
176
  template_key = util.get_template_key(k)
@@ -175,17 +183,29 @@ class AdversarialTemplateHandler:
175
183
 
176
184
  template_category = collection_key.split("adv_")[-1]
177
185
 
186
+ # Handle both qa_enterprise and qa_documents mapping to qa
187
+ if template_category in ["qa_enterprise", "qa_documents"]:
188
+ template_category = "qa"
189
+
178
190
  plist = self.categorized_ch_parameters
179
191
  ch_templates = []
192
+
180
193
  for key, value in plist.items():
194
+ # Skip enterprise templates for ADVERSARIAL_QA
195
+ if collection_key == AdversarialScenario.ADVERSARIAL_QA.value and "enterprise" in key:
196
+ continue
197
+ # Skip non-enterprise templates for ADVERSARIAL_QA_DOCUMENTS
198
+ if collection_key == AdversarialScenario.ADVERSARIAL_QA_DOCUMENTS.value and "enterprise" not in key:
199
+ continue
200
+
181
201
  if value["category"] == template_category:
182
202
  params = value["parameters"]
183
203
  for p in params:
184
204
  p.update({"ch_template_placeholder": "{{ch_template_placeholder}}"})
185
205
 
186
206
  template = AdversarialTemplate(template_name=key, text=None, context_key=[], template_parameters=params)
187
-
188
207
  ch_templates.append(template)
208
+
189
209
  return ch_templates
190
210
 
191
211
  def get_template(self, template_name: str) -> Optional[AdversarialTemplate]:
@@ -12,6 +12,8 @@ from abc import ABC, abstractmethod
12
12
  from collections import deque
13
13
  from typing import Deque, Dict, List, Optional, Union
14
14
  from urllib.parse import urlparse
15
+ from azure.ai.evaluation._common.onedp._client import ProjectsClient as AIProjectClient
16
+ from ._rai_client import RAIClient
15
17
 
16
18
  from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException
17
19
  from azure.ai.evaluation._http_utils import AsyncHttpPipeline
@@ -78,7 +80,7 @@ class LLMBase(ABC):
78
80
  async def get_completion(
79
81
  self,
80
82
  prompt: str,
81
- session: AsyncHttpPipeline,
83
+ session: Union[AsyncHttpPipeline, AIProjectClient],
82
84
  **request_params,
83
85
  ) -> dict:
84
86
  """
@@ -100,7 +102,7 @@ class LLMBase(ABC):
100
102
  async def get_all_completions(
101
103
  self,
102
104
  prompts: List[str],
103
- session: AsyncHttpPipeline,
105
+ session: Union[AsyncHttpPipeline, AIProjectClient],
104
106
  api_call_max_parallel_count: int,
105
107
  api_call_delay_seconds: float,
106
108
  request_error_rate_threshold: float,
@@ -120,7 +122,7 @@ class LLMBase(ABC):
120
122
  async def get_conversation_completion(
121
123
  self,
122
124
  messages: List[dict],
123
- session: AsyncHttpPipeline,
125
+ session: Union[AsyncHttpPipeline, AIProjectClient],
124
126
  role: str,
125
127
  **request_params,
126
128
  ) -> dict:
@@ -274,7 +276,7 @@ class OpenAICompletionsModel(LLMBase):
274
276
  async def get_conversation_completion(
275
277
  self,
276
278
  messages: List[dict],
277
- session: AsyncHttpPipeline,
279
+ session: Union[AsyncHttpPipeline, AIProjectClient],
278
280
  role: str = "assistant",
279
281
  **request_params,
280
282
  ) -> dict:
@@ -304,7 +306,7 @@ class OpenAICompletionsModel(LLMBase):
304
306
  async def get_all_completions( # type: ignore[override]
305
307
  self,
306
308
  prompts: List[Dict[str, str]],
307
- session: AsyncHttpPipeline,
309
+ session: Union[AsyncHttpPipeline, AIProjectClient],
308
310
  api_call_max_parallel_count: int = 1,
309
311
  api_call_delay_seconds: float = 0.1,
310
312
  request_error_rate_threshold: float = 0.5,
@@ -372,7 +374,7 @@ class OpenAICompletionsModel(LLMBase):
372
374
  self,
373
375
  request_datas: List[dict],
374
376
  output_collector: List,
375
- session: AsyncHttpPipeline,
377
+ session: Union[AsyncHttpPipeline, AIProjectClient],
376
378
  api_call_delay_seconds: float = 0.1,
377
379
  request_error_rate_threshold: float = 0.5,
378
380
  ) -> None:
@@ -433,7 +435,7 @@ class OpenAICompletionsModel(LLMBase):
433
435
 
434
436
  async def request_api(
435
437
  self,
436
- session: AsyncHttpPipeline,
438
+ session: Union[AsyncHttpPipeline, AIProjectClient],
437
439
  request_data: dict,
438
440
  ) -> dict:
439
441
  """
@@ -476,11 +478,12 @@ class OpenAICompletionsModel(LLMBase):
476
478
  time_start = time.time()
477
479
  full_response = None
478
480
 
479
- response = await session.post(url=self.endpoint_url, headers=headers, json=request_data, params=params)
480
-
481
- response.raise_for_status()
482
-
483
- response_data = response.json()
481
+ if isinstance(session, AIProjectClient):
482
+ response_data = session.red_teams.submit_simulation(request_data, headers, params)
483
+ else:
484
+ response = await session.post(url=self.endpoint_url, headers=headers, json=request_data, params=params)
485
+ response.raise_for_status()
486
+ response_data = response.json()
484
487
 
485
488
  self.logger.info(f"Response: {response_data}")
486
489
 
@@ -533,7 +536,7 @@ class OpenAIChatCompletionsModel(OpenAICompletionsModel):
533
536
  async def get_conversation_completion(
534
537
  self,
535
538
  messages: List[dict],
536
- session: AsyncHttpPipeline,
539
+ session: Union[AsyncHttpPipeline, AIProjectClient],
537
540
  role: str = "assistant",
538
541
  **request_params,
539
542
  ) -> dict:
@@ -544,7 +547,7 @@ class OpenAIChatCompletionsModel(OpenAICompletionsModel):
544
547
  ----------
545
548
  messages: List of messages to query the model with.
546
549
  Expected format: [{"role": "user", "content": "Hello!"}, ...]
547
- session: AsyncHttpPipeline object to query the model with.
550
+ session: Union[AsyncHttpPipeline, AIProjectClient] object to query the model with.
548
551
  role: Not used for this model, since it is a chat model.
549
552
  request_params: Additional parameters to pass to the model.
550
553
  """
@@ -560,7 +563,7 @@ class OpenAIChatCompletionsModel(OpenAICompletionsModel):
560
563
  async def get_completion(
561
564
  self,
562
565
  prompt: str,
563
- session: AsyncHttpPipeline,
566
+ session: Union[AsyncHttpPipeline, AIProjectClient],
564
567
  **request_params,
565
568
  ) -> dict:
566
569
  """
@@ -569,7 +572,7 @@ class OpenAIChatCompletionsModel(OpenAICompletionsModel):
569
572
  Parameters
570
573
  ----------
571
574
  prompt: Prompt str to query model with.
572
- session: AsyncHttpPipeline object to use for the request.
575
+ session: Union[AsyncHttpPipeline, AIProjectClient] object to use for the request.
573
576
  **request_params: Additional parameters to pass to the request.
574
577
  """
575
578
  messages = [{"role": "system", "content": prompt}]
@@ -583,7 +586,7 @@ class OpenAIChatCompletionsModel(OpenAICompletionsModel):
583
586
  async def get_all_completions(
584
587
  self,
585
588
  prompts: List[str], # type: ignore[override]
586
- session: AsyncHttpPipeline,
589
+ session: Union[AsyncHttpPipeline, AIProjectClient],
587
590
  api_call_max_parallel_count: int = 1,
588
591
  api_call_delay_seconds: float = 0.1,
589
592
  request_error_rate_threshold: float = 0.5,