Skip to content

Commit b564177

Browse files
authored
Conversation turn fix (Azure#34886)
* Reverting models to make sure calls to the simulator work * quotes * Spellcheck fixes * ignore the models for doc generation * Fixed the quotes on f strings * pylint skip file * Support for summarization * Adding a limit of 2 conversation turns for all but conversation simulators * exclude synthetic from mypy * Another lint fix * Skip the file causing linting issues * Bugfix on output to json_qa_lines and empty response from callbacks * Skip pylint * Add if/else on message to eval json util * max conversation turns defaulted to 1 and multiplied by 2 for coversation simulations * Param rename * Changed the usage of max_conversation_turns in the tests
1 parent 484c233 commit b564177

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

sdk/ai/azure-ai-generative/azure/ai/generative/synthetic/simulator/simulator/simulator.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ def _join_conversation_starter(self, parameters, to_join):
215215
async def simulate_async(
216216
self,
217217
template: "Template",
218-
max_conversation_turns: int = 2,
218+
max_conversation_turns: int = 1,
219219
parameters: Optional[List[dict]] = None,
220220
jailbreak: bool = False,
221221
api_call_retry_limit: int = 3,
222222
api_call_retry_sleep_sec: int = 1, # pylint: disable=unused-argument
223223
api_call_delay_sec: float = 0,
224224
concurrent_async_task: int = 3,
225-
simulation_result_limit: int = 3,
225+
max_simulation_results: int = 3,
226226
):
227227
"""Asynchronously simulate conversations using the provided template and parameters
228228
@@ -245,8 +245,8 @@ async def simulate_async(
245245
:paramtype api_call_delay_sec: float, optional
246246
:keyword concurrent_async_task: The maximum number of asynchronous tasks to run concurrently. Defaults to 3.
247247
:paramtype concurrent_async_task: int, optional
248-
:keyword simulation_result_limit: The maximum number of simulation results to return. Defaults to 3.
249-
:paramtype simulation_result_limit: int, optional
248+
:keyword max_simulation_results: The maximum number of simulation results to return. Defaults to 3.
249+
:paramtype max_simulation_results: int, optional
250250
251251
:return: A list of dictionaries containing the simulation results.
252252
:rtype: List[Dict]
@@ -267,6 +267,8 @@ async def simulate_async(
267267
)
268268
if "conversation" not in template.template_name:
269269
max_conversation_turns = 2
270+
else:
271+
max_conversation_turns = max_conversation_turns * 2
270272
if template.content_harm:
271273
self._ensure_service_dependencies()
272274
self.adversarial = True
@@ -283,15 +285,15 @@ async def simulate_async(
283285
tasks = []
284286
total_tasks = sum(len(t.template_parameters) for t in templates)
285287

286-
if simulation_result_limit > total_tasks and self.adversarial:
288+
if max_simulation_results > total_tasks and self.adversarial:
287289
logger.warning(
288290
"Cannot provide %s results due to maximum number of adversarial simulations that can be generated: %s."
289291
"\n %s simulations will be generated.",
290-
simulation_result_limit,
292+
max_simulation_results,
291293
total_tasks,
292294
total_tasks,
293295
)
294-
total_tasks = min(total_tasks, simulation_result_limit)
296+
total_tasks = min(total_tasks, max_simulation_results)
295297
progress_bar = tqdm(
296298
total=total_tasks,
297299
desc="generating simulations",
@@ -321,10 +323,10 @@ async def simulate_async(
321323
)
322324
)
323325

324-
if len(tasks) >= simulation_result_limit:
326+
if len(tasks) >= max_simulation_results:
325327
break
326328

327-
if len(tasks) >= simulation_result_limit:
329+
if len(tasks) >= max_simulation_results:
328330
break
329331

330332
sim_results = []

sdk/ai/azure-ai-generative/tests/simulator/unittests/test_simulator.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_simulator_returns_formatted_conversations(self, _, simulate_conversatio
108108
conv = simulator.simulate(
109109
template=conv_template,
110110
parameters=[task_parameters],
111-
max_conversation_turns=2)
111+
max_conversation_turns=1)
112112

113113
expected_keys = set(["messages", "$schema", "template_parameters"])
114114
assert issubclass(type(conv), list)
@@ -165,7 +165,7 @@ def test_simulator_from_openai_callback(self, to_chat_completion_model, mock_con
165165
conv = sim.simulate(
166166
template=conv_template,
167167
parameters=[task_parameters],
168-
max_conversation_turns=2)
168+
max_conversation_turns=1)
169169

170170
oai_mock.assert_called_once()
171171
assert(len(conv) == 1)
@@ -201,7 +201,7 @@ async def callback(cm):
201201
conv = sim.simulate(
202202
template=conv_template,
203203
parameters=[task_parameters],
204-
max_conversation_turns=2)
204+
max_conversation_turns=1)
205205

206206
assert(len(conv) == 1)
207207
assert(conv[0]["messages"][1]["content"] == content)
@@ -226,7 +226,7 @@ async def callback(cm):
226226
conv = sim.simulate(
227227
template=conv_template,
228228
parameters=[task_parameters],
229-
max_conversation_turns=2)
229+
max_conversation_turns=1)
230230

231231
assert(len(conv) == 1)
232232
assert(conv[0]["messages"][1]["content"] == content)
@@ -242,7 +242,7 @@ def test_simulator_throws_expected_error_from_incorrect_template_type(self, mock
242242
asyncio.set_event_loop(loop)
243243
loop.run_until_complete(simulator.simulate_async(
244244
template="wrong template type",
245-
max_conversation_turns=2,
245+
max_conversation_turns=1,
246246
parameters=[task_parameters]
247247
)
248248
)
@@ -274,4 +274,4 @@ def test_simulator_throws_expected_error_from_unset_ai_client_or_connection(self
274274
)
275275

276276
assert(str(all_none_exc_info.value).startswith("One and only one of the parameters [ai_client, simulator_connection]"))
277-
assert(str(all_set_exc_info.value).startswith("One and only one of the parameters [ai_client, simulator_connection]"))
277+
assert(str(all_set_exc_info.value).startswith("One and only one of the parameters [ai_client, simulator_connection]"))

0 commit comments

Comments
 (0)