pyrit.prompt_target.HuggingFaceChatTarget#
- class HuggingFaceChatTarget(*, model_id: str | None = None, model_path: str | None = None, hf_access_token: str | None = None, use_cuda: bool = False, tensor_format: str = 'pt', necessary_files: list = None, max_new_tokens: int = 20, temperature: float = 1.0, top_p: float = 1.0, skip_special_tokens: bool = True, trust_remote_code: bool = False)[source]#
Bases:
PromptChatTarget
The HuggingFaceChatTarget interacts with HuggingFace models, specifically for conducting red teaming activities. Inherits from PromptTarget to comply with the current design standards.
- __init__(*, model_id: str | None = None, model_path: str | None = None, hf_access_token: str | None = None, use_cuda: bool = False, tensor_format: str = 'pt', necessary_files: list = None, max_new_tokens: int = 20, temperature: float = 1.0, top_p: float = 1.0, skip_special_tokens: bool = True, trust_remote_code: bool = False) None [source]#
Methods
__init__
(*[, model_id, model_path, ...])Disables the class-level cache and clears the cache.
dispose_db_engine
()Dispose DuckDB database engine to release database connections and resources.
Enables the class-level cache.
get_identifier
()Check if the HuggingFace model ID is valid.
Loads the model and tokenizer, downloading if necessary.
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 asynchronously to the HuggingFace model.
set_system_prompt
(*, system_prompt, ...[, ...])Sets the system prompt for the prompt target.
Attributes
supported_converters
- HUGGINGFACE_TOKEN_ENVIRONMENT_VARIABLE = 'HUGGINGFACE_TOKEN'#
- is_model_id_valid() bool [source]#
Check if the HuggingFace model ID is valid. :return: True if valid, False otherwise.
- async load_model_and_tokenizer()[source]#
Loads the model and tokenizer, downloading if necessary.
Downloads the model to the HF_MODELS_DIR folder if it does not exist, then loads it from there.
- Raises:
Exception – If the model loading fails.
- async send_prompt_async(*, prompt_request: PromptRequestResponse) PromptRequestResponse [source]#
Sends a normalized prompt asynchronously to the HuggingFace model.