pyrit.score.AzureContentFilterScorer#
- class AzureContentFilterScorer(*, endpoint: str = None, api_key: str = None, use_aad_auth: bool = False, harm_categories: list[TextCategory] = None)[source]#
Bases:
Scorer
- __init__(*, endpoint: str = None, api_key: str = None, use_aad_auth: bool = False, harm_categories: list[TextCategory] = None) None [source]#
Class that initializes an Azure Content Filter Scorer
- Parameters:
api_key (str, Optional) – The API key for accessing the Azure OpenAI service. Defaults to the API_KEY_ENVIRONMENT_VARIABLE environment variable.
endpoint (str, Optional) – The endpoint URL for the Azure OpenAI service. Defaults to the ENDPOINT_URI_ENVIRONMENT_VARIABLE environment variable.
use_aad_auth (bool, Optional) – Attempt to use DefaultAzureCredential If set to true, attempt to use DefaultAzureCredential for auth
harm_categories – The harm categories you want to query for as per defined in azure.ai.contentsafety.models.TextCategory.
Methods
__init__
(*[, endpoint, api_key, ...])Class that initializes an Azure Content Filter Scorer
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])Evaluating the input text or image using the Azure Content Filter API
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
- async score_async(request_response: PromptRequestPiece, *, task: str | None = None) list[Score] [source]#
Evaluating the input text or image using the Azure Content Filter API
- Parameters:
request_response (PromptRequestPiece) – The prompt request piece containing the text to be scored. Applied to converted_value; must be of converted_value_data_type “text” or “image_path”. In case of an image, the image size needs to less than image size is 2048 x 2048 pixels, but more than 50x50 pixels. The data size should not exceed exceed 4 MB. Image must be of type JPEG, PNG, GIF, BMP, TIFF, or WEBP.
task (str) – The task based on which the text should be scored (the original attacker model’s objective). Currently not supported for this scorer.
- Returns:
A Score object with the score value mapping to severity utilizing the get_azure_severity function. The value will be on a 0-7 scale with 0 being least and 7 being most harmful for text or image. Definition of the severity levels can be found at https://learn.microsoft.com/en-us/azure/ai-services/content-safety/concepts/harm-categories? tabs=definitions#severity-levels
- Raises:
ValueError if converted_value_data_type is not "text" or "image_path" or image isn't in supported format –
- 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).