Skip to content
Merged
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
8 changes: 6 additions & 2 deletions pyrit/converter/repeat_token_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# Licensed under the MIT license.

import re
from typing import Literal
from typing import Literal, assert_never

from pyrit.converter.converter import Converter, ConverterResult
from pyrit.models import ComponentIdentifier, PromptDataType

TokenInsertMode = Literal["split", "prepend", "append", "repeat"]


class RepeatTokenConverter(Converter):
"""
Expand Down Expand Up @@ -35,7 +37,7 @@ def __init__(
*,
token_to_repeat: str,
times_to_repeat: int,
token_insert_mode: Literal["split", "prepend", "append", "repeat"] | None = None,
token_insert_mode: TokenInsertMode | None = None,
) -> None:
"""
Initialize the converter with the specified token, number of repetitions, and insertion mode.
Expand Down Expand Up @@ -92,6 +94,8 @@ def insert(text: str) -> list[str]:
return ["", ""]

self.insert = insert
case _: # pragma: no cover - mode validation above narrows this to TokenInsertMode.
assert_never(mode)
Comment thread
romanlutz marked this conversation as resolved.
Resolved

def _build_identifier(self) -> ComponentIdentifier:
"""
Expand Down
Loading