Skip to content

Commit 4748750

Browse files
authored
FIX: integration tests and ImageTarget refactor (#1293)
1 parent 97ebac5 commit 4748750

13 files changed

Lines changed: 1270 additions & 1789 deletions

File tree

.env_example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ AZURE_FOUNDRY_DEEPSEEK_KEY="xxxxx"
4141
AZURE_FOUNDRY_PHI4_ENDPOINT="https://xxxxx.models.ai.azure.com"
4242
AZURE_CHAT_PHI4_KEY="xxxxx"
4343

44-
AZURE_FOUNDRY_MINSTRAL3B_ENDPOINT="https://xxxxx.eastus2.models.ai.azure.com"
45-
AZURE_CHAT_MINSTRAL3B_KEY="xxxxx"
44+
AZURE_FOUNDRY_MISTRAL_LARGE_ENDPOINT="https://xxxxx.services.ai.azure.com/openai/v1/"
45+
AZURE_FOUNDRY_MISTRAL_LARGE_KEY="xxxxx"
46+
AZURE_FOUNDRY_MISTRAL_LARGE_MODEL="Mistral-Large-3"
4647

4748
GROQ_ENDPOINT="https://api.groq.com/openai/v1"
4849
GROQ_KEY="gsk_xxxxxxxx"

doc/code/targets/5_multi_modal_targets.ipynb

Lines changed: 753 additions & 57 deletions
Large diffs are not rendered by default.

doc/code/targets/5_multi_modal_targets.py

Lines changed: 57 additions & 59 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.18.1
9+
# kernelspec:
10+
# display_name: pyrit (3.13.5)
11+
# language: python
12+
# name: python3
913
# ---
1014

1115
# %% [markdown]
@@ -35,14 +39,6 @@
3539
objective = "Give me an image of a raccoon pirate as a Spanish baker in Spain"
3640

3741
img_prompt_target = OpenAIImageTarget()
38-
# For Azure OpenAI with Entra ID authentication enabled, use the following command instead. Make sure to run `az login` first.
39-
# from pyrit.auth import get_azure_openai_auth
40-
# endpoint = "https://your-endpoint.openai.azure.com"
41-
# target = OpenAIChatTarget(
42-
# endpoint=endpoint,
43-
# api_key=get_azure_openai_auth(endpoint),
44-
# model_name="your-deployment-name"
45-
# )
4642

4743
image_scorer = SelfAskTrueFalseScorer(
4844
chat_target=OpenAIChatTarget(),
@@ -98,57 +94,60 @@
9894
#
9995
# This example demonstrates how to use the video target to create a video from a text-based prompt.
10096
#
101-
# from pyrit.executor.attack import (
102-
# AttackExecutor,
103-
# AttackScoringConfig,
104-
# ConsoleAttackResultPrinter,
105-
# PromptSendingAttack,
106-
# )
107-
# from pyrit.prompt_target import OpenAIChatTarget, OpenAIVideoTarget
108-
# from pyrit.score import (
109-
# AzureContentFilterScorer,
110-
# SelfAskTrueFalseScorer,
111-
# TrueFalseQuestion,
112-
# VideoFloatScaleScorer,
113-
# VideoTrueFalseScorer,
114-
# )
115-
# from pyrit.setup import IN_MEMORY, initialize_pyrit_async
116-
#
117-
# await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore
118-
#
119-
# objectives = [
120-
# "Video of a raccoon pirate eating flan at a cafe in Spain",
121-
# "Video of a raccoon pirate eating a croissant at a cafe in France",
122-
# ]
123-
#
124-
# video_target = OpenAIVideoTarget()
125-
# objective_scorer = SelfAskTrueFalseScorer(
126-
# chat_target=OpenAIChatTarget(),
127-
# true_false_question=TrueFalseQuestion(true_description="A raccoon dressed as a pirate is actively eating a pastry"),
128-
# )
129-
#
130-
# video_scorer = VideoTrueFalseScorer(
131-
# image_capable_scorer=objective_scorer,
132-
# num_sampled_frames=10,
133-
# )
134-
#
135-
# attack = PromptSendingAttack(
136-
# objective_target=video_target,
137-
# attack_scoring_config=AttackScoringConfig(
138-
# objective_scorer=video_scorer,
139-
# auxiliary_scorers=[VideoFloatScaleScorer(image_capable_scorer=AzureContentFilterScorer())],
140-
# ),
141-
# )
142-
#
143-
# results = await AttackExecutor().execute_attack_async( # type: ignore
144-
# attack=attack,
145-
# objectives=objectives,
146-
# )
147-
#
148-
# for result in results:
149-
# await ConsoleAttackResultPrinter().print_result_async(result=result, include_auxiliary_scores=True) # type: ignore
15097

15198

99+
# %%
100+
101+
from pyrit.executor.attack import (
102+
AttackExecutor,
103+
AttackScoringConfig,
104+
ConsoleAttackResultPrinter,
105+
PromptSendingAttack,
106+
)
107+
from pyrit.prompt_target import OpenAIChatTarget, OpenAIVideoTarget
108+
from pyrit.score import (
109+
AzureContentFilterScorer,
110+
SelfAskTrueFalseScorer,
111+
TrueFalseQuestion,
112+
VideoFloatScaleScorer,
113+
VideoTrueFalseScorer,
114+
)
115+
from pyrit.setup import IN_MEMORY, initialize_pyrit_async
116+
117+
await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore
118+
119+
objectives = [
120+
"Video of a raccoon pirate eating flan at a cafe in Spain",
121+
"Video of a raccoon pirate eating a croissant at a cafe in France",
122+
]
123+
124+
video_target = OpenAIVideoTarget()
125+
objective_scorer = SelfAskTrueFalseScorer(
126+
chat_target=OpenAIChatTarget(),
127+
true_false_question=TrueFalseQuestion(true_description="A raccoon dressed as a pirate is actively eating a pastry"),
128+
)
129+
130+
video_scorer = VideoTrueFalseScorer(
131+
image_capable_scorer=objective_scorer,
132+
num_sampled_frames=10,
133+
)
134+
135+
attack = PromptSendingAttack(
136+
objective_target=video_target,
137+
attack_scoring_config=AttackScoringConfig(
138+
objective_scorer=video_scorer,
139+
auxiliary_scorers=[VideoFloatScaleScorer(image_capable_scorer=AzureContentFilterScorer())],
140+
),
141+
)
142+
143+
results = await AttackExecutor().execute_attack_async( # type: ignore
144+
attack=attack,
145+
objectives=objectives,
146+
)
147+
148+
for result in results:
149+
await ConsoleAttackResultPrinter().print_result_async(result=result, include_auxiliary_scores=True) # type: ignore
150+
152151
# %% [markdown]
153152
# ## OpenAI Chat Target (Text + Image --> Text)
154153
# This demo showcases the capabilities of `AzureOpenAIGPT4OChatTarget` for generating text based on multimodal inputs, including both text and images.
@@ -179,7 +178,6 @@
179178
image_path = str(pathlib.Path(".") / ".." / ".." / ".." / "assets" / "pyrit_architecture.png")
180179

181180
# This is a single request with two parts, one image and one text
182-
183181
seed = SeedGroup(
184182
seeds=[
185183
SeedPrompt(

0 commit comments

Comments
 (0)