artkit.model.llm.huggingface.HuggingfaceChatLocal#
- class artkit.model.llm.huggingface.HuggingfaceChatLocal(*, model_id, api_key_env=None, use_cuda=False, **model_params)[source]#
Huggingface model base local chat.
- Bases:
HuggingfaceLocalConnectorMixin
,HuggingfaceChatConnectorMixin
[AutoModelForCausalLM
]- Metaclasses:
- Parameters:
model_id (
str
) – the ID of the model to useapi_key_env (
Optional
[str
]) – the environment variable that holds the API key; if not specified, use the default API key environment variable for the model as returned byget_default_api_key_env()
(defaults to5
) parameters withNone
values are considered unset and will be ignoreduse_cuda (
bool
) – ifTrue
, use CUDA; ifFalse
, use CPUmodel_params (
Any
) – additional parameters for the model
- Raises:
RuntimeError – if CUDA is requested but not available
Method summary
Get the API key from the environment variable specified by
api_key_env
.Get a shared client instance for this connector; return a cached instance if for this model's API key if available.
Get the default name of the environment variable that holds the API key.
Get the parameters of the model as a mapping.
Get a response, or multiple alternative responses, from the chat system.
The tokenizer used by this connector.
Render this object as an expression.
Set the system prompt for the LLM system.
Attribute summary
The ID of the model to use.
The system prompt used to set up the LLM system.
If
True
, use CUDA; ifFalse
, use CPUThe chat template to use for the model;
None
if using the default template.Additional chat template parameters.
The environment variable that holds the API key.
The initial delay in seconds between client requests.
The base for the exponential backoff.
Whether to add jitter to the delay.
The maximum number of retries for client requests.
Additional model parameters, passed with every request.
Definitions
- get_api_key()#
Get the API key from the environment variable specified by
api_key_env
.- Return type:
- Returns:
the API key
- Raises:
ValueError – if the environment variable is not set
- get_client()#
Get a shared client instance for this connector; return a cached instance if for this model’s API key if available.
- Return type:
- Returns:
the shared client instance
- classmethod get_default_api_key_env()#
Get the default name of the environment variable that holds the API key.
- Return type:
- Returns:
the default name of the api key environment variable
- get_model_params()#
Get the parameters of the model as a mapping.
This includes all parameters that influence the model’s behavior, but not parameters that determine the model itself or are are specific to the client such as the model ID or the API key.
- async get_response(message, *, history=None, **model_params)#
Get a response, or multiple alternative responses, from the chat system.
- Parameters:
- Return type:
- Returns:
the response or alternative responses generated by the chat system
- Raises:
RequestLimitException – if an error occurs while communicating with the chat system
- get_tokenizer()#
The tokenizer used by this connector.
Gets loaded on first access.
- Return type:
AutoTokenizer
- Returns:
the tokenizer
- to_expression()#
Render this object as an expression.
- Return type:
Expression
- Returns:
the expression representing this object
- with_system_prompt(system_prompt)#
Set the system prompt for the LLM system.
- Parameters:
system_prompt (
str
) – the system prompt to use- Return type:
Self
- Returns:
a new LLM system with the system prompt set