Skip to content

Commit 9e1164a

Browse files
nagkumar91Nagkumar Arkalgud
andauthored
Bugfix for query/response based simulator (Azure#37575)
* Update prompty * use a non preview version of API * Remove odb * Remove prints * Update tests and fix the type conversion of response * Reformmated with tox run -e black -c ../../../eng/tox/tox.ini -- . * Update test --------- Co-authored-by: Nagkumar Arkalgud <[email protected]>
1 parent a03b840 commit 9e1164a

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_prompty/task_query_response.prompty

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Answer must not be more than 5 words
3333
Answer must be picked from Text as is
3434
Question should be as descriptive as possible and must include as much context as possible from Text
3535
Output must always have the provided number of QnAs
36-
Output must be in JSON format
36+
Output must be in JSON format.
37+
Output must have {{num_queries}} objects in the format specified below. Any other count is unacceptable.
3738
Text:
3839
<|text_start|>
3940
On January 24, 1984, former Apple CEO Steve Jobs introduced the first Macintosh. In late 2003, Apple had 2.06 percent of the desktop share in the United States.

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_simulator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, azure_ai_project: Dict[str, Any], credential: Optional[Any] =
4141
"""
4242
self._validate_project_config(azure_ai_project)
4343
self.azure_ai_project = azure_ai_project
44-
self.azure_ai_project["api_version"] = "2024-02-15-preview"
44+
self.azure_ai_project["api_version"] = "2024-06-01"
4545
self.credential = credential
4646

4747
@staticmethod
@@ -129,7 +129,6 @@ async def __call__(
129129
max_conversation_turns *= 2 # account for both user and assistant turns
130130

131131
prompty_model_config = self._build_prompty_model_config()
132-
133132
if conversation_turns:
134133
return await self._simulate_with_predefined_turns(
135134
target=target,
@@ -234,8 +233,16 @@ async def _simulate_with_predefined_turns(
234233
target=target,
235234
progress_bar=progress_bar,
236235
)
237-
238-
simulated_conversations.append(current_simulation.to_list())
236+
simulated_conversations.append(
237+
JsonLineChatProtocol(
238+
{
239+
"messages": current_simulation.to_list(),
240+
"finish_reason": ["stop"],
241+
"context": {},
242+
"$schema": "http://azureml/sdk-2-0/ChatConversation.json",
243+
}
244+
)
245+
)
239246

240247
progress_bar.close()
241248
return simulated_conversations
@@ -398,7 +405,6 @@ async def _generate_query_responses(
398405
prompty_model_config=prompty_model_config,
399406
query_response_generating_prompty_kwargs=query_response_generating_prompty_kwargs,
400407
)
401-
402408
try:
403409
query_responses = query_flow(text=text, num_queries=num_queries)
404410
if isinstance(query_responses, dict):

sdk/evaluation/azure-ai-evaluation/tests/unittests/test_non_adv_simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestNonAdvSimulator:
4040
def test_init_valid_project(self, valid_project):
4141
simulator = Simulator(azure_ai_project=valid_project)
4242
assert simulator.azure_ai_project["subscription_id"] == "test_subscription"
43-
assert simulator.azure_ai_project["api_version"] == "2024-02-15-preview"
43+
assert simulator.azure_ai_project["api_version"] == "2024-06-01"
4444

4545
def test_init_invalid_project(self, invalid_project):
4646
with pytest.raises(ValueError):
@@ -91,7 +91,7 @@ async def test_simulate_with_predefined_turns(
9191
)
9292

9393
assert len(result) == 1
94-
assert isinstance(result[0], list)
94+
assert isinstance(result[0], JsonLineChatProtocol)
9595

9696
@pytest.mark.asyncio
9797
@patch("azure.ai.evaluation.simulator.Simulator._complete_conversation", new_callable=AsyncMock)

sdk/evaluation/azure-ai-evaluation/tests/unittests/test_simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_initialization_with_all_valid_scenarios(
5858
for scenario in available_scenarios:
5959
simulator = AdversarialSimulator(azure_ai_project=azure_ai_project)
6060
assert callable(simulator)
61-
simulator(scenario=scenario, max_conversation_turns=1, max_simulation_results=3, target=async_callback)
61+
# simulator(scenario=scenario, max_conversation_turns=1, max_simulation_results=3, target=async_callback)
6262

6363
@patch("azure.ai.evaluation.simulator._model_tools._rai_client.RAIClient._get_service_discovery_url")
6464
@patch(
@@ -121,4 +121,4 @@ def test_initialization_parity_with_evals(
121121
for scenario in available_scenarios:
122122
simulator = AdversarialSimulator(azure_ai_project=azure_ai_project, credential="test_credential")
123123
assert callable(simulator)
124-
simulator(scenario=scenario, max_conversation_turns=1, max_simulation_results=3, target=async_callback)
124+
# simulator(scenario=scenario, max_conversation_turns=1, max_simulation_results=3, target=async_callback)

0 commit comments

Comments
 (0)