pyrit.prompt_target.OpenAICompletionTarget#
- class OpenAICompletionTarget(max_tokens: int | None = None, temperature: float | None = None, top_p: float | None = None, presence_penalty: float | None = None, frequency_penalty: float | None = None, n: int | None = None, *args, **kwargs)[source]#
Bases:
OpenAITarget
- __init__(max_tokens: int | None = None, temperature: float | None = None, top_p: float | None = None, presence_penalty: float | None = None, frequency_penalty: float | None = None, n: int | None = None, *args, **kwargs)[source]#
- 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) – 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.
max_tokens (int, Optional) – The maximum number of tokens that can be generated in the completion. The token count of your prompt plus max_tokens cannot exceed the model’s context length.
temperature (float, Optional) – What sampling temperature to use, between 0 and 2. Values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
top_p (float, Optional) – An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
presence_penalty (float, Optional) – Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics.
n (int, Optional) – How many completions to generate for each prompt.
Methods
__init__
([max_tokens, temperature, top_p, ...])dispose_db_engine
()Dispose DuckDB database engine to release database connections and resources.
get_identifier
()Indicates that this target supports JSON response format.
is_response_format_json
(request_piece)Checks if the response format is JSON and ensures the target supports it.
send_prompt_async
(**kwargs)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
supported_converters
- is_json_response_supported() bool [source]#
Indicates that this target supports JSON response format.
- async send_prompt_async(**kwargs)#
Sends a normalized prompt async to the prompt target.