deepeval 3.7.1__py3-none-any.whl → 3.7.2__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.
@@ -1,3 +1,12 @@
1
- from .template import SynthesizerTemplate, EvolutionTemplate, FilterTemplate
2
- from .template_prompt import PromptSynthesizerTemplate, PromptEvolutionTemplate
1
+ from .template import (
2
+ SynthesizerTemplate,
3
+ EvolutionTemplate,
4
+ FilterTemplate,
5
+ ConversationalEvolutionTemplate,
6
+ )
7
+ from .template_prompt import (
8
+ PromptSynthesizerTemplate,
9
+ PromptEvolutionTemplate,
10
+ ConversationalPromptEvolutionTemplate,
11
+ )
3
12
  from .template_extraction import ExtractionTemplate
@@ -120,7 +120,7 @@ class SynthesizerTemplate:
120
120
  )
121
121
 
122
122
  scenario_section = (
123
- f"`input`s MUST be relevant to this specific scenario: ```{scenario}``` (The scenario describes the circumstances under which the inputs are generated and the users intent in eliciting a response)."
123
+ f"`input`s MUST be relevant to this specific scenario: ```{scenario}``` (The scenario describes the circumstances under which the inputs are generated and the user's intent in eliciting a response)."
124
124
  if scenario
125
125
  else ""
126
126
  )
@@ -246,6 +246,212 @@ class SynthesizerTemplate:
246
246
  JSON:
