LLMs#
ragbits.core.llms.LLM
#
Bases: ConfigurableComponent[LLMClientOptionsT]
, 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
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory. Supports both synchronous and asynchronous factory functions.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
get_model_id
abstractmethod
#
get_estimated_cost
abstractmethod
#
Returns the estimated cost of the LLM call.
PARAMETER | DESCRIPTION |
---|---|
prompt_tokens |
The number of tokens in the prompt.
TYPE:
|
completion_tokens |
The number of tokens in the completion.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The estimated cost of the LLM call. |
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
get_token_id
#
Gets token id.
PARAMETER | DESCRIPTION |
---|---|
token |
The token to encode.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The id for the given token. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_raw
async
#
generate_raw(prompt: BasePrompt | str | ChatFormat, *, options: LLMClientOptionsT | None = None) -> dict
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Raw response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
generate(prompt: str | ChatFormat | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[ChatFormat | str] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
Prepares and sends a prompt to the LLM and returns the parsed response.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
|
Parsed response(s) from LLM or list of tool calls. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_with_metadata
async
#
generate_with_metadata(prompt: str | ChatFormat | MutableSequence[str | ChatFormat] | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
|
ResponseWithMetadata object(s) with text response, list of tool calls and metadata information. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
generate_streaming
#
generate_streaming(prompt: str | ChatFormat | BasePrompt, *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResultStreaming
This method returns an LLMResultStreaming
object that can be asynchronously
iterated over. After the loop completes, metadata is available as metadata
attribute.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResultStreaming
|
Response stream from LLM or list of tool calls. |
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, price_per_prompt_token: float = 0.0, price_per_completion_token: float = 0.0)
Bases: LLM[LocalLLMOptions]
Class for interaction with any LLM available in HuggingFace.
Note: Local implementation is not dedicated for production. Use it only in experiments / evaluation
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:
|
price_per_prompt_token |
The price per prompt token.
TYPE:
|
price_per_completion_token |
The price per completion token.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the 'local' extra requirements are not installed. |
ValueError
|
If the model was not trained as a chat model. |
Source code in packages/ragbits-core/src/ragbits/core/llms/local.py
model
instance-attribute
#
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory. Supports both synchronous and asynchronous factory functions.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
get_token_id
#
Gets token id.
PARAMETER | DESCRIPTION |
---|---|
token |
The token to encode.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The id for the given token. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_raw
async
#
generate_raw(prompt: BasePrompt | str | ChatFormat, *, options: LLMClientOptionsT | None = None) -> dict
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Raw response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
generate(prompt: str | ChatFormat | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[ChatFormat | str] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
Prepares and sends a prompt to the LLM and returns the parsed response.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
|
Parsed response(s) from LLM or list of tool calls. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_with_metadata
async
#
generate_with_metadata(prompt: str | ChatFormat | MutableSequence[str | ChatFormat] | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
|
ResponseWithMetadata object(s) with text response, list of tool calls and metadata information. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
generate_streaming
#
generate_streaming(prompt: str | ChatFormat | BasePrompt, *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResultStreaming
This method returns an LLMResultStreaming
object that can be asynchronously
iterated over. After the loop completes, metadata is available as metadata
attribute.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResultStreaming
|
Response stream from LLM or list of tool calls. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
get_model_id
#
get_estimated_cost
#
Returns the estimated cost of the LLM call.
Source code in packages/ragbits-core/src/ragbits/core/llms/local.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, *, api_base: str | None = None, base_url: str | None = None, api_key: str | None = None, api_version: str | None = None, use_structured_output: bool = False, router: Router | None = None, custom_model_cost_config: dict | None = None)
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:
|
api_base |
Base URL of the LLM API.
TYPE:
|
base_url |
Alias for api_base. If both are provided, api_base takes precedence.
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:
|
router |
Router to be used to route requests to different models.
TYPE:
|
custom_model_cost_config |
Custom cost and capabilities configuration for the model. Necessary for custom model cost and capabilities tracking in LiteLLM. See the LiteLLM documentation for more information.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/llms/litellm.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory. Supports both synchronous and asynchronous factory functions.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
generate_raw
async
#
generate_raw(prompt: BasePrompt | str | ChatFormat, *, options: LLMClientOptionsT | None = None) -> dict
Prepares and sends a prompt to the LLM and returns the raw response (without parsing).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
Raw response from LLM. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate
async
#
generate(prompt: str | ChatFormat | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[ChatFormat | str] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
Prepares and sends a prompt to the LLM and returns the parsed response.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | PromptOutputT | list[ToolCall] | list[list[ToolCall] | str] | list[str | PromptOutputT | list[ToolCall]]
|
Parsed response(s) from LLM or list of tool calls. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
generate_with_metadata
async
#
generate_with_metadata(prompt: str | ChatFormat | MutableSequence[str | ChatFormat] | BasePrompt | BasePromptWithParser[PromptOutputT] | MutableSequence[BasePrompt | BasePromptWithParser[PromptOutputT]], *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
Prepares and sends a prompt to the LLM and returns response parsed to the output type of the prompt (if available).
PARAMETER | DESCRIPTION |
---|---|
prompt |
Can be one of: - BasePrompt instance: Formatted prompt template with conversation - str: Simple text prompt that will be sent as a user message - ChatFormat: List of message dictionaries in OpenAI chat format - Iterable of any of the above (MutableSequence is only for typing purposes)
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM client.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResponseWithMetadata[str] | list[LLMResponseWithMetadata[str]] | LLMResponseWithMetadata[PromptOutputT] | list[LLMResponseWithMetadata[PromptOutputT]]
|
ResponseWithMetadata object(s) with text response, list of tool calls and metadata information. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
generate_streaming
#
generate_streaming(prompt: str | ChatFormat | BasePrompt, *, tools: list[Tool] | None = None, options: LLMClientOptionsT | None = None) -> LLMResultStreaming
This method returns an LLMResultStreaming
object that can be asynchronously
iterated over. After the loop completes, metadata is available as metadata
attribute.
PARAMETER | DESCRIPTION |
---|---|
prompt |
Formatted prompt template with conversation.
TYPE:
|
tools |
Functions to be used as tools by the LLM.
TYPE:
|
options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMResultStreaming
|
Response stream from LLM or list of tool calls. |
Source code in packages/ragbits-core/src/ragbits/core/llms/base.py
get_model_id
#
get_estimated_cost
#
Returns the estimated cost of the LLM call.
PARAMETER | DESCRIPTION |
---|---|
prompt_tokens |
The number of tokens in the prompt.
TYPE:
|
completion_tokens |
The number of tokens in the completion.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The estimated cost of the LLM call. |
Source code in packages/ragbits-core/src/ragbits/core/llms/litellm.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/litellm.py
get_token_id
#
Gets token id.
PARAMETER | DESCRIPTION |
---|---|
token |
The token to encode.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The id for the given token. |
Source code in packages/ragbits-core/src/ragbits/core/llms/litellm.py
from_config
classmethod
#
Creates and returns a LiteLLM instance.
PARAMETER | DESCRIPTION |
---|---|
config |
A configuration object containing the configuration for initializing the LiteLLM instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LiteLLM
|
An initialized LiteLLM instance.
TYPE:
|