From d8e28f569c838e52e1fa804de62b786bd971cb96 Mon Sep 17 00:00:00 2001 From: Peter Muller Date: Fri, 7 Jun 2024 11:27:45 -0700 Subject: [PATCH] Fix None values from config file where array is expected (#24) --- lib/schema.ts | 7 ++++++- lib/serve/rest-api/src/utils/generate_litellm_config.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/schema.ts b/lib/schema.ts index 7078e718..759ccef1 100644 --- a/lib/schema.ts +++ b/lib/schema.ts @@ -727,7 +727,12 @@ const LiteLLMModel = z.object({ */ const LiteLLMConfig = z.object({ environment_variables: z.map(z.string(), z.string()).optional(), - model_list: z.array(LiteLLMModel).optional().nullable().default([]), + model_list: z + .array(LiteLLMModel) + .optional() + .nullable() + .default([]) + .transform((value) => value ?? []), litellm_settings: z.object({ // ALL (https://github.com/BerriAI/litellm/blob/main/litellm/__init__.py) telemetry: z.boolean().default(false).optional(), diff --git a/lib/serve/rest-api/src/utils/generate_litellm_config.py b/lib/serve/rest-api/src/utils/generate_litellm_config.py index 81a1ba27..57cae97c 100644 --- a/lib/serve/rest-api/src/utils/generate_litellm_config.py +++ b/lib/serve/rest-api/src/utils/generate_litellm_config.py @@ -48,7 +48,9 @@ def generate_config(filepath: str) -> None: } for model in registered_models ] - config_contents["model_list"].extend(litellm_model_params) + config_models = config_contents["model_list"] or [] # ensure config_models is a list and not None + config_models.extend(litellm_model_params) + config_contents["model_list"] = config_models # Write updated config back to original path with open(filepath, "w") as fp: yaml.safe_dump(config_contents, fp)