Define and load a custom model
ModelClient
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.
SimpleNamespace
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.
config_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:
model_client_cls
field and set it to a
string that corresponds to the class name: "CustomModelClient"
.