pyrit.prompt_converter.RandomTranslationConverter#
- class RandomTranslationConverter(*, converter_target: PromptChatTarget = REQUIRED_VALUE, system_prompt_template: SeedPrompt | None = None, languages: List[str] | None = None, word_selection_strategy: WordSelectionStrategy | None = None)[source]#
Bases:
LLMGenericTextConverter,WordLevelConverterTranslates each individual word in a prompt to a random language using an LLM.
An existing
PromptChatTargetis used to perform the translation (like Azure OpenAI).- __init__(*, converter_target: PromptChatTarget = REQUIRED_VALUE, system_prompt_template: SeedPrompt | None = None, languages: List[str] | None = None, word_selection_strategy: WordSelectionStrategy | None = None)[source]#
Initializes the converter with a target, an optional system prompt template, and language options.
- Parameters:
converter_target (PromptChatTarget) – The target for the prompt conversion. Can be omitted if a default has been configured via PyRIT initialization.
system_prompt_template (Optional[SeedPrompt]) – The system prompt template to use for the conversion. If not provided, a default template will be used.
languages (Optional[List[str]]) – The list of available languages to use for translation.
word_selection_strategy (Optional[WordSelectionStrategy]) – Strategy for selecting which words to convert. If None, all words will be converted.
- Raises:
ValueError – If converter_target is not provided and no default has been configured.
Methods
__init__(*[, converter_target, ...])Initializes the converter with a target, an optional system prompt template, and language options.
convert_async(*, prompt[, input_type])Converts the given prompt into the target format supported by the converter.
convert_tokens_async(*, prompt[, ...])Converts substrings within a prompt that are enclosed by specified start and end tokens.
convert_word_async(word)Converts a single word into the target format supported by the converter.
get_identifier()Returns an identifier dictionary for the converter.
input_supported(input_type)Checks if the input type is supported by the converter.
join_words(words)Provides a way for subclasses to override the default behavior of joining words.
output_supported(output_type)Checks if the output type is supported by the converter.
validate_input(prompt)Validates the input before processing (can be overridden by subclasses).
Attributes
supported_input_typesReturns a list of supported input types for the converter.
supported_output_typesReturns a list of supported output types for the converter.
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text') ConverterResult[source]#
Converts the given prompt into the target format supported by the converter.
- Parameters:
prompt (str) – The prompt to be converted.
input_type (PromptDataType) – The type of input data.
- Returns:
The result containing the converted output and its type.
- Return type: