➕How to add new LLM?
We're living in a time where there are many Large language models available. Each possessing its distinct characteristics. To integrate these models effectively, one must adhere to three common practices:
Configuring parameters required by the LLM, such as API Key and model name.
Loading the LLM through appropriate function calls.
Predicting responses from the LLM based on user prompts.
We follow the same procedures for integrating new LLMs. Here's an example of how to add a new LLM, such as Gemini.
Note:
Each LLM has its own documentation. We should refer to their documentation to learn how to initialise and make predictions with them.
Configure Parameters
As mentioned, each LLM model requires certain user inputs and configurations for integration. We define a dataclass that encapsulates the possible parameters needed to configure the LLM. By using a dataclass, we can implement a static method to load the keyword arguments. In the __post_init__
function, we typically initialize the model. If the model requires an API key to be read from an environment variable, this can be declared in the __post_init__
function. This format is consistent across other models such as ChatOpenAI
and HuggingFace
.
Note: load_from_kwargs
is a default static method, that is used in every LLM. This ensures that the user can enter any parameters that is supported by that model.
Load LLM
At Enterprise RAG we provide the flexibility to use any LLM based on user choice, this is where we provide the flexibility to add new LLM, and install only when they use it. The load LLM is a simple function that just initialize the model.
predict
The predict
function takes user input and generates the response. Here, various API formats are used to generate the response, and we select the index where the complete response is displayed.
Last updated