azure-ai-evaluation 1.0.0b5__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of azure-ai-evaluation might be problematic. Click here for more details.
- azure/ai/evaluation/_azure/__init__.py +3 -0
- azure/ai/evaluation/_azure/_clients.py +188 -0
- azure/ai/evaluation/_azure/_models.py +227 -0
- azure/ai/evaluation/_azure/_token_manager.py +118 -0
- azure/ai/evaluation/_common/_experimental.py +4 -0
- azure/ai/evaluation/_common/math.py +62 -2
- azure/ai/evaluation/_common/rai_service.py +110 -50
- azure/ai/evaluation/_common/utils.py +50 -16
- azure/ai/evaluation/_constants.py +2 -0
- azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +9 -0
- azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +13 -3
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +12 -1
- azure/ai/evaluation/_evaluate/_eval_run.py +38 -43
- azure/ai/evaluation/_evaluate/_evaluate.py +62 -131
- azure/ai/evaluation/_evaluate/_telemetry/__init__.py +2 -1
- azure/ai/evaluation/_evaluate/_utils.py +72 -38
- azure/ai/evaluation/_evaluators/_bleu/_bleu.py +16 -17
- azure/ai/evaluation/_evaluators/_coherence/_coherence.py +60 -29
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +88 -6
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +16 -3
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +39 -10
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +58 -52
- azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +79 -34
- azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +73 -34
- azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +74 -33
- azure/ai/evaluation/_evaluators/_content_safety/_violence.py +76 -34
- azure/ai/evaluation/_evaluators/_eci/_eci.py +28 -3
- azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +20 -13
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +57 -26
- azure/ai/evaluation/_evaluators/_gleu/_gleu.py +13 -15
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +68 -30
- azure/ai/evaluation/_evaluators/_meteor/_meteor.py +17 -20
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +10 -8
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -2
- azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +6 -2
- azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +10 -6
- azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +6 -2
- azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +6 -2
- azure/ai/evaluation/_evaluators/_multimodal/_violence.py +6 -2
- azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +57 -34
- azure/ai/evaluation/_evaluators/_qa/_qa.py +25 -37
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +63 -29
- azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +76 -161
- azure/ai/evaluation/_evaluators/_rouge/_rouge.py +24 -25
- azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +65 -67
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +26 -20
- azure/ai/evaluation/_evaluators/_xpia/xpia.py +74 -40
- azure/ai/evaluation/_exceptions.py +2 -0
- azure/ai/evaluation/_http_utils.py +6 -4
- azure/ai/evaluation/_model_configurations.py +65 -14
- azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -4
- azure/ai/evaluation/_version.py +1 -1
- azure/ai/evaluation/simulator/_adversarial_scenario.py +17 -1
- azure/ai/evaluation/simulator/_adversarial_simulator.py +57 -47
- azure/ai/evaluation/simulator/_constants.py +11 -1
- azure/ai/evaluation/simulator/_conversation/__init__.py +128 -7
- azure/ai/evaluation/simulator/_conversation/_conversation.py +0 -1
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +16 -8
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +12 -1
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +3 -1
- azure/ai/evaluation/simulator/_model_tools/_rai_client.py +48 -4
- azure/ai/evaluation/simulator/_model_tools/_template_handler.py +1 -0
- azure/ai/evaluation/simulator/_simulator.py +54 -45
- azure/ai/evaluation/simulator/_utils.py +25 -7
- {azure_ai_evaluation-1.0.0b5.dist-info → azure_ai_evaluation-1.1.0.dist-info}/METADATA +240 -327
- {azure_ai_evaluation-1.0.0b5.dist-info → azure_ai_evaluation-1.1.0.dist-info}/RECORD +71 -68
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety_chat.py +0 -322
- {azure_ai_evaluation-1.0.0b5.dist-info → azure_ai_evaluation-1.1.0.dist-info}/NOTICE.txt +0 -0
- {azure_ai_evaluation-1.0.0b5.dist-info → azure_ai_evaluation-1.1.0.dist-info}/WHEEL +0 -0
- {azure_ai_evaluation-1.0.0b5.dist-info → azure_ai_evaluation-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -25,20 +25,29 @@ from ._helpers import ConversationHistory, Turn
|
|
|
25
25
|
from ._utils import JsonLineChatProtocol
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
USER_AGENT += " (type=simulator; subtype=Simulator)"
|
|
29
|
+
|
|
30
|
+
|
|
28
31
|
@experimental
|
|
29
32
|
class Simulator:
|
|
30
33
|
"""
|
|
31
34
|
Simulator for generating synthetic conversations.
|
|
35
|
+
|
|
36
|
+
:param model_config: A dictionary defining the configuration for the model. Acceptable types are AzureOpenAIModelConfiguration and OpenAIModelConfiguration.
|
|
37
|
+
:type model_config: Union[~azure.ai.evaluation.AzureOpenAIModelConfiguration, ~azure.ai.evaluation.OpenAIModelConfiguration]
|
|
38
|
+
:raises ValueError: If the model_config does not contain the required keys or any value is None.
|
|
39
|
+
|
|
40
|
+
.. admonition:: Example:
|
|
41
|
+
|
|
42
|
+
.. literalinclude:: ../samples/evaluation_samples_simulate.py
|
|
43
|
+
:start-after: [START nonadversarial_simulator]
|
|
44
|
+
:end-before: [END nonadversarial_simulator]
|
|
45
|
+
:language: python
|
|
46
|
+
:dedent: 8
|
|
47
|
+
:caption: Run a Simulator for 2 queries and 4 conversation turns.
|
|
32
48
|
"""
|
|
33
49
|
|
|
34
50
|
def __init__(self, model_config: Union[AzureOpenAIModelConfiguration, OpenAIModelConfiguration]):
|
|
35
|
-
"""
|
|
36
|
-
Initializes the task simulator with the model configuration.
|
|
37
|
-
|
|
38
|
-
:param model_config: A dictionary defining the configuration for the model. Acceptable types are AzureOpenAIModelConfiguration and OpenAIModelConfiguration.
|
|
39
|
-
:type model_config: Union[~azure.ai.evaluation.AzureOpenAIModelConfiguration, ~azure.ai.evaluation.OpenAIModelConfiguration]
|
|
40
|
-
:raises ValueError: If the model_config does not contain the required keys or any value is None.
|
|
41
|
-
"""
|
|
42
51
|
self._validate_model_config(model_config)
|
|
43
52
|
self.model_config = model_config
|
|
44
53
|
if "api_version" not in self.model_config:
|
|
@@ -90,8 +99,8 @@ class Simulator:
|
|
|
90
99
|
query_response_generating_prompty: Optional[str] = None,
|
|
91
100
|
user_simulator_prompty: Optional[str] = None,
|
|
92
101
|
api_call_delay_sec: float = 1,
|
|
93
|
-
|
|
94
|
-
|
|
102
|
+
query_response_generating_prompty_options: Dict[str, Any] = {},
|
|
103
|
+
user_simulator_prompty_options: Dict[str, Any] = {},
|
|
95
104
|
conversation_turns: List[List[Union[str, Dict[str, Any]]]] = [],
|
|
96
105
|
concurrent_async_tasks: int = 5,
|
|
97
106
|
**kwargs,
|
|
@@ -115,10 +124,10 @@ class Simulator:
|
|
|
115
124
|
:paramtype user_simulator_prompty: Optional[str]
|
|
116
125
|
:keyword api_call_delay_sec: Delay in seconds between API calls.
|
|
117
126
|
:paramtype api_call_delay_sec: float
|
|
118
|
-
:keyword
|
|
119
|
-
:paramtype
|
|
120
|
-
:keyword
|
|
121
|
-
:paramtype
|
|
127
|
+
:keyword query_response_generating_prompty_options: Additional keyword arguments for the query response generating prompty.
|
|
128
|
+
:paramtype query_response_generating_prompty_options: Dict[str, Any]
|
|
129
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
130
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any]
|
|
122
131
|
:keyword conversation_turns: Predefined conversation turns to simulate.
|
|
123
132
|
:paramtype conversation_turns: List[List[Union[str, Dict[str, Any]]]]
|
|
124
133
|
:keyword concurrent_async_tasks: The number of asynchronous tasks to run concurrently during the simulation.
|
|
@@ -158,7 +167,7 @@ class Simulator:
|
|
|
158
167
|
max_conversation_turns=max_conversation_turns,
|
|
159
168
|
conversation_turns=conversation_turns,
|
|
160
169
|
user_simulator_prompty=user_simulator_prompty,
|
|
161
|
-
|
|
170
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
162
171
|
api_call_delay_sec=api_call_delay_sec,
|
|
163
172
|
prompty_model_config=prompty_model_config,
|
|
164
173
|
concurrent_async_tasks=concurrent_async_tasks,
|
|
@@ -168,7 +177,7 @@ class Simulator:
|
|
|
168
177
|
text=text,
|
|
169
178
|
num_queries=num_queries,
|
|
170
179
|
query_response_generating_prompty=query_response_generating_prompty,
|
|
171
|
-
|
|
180
|
+
query_response_generating_prompty_options=query_response_generating_prompty_options,
|
|
172
181
|
prompty_model_config=prompty_model_config,
|
|
173
182
|
**kwargs,
|
|
174
183
|
)
|
|
@@ -177,7 +186,7 @@ class Simulator:
|
|
|
177
186
|
max_conversation_turns=max_conversation_turns,
|
|
178
187
|
tasks=tasks,
|
|
179
188
|
user_simulator_prompty=user_simulator_prompty,
|
|
180
|
-
|
|
189
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
181
190
|
target=target,
|
|
182
191
|
api_call_delay_sec=api_call_delay_sec,
|
|
183
192
|
text=text,
|
|
@@ -190,7 +199,7 @@ class Simulator:
|
|
|
190
199
|
max_conversation_turns: int,
|
|
191
200
|
conversation_turns: List[List[Union[str, Dict[str, Any]]]],
|
|
192
201
|
user_simulator_prompty: Optional[str],
|
|
193
|
-
|
|
202
|
+
user_simulator_prompty_options: Dict[str, Any],
|
|
194
203
|
api_call_delay_sec: float,
|
|
195
204
|
prompty_model_config: Any,
|
|
196
205
|
concurrent_async_tasks: int,
|
|
@@ -206,8 +215,8 @@ class Simulator:
|
|
|
206
215
|
:paramtype conversation_turns: List[List[Union[str, Dict[str, Any]]]]
|
|
207
216
|
:keyword user_simulator_prompty: Path to the user simulator prompty file.
|
|
208
217
|
:paramtype user_simulator_prompty: Optional[str]
|
|
209
|
-
:keyword
|
|
210
|
-
:paramtype
|
|
218
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
219
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any]
|
|
211
220
|
:keyword api_call_delay_sec: Delay in seconds between API calls.
|
|
212
221
|
:paramtype api_call_delay_sec: float
|
|
213
222
|
:keyword prompty_model_config: The configuration for the prompty model.
|
|
@@ -258,7 +267,7 @@ class Simulator:
|
|
|
258
267
|
current_simulation=current_simulation,
|
|
259
268
|
max_conversation_turns=max_conversation_turns,
|
|
260
269
|
user_simulator_prompty=user_simulator_prompty,
|
|
261
|
-
|
|
270
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
262
271
|
api_call_delay_sec=api_call_delay_sec,
|
|
263
272
|
prompty_model_config=prompty_model_config,
|
|
264
273
|
target=target,
|
|
@@ -285,7 +294,7 @@ class Simulator:
|
|
|
285
294
|
current_simulation: ConversationHistory,
|
|
286
295
|
max_conversation_turns: int,
|
|
287
296
|
user_simulator_prompty: Optional[str],
|
|
288
|
-
|
|
297
|
+
user_simulator_prompty_options: Dict[str, Any],
|
|
289
298
|
api_call_delay_sec: float,
|
|
290
299
|
prompty_model_config: Dict[str, Any],
|
|
291
300
|
target: Callable,
|
|
@@ -301,8 +310,8 @@ class Simulator:
|
|
|
301
310
|
:paramtype max_conversation_turns: int,
|
|
302
311
|
:keyword user_simulator_prompty: Path to the user simulator prompty file.
|
|
303
312
|
:paramtype user_simulator_prompty: Optional[str],
|
|
304
|
-
:keyword
|
|
305
|
-
:paramtype
|
|
313
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
314
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any],
|
|
306
315
|
:keyword api_call_delay_sec: Delay in seconds between API calls.
|
|
307
316
|
:paramtype api_call_delay_sec: float,
|
|
308
317
|
:keyword prompty_model_config: The configuration for the prompty model.
|
|
@@ -317,14 +326,14 @@ class Simulator:
|
|
|
317
326
|
user_flow = self._load_user_simulation_flow(
|
|
318
327
|
user_simulator_prompty=user_simulator_prompty, # type: ignore
|
|
319
328
|
prompty_model_config=prompty_model_config,
|
|
320
|
-
|
|
329
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
321
330
|
)
|
|
322
331
|
|
|
323
332
|
while len(current_simulation) < max_conversation_turns:
|
|
324
333
|
user_response_content = await user_flow(
|
|
325
334
|
task="Continue the conversation",
|
|
326
335
|
conversation_history=current_simulation.to_context_free_list(),
|
|
327
|
-
**
|
|
336
|
+
**user_simulator_prompty_options,
|
|
328
337
|
)
|
|
329
338
|
user_response = self._parse_prompty_response(response=user_response_content)
|
|
330
339
|
user_turn = Turn(role=ConversationRole.USER, content=user_response["content"])
|
|
@@ -345,7 +354,7 @@ class Simulator:
|
|
|
345
354
|
*,
|
|
346
355
|
user_simulator_prompty: Optional[Union[str, os.PathLike]],
|
|
347
356
|
prompty_model_config: Dict[str, Any],
|
|
348
|
-
|
|
357
|
+
user_simulator_prompty_options: Dict[str, Any],
|
|
349
358
|
) -> "AsyncPrompty": # type: ignore
|
|
350
359
|
"""
|
|
351
360
|
Loads the flow for simulating user interactions.
|
|
@@ -354,8 +363,8 @@ class Simulator:
|
|
|
354
363
|
:paramtype user_simulator_prompty: Optional[Union[str, os.PathLike]]
|
|
355
364
|
:keyword prompty_model_config: The configuration for the prompty model.
|
|
356
365
|
:paramtype prompty_model_config: Dict[str, Any]
|
|
357
|
-
:keyword
|
|
358
|
-
:paramtype
|
|
366
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
367
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any]
|
|
359
368
|
:return: The loaded flow for simulating user interactions.
|
|
360
369
|
:rtype: AsyncPrompty
|
|
361
370
|
"""
|
|
@@ -388,7 +397,7 @@ class Simulator:
|
|
|
388
397
|
return AsyncPrompty.load(
|
|
389
398
|
source=user_simulator_prompty,
|
|
390
399
|
model=prompty_model_config,
|
|
391
|
-
**
|
|
400
|
+
**user_simulator_prompty_options,
|
|
392
401
|
) # type: ignore
|
|
393
402
|
|
|
394
403
|
def _parse_prompty_response(self, *, response: str) -> Dict[str, Any]:
|
|
@@ -436,7 +445,7 @@ class Simulator:
|
|
|
436
445
|
text: str,
|
|
437
446
|
num_queries: int,
|
|
438
447
|
query_response_generating_prompty: Optional[str],
|
|
439
|
-
|
|
448
|
+
query_response_generating_prompty_options: Dict[str, Any],
|
|
440
449
|
prompty_model_config: Any,
|
|
441
450
|
**kwargs,
|
|
442
451
|
) -> List[Dict[str, str]]:
|
|
@@ -449,8 +458,8 @@ class Simulator:
|
|
|
449
458
|
:paramtype num_queries: int
|
|
450
459
|
:keyword query_response_generating_prompty: Path to the query response generating prompty file.
|
|
451
460
|
:paramtype query_response_generating_prompty: Optional[str]
|
|
452
|
-
:keyword
|
|
453
|
-
:paramtype
|
|
461
|
+
:keyword query_response_generating_prompty_options: Additional keyword arguments for the query response generating prompty.
|
|
462
|
+
:paramtype query_response_generating_prompty_options: Dict[str, Any]
|
|
454
463
|
:keyword prompty_model_config: The configuration for the prompty model.
|
|
455
464
|
:paramtype prompty_model_config: Any
|
|
456
465
|
:return: A list of query-response dictionaries.
|
|
@@ -460,7 +469,7 @@ class Simulator:
|
|
|
460
469
|
query_flow = self._load_query_generation_flow(
|
|
461
470
|
query_response_generating_prompty=query_response_generating_prompty, # type: ignore
|
|
462
471
|
prompty_model_config=prompty_model_config,
|
|
463
|
-
|
|
472
|
+
query_response_generating_prompty_options=query_response_generating_prompty_options,
|
|
464
473
|
)
|
|
465
474
|
try:
|
|
466
475
|
query_responses = await query_flow(text=text, num_queries=num_queries)
|
|
@@ -484,7 +493,7 @@ class Simulator:
|
|
|
484
493
|
*,
|
|
485
494
|
query_response_generating_prompty: Optional[Union[str, os.PathLike]],
|
|
486
495
|
prompty_model_config: Dict[str, Any],
|
|
487
|
-
|
|
496
|
+
query_response_generating_prompty_options: Dict[str, Any],
|
|
488
497
|
) -> "AsyncPrompty":
|
|
489
498
|
"""
|
|
490
499
|
Loads the flow for generating query responses.
|
|
@@ -493,8 +502,8 @@ class Simulator:
|
|
|
493
502
|
:paramtype query_response_generating_prompty: Optional[Union[str, os.PathLike]]
|
|
494
503
|
:keyword prompty_model_config: The configuration for the prompty model.
|
|
495
504
|
:paramtype prompty_model_config: Dict[str, Any]
|
|
496
|
-
:keyword
|
|
497
|
-
:paramtype
|
|
505
|
+
:keyword query_response_generating_prompty_options: Additional keyword arguments for the flow.
|
|
506
|
+
:paramtype query_response_generating_prompty_options: Dict[str, Any]
|
|
498
507
|
:return: The loaded flow for generating query responses.
|
|
499
508
|
:rtype: AsyncPrompty
|
|
500
509
|
"""
|
|
@@ -527,7 +536,7 @@ class Simulator:
|
|
|
527
536
|
return AsyncPrompty.load(
|
|
528
537
|
source=query_response_generating_prompty,
|
|
529
538
|
model=prompty_model_config,
|
|
530
|
-
**
|
|
539
|
+
**query_response_generating_prompty_options,
|
|
531
540
|
) # type: ignore
|
|
532
541
|
|
|
533
542
|
async def _create_conversations_from_query_responses(
|
|
@@ -537,7 +546,7 @@ class Simulator:
|
|
|
537
546
|
max_conversation_turns: int,
|
|
538
547
|
tasks: List[str],
|
|
539
548
|
user_simulator_prompty: Optional[str],
|
|
540
|
-
|
|
549
|
+
user_simulator_prompty_options: Dict[str, Any],
|
|
541
550
|
target: Callable,
|
|
542
551
|
api_call_delay_sec: float,
|
|
543
552
|
text: str,
|
|
@@ -553,8 +562,8 @@ class Simulator:
|
|
|
553
562
|
:paramtype tasks: List[str]
|
|
554
563
|
:keyword user_simulator_prompty: Path to the user simulator prompty file.
|
|
555
564
|
:paramtype user_simulator_prompty: Optional[str]
|
|
556
|
-
:keyword
|
|
557
|
-
:paramtype
|
|
565
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
566
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any]
|
|
558
567
|
:keyword target: The target function to call for responses.
|
|
559
568
|
:paramtype target: Callable
|
|
560
569
|
:keyword api_call_delay_sec: Delay in seconds between API calls.
|
|
@@ -584,7 +593,7 @@ class Simulator:
|
|
|
584
593
|
max_conversation_turns=max_conversation_turns,
|
|
585
594
|
task=task, # type: ignore
|
|
586
595
|
user_simulator_prompty=user_simulator_prompty,
|
|
587
|
-
|
|
596
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
588
597
|
target=target,
|
|
589
598
|
api_call_delay_sec=api_call_delay_sec,
|
|
590
599
|
progress_bar=progress_bar,
|
|
@@ -614,7 +623,7 @@ class Simulator:
|
|
|
614
623
|
max_conversation_turns: int,
|
|
615
624
|
task: str,
|
|
616
625
|
user_simulator_prompty: Optional[str],
|
|
617
|
-
|
|
626
|
+
user_simulator_prompty_options: Dict[str, Any],
|
|
618
627
|
target: Callable,
|
|
619
628
|
api_call_delay_sec: float,
|
|
620
629
|
progress_bar: tqdm,
|
|
@@ -630,8 +639,8 @@ class Simulator:
|
|
|
630
639
|
:paramtype task: str
|
|
631
640
|
:keyword user_simulator_prompty: Path to the user simulator prompty file.
|
|
632
641
|
:paramtype user_simulator_prompty: Optional[str]
|
|
633
|
-
:keyword
|
|
634
|
-
:paramtype
|
|
642
|
+
:keyword user_simulator_prompty_options: Additional keyword arguments for the user simulator prompty.
|
|
643
|
+
:paramtype user_simulator_prompty_options: Dict[str, Any]
|
|
635
644
|
:keyword target: The target function to call for responses.
|
|
636
645
|
:paramtype target: Callable
|
|
637
646
|
:keyword api_call_delay_sec: Delay in seconds between API calls.
|
|
@@ -647,7 +656,7 @@ class Simulator:
|
|
|
647
656
|
user_flow = self._load_user_simulation_flow(
|
|
648
657
|
user_simulator_prompty=user_simulator_prompty, # type: ignore
|
|
649
658
|
prompty_model_config=self.model_config, # type: ignore
|
|
650
|
-
|
|
659
|
+
user_simulator_prompty_options=user_simulator_prompty_options,
|
|
651
660
|
)
|
|
652
661
|
if len(conversation_history) == 0:
|
|
653
662
|
conversation_starter_from_simulated_user = await user_flow(
|
|
@@ -44,23 +44,41 @@ class JsonLineList(list):
|
|
|
44
44
|
for item in self:
|
|
45
45
|
user_message = None
|
|
46
46
|
assistant_message = None
|
|
47
|
-
|
|
47
|
+
user_context = None
|
|
48
|
+
assistant_context = None
|
|
49
|
+
template_parameters = item.get("template_parameters", {})
|
|
50
|
+
category = template_parameters.get("category", None)
|
|
48
51
|
for message in item["messages"]:
|
|
49
52
|
if message["role"] == "user":
|
|
50
53
|
user_message = message["content"]
|
|
54
|
+
user_context = message.get("context", "")
|
|
51
55
|
elif message["role"] == "assistant":
|
|
52
56
|
assistant_message = message["content"]
|
|
53
|
-
|
|
54
|
-
context = message.get("context", None)
|
|
57
|
+
assistant_context = message.get("context", "")
|
|
55
58
|
if user_message and assistant_message:
|
|
56
|
-
if
|
|
59
|
+
if user_context or assistant_context:
|
|
57
60
|
json_lines += (
|
|
58
|
-
json.dumps(
|
|
61
|
+
json.dumps(
|
|
62
|
+
{
|
|
63
|
+
"query": user_message,
|
|
64
|
+
"response": assistant_message,
|
|
65
|
+
"context": str(
|
|
66
|
+
{
|
|
67
|
+
"user_context": user_context,
|
|
68
|
+
"assistant_context": assistant_context,
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
"category": category,
|
|
72
|
+
}
|
|
73
|
+
)
|
|
59
74
|
+ "\n"
|
|
60
75
|
)
|
|
61
|
-
user_message = assistant_message =
|
|
76
|
+
user_message = assistant_message = None
|
|
62
77
|
else:
|
|
63
|
-
json_lines +=
|
|
78
|
+
json_lines += (
|
|
79
|
+
json.dumps({"query": user_message, "response": assistant_message, "category": category})
|
|
80
|
+
+ "\n"
|
|
81
|
+
)
|
|
64
82
|
user_message = assistant_message = None
|
|
65
83
|
|
|
66
84
|
return json_lines
|