pyrit.prompt_converter.KeywordSelectionStrategy#

class KeywordSelectionStrategy(*, keyword: str, context_before: int = 0, context_after: int = 0, case_sensitive: bool = True)[source]#

Bases: TextSelectionStrategy

Selects text around a keyword with optional context.

__init__(*, keyword: str, context_before: int = 0, context_after: int = 0, case_sensitive: bool = True) None[source]#

Initializes the keyword selection strategy.

Parameters:
  • keyword (str) – The keyword to search for.

  • context_before (int) – Number of characters to include before the keyword. Defaults to 0.

  • context_after (int) – Number of characters to include after the keyword. Defaults to 0.

  • case_sensitive (bool) – Whether the keyword search is case-sensitive. Defaults to True.

Methods

__init__(*, keyword[, context_before, ...])

Initializes the keyword selection strategy.

select_range(*, text)

Selects the range around the first occurrence of the keyword.

select_range(*, text: str) tuple[int, int][source]#

Selects the range around the first occurrence of the keyword.

Parameters:

text (str) – The input text to select from.

Returns:

A tuple of (start_index, end_index) including context,

or (0, 0) if keyword not found.

Return type:

tuple[int, int]