Skip to content

Commit a99c07a

Browse files
authored
FIX: integration test fixes (microsoft#1185)
1 parent adb78a1 commit a99c07a

9 files changed

Lines changed: 44 additions & 45 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ recursive-include pyrit *.json
22
recursive-include pyrit *.prompt
33
recursive-include pyrit *.yaml
44
recursive-include pyrit/datasets/seed_prompts *
5-
recursive-include pyrit/datasets/score/scorer_evals *
5+
recursive-include pyrit/datasets/score/config/scorer_evals *
66
include pyrit/auxiliary_attacks/gcg/src/Dockerfile

doc/code/executor/promptgen/1_anecdoctor_generator.ipynb

Lines changed: 14 additions & 13 deletions
Large diffs are not rendered by default.

doc/code/executor/promptgen/1_anecdoctor_generator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
# extension: .py
66
# format_name: percent
77
# format_version: '1.3'
8-
# jupytext_version: 1.17.3
8+
# jupytext_version: 1.17.2
9+
# kernelspec:
10+
# display_name: pyrit-dev
11+
# language: python
12+
# name: python3
913
# ---
1014

1115
# %% [markdown]
@@ -130,13 +134,13 @@
130134
from pyrit.executor.promptgen import AnecdoctorContext
131135

132136

133-
def visualize_knowledge_graph(kg_result):
137+
def visualize_knowledge_graph(kg_result: str):
134138
"""
135139
Parses the knowledge graph result, converts it to a DataFrame, and visualizes it as a graph.
136140
"""
137141
# 1) Parse as JSON
138142
clean_output = kg_result.strip("`")
139-
clean_output = kg_result.replace("json\n", "") # Remove "json\n" if present
143+
clean_output = clean_output.replace("json\n", "") # Remove "json\n" if present
140144
data = json.loads(clean_output)
141145

142146
# 2) Convert to DataFrame

doc/code/targets/8_openai_responses_target.ipynb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
" \"tool_choice\": \"auto\",\n",
141141
" },\n",
142142
" httpx_client_kwargs={\"timeout\": 60.0},\n",
143-
" # api_version=None, # this can be uncommented if using api.openai.com\n",
144143
")\n",
145144
"\n",
146145
"# Build the user prompt\n",
@@ -302,7 +301,6 @@
302301
" endpoint=os.getenv(\"PLATFORM_OPENAI_RESPONSES_ENDPOINT\"),\n",
303302
" api_key=os.getenv(\"PLATFORM_OPENAI_RESPONSES_KEY\"),\n",
304303
" model_name=\"gpt-5\",\n",
305-
" api_version=None,\n",
306304
" extra_body_parameters={\"tools\": [grammar_tool], \"tool_choice\": \"required\"},\n",
307305
" temperature=1.0,\n",
308306
")\n",
@@ -311,7 +309,6 @@
311309
" endpoint=os.getenv(\"PLATFORM_OPENAI_RESPONSES_ENDPOINT\"),\n",
312310
" api_key=os.getenv(\"PLATFORM_OPENAI_RESPONSES_KEY\"),\n",
313311
" model_name=\"gpt-5\",\n",
314-
" api_version=None,\n",
315312
" temperature=1.0,\n",
316313
")\n",
317314
"\n",
@@ -331,14 +328,6 @@
331328
" if piece.original_value_data_type != \"reasoning\":\n",
332329
" print(f\"{idx} | {piece.role}: {piece.original_value}\")"
333330
]
334-
},
335-
{
336-
"cell_type": "code",
337-
"execution_count": null,
338-
"id": "8",
339-
"metadata": {},
340-
"outputs": [],
341-
"source": []
342331
}
343332
],
344333
"metadata": {

doc/code/targets/8_openai_responses_target.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# extension: .py
66
# format_name: percent
77
# format_version: '1.3'
8-
# jupytext_version: 1.17.3
8+
# jupytext_version: 1.17.2
99
# ---
1010

1111
# %% [markdown]
@@ -97,7 +97,6 @@ async def get_current_weather(args):
9797
"tool_choice": "auto",
9898
},
9999
httpx_client_kwargs={"timeout": 60.0},
100-
# api_version=None, # this can be uncommented if using api.openai.com
101100
)
102101

