pyrit.prompt_target.OpenAITarget#

class OpenAITarget(*, deployment_name: str = None, endpoint: str = None, api_key: str = None, headers: str = None, is_azure_target=True, use_aad_auth: bool = False, api_version: str = '2024-06-01', max_requests_per_minute: int | None = None)[source]#

Bases: PromptChatTarget

__init__(*, deployment_name: str = None, endpoint: str = None, api_key: str = None, headers: str = None, is_azure_target=True, use_aad_auth: bool = False, api_version: str = '2024-06-01', max_requests_per_minute: int | None = None) None[source]#

Abstract class that initializes an Azure or non-Azure OpenAI chat target.

Read more about the various models here: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models.

Parameters:
  • deployment_name (str, Optional) – The name of the deployment. Defaults to the AZURE_OPENAI_CHAT_DEPLOYMENT environment variable .

  • endpoint (str, Optional) – The endpoint URL for the Azure OpenAI service. Defaults to the AZURE_OPENAI_CHAT_ENDPOINT environment variable.

  • api_key (str, Optional) – The API key for accessing the Azure OpenAI service. Defaults to the AZURE_OPENAI_CHAT_KEY environment variable.

  • headers (str, Optional) – Headers of the endpoint (JSON).

  • is_azure_target (bool, Optional) – Whether the target is an Azure target.

  • use_aad_auth (bool, Optional) – When set to True, user authentication is used instead of API Key. DefaultAzureCredential is taken for https://cognitiveservices.azure.com/.default . Please run az login locally to leverage user AuthN.

  • api_version (str, Optional) – The version of the Azure OpenAI API. Defaults to “2024-06-01”.

  • max_requests_per_minute (int, Optional) – Number of requests the target can handle per minute before hitting a rate limit. The number of requests sent to the target will be capped at the value provided.

Methods

__init__(*[, deployment_name, endpoint, ...])

Abstract class that initializes an Azure or non-Azure OpenAI chat target.

dispose_db_engine()

Dispose DuckDB database engine to release database connections and resources.

get_identifier()

send_chat_prompt_async(*, prompt, ...[, ...])

Sends a text prompt to the target without having to build the prompt request.

send_prompt_async(*, prompt_request)

Sends a normalized prompt async to the prompt target.

set_system_prompt(*, system_prompt, ...[, ...])

Sets the system prompt for the prompt target.

Attributes

ADDITIONAL_REQUEST_HEADERS: str = 'OPENAI_ADDITIONAL_REQUEST_HEADERS'#
api_key_environment_variable: str#
deployment_environment_variable: str#
endpoint_uri_environment_variable: str#