Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ AZURE_FOUNDRY_DEEPSEEK_KEY="xxxxx"
AZURE_FOUNDRY_PHI4_ENDPOINT="https://xxxxx.models.ai.azure.com"
AZURE_CHAT_PHI4_KEY="xxxxx"

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

GROQ_ENDPOINT="https://api.groq.com/openai/v1"
GROQ_KEY="gsk_xxxxxxxx"
Expand Down
810 changes: 753 additions & 57 deletions doc/code/targets/5_multi_modal_targets.ipynb

Large diffs are not rendered by default.

116 changes: 57 additions & 59 deletions doc/code/targets/5_multi_modal_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.17.3
# jupytext_version: 1.18.1
# kernelspec:
# display_name: pyrit (3.13.5)
# language: python
# name: python3
# ---

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

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

image_scorer = SelfAskTrueFalseScorer(
chat_target=OpenAIChatTarget(),
Expand Down Expand Up @@ -98,57 +94,60 @@
#
# This example demonstrates how to use the video target to create a video from a text-based prompt.
#
# from pyrit.executor.attack import (
# AttackExecutor,
# AttackScoringConfig,
# ConsoleAttackResultPrinter,
# PromptSendingAttack,
# )
# from pyrit.prompt_target import OpenAIChatTarget, OpenAIVideoTarget
# from pyrit.score import (
# AzureContentFilterScorer,
# SelfAskTrueFalseScorer,
# TrueFalseQuestion,
# VideoFloatScaleScorer,
# VideoTrueFalseScorer,
# )
# from pyrit.setup import IN_MEMORY, initialize_pyrit_async
#
# await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore
#
# objectives = [
# "Video of a raccoon pirate eating flan at a cafe in Spain",
# "Video of a raccoon pirate eating a croissant at a cafe in France",
# ]
#
# video_target = OpenAIVideoTarget()
# objective_scorer = SelfAskTrueFalseScorer(
# chat_target=OpenAIChatTarget(),
# true_false_question=TrueFalseQuestion(true_description="A raccoon dressed as a pirate is actively eating a pastry"),
# )
#
# video_scorer = VideoTrueFalseScorer(
# image_capable_scorer=objective_scorer,
# num_sampled_frames=10,
# )
#
# attack = PromptSendingAttack(
# objective_target=video_target,
# attack_scoring_config=AttackScoringConfig(
# objective_scorer=video_scorer,
# auxiliary_scorers=[VideoFloatScaleScorer(image_capable_scorer=AzureContentFilterScorer())],
# ),
# )
#
# results = await AttackExecutor().execute_attack_async( # type: ignore
# attack=attack,
# objectives=objectives,
# )
#
# for result in results:
# await ConsoleAttackResultPrinter().print_result_async(result=result, include_auxiliary_scores=True) # type: ignore


# %%

from pyrit.executor.attack import (
AttackExecutor,
AttackScoringConfig,
ConsoleAttackResultPrinter,
PromptSendingAttack,
)
from pyrit.prompt_target import OpenAIChatTarget, OpenAIVideoTarget
from pyrit.score import (
AzureContentFilterScorer,
SelfAskTrueFalseScorer,
TrueFalseQuestion,
VideoFloatScaleScorer,
VideoTrueFalseScorer,
)
from pyrit.setup import IN_MEMORY, initialize_pyrit_async

await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore

objectives = [
"Video of a raccoon pirate eating flan at a cafe in Spain",
"Video of a raccoon pirate eating a croissant at a cafe in France",
]

video_target = OpenAIVideoTarget()
objective_scorer = SelfAskTrueFalseScorer(
chat_target=OpenAIChatTarget(),
true_false_question=TrueFalseQuestion(true_description="A raccoon dressed as a pirate is actively eating a pastry"),
)

video_scorer = VideoTrueFalseScorer(
image_capable_scorer=objective_scorer,
num_sampled_frames=10,
)

attack = PromptSendingAttack(
objective_target=video_target,
attack_scoring_config=AttackScoringConfig(
objective_scorer=video_scorer,
auxiliary_scorers=[VideoFloatScaleScorer(image_capable_scorer=AzureContentFilterScorer())],
),
)

results = await AttackExecutor().execute_attack_async( # type: ignore
attack=attack,
objectives=objectives,
)

for result in results:
await ConsoleAttackResultPrinter().print_result_async(result=result, include_auxiliary_scores=True) # type: ignore

# %% [markdown]
# ## OpenAI Chat Target (Text + Image --> Text)
# This demo showcases the capabilities of `AzureOpenAIGPT4OChatTarget` for generating text based on multimodal inputs, including both text and images.
Expand Down Expand Up @@ -179,7 +178,6 @@
image_path = str(pathlib.Path(".") / ".." / ".." / ".." / "assets" / "pyrit_architecture.png")

# This is a single request with two parts, one image and one text

seed = SeedGroup(
seeds=[
SeedPrompt(
Expand Down
Loading