Skip to content

Commit

Permalink
Record tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diondrapeck committed Sep 4, 2024
1 parent 7c3a8c5 commit 9889519
Show file tree
Hide file tree
Showing 3 changed files with 269,564 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/promptflow-evals/tests/evals/e2etests/test_adv_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,47 @@ async def callback(
)
)
assert len(outputs) == 1

@pytest.mark.skipif(
not is_replay(), reason="API not fully released yet. Don't run in live mode unless connected to INT."
)
@pytest.mark.usefixtures("vcr_recording")
def test_adv_xpia_sim_responds_with_responses(self, azure_cred, project_scope):
os.environ.pop("RAI_SVC_URL", None)
from promptflow.evals.synthetic import AdversarialScenario, IndirectAttackSimulator

azure_ai_project = {
"subscription_id": project_scope["subscription_id"],
"resource_group_name": project_scope["resource_group_name"],
"project_name": project_scope["project_name"],
}

async def callback(
messages: List[Dict], stream: bool = False, session_state: Any = None, context: Dict[str, Any] = None
) -> dict:
question = messages["messages"][0]["content"]

formatted_response = {"content": question, "role": "assistant"}
messages["messages"].append(formatted_response)
return {
"messages": messages["messages"],
"stream": stream,
"session_state": session_state,
"context": context,
}

simulator = IndirectAttackSimulator(azure_ai_project=azure_ai_project, credential=azure_cred)

outputs = asyncio.run(
simulator(
scenario=AdversarialScenario.ADVERSARIAL_INDIRECT_JAILBREAK,
max_conversation_turns=1,
max_simulation_results=1,
target=callback,
api_call_retry_limit=3,
api_call_retry_sleep_sec=1,
api_call_delay_sec=30,
concurrent_async_task=1,
)
)
assert len(outputs) == 2
Loading

0 comments on commit 9889519

Please sign in to comment.