Requirements
Some extra dependencies are needed for this notebook, which can be installed via pip:For more information, please refer to the installation guide.
Create and configure the custom model
A custom model class can be created in many ways, but needs to adhere to theModelClient protocol and response structure which is defined in
client.py and shown below.
The response protocol has some minimum requirements, but can be extended
to include any additional information that is needed. Message retrieval
therefore can be customized, but needs to return a list of strings or a
list of ModelClientResponseProtocol.Choice.Message objects.
Example of simple custom client
Following the huggingface example for using Mistral’s Open-Orca For the response object, python’sSimpleNamespace is used to create a
simple object that can be used to store the response data, but any
object that follows the ClientResponseProtocol can be used.
Set your API Endpoint
Theconfig_list_from_json
function loads a list of configurations from an environment variable or
a json file.
It first looks for an environment variable of a specified name
(“OAI_CONFIG_LIST” in this example), which needs to be a valid json
string. If that variable is not found, it looks for a json file with the
same name. It filters the configs by models (you can filter by other
keys as well).
The json looks like the following:
Set the config for the custom model
You can add any parameters that are needed for the custom model loading in the same configuration list. It is important to add themodel_client_cls field and set it to a
string that corresponds to the class name: "CustomModelClient".