Skip to content

Commit

Permalink
migrate guardrails generator
Browse files Browse the repository at this point in the history
  • Loading branch information
leondz committed Jan 28, 2025
1 parent 0005245 commit 7c350da
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions garak/generators/guardrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import List, Union

from garak import _config
from garak.attempt import Turn
from garak.generators.base import Generator


Expand All @@ -21,7 +22,6 @@ def __init__(self, name="", config_root=_config):
# another class that may need to skip testing due to non required dependency
try:
from nemoguardrails import RailsConfig, LLMRails
from nemoguardrails.logging.verbose import set_verbose
except ImportError as e:
raise NameError(
"You must first install NeMo Guardrails using `pip install nemoguardrails`."
Expand All @@ -39,12 +39,12 @@ def __init__(self, name="", config_root=_config):
super().__init__(self.name, config_root=config_root)

def _call_model(
self, prompt: str, generations_this_call: int = 1
) -> List[Union[str, None]]:
self, prompt: Turn, generations_this_call: int = 1
) -> List[Union[Turn, None]]:
with redirect_stderr(io.StringIO()) as f: # quieten the tqdm
result = self.rails.generate(prompt)

return [result]
return [Turn(result)]


DEFAULT_CLASS = "NeMoGuardrails"

0 comments on commit 7c350da

Please sign in to comment.