pyrit.prompt_converter.FirstLetterConverter#

class FirstLetterConverter(*, letter_separator: str = ' ', word_selection_strategy: WordSelectionStrategy | None = None)[source]#

Bases: WordLevelConverter

Replaces each word of the prompt with its first letter (or digit). Whitespace and words that do not contain any letter or digit are ignored.

__init__(*, letter_separator: str = ' ', word_selection_strategy: WordSelectionStrategy | None = None) None[source]#

Initialize the converter with the specified letter separator and selection strategy.

Parameters:
  • letter_separator (str) – The string used to join the first letters.

  • word_selection_strategy (Optional[WordSelectionStrategy]) – Strategy for selecting which words to convert. If None, all words will be converted.

Methods

__init__(*[, letter_separator, ...])

Initialize the converter with the specified letter separator and selection strategy.

convert_async(*, prompt[, input_type])

Convert the given prompt into the target format supported by the converter.

convert_tokens_async(*, prompt[, ...])

Convert substrings within a prompt that are enclosed by specified start and end tokens.

convert_word_async(word)

Convert a single word into the target format supported by the converter.

get_identifier()

Return an identifier dictionary for the converter.

input_supported(input_type)

Check if the input type is supported by the converter.

join_words(words)

Join the converted words using the specified letter separator.

output_supported(output_type)

Check if the output type is supported by the converter.

validate_input(prompt)

Validate the input before processing (can be overridden by subclasses).

Attributes

SUPPORTED_INPUT_TYPES

Tuple of input modalities supported by this converter.

SUPPORTED_OUTPUT_TYPES

Tuple of output modalities supported by this converter.

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns a list of supported output types for the converter.

async convert_word_async(word: str) str[source]#

Convert a single word into the target format supported by the converter.

Parameters:

word (str) – The word to be converted.

Returns:

The converted word.

Return type:

str

join_words(words: list[str]) str[source]#

Join the converted words using the specified letter separator.

Parameters:

words (list[str]) – The list of converted words.

Returns:

The joined string of converted words.

Return type:

str