Skip to content
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

Fix a few issues related to jailbreak detection heuristics. #352

Merged
merged 3 commits into from
Feb 23, 2024
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
2 changes: 1 addition & 1 deletion nemoguardrails/embeddings/embedding_providers/fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FastEmbedEmbeddingModel(EmbeddingModel):
"""

def __init__(self, embedding_model: str):
from fastembed.embedding import FlagEmbedding as Embedding
from fastembed import TextEmbedding as Embedding

# Enabling a short form model name for all-MiniLM-L6-v2.
if embedding_model == "all-MiniLM-L6-v2":
Expand Down
3 changes: 3 additions & 0 deletions nemoguardrails/library/jailbreak_detection/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ RUN pip install -r requirements.txt
# Set the device on which the model should load e.g., "cpu", "cuda:0", etc.
ENV JAILBREAK_CHECK_DEVICE=cpu

# Predownload the GPT2 model.
RUN python -c "from transformers import GPT2LMHeadModel, GPT2TokenizerFast; GPT2LMHeadModel.from_pretrained('gpt2-large'); GPT2TokenizerFast.from_pretrained('gpt2-large');"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is smart thinking.


# Expose a port for the server
EXPOSE 1337

Expand Down
3 changes: 3 additions & 0 deletions nemoguardrails/library/jailbreak_detection/Dockerfile-GPU
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ RUN pip install -r requirements.txt
# Set the device on which the model should load e.g., "cpu", "cuda:0", etc.
ENV JAILBREAK_CHECK_DEVICE=cuda:0

# Predownload the GPT2 model.
RUN python -c "from transformers import GPT2LMHeadModel, GPT2TokenizerFast; GPT2LMHeadModel.from_pretrained('gpt2-large'); GPT2TokenizerFast.from_pretrained('gpt2-large');"

# Expose a port for the server
EXPOSE 1337

Expand Down
9 changes: 5 additions & 4 deletions nemoguardrails/library/jailbreak_detection/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
from typing import Optional

from nemoguardrails.actions import action
from nemoguardrails.library.jailbreak_detection.heuristics.checks import (
check_jailbreak_length_per_perplexity,
check_jailbreak_prefix_suffix_perplexity,
)
from nemoguardrails.library.jailbreak_detection.request import (
jailbreak_detection_heuristics_request,
)
Expand All @@ -43,6 +39,11 @@ async def jailbreak_detection_heuristics(
prompt = context.get("user_message")

if not jailbreak_api_url:
from nemoguardrails.library.jailbreak_detection.heuristics.checks import (
check_jailbreak_length_per_perplexity,
check_jailbreak_prefix_suffix_perplexity,
)

log.warning(
"No jailbreak heuristics endpoint set. Running in-process, NOT RECOMMENDED FOR PRODUCTION."
)
Expand Down
Loading