pyrit.prompt_converter.BinaryConverter#
- class BinaryConverter(bits_per_char: BitsPerChar = BitsPerChar.BITS_16)[source]#
Bases:
PromptConverter
A converter that transforms input text into its binary representation with configurable bits per character (8, 16, or 32).
- __init__(bits_per_char: BitsPerChar = BitsPerChar.BITS_16)[source]#
Methods
__init__
([bits_per_char])convert_async
(*, prompt[, input_type])Converts the input text to binary representation with specified bits per character.
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
output_supported
(output_type)Checks if the output type is supported by the converter
Attributes
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.
- class BitsPerChar(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
- BITS_16 = 16#
- BITS_32 = 32#
- BITS_8 = 8#
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text') ConverterResult [source]#
Converts the input text to binary representation with specified bits per character.
- Parameters:
prompt (str) – The input text to be converted.
input_type (PromptDataType) – The type of the input data.
- Returns:
The result containing the binary representation of the input text.
- Return type:
- Raises:
ValueError – If the input type is not supported or bits_per_char is invalid.
- input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']) bool [source]#
Checks if the input type is supported by the converter
- Parameters:
input_type – The input type to check
- Returns:
True if the input type is supported, False otherwise
- Return type:
- output_supported(output_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']) bool [source]#
Checks if the output type is supported by the converter
- Parameters:
output_type – The output type to check
- Returns:
True if the output type is supported, False otherwise
- Return type: