-
Notifications
You must be signed in to change notification settings - Fork 800
FEAT Plug-in mechanism for private scenarios #2131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9f409ab
c7a7528
e7d63cf
eca5928
0b11b6c
8781038
e6159e5
f8e761d
ed3fc0d
fb822e0
95de68c
c108578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,6 +250,36 @@ AZURE_OPENAI_VIDEO_MODEL="sora-2" | |
| AZURE_OPENAI_VIDEO_UNDERLYING_MODEL="sora-2" | ||
|
|
||
| OPENAI_VIDEO_ENDPOINT = ${AZURE_OPENAI_VIDEO_ENDPOINT} | ||
|
|
||
| ################################## | ||
| # PLUG-INS | ||
| # | ||
| # PyRIT can load a non-disclosable plug-in (extra datasets + scenarios) from a | ||
| # pre-built wheel at initialization time. Plug-in loading runs automatically as a | ||
| # guaranteed-first phase inside initialize_pyrit_async (before the configured | ||
| # initializers) — there is nothing to add to .pyrit_conf. The wheel is extracted to | ||
| # .plugin/<name>/, prepended to sys.path, imported, and its bootstrap is run so its | ||
| # datasets/scenarios register like built-ins. Extraction only — never pip/.venv. | ||
| # | ||
| # WARNING: loading a plug-in executes third-party code in the PyRIT process. | ||
| # Whoever can set PLUGIN_* / write this .env can run code on the host. Treat this | ||
| # file as sensitive. | ||
| ################################### | ||
|
|
||
| # Path to a pre-built plug-in wheel on disk. Setting it enables plug-in loading; | ||
| # leaving it unset is a no-op. | ||
| # PLUGIN_WHEEL="/abs/path/to/my_plugin-0.0.0-py3-none-any.whl" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean we support only one plugin? If so, I think it's a design limitation that might bite us later.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To answer your first question, yes, but not as an explicit constraint. I see two solutions to plug-in composition: we can just load multiple plug-ins and place the burden of compatibility on the user, or we can add a layer of abstraction, so that plug-in components can be collected, compared, and initialized in a certain order. I lean towards the second long-term, but in either case I don't think we should support only one plugin on purpose. |
||
|
|
||
| # Optional: the wheel's top-level import package. Auto-detected from the wheel | ||
| # when omitted; set this to disambiguate multi-package wheels. | ||
| # PLUGIN_PACKAGE="my_plugin" | ||
|
|
||
| # Optional: continue (with a warning) instead of failing when the plug-in cannot | ||
| # be loaded. Equivalent to initialize_pyrit_async(plugin_fail_open=True). | ||
| # PLUGIN_FAIL_OPEN="false" | ||
|
|
||
| # Optional: override the base extraction directory (defaults to <pyrit home>/.plugin). | ||
| # PLUGIN_DIR="/abs/path/to/.plugin" | ||
| OPENAI_VIDEO_KEY = ${AZURE_OPENAI_VIDEO_KEY} | ||
| OPENAI_VIDEO_MODEL = ${AZURE_OPENAI_VIDEO_MODEL} | ||
| OPENAI_VIDEO_UNDERLYING_MODEL = "" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Keeps the .plugin/ directory in version control while its contents stay ignored. | ||
| # PyRIT extracts plug-in wheels here at runtime (see PLUGIN_WHEEL). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,6 +203,7 @@ async def initialize_pyrit_async( | |
| env_files: Sequence[pathlib.Path] | None = None, | ||
| env_akv_ref: Sequence[str] | None = None, | ||
| silent: bool = False, | ||
| plugin_fail_open: bool | None = None, | ||
| **memory_instance_kwargs: Any, | ||
| ) -> None: | ||
| """ | ||
|
|
@@ -224,6 +225,9 @@ async def initialize_pyrit_async( | |
| so local files take precedence over AKV. Requires ``azure-keyvault-secrets``. | ||
| silent (bool): If True, suppresses print statements about environment file loading and | ||
| schema migration. Defaults to False. | ||
| plugin_fail_open (bool | None): Overrides ``PLUGIN_FAIL_OPEN`` for plug-in loading. When True, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we find a naming for this flag that's a bit clearer about what it does?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Will patch this |
||
| a plug-in (``PLUGIN_WHEEL``) that fails to load is skipped with a warning instead of raising. | ||
| Defaults to None (use the ``PLUGIN_FAIL_OPEN`` environment variable, else fail-closed). | ||
| **memory_instance_kwargs (Any | None): Additional keyword arguments to pass to the memory instance. | ||
|
|
||
| Raises: | ||
|
|
@@ -259,6 +263,15 @@ async def initialize_pyrit_async( | |
|
|
||
| CentralMemory.set_memory_instance(memory) | ||
|
|
||
| # Load a configured plug-in (PLUGIN_WHEEL) as a guaranteed-first phase: after memory | ||
| # is set (a plug-in bootstrap may use it) and BEFORE any configured initializers run, | ||
| # so plug-in datasets/scenarios are registered before LoadDefaultDatasets and | ||
| # PreloadScenarioMetadata read the registry. Ordering is true by construction here, so | ||
| # it does not depend on .pyrit_conf list position. No-op unless PLUGIN_WHEEL is set. | ||
| from pyrit.setup.plugin_loader import load_plugin_if_configured_async | ||
|
|
||
| await load_plugin_if_configured_async(fail_open=plugin_fail_open) | ||
|
|
||
| # Combine directly provided initializers with those loaded from scripts | ||
| all_initializers = list(initializers) if initializers else [] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
.envthe right place for this? Intuitively I would have put it in.pyrit.conf.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a much better place for it! I agree, I'll move it