Local#
dbally.llms.local.LocalLLM
#
LocalLLM(model_name: str, default_options: Optional[LocalLLMOptions] = None, *, api_key: Optional[str] = None)
Bases: LLM[LocalLLMOptions]
Class for interaction with any LLM available in HuggingFace.
Constructs a new local LLM instance.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the model to use. This should be a model from the CausalLM class.
TYPE:
|
default_options |
Default options for the LLM.
TYPE:
|
api_key |
The API key for Hugging Face authentication.
TYPE:
|
Source code in src/dbally/llms/local.py
client
cached
property
#
client: LocalLLMClient
Client for the LLM.
RETURNS | DESCRIPTION |
---|---|
LocalLLMClient
|
The client used to interact with the LLM. |
generate_text
async
#
generate_text(prompt: PromptTemplate, *, event_tracker: Optional[EventTracker] = None, options: Optional[LLMOptions] = None) -> str
Prepares and sends a prompt to the LLM and returns the response.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and response parsing configuration.
TYPE:
|
event_tracker |
Event store used to audit the generation process.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Text response from LLM. |
RAISES | DESCRIPTION |
---|---|
LLMError
|
If LLM text generation fails. |
Source code in src/dbally/llms/base.py
count_tokens
#
count_tokens(prompt: PromptTemplate) -> int
Counts tokens in the messages.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Messages to count tokens for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Number of tokens in the messages. |
Source code in src/dbally/llms/local.py
dbally.llms.clients.local.LocalLLMClient
#
Bases: LLMClient[LocalLLMOptions]
Client for the local LLM that supports Hugging Face models.
Constructs a new local LLMClient instance.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the model to use.
TYPE:
|
hf_api_key |
The Hugging Face API key for authentication.
TYPE:
|
Source code in src/dbally/llms/clients/local.py
model
instance-attribute
#
call
async
#
call(conversation: ChatFormat, options: LocalLLMOptions, event: LLMEvent, json_mode: bool = False) -> str
Makes a call to the local LLM with the provided prompt and options.
PARAMETER | DESCRIPTION |
---|---|
conversation |
List of dicts with "role" and "content" keys, representing the chat history so far.
TYPE:
|
options |
Additional settings used by the LLM.
TYPE:
|
event |
Container with the prompt, LLM response, and call metrics.
TYPE:
|
json_mode |
Force the response to be in JSON format.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Response string from LLM. |
Source code in src/dbally/llms/clients/local.py
dbally.llms.clients.local.LocalLLMOptions
dataclass
#
LocalLLMOptions(repetition_penalty: Union[Optional[float], NotGiven] = NOT_GIVEN, do_sample: Union[Optional[bool], NotGiven] = NOT_GIVEN, best_of: Union[Optional[int], NotGiven] = NOT_GIVEN, max_new_tokens: Union[Optional[int], NotGiven] = NOT_GIVEN, top_k: Union[Optional[int], NotGiven] = NOT_GIVEN, top_p: Union[Optional[float], NotGiven] = NOT_GIVEN, seed: Union[Optional[int], NotGiven] = NOT_GIVEN, stop_sequences: Union[Optional[List[str]], NotGiven] = NOT_GIVEN, temperature: Union[Optional[float], NotGiven] = NOT_GIVEN)
Bases: LLMOptions
Dataclass that represents all available LLM call options for the local LLM client. Each of them is described in the [HuggingFace documentation] (https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client#huggingface_hub.InferenceClient.text_generation). # pylint: disable=line-too-long
repetition_penalty
class-attribute
instance-attribute
#
do_sample
class-attribute
instance-attribute
#
max_new_tokens
class-attribute
instance-attribute
#
stop_sequences
class-attribute
instance-attribute
#
temperature
class-attribute
instance-attribute
#
dict
#
Creates a dictionary representation of the LLMOptions instance. If a value is None, it will be replaced with a provider-specific not-given sentinel.
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any]
|
A dictionary representation of the LLMOptions instance. |