feat(jailbreak): Add direct API key configuration support#1260
feat(jailbreak): Add direct API key configuration support#1260tgasser-nv merged 4 commits intodevelopfrom
Conversation
Documentation preview |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1260 +/- ##
===========================================
+ Coverage 69.57% 69.59% +0.02%
===========================================
Files 161 161
Lines 16023 16029 +6
===========================================
+ Hits 11148 11156 +8
+ Misses 4875 4873 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…variable exists with the value
|
Thank you @tgasser-nv for the PR, I've added some technical comments. on a different note, AFAIK, it was decided not to support hardcoded api key due to various reasons one being inconsistency with other integrations in guardrails library. for example:
Now jailbreak detection supports both approaches:
Questions:
|
erickgalinkin
left a comment
There was a problem hiding this comment.
LGTM. Thanks Tim!
Thanks for the context, I wasn't aware of a previous decision to use environment variables only. The list above is all for 3rd-party integrations into Guardrails, not 1st-party (i.e. NVIDIA) Nemoguard NIMs. I think aligning the Jailbreak Nemoguard NIM with the other Nemoguard NIMs makes more sense than with 3rd-party integrations. We're already using langchain-openai and optionally langchain-nvidia-ai-endpoints for LLM interfaces. Both of these support an
Yes, we should standardise this, let's address this in a future MR. What are your thoughts on this as a backwards-compatible approach? Let's discuss this
What secret store implementation did you have in mind? Assuming it's something similar to AWS IAM we need to implement a background task to authenticate and fetch ephemeral credentials on a regular cadence. This would have to work when we scale out horizontally too. |
|
@jeffreyscarpenter Could you give us some more context on the need to provide API keys directly rather than by environment variables? IIRC you need this for multi-tenancy on your infra (i.e. multiple customers running on a single machine, each with different API keys for OpenAI / Nvidia LLMs). But I'd like to double check. Thanks! |
|
Thank you @tgasser-nv , your points are valid 👍🏻 As long as we are aligned and we maintain consistency then I don't see any problem, let's cat back to this later. I think we are good to merge. |
|
It makes sense to be able to also specify API keys directly as parameters in the config, besides using environment variables. But I agree with @Pouyanpi that it would be nice to have a standardized way of doing this. I think for Langchain supported LLMs, this behavior is default for most models (e.g. |
Yes and Tim actually used that feature in #1142 by supporting |
* Support direct jailbreak api key, not via environment variable * Add unit-test to cover api_key_env_var being set, but no environment variable exists with the value * Removed unused imports, fixed test docstring copy-and-paste * Rename get_auth_token() to get_api_key()
Description
This change adds a new optional field
api_keyto theJailbreakDetectionConfigPydantic model. This allows customers to provide an API Key in a RailsConfig object or YAML file, for use in Jailbreak NIM calls. Prior to this change, theapi_key_env_varfield used an environment variable (for example NVIDIA_API_KEY) to get the API Key for the Jailbreak NIM.A new config is included in the PR (examples/configs/jailbreak_detection_nim) used to integration test this locally. By setting the NVCF API key in the main model's
parameters.api_keyfield, and in the Jailbreak model'sapi_keyfield, API keys can be injected programmatically without setting theNVIDIA_API_KEYenvironment variable.The test plan below validates the main model and Jailbreak NIM API Keys are being used by commenting out one or both and checking the error messages.
Test Plan
Run pre-commits
Run unit-tests
Local integration tests
In all tests below, the following client command is POSTed to the nemoguardrails server. It isn't copied for each case for clarity.
Client command
The terminal running the server also has no NVIDIA_API_KEY or OPENAI_API_KEY values set:
Case 1: Both main model
parameters.api_keyand jailbreakapi_keyare missing.Case 2: Main model
parameters.api_keyset correctly, jailbreakapi_keyare missing.Now the main LLM returns a response, but the Jailbreak NIM isn't being called with a 401 Unauthorized error (expected since there's no api_key provided in this test-case).
Case 3: Both Main model
parameters.api_keyand jailbreakapi_keyare set.Now we have both API key fields set, the jailbreak check and response both succeed. The jailbreak_detection_model action succeeds because we're using the API key set in the config.
Mentions
@Pouyanpi , @jeffreyscarpenter
Checklist