LLMs#
ragbits.core.llms.LLM
#
Bases: Generic[LLMClientOptions]
, ABC
Abstract class for interaction with Large Language Model.
Constructs a new LLM instance.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the model to be used.
TYPE:
|
default_options |
Default options to be used.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the subclass is missing the '_options_cls' attribute. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
count_tokens
#
Counts tokens in the prompt.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and response parsing configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Number of tokens in the prompt. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_raw
async
#
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Raw text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and optional response parsing configuration.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OutputT
|
Text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_streaming
async
#
generate_streaming(prompt: BasePrompt, *, options: LLMOptions | None = None) -> AsyncGenerator[str, None]
Prepares and sends a prompt to the LLM and streams the results.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncGenerator[str, None]
|
Response stream from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
ragbits.core.llms.local.LocalLLM
#
LocalLLM(model_name: str, default_options: LocalLLMOptions | None = None, *, api_key: str | None = 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:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the 'local' extra requirements are not installed. |
Source code in packages/ragbits-core/src/ragbits/core/llms/local.py
client
cached
property
#
Client for the LLM.
RETURNS | DESCRIPTION |
---|---|
LocalLLMClient
|
The client used to interact with the LLM. |
generate_raw
async
#
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Raw text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and optional response parsing configuration.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OutputT
|
Text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_streaming
async
#
generate_streaming(prompt: BasePrompt, *, options: LLMOptions | None = None) -> AsyncGenerator[str, None]
Prepares and sends a prompt to the LLM and streams the results.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncGenerator[str, None]
|
Response stream from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
count_tokens
#
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 packages/ragbits-core/src/ragbits/core/llms/local.py
ragbits.core.llms.litellm.LiteLLM
#
LiteLLM(model_name: str = 'gpt-3.5-turbo', default_options: LiteLLMOptions | None = None, *, base_url: str | None = None, api_key: str | None = None, api_version: str | None = None, use_structured_output: bool = False)
Bases: LLM[LiteLLMOptions]
Class for interaction with any LLM supported by LiteLLM API.
Constructs a new LiteLLM instance.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the LiteLLM supported model to be used. Default is "gpt-3.5-turbo".
TYPE:
|
default_options |
Default options to be used.
TYPE:
|
base_url |
Base URL of the LLM API.
TYPE:
|
api_key |
API key to be used. API key to be used. If not specified, an environment variable will be used, for more information, follow the instructions for your specific vendor in the LiteLLM documentation.
TYPE:
|
api_version |
API version to be used. If not specified, the default version will be used.
TYPE:
|
use_structured_output |
Whether to request a structured output from the model. Default is False. Can only be combined with models that support structured output.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the 'litellm' extra requirements are not installed. |
Source code in packages/ragbits-core/src/ragbits/core/llms/litellm.py
generate_raw
async
#
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Raw text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and optional response parsing configuration.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OutputT
|
Text response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_streaming
async
#
generate_streaming(prompt: BasePrompt, *, options: LLMOptions | None = None) -> AsyncGenerator[str, None]
Prepares and sends a prompt to the LLM and streams the results.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncGenerator[str, None]
|
Response stream from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
count_tokens
#
Counts tokens in the prompt.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation and response parsing configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Number of tokens in the prompt. |