pyrit.prompt_converter.PersuasionConverter#
- class PersuasionConverter(*, converter_target: PromptChatTarget, persuasion_technique: str)[source]#
Bases:
PromptConverter
Rephrases prompts using a variety of persuasion techniques.
Based on https://arxiv.org/abs/2401.06373 by Zeng et al.
- Supported persuasion techniques:
- “authority_endorsement”:
Citing authoritative sources in support of a claim.
- “evidence_based”:
Using empirical data, statistics, and facts to support a claim or decision.
- “expert_endorsement”:
Citing domain experts in support of a claim.
- “logical_appeal”:
Using logic or reasoning to support a claim.
- “misrepresentation”:
Presenting oneself or an issue in a way that’s not genuine or true.
- __init__(*, converter_target: PromptChatTarget, persuasion_technique: str)[source]#
Initializes the converter with the specified target and prompt template.
- Parameters:
converter_target (PromptChatTarget) – The chat target used to perform rewriting on user prompts.
persuasion_technique (str) – Persuasion technique to be used by the converter, determines the system prompt to be used to generate new prompts. Must be one of “authority_endorsement”, “evidence_based”, “expert_endorsement”, “logical_appeal”, “misrepresentation”.
- Raises:
ValueError – If the persuasion technique is not supported or does not exist.
Methods
__init__
(*, converter_target, ...)Initializes the converter with the specified target and prompt template.
convert_async
(*, prompt[, input_type])Converts the given prompt using the persuasion technique specified during initialization.
convert_tokens_async
(*, prompt[, ...])Converts substrings within a prompt that are enclosed by specified start and end tokens.
get_identifier
()Returns an identifier dictionary for the converter.
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.
send_persuasion_prompt_async
(request)Sends the prompt to the converter target and processes the response.
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.
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error'] = 'text') ConverterResult [source]#
Converts the given prompt using the persuasion technique specified during initialization.
- input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error']) bool [source]#
Checks if the input type is supported by the converter.
- Parameters:
input_type (PromptDataType) – 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', 'reasoning', 'error']) bool [source]#
Checks if the output type is supported by the converter.
- Parameters:
output_type (PromptDataType) – The output type to check.
- Returns:
True if the output type is supported, False otherwise.
- Return type: