pyrit.prompt_converter.RepeatTokenConverter#
- class RepeatTokenConverter(*, token_to_repeat: str = None, times_to_repeat: int = None, token_insert_mode: str = 'split')[source]#
Bases:
PromptConverter
Repeat a specified token a specified number of times in addition to a given prompt. Based on: https://dropbox.tech/machine-learning/bye-bye-bye-evolution-of-repeated-token-attacks-on-chatgpt-models
- Parameters:
token_to_repeat (string, default=None) – The string to be repeated
times_to_repeat (int, default=None) – The number of times the string will be repeated
token_insert_mode ({"split", "prepend", "append", "repeat"}, default="prepend") –
Method to insert repeated tokens:
If “split” prompt text will be split on the first occurance of (.?!) punctuation, and repeated tokens will be inserted at location of split.
If “prepend” repeated tokens will be inserted before the prompt text.
If “append” repeated tokens will be inserted after the prompt text.
If “repeat” prompt text will be ignored and result will only be repeated tokens.
- __init__(*, token_to_repeat: str = None, times_to_repeat: int = None, token_insert_mode: str = 'split') None [source]#
Methods
__init__
(*[, token_to_repeat, ...])convert_async
(*, prompt[, input_type])Converter to insert repeated tokens into the prompt.
convert_tokens_async
(*, prompt[, ...])Converts substrings within a prompt that are enclosed by specified start and end tokens.
get_identifier
()input_supported
(input_type)Checks if the input type is supported by the converter
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'url', 'error'] = 'text') ConverterResult [source]#
Converter to insert repeated tokens into the prompt.