pyrit.prompt_converter.RandomCapitalLettersConverter#
- class RandomCapitalLettersConverter(percentage: float = 100.0)[source]#
Bases:
PromptConverterTakes a prompt and randomly capitalizes it by a percentage of the total characters.
- __init__(percentage: float = 100.0) None[source]#
Initialize the converter with the specified percentage of randomization.
- Parameters:
percentage (float) – The percentage of characters to capitalize in the prompt. Must be between 1 and 100. Defaults to 100.0. This includes decimal points in that range.
Methods
__init__([percentage])Initialize the converter with the specified percentage of randomization.
convert_async(*, prompt[, input_type])Convert the given prompt by randomly capitalizing a percentage of its characters.
convert_tokens_async(*, prompt[, ...])Convert substrings within a prompt that are enclosed by specified start and end tokens.
generate_random_positions(total_length, ...)Generate a list of unique random positions within the range of total_length.
get_identifier()Get the typed identifier for this object.
input_supported(input_type)Check if the input type is supported by the converter.
is_percentage(input_string)Check if the input string is a valid percentage between 1 and 100.
output_supported(output_type)Check if the output type is supported by the converter.
Convert a string by randomly capitalizing a percentage of its characters.
Attributes
Tuple of input modalities supported by this converter.
Tuple of output modalities supported by this converter.
supported_input_typesReturns a list of supported input types for the converter.
supported_output_typesReturns a list of supported output types for the converter.
- SUPPORTED_INPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of input modalities supported by this converter. Subclasses must override this.
- SUPPORTED_OUTPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of output modalities supported by this converter. Subclasses must override this.
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text') ConverterResult[source]#
Convert the given prompt by randomly capitalizing a percentage of its characters.
- Parameters:
prompt (str) – The input text prompt to be converted.
input_type (PromptDataType) – The type of input data.
- Returns:
The result containing the converted text.
- Return type:
- Raises:
ValueError – If the input type is not supported.
- generate_random_positions(total_length: int, set_number: int) list[int][source]#
Generate a list of unique random positions within the range of total_length.
- Parameters:
- Returns:
A list of unique random positions.
- Return type:
- Raises:
ValueError – If set_number is greater than total_length.
- is_percentage(input_string: float) bool[source]#
Check if the input string is a valid percentage between 1 and 100.
- string_to_upper_case_by_percentage(percentage: float, prompt: str) str[source]#
Convert a string by randomly capitalizing a percentage of its characters.
- Parameters:
- Returns:
The converted string with randomly capitalized characters.
- Return type:
- Raises:
ValueError – If the percentage is not between 1 and 100.