Skip to content

Commit ce7e6e3

Browse files
committed
indicate how generators might return none; remove None entries from parallel_requests
1 parent decd8ca commit ce7e6e3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

garak/generators/base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ def __init__(self, name="", generations=10):
4747
)
4848
logging.info("generator init: %s", self)
4949

50-
def _call_model(self, prompt: str) -> Union[List[str], str]:
50+
def _call_model(self, prompt: str) -> Union[List[str], str, None]:
5151
"""Takes a prompt and returns an API output
5252
5353
_call_api() is fully responsible for the request, and should either
5454
succeed or raise an exception. The @backoff decorator can be helpful
55-
here - see garak.generators.openai for an example usage."""
55+
here - see garak.generators.openai for an example usage.
56+
57+
Can return None if no reponse was elicited"""
5658
raise NotImplementedError
5759

5860
def _pre_generate_hook(self):
@@ -103,4 +105,7 @@ def generate(self, prompt: str) -> List[str]:
103105
for i in generation_iterator:
104106
outputs.append(self._call_model(prompt))
105107

108+
cleaned_outputs = [o for o in outputs if o is not None]
109+
outputs = cleaned_outputs
110+
106111
return outputs

0 commit comments

Comments
 (0)