Uses lm mixin
Defines a mixin to initialize classes that use LMRequestProcessor by providing the components directly.
References
NONE
UsesLM
A mixin to initialize classes that use LMRequestProcessor by providing the components directly.
This mixin should be extended by classes that use LMRequestProcessor. Extending this mixin allows the class to create an instance of itself by providing the LMRequestProcessor components directly.
For example:
class LMBasedComponent(BaseComponent, UsesLM):
def __init__(self, lm_request_processor: LMRequestProcessor, custom_kwarg: str):
self.lm_request_processor = lm_request_processor
self.custom_kwarg = custom_kwarg
Then, the class can be instantiated with the following:
component = LMBasedComponent.from_lm_components(
prompt_builder,
lm_invoker,
output_parser,
**{"custom_kwarg": "custom_value"},
)
Note
Classes that extend this mixin must have a constructor that accepts the LMRequestProcessor instance as its first argument.
from_lm_components(prompt_builder, lm_invoker, output_parser=None, **kwargs)
classmethod
Creates an instance by initializing LMRequestProcessor with given components.
This method is a shortcut to initialize the class by providing the LMRequestProcessor components directly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_builder |
PromptBuilder | BasePromptBuilder | MultimodalPromptBuilder
|
The prompt builder used to format the prompt. |
required |
lm_invoker |
BaseLMInvoker | BaseMultimodalLMInvoker
|
The language model invoker that handles the model inference. |
required |
output_parser |
BaseOutputParser
|
An optional parser to process the model's output. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments to be passed to the class constructor. |
{}
|
Returns:
Type | Description |
---|---|
An instance of the class that mixes in this mixin. |
WARNING: Support for MultimodalPromptBuilder is deprecated and will be removed in version 0.5.0.