103102
# Build the user prompt
@@ -203,7 +202,6 @@ async def get_current_weather(args):
203202
endpoint=os.getenv("PLATFORM_OPENAI_RESPONSES_ENDPOINT"),
204203
api_key=os.getenv("PLATFORM_OPENAI_RESPONSES_KEY"),
205204
model_name="gpt-5",
206-
api_version=None,
207205
extra_body_parameters={"tools": [grammar_tool], "tool_choice": "required"},
208206
temperature=1.0,
209207
)
@@ -212,7 +210,6 @@ async def get_current_weather(args):
212210
endpoint=os.getenv("PLATFORM_OPENAI_RESPONSES_ENDPOINT"),
213211
api_key=os.getenv("PLATFORM_OPENAI_RESPONSES_KEY"),
214212
model_name="gpt-5",
215-
api_version=None,
216213
temperature=1.0,
217214
)
218215

@@ -231,5 +228,3 @@ async def get_current_weather(args):
231228
for idx, piece in enumerate(result.message_pieces):
232229
if piece.original_value_data_type != "reasoning":
233230
print(f"{idx} | {piece.role}: {piece.original_value}")
234-
235-
# %%

pyrit/datasets/sorry_bench_dataset.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT license.
33

44
import logging
5+
import os
56
from typing import List, Optional
67

78
from datasets import load_dataset
@@ -84,9 +85,11 @@
8485

8586

8687
def fetch_sorry_bench_dataset(
88+
*,
8789
cache_dir: Optional[str] = None,
8890
categories: Optional[List[str]] = None,
8991
prompt_style: Optional[str] = None,
92+
token: Optional[str] = None,
9093
) -> SeedDataset:
9194
"""
9295
Fetch Sorry-Bench dataset from Hugging Face (updated 2025/03 version).
@@ -97,23 +100,29 @@ def fetch_sorry_bench_dataset(
97100
Reference: https://arxiv.org/abs/2406.14598
98101
99102
Args:
100-
cache_dir: Optional cache directory for Hugging Face datasets
101-
categories: Optional list of categories to filter. Full list in:
103+
cache_dir (Optional[str]): Optional cache directory for Hugging Face datasets.
104+
categories (Optional[List[str]]): Optional list of categories to filter. Full list in:
102105
https://huggingface.co/datasets/sorry-bench/sorry-bench-202503/blob/main/meta_info.py
103-
prompt_style: Optional prompt style to filter. Available styles:
106+
prompt_style (Optional[str]): Optional prompt style to filter. Available styles:
104107
"base", "ascii", "caesar", "slang", "authority_endorsement", etc.
105108
Default: "base" (only base prompts, no mutations)
106109
Full list: https://huggingface.co/datasets/sorry-bench/sorry-bench-202503
110+
token (Optional[str]): Hugging Face authentication token. If not provided,
111+
will attempt to read from HUGGINGFACE_TOKEN environment variable. This is needed for
112+
accessing gated datasets on Hugging Face.
107113
108114
Returns:
109-
SeedDataset containing Sorry-Bench prompts with harm categories.
115+
SeedDataset: SeedDataset containing Sorry-Bench prompts with harm categories.
110116
111117
Raises:
112118
ValueError: If invalid categories or prompt_style are provided.
113119
"""
114120
if prompt_style is None:
115121
prompt_style = "base"
116122

123+
if token is None:
124+
token = os.environ.get("HUGGINGFACE_TOKEN")
125+
117126
if prompt_style not in VALID_PROMPT_STYLES:
118127
raise ValueError(f"Invalid prompt_style '{prompt_style}'. Must be one of: {', '.join(VALID_PROMPT_STYLES)}")
119128

