pyrit.score.SelfAskScaleScorer#

class SelfAskScaleScorer(*, chat_target: PromptChatTarget, scale_arguments_path: Path | None, system_prompt_path: Path | None)[source]#

Bases: Scorer

A class that represents a “self-ask” score for text scoring for a customizable numeric scale.

__init__(*, chat_target: PromptChatTarget, scale_arguments_path: Path | None, system_prompt_path: Path | None) None[source]#

Methods

__init__(*, chat_target, ...)

get_identifier()

Returns an identifier dictionary for the scorer.

scale_value_float(value, min_value, max_value)

Scales a value from 0 to 1 based on the given min and max values.

score_async(request_response, *[, task])

Scores the given request_response using "self-ask" for the chat target and adds score to memory.

score_image_async(image_path, *[, task])

Scores the given image using the chat target.

score_prompts_batch_async(*, request_responses)

score_text_async(text, *[, task])

Scores the given text based on the task using the chat target.

validate(request_response, *[, task])

Validates the request_response piece to score.

Attributes

scorer_type

class ScalePaths(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

TASK_ACHIEVED_SCALE = PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit/datasets/score/scales/task_achieved_scale.yaml')#
TREE_OF_ATTACKS_SCALE = PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit/datasets/score/scales/tree_of_attacks_scale.yaml')#
class SystemPaths(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

GENERAL_SYSTEM_PROMPT = PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit/datasets/score/scales/general_system_prompt.yaml')#
RED_TEAMER_SYSTEM_PROMPT = PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit/datasets/score/scales/red_teamer_system_prompt.yaml')#
async score_async(request_response: PromptRequestPiece, *, task: str | None = None) list[Score][source]#

Scores the given request_response using “self-ask” for the chat target and adds score to memory.

Parameters:
  • request_response (PromptRequestPiece) – The prompt request piece containing the text to be scored.

  • task (str) – The task based on which the text should be scored (the original attacker model’s objective).

Returns:

The request_response scored.

The score_value is a value from [0,1] that is scaled based on the scorer’s scale.

Return type:

list[Score]

validate(request_response: PromptRequestPiece, *, task: str | None = None)[source]#

Validates the request_response piece to score. Because some scorers may require specific PromptRequestPiece types or values.

Parameters:
  • request_response (PromptRequestPiece) – The request response to be validated.

  • task (str) – The task based on which the text should be scored (the original attacker model’s objective).