pyrit.prompt_converter.TokenSelectionStrategy#
- class TokenSelectionStrategy[source]#
Bases:
TextSelectionStrategyA special selection strategy that signals SelectiveTextConverter to auto-detect and convert text between start/end tokens (e.g., ⟪ and ⟫).
This strategy is used when chaining converters with preserve_tokens=True. Instead of programmatically selecting text, it relies on tokens already present in the text from a previous converter.
Example
>>> first_converter = SelectiveTextConverter( ... converter=Base64Converter(), ... selection_strategy=WordPositionSelectionStrategy(start_proportion=0.5, end_proportion=1.0), ... preserve_tokens=True ... ) >>> # Text after first converter: "hello world ⟪Y29udmVydGVk⟫" >>> >>> second_converter = SelectiveTextConverter( ... converter=ROT13Converter(), ... selection_strategy=TokenSelectionStrategy(), # Auto-detect tokens ... preserve_tokens=True ... )
- __init__()#
Methods
__init__()select_range(*, text)This method is not used for TokenSelectionStrategy.