Skip to content

Commit

Permalink
Add converter
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Apr 13, 2024
1 parent 770e15a commit 16e956d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions aisploit/redteam/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..core import (
BaseChatModel,
BaseJob,
BaseConverter,
BaseTarget,
Callbacks,
CallbackManager,
Expand All @@ -36,6 +37,7 @@ def __init__(
task: RedTeamTask,
target: BaseTarget,
get_session_history: GetSessionHistoryCallable = get_session_history,
converter: Optional[BaseConverter] = None,
callbacks: Callbacks = [],
verbose=False,
) -> None:
Expand All @@ -45,6 +47,7 @@ def __init__(
self._task = task
self._target = target
self._get_session_history = get_session_history
self._converter = converter
self._callbacks = callbacks

def execute(
Expand Down Expand Up @@ -80,7 +83,11 @@ def execute(
config={"configurable": {"session_id": run_id}},
)

current_prompt = StringPromptValue(text=current_prompt_text)
current_prompt = (
self._converter.convert(current_prompt_text)
if self._converter
else StringPromptValue(text=current_prompt_text)
)

callback_manager.on_redteam_attempt_start(attempt, current_prompt)

Expand All @@ -101,8 +108,7 @@ def execute(
)
)

# task.is_completed
if score.flagged:
if score.flagged: # task is completed
break

current_prompt_text = response.content
Expand Down

0 comments on commit 16e956d

Please sign in to comment.