Skip to content

Commit

Permalink
some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KutalVolkan committed Feb 1, 2025
1 parent 00ac5de commit 97c20ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 84 deletions.
96 changes: 13 additions & 83 deletions doc/code/converters/pdf_converter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{'__type__': 'TextTarget', '__module__': 'pyrit.prompt_target.text_target'}: user: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380366071865.pdf\n",
"\u001b[1m\u001b[34muser: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380366071865.pdf\n"
"{'__type__': 'TextTarget', '__module__': 'pyrit.prompt_target.text_target'}: user: https://airtstorageaccountdev.blob.core.windows.net/dbdata/prompt-memory-entries/urls/1736273802673024.pdf\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[34muser: https://airtstorageaccountdev.blob.core.windows.net/dbdata/prompt-memory-entries/urls/1736273802673024.pdf\n"
]
}
],
Expand Down Expand Up @@ -115,14 +121,14 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{'__type__': 'TextTarget', '__module__': 'pyrit.prompt_target.text_target'}: user: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380368779812.pdf\n"
"{'__type__': 'TextTarget', '__module__': 'pyrit.prompt_target.text_target'}: user: https://airtstorageaccountdev.blob.core.windows.net/dbdata/prompt-memory-entries/urls/1736273817760662.pdf\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[34muser: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380368779812.pdf\n"
"\u001b[1m\u001b[34muser: https://airtstorageaccountdev.blob.core.windows.net/dbdata/prompt-memory-entries/urls/1736273817760662.pdf\n"
]
}
],
Expand Down Expand Up @@ -156,86 +162,10 @@
"await orchestrator.print_conversations_async() # type: ignore"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"# Modify Existing PDF with Injection Items"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[19:26:19][41][ai-red-team][INFO][Processing page 0 with 2 injection items.]\n",
"[19:26:19][41][ai-red-team][INFO][Processing page 1 with 2 injection items.]\n",
"[19:26:19][49][ai-red-team][INFO][Processing page 2 with 2 injection items.]\n",
"{'__type__': 'TextTarget', '__module__': 'pyrit.prompt_target.text_target'}: user: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380379051518.pdf\n",
"\u001b[1m\u001b[34muser: D:\\git\\PyRIT-internal\\PyRIT\\dbdata\\prompt-memory-entries\\urls\\1738380379051518.pdf\n"
]
}
],
"source": [
"from pyrit.common import IN_MEMORY, initialize_pyrit\n",
"from pyrit.orchestrator import PromptSendingOrchestrator\n",
"from pyrit.prompt_converter import PDFConverter\n",
"from pyrit.prompt_target import TextTarget\n",
"\n",
"initialize_pyrit(memory_db_type=IN_MEMORY)\n",
"\n",
"cv_pdf_path = pathlib.Path(DATASETS_PATH) / \"prompt_converters\" / \"pdf_converters\" / \"fake_CV.pdf\"\n",
"\n",
"# Define injection items\n",
"injection_items = [\n",
" {\"page\": 0, \"x\": 50, \"y\": 700, \"text\": \"Injected Text\", \"font_size\": 12, \"font\": \"Helvetica\", \"font_color\": (255, 0, 0)}, # Red text\n",
" {\"page\": 1, \"x\": 100, \"y\": 600, \"text\": \"Confidential\", \"font_size\": 10, \"font\": \"Helvetica\", \"font_color\": (0, 0, 255)} # Blue text\n",
"]\n",
"\n",
"# Define a simple string prompt (no templates)\n",
"prompt = \"This is a simple test string for PDF generation. No templates here!\"\n",
"\n",
"# Initialize the TextTarget (mock target for testing)\n",
"prompt_target = TextTarget()\n",
"\n",
"# Initialize the PDFConverter with the existing PDF and injection items\n",
"pdf_converter = PDFConverter(\n",
" prompt_template=None, # No template provided\n",
" font_type=\"Arial\",\n",
" font_size=12,\n",
" page_width=210,\n",
" page_height=297,\n",
" existing_pdf=cv_pdf_path, # Provide the existing PDF\n",
" injection_items=injection_items, # Provide the injection items\n",
")\n",
"\n",
"# Define the list of prompts as strings (required by PromptSendingOrchestrator)\n",
"prompts = [prompt]\n",
"\n",
"# Initialize the orchestrator\n",
"orchestrator = PromptSendingOrchestrator(\n",
" objective_target=prompt_target,\n",
" prompt_converters=[pdf_converter],\n",
" verbose=False,\n",
")\n",
"\n",
"# Run the orchestrator to modify the PDF and inspect the result\n",
"await orchestrator.send_prompts_async(prompt_list=prompts) # type: ignore\n",
"await orchestrator.print_conversations_async() # type: ignore"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,7 +178,7 @@
"cell_metadata_filter": "-all"
},
"kernelspec": {
"display_name": "pyrit-312",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -262,7 +192,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion doc/code/orchestrators/1_prompt_sending_orchestrator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 97c20ae

Please sign in to comment.