From fa998d965dd3c4598b90ce34a257b8f51aacd47c Mon Sep 17 00:00:00 2001 From: Roman Lutz Date: Mon, 22 Dec 2025 16:31:13 -0800 Subject: [PATCH] remove dispose calls in docs --- doc/code/converters/0_converters.ipynb | 14 -------------- doc/code/converters/0_converters.py | 8 -------- doc/code/converters/3_audio_converters.ipynb | 13 ------------- doc/code/converters/3_audio_converters.py | 6 ------ doc/code/converters/4_image_converters.ipynb | 13 ------------- doc/code/converters/4_image_converters.py | 6 ------ doc/code/converters/6_human_converter.ipynb | 14 -------------- doc/code/converters/6_human_converter.py | 7 ------- .../transparency_attack_converter.ipynb | 14 -------------- .../transparency_attack_converter.py | 7 ------- .../executor/attack/3_crescendo_attack.ipynb | 13 ------------- doc/code/executor/attack/3_crescendo_attack.py | 7 ------- .../executor/workflow/1_xpia_website.ipynb | 18 ------------------ doc/code/executor/workflow/1_xpia_website.py | 3 --- doc/code/memory/1_sqlite_memory.ipynb | 4 +--- doc/code/memory/1_sqlite_memory.py | 2 -- .../memory/2_basic_memory_programming.ipynb | 5 +---- doc/code/memory/2_basic_memory_programming.py | 3 --- doc/code/memory/6_azure_sql_memory.ipynb | 6 +----- doc/code/memory/6_azure_sql_memory.py | 4 ---- doc/code/targets/playwright_target.ipynb | 14 -------------- doc/code/targets/playwright_target.py | 7 ------- .../targets/playwright_target_copilot.ipynb | 14 -------------- doc/code/targets/playwright_target_copilot.py | 7 ------- .../targets/use_huggingface_chat_target.ipynb | 13 ------------- .../targets/use_huggingface_chat_target.py | 6 ------ 26 files changed, 3 insertions(+), 225 deletions(-) diff --git a/doc/code/converters/0_converters.ipynb b/doc/code/converters/0_converters.ipynb index 6820b2a302..27db35f95c 100644 --- a/doc/code/converters/0_converters.ipynb +++ b/doc/code/converters/0_converters.ipynb @@ -79,20 +79,6 @@ "print(await BinaryConverter().convert_tokens_async(prompt=prompt)) # type: ignore\n", "print(await FirstLetterConverter().convert_tokens_async(prompt=prompt)) # type: ignore" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "# Close connection\n", - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/converters/0_converters.py b/doc/code/converters/0_converters.py index d0e7dd6019..213745bf4b 100644 --- a/doc/code/converters/0_converters.py +++ b/doc/code/converters/0_converters.py @@ -44,11 +44,3 @@ print(await AsciiArtConverter().convert_tokens_async(prompt=prompt)) # type: ignore print(await BinaryConverter().convert_tokens_async(prompt=prompt)) # type: ignore print(await FirstLetterConverter().convert_tokens_async(prompt=prompt)) # type: ignore - - -# %% -# Close connection -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/converters/3_audio_converters.ipynb b/doc/code/converters/3_audio_converters.ipynb index 75f2c754d2..aa8fa0a8f9 100644 --- a/doc/code/converters/3_audio_converters.ipynb +++ b/doc/code/converters/3_audio_converters.ipynb @@ -128,19 +128,6 @@ "\n", "print(converted_audio_file)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/converters/3_audio_converters.py b/doc/code/converters/3_audio_converters.py index 26bb5d7b20..c38d5efcef 100644 --- a/doc/code/converters/3_audio_converters.py +++ b/doc/code/converters/3_audio_converters.py @@ -78,9 +78,3 @@ converted_audio_file = await audio_frequency_converter.convert_async(prompt=prompt) # type: ignore print(converted_audio_file) - -# %% -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/converters/4_image_converters.ipynb b/doc/code/converters/4_image_converters.ipynb index ece34af1f6..a901c76fd6 100644 --- a/doc/code/converters/4_image_converters.ipynb +++ b/doc/code/converters/4_image_converters.ipynb @@ -69,19 +69,6 @@ "image = Image.open(image_path)\n", "display(image)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/converters/4_image_converters.py b/doc/code/converters/4_image_converters.py index 0f0cbf1810..66e977ba34 100644 --- a/doc/code/converters/4_image_converters.py +++ b/doc/code/converters/4_image_converters.py @@ -37,9 +37,3 @@ image_path = output_image_file.output_text image = Image.open(image_path) display(image) - -# %% -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/converters/6_human_converter.ipynb b/doc/code/converters/6_human_converter.ipynb index d8032aa714..c65322d093 100644 --- a/doc/code/converters/6_human_converter.ipynb +++ b/doc/code/converters/6_human_converter.ipynb @@ -414,20 +414,6 @@ "result = await red_teaming_attack.execute_async(objective=conversation_objective) # type: ignore\n", "await ConsoleAttackResultPrinter().print_conversation_async(result=result) # type: ignore" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "# Close connection\n", - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/converters/6_human_converter.py b/doc/code/converters/6_human_converter.py index 3defd429f2..7e03b8188b 100644 --- a/doc/code/converters/6_human_converter.py +++ b/doc/code/converters/6_human_converter.py @@ -101,10 +101,3 @@ result = await red_teaming_attack.execute_async(objective=conversation_objective) # type: ignore await ConsoleAttackResultPrinter().print_conversation_async(result=result) # type: ignore - -# %% -# Close connection -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/converters/transparency_attack_converter.ipynb b/doc/code/converters/transparency_attack_converter.ipynb index c85d66d034..05b8bbff47 100644 --- a/doc/code/converters/transparency_attack_converter.ipynb +++ b/doc/code/converters/transparency_attack_converter.ipynb @@ -263,20 +263,6 @@ "\n", "If the model responds to the attack content (bomb-making) rather than the benign content (cake baking), the transparency attack was successful. This vulnerability underscores potential security risks: attackers could bypass content filters, poison training datasets, or mislead AI systems by disguising harmful material as benign." ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "14", - "metadata": {}, - "outputs": [], - "source": [ - "# Close connection\n", - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/converters/transparency_attack_converter.py b/doc/code/converters/transparency_attack_converter.py index 18eb21ae7d..f326f97b28 100644 --- a/doc/code/converters/transparency_attack_converter.py +++ b/doc/code/converters/transparency_attack_converter.py @@ -150,10 +150,3 @@ # ## Analyzing the Results # # If the model responds to the attack content (bomb-making) rather than the benign content (cake baking), the transparency attack was successful. This vulnerability underscores potential security risks: attackers could bypass content filters, poison training datasets, or mislead AI systems by disguising harmful material as benign. - -# %% -# Close connection -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/executor/attack/3_crescendo_attack.ipynb b/doc/code/executor/attack/3_crescendo_attack.ipynb index 24f45b2a2d..f1536cbd46 100644 --- a/doc/code/executor/attack/3_crescendo_attack.ipynb +++ b/doc/code/executor/attack/3_crescendo_attack.ipynb @@ -1441,19 +1441,6 @@ " await ConsoleAttackResultPrinter().print_result_async(result=result) # type: ignore\n", "\"\"\"" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/executor/attack/3_crescendo_attack.py b/doc/code/executor/attack/3_crescendo_attack.py index f09944d0c9..def9e24a27 100644 --- a/doc/code/executor/attack/3_crescendo_attack.py +++ b/doc/code/executor/attack/3_crescendo_attack.py @@ -89,10 +89,3 @@ for result in results: await ConsoleAttackResultPrinter().print_result_async(result=result) # type: ignore """ - - -# %% -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/executor/workflow/1_xpia_website.ipynb b/doc/code/executor/workflow/1_xpia_website.ipynb index 197e3d0064..4f2bbc6275 100644 --- a/doc/code/executor/workflow/1_xpia_website.ipynb +++ b/doc/code/executor/workflow/1_xpia_website.ipynb @@ -753,24 +753,6 @@ "print(f\"Attack result status: {result.status}\")\n", "print(f\"Response from processing callback: {processing_response}\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "INFO:pyrit.memory.sqlite_memory:Engine disposed and all connections closed.\n" - ] - } - ], - "source": [ - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/executor/workflow/1_xpia_website.py b/doc/code/executor/workflow/1_xpia_website.py index ac03b3f4b3..4c72dca1d4 100644 --- a/doc/code/executor/workflow/1_xpia_website.py +++ b/doc/code/executor/workflow/1_xpia_website.py @@ -169,6 +169,3 @@ async def processing_callback() -> str: print(f"Attack result status: {result.status}") print(f"Response from processing callback: {processing_response}") - -# %% -memory.dispose_engine() diff --git a/doc/code/memory/1_sqlite_memory.ipynb b/doc/code/memory/1_sqlite_memory.ipynb index 1681dfcf11..9a20766708 100644 --- a/doc/code/memory/1_sqlite_memory.ipynb +++ b/doc/code/memory/1_sqlite_memory.ipynb @@ -132,9 +132,7 @@ "\n", "# Use in-memory database to avoid file corruption issues\n", "memory = SQLiteMemory(db_path=\":memory:\")\n", - "memory.print_schema()\n", - "\n", - "memory.dispose_engine()" + "memory.print_schema()" ] } ], diff --git a/doc/code/memory/1_sqlite_memory.py b/doc/code/memory/1_sqlite_memory.py index 6578d3da17..7da93d9c81 100644 --- a/doc/code/memory/1_sqlite_memory.py +++ b/doc/code/memory/1_sqlite_memory.py @@ -22,5 +22,3 @@ # Use in-memory database to avoid file corruption issues memory = SQLiteMemory(db_path=":memory:") memory.print_schema() - -memory.dispose_engine() diff --git a/doc/code/memory/2_basic_memory_programming.ipynb b/doc/code/memory/2_basic_memory_programming.ipynb index 3cecd93ba3..22e7d33894 100644 --- a/doc/code/memory/2_basic_memory_programming.ipynb +++ b/doc/code/memory/2_basic_memory_programming.ipynb @@ -57,10 +57,7 @@ "entries = memory.get_conversation(conversation_id=conversation_id)\n", "\n", "for entry in entries:\n", - " print(entry)\n", - "\n", - "# Cleanup memory resources\n", - "memory.dispose_engine()" + " print(entry)" ] } ], diff --git a/doc/code/memory/2_basic_memory_programming.py b/doc/code/memory/2_basic_memory_programming.py index 845096d1b5..4aed9bbf88 100644 --- a/doc/code/memory/2_basic_memory_programming.py +++ b/doc/code/memory/2_basic_memory_programming.py @@ -46,6 +46,3 @@ for entry in entries: print(entry) - -# Cleanup memory resources -memory.dispose_engine() diff --git a/doc/code/memory/6_azure_sql_memory.ipynb b/doc/code/memory/6_azure_sql_memory.ipynb index 86c18174b8..7aff4a5cf4 100644 --- a/doc/code/memory/6_azure_sql_memory.ipynb +++ b/doc/code/memory/6_azure_sql_memory.ipynb @@ -183,11 +183,7 @@ "entries = memory.get_conversation(conversation_id=conversation_id)\n", "\n", "for entry in entries:\n", - " print(entry)\n", - "\n", - "\n", - "# Cleanup memory resources\n", - "memory.dispose_engine()" + " print(entry)" ] } ], diff --git a/doc/code/memory/6_azure_sql_memory.py b/doc/code/memory/6_azure_sql_memory.py index 19f54f322a..bf6138a243 100644 --- a/doc/code/memory/6_azure_sql_memory.py +++ b/doc/code/memory/6_azure_sql_memory.py @@ -83,7 +83,3 @@ for entry in entries: print(entry) - - -# Cleanup memory resources -memory.dispose_engine() diff --git a/doc/code/targets/playwright_target.ipynb b/doc/code/targets/playwright_target.ipynb index 75d35c1a72..008091dc55 100644 --- a/doc/code/targets/playwright_target.ipynb +++ b/doc/code/targets/playwright_target.ipynb @@ -275,20 +275,6 @@ "flask_process.wait() # Ensure the process has terminated\n", "print(\"Flask app has been terminated.\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9", - "metadata": {}, - "outputs": [], - "source": [ - "# Close connection to memory\n", - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/targets/playwright_target.py b/doc/code/targets/playwright_target.py index 07ab01932e..740dcbffdf 100644 --- a/doc/code/targets/playwright_target.py +++ b/doc/code/targets/playwright_target.py @@ -183,10 +183,3 @@ async def run() -> None: flask_process.terminate() flask_process.wait() # Ensure the process has terminated print("Flask app has been terminated.") - -# %% -# Close connection to memory -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/targets/playwright_target_copilot.ipynb b/doc/code/targets/playwright_target_copilot.ipynb index e1bf0320ec..3c890c37cc 100644 --- a/doc/code/targets/playwright_target_copilot.ipynb +++ b/doc/code/targets/playwright_target_copilot.ipynb @@ -205,20 +205,6 @@ "\n", "asyncio.run(connect_to_existing_browser(browser_debug_port=9222, run_function=run_multimodal))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8", - "metadata": {}, - "outputs": [], - "source": [ - "# Close connection to memory\n", - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/targets/playwright_target_copilot.py b/doc/code/targets/playwright_target_copilot.py index 54ed5407b3..4ff22c5509 100644 --- a/doc/code/targets/playwright_target_copilot.py +++ b/doc/code/targets/playwright_target_copilot.py @@ -165,10 +165,3 @@ async def run_multimodal(page: Page) -> None: asyncio.run(connect_to_existing_browser(browser_debug_port=9222, run_function=run_multimodal)) - -# %% -# Close connection to memory -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine() diff --git a/doc/code/targets/use_huggingface_chat_target.ipynb b/doc/code/targets/use_huggingface_chat_target.ipynb index 5cf91a130c..31afe57b56 100644 --- a/doc/code/targets/use_huggingface_chat_target.ipynb +++ b/doc/code/targets/use_huggingface_chat_target.ipynb @@ -152,19 +152,6 @@ "else:\n", " print(f\"{model_id}: Error occurred, no average time calculated.\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "from pyrit.memory import CentralMemory\n", - "\n", - "memory = CentralMemory.get_memory_instance()\n", - "memory.dispose_engine()" - ] } ], "metadata": { diff --git a/doc/code/targets/use_huggingface_chat_target.py b/doc/code/targets/use_huggingface_chat_target.py index b455ba9e70..5898050007 100644 --- a/doc/code/targets/use_huggingface_chat_target.py +++ b/doc/code/targets/use_huggingface_chat_target.py @@ -102,9 +102,3 @@ print(f"{model_id}: {model_times[model_id]:.2f} seconds") else: print(f"{model_id}: Error occurred, no average time calculated.") - -# %% -from pyrit.memory import CentralMemory - -memory = CentralMemory.get_memory_instance() -memory.dispose_engine()