@@ -128,7 +137,7 @@ def fetch_sorry_bench_dataset(
128137
try:
129138
source = "sorry-bench/sorry-bench-202503"
130139
logger.info(f"Loading Sorry-Bench dataset from {source}")
131-
data = load_dataset(source, cache_dir=cache_dir)
140+
data = load_dataset(source, cache_dir=cache_dir, token=token)
132141

133142
dataset_split = data["train"]
134143

pyrit/prompt_target/openai/openai_chat_target.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class OpenAIChatTarget(OpenAIChatTargetBase):
3434
endpoint (str): The endpoint for the OpenAI API
3535
model_name (str): The model name for the OpenAI API
3636
deployment_name (str): For Azure, the deployment name
37-
api_version (str): The api version for the OpenAI API
3837
temperature (float): The temperature for the completion
3938
max_completion_tokens (int): The maximum number of tokens to be returned by the model.
4039
The total length of input tokens and generated tokens is limited by

tests/integration/targets/test_openai_responses_gpt5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def test_openai_responses_gpt5(sqlite_instance):
1616
args = {
1717
"endpoint": os.getenv("AZURE_OPENAI_GPT5_RESPONSES_ENDPOINT"),
1818
"model_name": os.getenv("AZURE_OPENAI_GPT5_MODEL"),
19-
"api_key": os.getenv("AZURE_OPENAI_GPT5_RESPONSES_KEY"),
19+
"api_key": os.getenv("AZURE_OPENAI_GPT5_KEY"),
2020
}
2121

2222
target = OpenAIResponseTarget(**args)

tests/unit/datasets/test_sorry_bench_dataset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_fetch_sorry_bench_dataset_success(self, mock_load_dataset, mock_sorry_b
5151
mock_load_dataset.return_value = mock_dataset
5252

5353
# Call the function (defaults to base only)
54-
result = fetch_sorry_bench_dataset()
54+
result = fetch_sorry_bench_dataset(token="mock_token")
5555

5656
# Assertions
5757
assert isinstance(result, SeedDataset)
@@ -71,7 +71,7 @@ def test_fetch_sorry_bench_dataset_success(self, mock_load_dataset, mock_sorry_b
7171
assert "base" in prompt1.groups
7272

7373
# Verify load_dataset was called correctly
74-
mock_load_dataset.assert_called_once_with("sorry-bench/sorry-bench-202503", cache_dir=None)
74+
mock_load_dataset.assert_called_once_with("sorry-bench/sorry-bench-202503", cache_dir=None, token="mock_token")
7575

7676
@patch("pyrit.datasets.sorry_bench_dataset.load_dataset")
7777
def test_fetch_sorry_bench_dataset_ascii_style(self, mock_load_dataset, mock_sorry_bench_data):
@@ -211,10 +211,12 @@ def test_fetch_sorry_bench_dataset_custom_cache_dir(self, mock_load_dataset, moc
211211
mock_load_dataset.return_value = mock_dataset
212212

213213
custom_cache = "/custom/cache/path"
214-
result = fetch_sorry_bench_dataset(cache_dir=custom_cache)
214+
result = fetch_sorry_bench_dataset(cache_dir=custom_cache, token="mock_token")
215215

216216
assert isinstance(result, SeedDataset)
217-
mock_load_dataset.assert_called_once_with("sorry-bench/sorry-bench-202503", cache_dir=custom_cache)
217+
mock_load_dataset.assert_called_once_with(
218+
"sorry-bench/sorry-bench-202503", cache_dir=custom_cache, token="mock_token"
219+
)
218220

219221
def test_fetch_sorry_bench_dataset_invalid_prompt_style(self):
220222
"""Test error handling for invalid prompt_style."""

0 commit comments

Comments
 (0)