247
247
  """
248
248
 
249
+ @staticmethod
250
+ def generate_synthetic_scenarios(
251
+ context: str,
252
+ max_goldens_per_context: int,
253
+ scenario_context: Optional[str],
254
+ conversational_task: Optional[str],
255
+ participant_roles: Optional[str],
256
+ ):
257
+ participant_section = (
258
+ f"Each scenario MUST involve these participant roles: {participant_roles}."
259
+ if participant_roles
260
+ else "Each scenario MUST clearly specify who the participants are (e.g., 'a teacher and a student', 'two colleagues')."
261
+ )
262
+
263
+ scenario_context_section = (
264
+ f"All scenarios MUST fit within this conversational context: {scenario_context}"
265
+ if scenario_context
266
+ else ""
267
+ )
268
+
269
+ task_section = (
270
+ f"The conversation in each scenario should work towards this goal: {conversational_task}"
271
+ if conversational_task
272
+ else ""
273
+ )
274
+
275
+ return f"""I want you to act as a conversation scenario designer. Based on the given context, generate a list of JSON objects with a `scenario` key.
276
+ Each `scenario` should describe a MULTI-TURN CONVERSATIONAL INTERACTION between specific participants discussing information from the context.
277
+
278
+ **
279
+ IMPORTANT: Please make sure to only return in JSON format, with the 'data' key as a list of JSON objects.
280
+ You MUST TRY to generate {max_goldens_per_context} data points, unless scenarios become repetitive.
281
+
282
+ Example context: ["Einstein won the Nobel Prize for his discovery of the photoelectric effect.", "Einstein won the Nobel Prize in 1921."]
283
+ Example max goldens per context: 2
284
+ Example JSON:
285
+ {{
286
+ "data": [
287
+ {{
288
+ "scenario": "A high school student asks their physics teacher when Einstein won the Nobel Prize and what discovery it was awarded for"
289
+ }},
290
+ {{
291
+ "scenario": "Two university students are studying together and one tests the other's knowledge about Einstein's Nobel Prize year and the scientific work that earned it"
292
+ }}
293
+ ]
294
+ }}
295
+
296
+ CRITICAL REQUIREMENTS FOR CONVERSATIONAL SCENARIOS:
297
+ - Each scenario MUST describe a conversation between specific participants (who is talking to whom)
298
+ - Each scenario MUST specify the conversational setting and context (where, why, what they're discussing)
299
+ - DO NOT write questions, prompts, or instructions - write descriptions of conversational SITUATIONS
300
+ - DO NOT use command phrases like "Explain...", "Compare...", "Describe..." - these are instructions, not conversations
301
+ - Scenarios should describe realistic multi-turn interactions where information from context would naturally be discussed
302
+ - Think: "Who is talking to whom, about what, and in what situation?"
303
+
304
+ GOOD examples:
305
+ ✓ "A patient asks their doctor about the side effects of a new medication during a consultation"
306
+ ✓ "A manager provides feedback to an employee about their recent project performance in a 1-on-1 meeting"
307
+ ✓ "Two friends debate the pros and cons of electric vehicles while carpooling to work"
308
+
309
+ BAD examples (these are prompts/questions, not conversational scenarios):
310
+ ✗ "Explain the side effects of medication"
311
+ ✗ "What happens when water freezes?"
312
+ ✗ "Compare electric vehicles to gas vehicles"
313
+
314
+ You should NOT incorporate any prior knowledge you have and take each context at face value.
315
+ {participant_section}
316
+ {scenario_context_section}
317
+ {task_section}
318
+ You MUST TRY to generate {max_goldens_per_context} data points, unless scenarios become repetitive.
319
+ **
320
+
321
+ Max Goldens Per Context:
322
+ {max_goldens_per_context}
323
+
324
+ Context:
325
+ {context}
326
+
327
+ JSON:
328
+ """
329
+
330
+ @staticmethod
331
+ def generate_synthetic_expected_outcome_conversational(
332
+ scenario: str, context: str, expected_outcome_format: Optional[str]
333
+ ):
334
+ format_section = (
335
+ f"The expected outcome MUST adhere to this format: {expected_outcome_format}"
336
+ if expected_outcome_format
337
+ else "Keep the expected outcome CONCISE (1-3 sentences maximum)"
338
+ )
339
+
340
+ return f"""Given the conversational scenario, generate a CONCISE expected outcome describing what should happen in the conversation or what is achieved by the end.
341
+
342
+ **
343
+ IMPORTANT: {format_section}
344
+
345
+ The expected outcome should briefly describe ONE of:
346
+ - What key information is shared/conveyed during the conversation
347
+ - What the participants learn or come to understand
348
+ - What decision, agreement, or resolution is reached
349
+ - How the conversational goal is accomplished
350
+
351
+ DO NOT write long explanatory paragraphs. Be direct and concise.
352
+ Use information from the context to ground the expected outcome.
353
+ **
354
+
355
+ Context:
356
+ {context}
357
+
358
+ Conversational Scenario:
359
+ {scenario}
360
+
361
+ Expected Outcome:
362
+ """
363
+
364
+ @staticmethod
365
+ def rewrite_evolved_scenario(
366
+ evolved_scenario: str,
367
+ scenario_context: Optional[str] = None,
368
+ conversational_task: Optional[str] = None,
369
+ participant_roles: Optional[str] = None,
370
+ ):
371
+ context_section = (
372
+ f'Scenario Context: "{scenario_context}"'
373
+ if scenario_context
374
+ else ""
375
+ )
376
+ task_section = (
377
+ f'Conversational Task: "{conversational_task}"'
378
+ if conversational_task
379
+ else ""
380
+ )
381
+ roles_section = (
382
+ f'Participant Roles: "{participant_roles}"'
383
+ if participant_roles
384
+ else ""
385
+ )
386
+
387
+ return f"""Given the evolved scenario, which describes a conversational situation, generate a JSON object with a key 'scenario'.
388
+ This key should contain a scenario description that fits the provided context, aligns with the conversational task, and involves the specified participant roles (if provided).
389
+
390
+ **
391
+ IMPORTANT: Try to change the evolved scenario as little as possible. However, if it does not align with the provided scenario context, conversational task, or participant roles, it must be adjusted to fit these requirements.
392
+
393
+ The output must be in JSON format with the 'scenario' key only.
394
+ The scenario MUST describe a conversational interaction, not a question or prompt.
395
+ **
396
+
397
+ Example Evolved Scenario: "Discuss the importance of meeting deadlines"
398
+ Example Scenario Context: "Workplace performance management"
399
+ Example Conversational Task: "Provide constructive feedback"
400
+ Example Participant Roles: "Manager and employee"
401
+ Example JSON: {{
402
+ "scenario": "A manager meets with an employee to discuss recent missed deadlines and collaboratively develop strategies for better time management"
403
+ }}
404
+
405
+ Evolved Scenario:
406
+ {evolved_scenario}
407
+
408
+ {context_section}
409
+ {task_section}
410
+ {roles_section}
411
+
412
+ JSON:
413
+ """
414
+
415
+ @staticmethod
416
+ def rewrite_synthetic_scenarios(context, original_scenario, feedback):
417
+ return f"""I want you to act as a scenario rewriter. Based on the provided context, original scenario, and feedback, generate a rewritten scenario that improves its clarity and conversational nature based on the feedback provided.
418
+
419
+ **
420
+ IMPORTANT: Please make sure to only return in JSON format, with the 'rewritten_scenario' key.
421
+ The rewritten scenario MUST describe a conversational interaction between participants, not a question or instruction.
422
+
423
+ Example context: "The Golden Gate Bridge, located in San Francisco, was completed in 1937 and is known for its Art Deco design. It connects the city of San Francisco to Marin County and spans the Golden Gate Strait."
424
+ Example scenario: "Someone asks about a bridge"
425
+ Example feedback: "The scenario is too vague and doesn't describe a conversational situation with specific participants. It should clearly identify who is talking to whom and in what context."
426
+ Example JSON:
427
+ {{
428
+ "rewritten_scenario": "A tourist visiting San Francisco asks their tour guide about the history and design features of the Golden Gate Bridge"
429
+ }}
430
+
431
+ Example context: "The paper 'Advancements in Quantum Computing' by Dr. Alice Thompson discusses breakthroughs in quantum algorithms and was published in 2022. It explores the potential applications of quantum computing in cryptography and drug discovery."
432
+ Example scenario: "A discussion about quantum computing"
433
+ Example feedback: "The scenario lacks specificity about who is having the discussion, what the setting is, and what aspect they're focused on. Frame this as a concrete conversational situation with identified participants."
434
+ Example JSON:
435
+ {{
436
+ "rewritten_scenario": "A graduate student presents Dr. Alice Thompson's 2022 paper on quantum computing to their research group, leading to a discussion about applications in cryptography and drug discovery"
437
+ }}
438
+
439
+ You should NOT incorporate any prior knowledge and should base the rewritten scenario only on the context and feedback provided.
440
+ The `rewritten_scenario` MUST be a STRING describing a multi-turn conversational interaction between specific participants.
441
+ **
442
+
443
+ Context:
444
+ {context}
445
+
446
+ Original Scenario:
447
+ {original_scenario}
448
+
449
+ Feedback:
450
+ {feedback}
451
+
452
+ JSON:
453
+ """
454
+
249
455
 
250
456
  ######################################################################################################
251
457
  ##### Filter #########################################################################################
@@ -374,6 +580,69 @@ class FilterTemplate:
374
580
  JSON:
375
581
  """
376
582
 
583
+ @staticmethod
584
+ def evaluate_synthetic_scenarios(scenario):
585
+ return f"""Evaluate the provided conversational scenario for clarity, conversational nature, and appropriateness. Use the following criteria:
586
+
587
+ 1. **Conversational Structure**: Does the scenario describe an actual conversation between identified participants (not just a question or prompt)?
588
+ 2. **Participant Clarity**: Are the participants clearly identified with specific roles (e.g., "teacher and student", "doctor and patient")?
589
+ 3. **Contextual Setting**: Is there a clear setting or context for when/where/why this conversation occurs?
590
+ 4. **Purposeful Interaction**: Does the scenario imply a multi-turn dialogue with a goal or purpose?
591
+ 5. **Naturalness**: Could this conversation realistically occur in the described situation?
592
+
593
+ Assign a score between 0 and 1:
594
+ - "1" = Perfect conversational scenario with clear participants, setting, and purpose
595
+ - "0.7-0.9" = Good scenario with minor issues (slightly vague participants or context)
596
+ - "0.4-0.6" = Mediocre scenario (missing clear participants OR setting OR purpose)
597
+ - "0-0.3" = Poor scenario (just a question/prompt, or very vague)
598
+
599
+ **
600
+ IMPORTANT: Return JSON format only, with 'feedback' and 'score' keys.
601
+
602
+ Example scenario: "A student asks about homework"
603
+ Example JSON:
604
+ {{
605
+ "feedback": "This scenario is too vague. It doesn't specify what subject, what specific aspect of homework, who the student is asking (teacher? parent?), or provide conversational context. It reads more like a prompt fragment than a conversational scenario. Needs: specific participants, setting, and what aspect of homework is being discussed.",
606
+ "score": 0.2
607
+ }}
608
+
609
+ Example scenario: "A new employee meets with their supervisor for a quarterly performance review to discuss progress over the first three months, areas for improvement, and goals for the next quarter"
610
+ Example JSON:
611
+ {{
612
+ "feedback": "Excellent conversational scenario. Clear participants (new employee and supervisor), specific setting (quarterly performance review), clear purpose (discuss progress, improvements, and goals), and describes a realistic multi-turn conversation. This would naturally involve back-and-forth dialogue.",
613
+ "score": 1.0
614
+ }}
615
+
616
+ Example scenario: "A patient explains symptoms to a doctor during a check-up"
617
+ Example JSON:
618
+ {{
619
+ "feedback": "Good conversational scenario with clear participants (patient and doctor) and setting (check-up). It describes a realistic interaction. Could be slightly more specific about what symptoms or the purpose beyond just explaining, but overall solid.",
620
+ "score": 0.8
621
+ }}
622
+
623
+ Example scenario: "Explain how photosynthesis works"
624
+ Example JSON:
625
+ {{
626
+ "feedback": "This is an instruction/prompt, not a conversational scenario. It doesn't describe who is talking to whom, what the setting is, or frame it as an interaction. Needs complete rewrite to describe an actual conversation (e.g., 'A biology teacher explains photosynthesis to a student who asks about...').",
627
+ "score": 0.1
628
+ }}
629
+
630
+ Example scenario: "Two colleagues discuss the benefits and drawbacks of remote work versus office work during their lunch break"
631
+ Example JSON:
632
+ {{
633
+ "feedback": "Strong conversational scenario. Clear participants (two colleagues), setting (lunch break), specific topic (remote vs office work), and implies a natural back-and-forth discussion. Realistic and purposeful.",
634
+ "score": 0.95
635
+ }}
636
+
637
+ The `feedback` MUST be a STRING and `score` must be a float from 0 to 1.
638
+ **
639
+
640
+ Scenario:
641
+ {scenario}
642
+
643
+ JSON:
644
+ """
645
+
377
646
 
378
647
  ######################################################################################################
379
648
  ##### Approach similar to https://github.com/nlpxucan/WizardLM/blob/main/Evol_Instruct/depth.py ######
@@ -726,3 +995,287 @@ class EvolutionTemplate:
726
995
  Rewritten Input:
727
996
  """
728
997
  )
998
+
999
+
1000
+ class ConversationalEvolutionTemplate:
1001
+
1002
+ base_instruction = """I want you to act as a conversational scenario rewriter.
1003
+ Your objective is to rewrite the given `Scenario` while preserving factual correctness according to the supporting information in `Context`.
1004
+ You MUST complicate the given `Scenario` using the following method:"""
1005
+
1006
+ @staticmethod
1007
+ def multi_context_evolution(scenario, context):
1008
+ return (
1009
+ ConversationalEvolutionTemplate.base_instruction
1010
+ + f"""
1011
+ 1. `Scenario` must be rewritten so participants must naturally rely on **all elements of `Context`** during the conversation.
1012
+ 2. `Rewritten Scenario` MUST remain a realistic multi-turn conversation setup.
1013
+ 3. Keep the rewritten scenario under **60 words**.
1014
+ 4. Do NOT use phrases like “based on the context” or “according to the context”.
1015
+
1016
+ **
1017
+ EXAMPLES
1018
+
1019
+ Example context:
1020
+ ["A startup is developing an AI tool for diagnosing skin conditions.",
1021
+ "Regulations require explainability for clinical AI systems.",
1022
+ "The team is under a tight deadline before a regulatory audit."]
1023
+ Example scenario:
1024
+ Two engineers review their prototype.
1025
+ Example rewritten scenario:
1026
+ During a tense late-night meeting, two AI engineers debate whether their skin-diagnosis model meets upcoming explainability regulations, forcing them to discuss audit risks and integrate overlooked clinical requirements across multiple conversational turns.
1027
+
1028
+ --------------------------
1029
+
1030
+ Example context:
1031
+ ["A research team is studying coral bleaching.",
1032
+ "Rising ocean temperatures accelerate bleaching events.",
1033
+ "Funding depends on publishing actionable mitigation strategies."]
1034
+ Example scenario:
1035
+ Two scientists talk about coral reefs.
1036
+ Example rewritten scenario:
1037
+ In a lab debrief, two marine biologists argue over how rising ocean temperatures, bleaching data, and funding-dependent mitigation strategies should shape their next field report.
1038
+
1039
+ **
1040
+
1041
+ Context:
1042
+ {context}
1043
+ Scenario:
1044
+ {scenario}
1045
+ Rewritten Scenario:
1046
+ """
1047
+ )
1048
+
1049
+ @staticmethod
1050
+ def reasoning_evolution(scenario, context):
1051
+ return (
1052
+ ConversationalEvolutionTemplate.base_instruction
1053
+ + f"""
1054
+ 1. Rewrite `Scenario` so the resulting conversation requires multi-step reasoning between participants.
1055
+ 2. Add layered inferential or analytical demands grounded in `Context`.
1056
+ 3. Keep the rewritten scenario under **60 words**.
1057
+ 4. Do NOT use phrases like “based on the context”.
1058
+ 5. Must remain a realistic multi-turn dialogue setup.
1059
+
1060
+ **
1061
+ EXAMPLES
1062
+
1063
+ Example context:
1064
+ "A school is transitioning to solar power, but initial costs are high and maintenance requires specialized knowledge."
1065
+ Example scenario:
1066
+ A teacher asks a technician about solar panels.
1067
+ Example rewritten scenario:
1068
+ A teacher and campus technician debate whether adopting solar panels makes financial sense, analyzing upfront costs, long-term energy savings, and specialized maintenance requirements across a multi-step reasoning exchange.
1069
+
1070
+ --------------------------
1071
+
1072
+ Example context:
1073
+ "An economic model predicts inflation rises when supply chains weaken."
1074
+ Example scenario:
1075
+ Two analysts discuss inflation.
1076
+ Example rewritten scenario:
1077
+ On a strategy call, two analysts unpack how supply-chain disruptions, demand shifts, and model predictions interact, forcing a layered reasoning conversation.
1078
+
1079
+ **
1080
+
1081
+ Context:
1082
+ {context}
1083
+ Scenario:
1084
+ {scenario}
1085
+ Rewritten Scenario:
1086
+ """
1087
+ )
1088
+
1089
+ @staticmethod
1090
+ def concretizing_evolution(scenario, context):
1091
+ return (
1092
+ ConversationalEvolutionTemplate.base_instruction
1093
+ + f"""
1094
+ 1. Rewrite `Scenario` by replacing general conversational settings with **highly specific**, concrete circumstances tied to `Context`.
1095
+ 2. Add situational cues, named events, or explicit constraints.
1096
+ 3. Keep the rewritten scenario under **60 words**.
1097
+ 4. Maintain realistic multi-turn dialogue structure.
1098
+
1099
+ **
1100
+ EXAMPLES
1101
+
1102
+ Example context:
1103
+ "A hospital is piloting a new triage AI system."
1104
+ Example scenario:
1105
+ A doctor and nurse discuss patient triage.
1106
+ Example rewritten scenario:
1107
+ During a chaotic evening shift, a doctor and nurse debate whether the new triage AI's risk-scores should override manual judgment in handling a surge of incoming trauma cases.
1108
+
1109
+ --------------------------
1110
+
1111
+ Example context:
1112
+ "A remote-work company is struggling with meeting overload."
1113
+ Example scenario:
1114
+ Two colleagues discuss productivity.
1115
+ Example rewritten scenario:
1116
+ In a Friday retrospective, two remote employees argue about whether asynchronous updates can replace their current schedule of back-to-back video meetings.
1117
+
1118
+ **
1119
+
1120
+ Context:
1121
+ {context}
1122
+ Scenario:
1123
+ {scenario}
1124
+ Rewritten Scenario:
1125
+ """
1126
+ )
1127
+
1128
+ @staticmethod
1129
+ def constrained_evolution(scenario, context):
1130
+ return (
1131
+ ConversationalEvolutionTemplate.base_instruction
1132
+ + f"""
1133
+ 1. Rewrite `Scenario` by adding at least **one new constraint** that shapes how the conversation unfolds.
1134
+ 2. The constraint must logically follow from `Context`.
1135
+ 3. Keep the rewritten scenario under **60 words**.
1136
+ 4. Keep it a realistic multi-turn setup.
1137
+
1138
+ **
1139
+ EXAMPLES
1140
+
1141
+ Example context:
1142
+ "A startup must deliver an AI model but cannot exceed strict GPU budgets."
1143
+ Example scenario:
1144
+ Two engineers discuss model performance.
1145
+ Example rewritten scenario:
1146
+ Two ML engineers debate model redesigns, but GPU usage is capped for the quarter, forcing them to reconsider heavier architectures while under deadline pressure.
1147
+
1148
+ --------------------------
1149
+
1150
+ Example context:
1151
+ "A university's ethics board is reviewing data-collection policies."
1152
+ Example scenario:
1153
+ A professor talks with a student researcher.
1154
+ Example rewritten scenario:
1155
+ Before submitting their study, a professor and student must revise their protocol to satisfy strict new privacy constraints imposed by the ethics board.
1156
+
1157
+ **
1158
+
1159
+ Context:
1160
+ {context}
1161
+ Scenario:
1162
+ {scenario}
1163
+ Rewritten Scenario:
1164
+ """
1165
+ )
1166
+
1167
+ @staticmethod
1168
+ def comparative_question_evolution(scenario, context):
1169
+ return (
1170
+ ConversationalEvolutionTemplate.base_instruction
1171
+ + f"""
1172
+ 1. Rewrite `Scenario` so the conversation naturally compares two or more concepts, tools, or approaches.
1173
+ 2. The comparison must be central to the multi-turn dialogue.
1174
+ 3. Keep the rewritten scenario under **60 words**.
1175
+
1176
+ **
1177
+ EXAMPLES
1178
+
1179
+ Example context:
1180
+ "Two project management tools differ in cost, automation, and integration options."
1181
+ Example scenario:
1182
+ Two coworkers evaluate a new tool.
1183
+ Example rewritten scenario:
1184
+ In a planning meeting, two coworkers compare switching from their legacy management tool to a cheaper automated one, weighing integration gaps and workflow impact.
1185
+
1186
+ --------------------------
1187
+
1188
+ Example context:
1189
+ "Electric and hydrogen vehicles have different refueling logistics."
1190
+ Example scenario:
1191
+ Two friends discuss cars.
1192
+ Example rewritten scenario:
1193
+ On a road trip, two friends debate electric vs hydrogen cars, comparing range limits, refueling times, and long-term reliability.
1194
+
1195
+ **
1196
+
1197
+ Context:
1198
+ {context}
1199
+ Scenario:
1200
+ {scenario}
1201
+ Rewritten Scenario:
1202
+ """
1203
+ )
1204
+
1205
+ @staticmethod
1206
+ def hypothetical_scenario_evolution(scenario, context):
1207
+ return (
1208
+ ConversationalEvolutionTemplate.base_instruction
1209
+ + f"""
1210
+ 1. Rewrite `Scenario` by adding a hypothetical twist grounded in `Context`.
1211
+ 2. The speculative change MUST drive the conversation.
1212
+ 3. Must remain realistic and multi-turn.
1213
+ 4. Keep the rewritten scenario under **60 words**.
1214
+
1215
+ **
1216
+ EXAMPLES
1217
+
1218
+ Example context:
1219
+ "A cybersecurity team is tracking frequent phishing attempts."
1220
+ Example scenario:
1221
+ Two analysts review security logs.
1222
+ Example rewritten scenario:
1223
+ During a nightly shift, two analysts discuss a hypothetical spike in coordinated phishing attacks and explore how it would strain their current detection pipeline.
1224
+
1225
+ --------------------------
1226
+
1227
+ Example context:
1228
+ "A city is experimenting with autonomous buses."
1229
+ Example scenario:
1230
+ A resident talks to a planner.
1231
+ Example rewritten scenario:
1232
+ At a community forum, a resident and transit planner imagine a scenario where all local buses become autonomous overnight and debate safety tradeoffs.
1233
+
1234
+ **
1235
+
1236
+ Context:
1237
+ {context}
1238
+ Scenario:
1239
+ {scenario}
1240
+ Rewritten Scenario:
1241
+ """
1242
+ )
1243
+
1244
+ @staticmethod
1245
+ def in_breadth_evolution(scenario, context):
1246
+ return (
1247
+ ConversationalEvolutionTemplate.base_instruction
1248
+ + f"""
1249
+ 1. Rewrite `Scenario` into a brand-new conversational setup.
1250
+ 2. It must remain in the **same domain** but shift toward a **rarer or niche** topic.
1251
+ 3. Must remain a realistic multi-turn dialogue setup.
1252
+ 4. Keep under **60 words**.
1253
+
1254
+ **
1255
+ EXAMPLES
1256
+
1257
+ Example context:
1258
+ "Wearables monitor heart rate and sleep cycles."
1259
+ Example scenario:
1260
+ Two people discuss fitness trackers.
1261
+ Example rewritten scenario:
1262
+ In a clinical trial briefing, two researchers debate implantable cardiac micro-sensors and their potential to outperform traditional wearables in long-term monitoring.
1263
+
1264
+ --------------------------
1265
+
1266
+ Example context:
1267
+ "Quantum computing is advancing rapidly."
1268
+ Example scenario:
1269
+ Two students study quantum algorithms.
1270
+ Example rewritten scenario:
1271
+ During a research seminar, two students examine the niche topic of quantum-secure error-correcting codes for next-generation cryptosystems.
1272
+
1273
+ **
1274
+
1275
+ Context:
1276
+ {context}
1277
+ Scenario:
1278
+ {scenario}
1279
+ Rewritten Scenario:
1280
+ """
1281
+ )
@@ -44,3 +44,35 @@ class ExtractionTemplate:
44
44
 
45
45
  {inputs}
46
46
  """
47
+
48
+ @staticmethod
49
+ def extract_conversational_structure_from_scenarios(example_scenarios):
50
+ scenarios_text = "\n".join(
51
+ [f"- {scenario}" for scenario in example_scenarios]
52
+ )
53
+
54
+ return f"""Analyze the following conversational scenarios and extract the common structural elements:
55
+
56
+ Example Scenarios:
57
+ {scenarios_text}
58
+
59
+ Based on these examples, identify and return in JSON format:
60
+ 1. **scenario_context**: The general context or domain in which these conversations occur (e.g., "customer service", "educational settings", "workplace interactions")
61
+ 2. **conversational_task**: The primary goal or purpose these conversations aim to achieve (e.g., "resolve issues", "provide information", "give feedback")
62
+ 3. **participant_roles**: The typical participants involved in these conversations (e.g., "customer and support agent", "teacher and student", "manager and employee")
63
+
64
+ **
65
+ IMPORTANT: Please make sure to only return in JSON format, with the 'scenario_context', 'conversational_task', and 'participant_roles' keys.
66
+
67
+ Example JSON:
68
+ {{
69
+ "scenario_context": "Educational settings and academic discussions",
70
+ "conversational_task": "Explain concepts and answer questions",
71
+ "participant_roles": "Teacher and student, or peer students"
72
+ }}
73
+
74
+ The values MUST be STRINGS that capture the essence of the conversational patterns in the examples.
75
+ **
76
+
77
+ JSON:
78
+ """