pyrit.prompt_target.OpenAITarget#

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

Bases: PromptChatTarget

__init__(*, model_name: str | None = None, endpoint: str | None = None, api_key: str | None = None, headers: str | None = None, use_aad_auth: bool | None = False, api_version: str | None = '2024-06-01', max_requests_per_minute: int | None = None, httpx_client_kwargs: dict | 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:
  • model_name (str, Optional) – The name of the model.

  • endpoint (str, Optional) – The target URL for the OpenAI service.

  • 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) – Extra headers of the endpoint (JSON).

  • 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.

  • httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor.

Methods

__init__(*[, model_name, endpoint, api_key, ...])

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()

is_json_response_supported()

Abstract method to determine if JSON response format is supported by the target.

is_response_format_json(request_piece)

Checks if the response format is JSON and ensures the target supports it.

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#
endpoint_environment_variable: str#
abstract is_json_response_supported() bool[source]#

Abstract method to determine if JSON response format is supported by the target.

Returns:

True if JSON response is supported, False otherwise.

Return type:

bool

model_name_environment_variable: str#