pyrit.prompt_converter.PositionSelectionStrategy#

class PositionSelectionStrategy(*, start_proportion: float, end_proportion: float)[source]#

Bases: TextSelectionStrategy

Selects text based on proportional start and end positions.

__init__(*, start_proportion: float, end_proportion: float) None[source]#

Initializes the position selection strategy.

Parameters:
  • start_proportion (float) – The starting position as a proportion (0.0 to 1.0).

  • end_proportion (float) – The ending position as a proportion (0.0 to 1.0).

Raises:

ValueError – If proportions are not between 0.0 and 1.0, or start >= end.

Methods

__init__(*, start_proportion, end_proportion)

Initializes the position selection strategy.

select_range(*, text)

Selects a range based on the relative position in the text.

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

Selects a range based on the relative position in the text.

Parameters:

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

Returns:

A tuple of (start_index, end_index).

Return type:

tuple[int, int]