forked from phoenix/litellm-mirror
(feat) Allow using include to include external YAML files in a config.yaml (#6922)
* add helper to process inlcudes directive on yaml * add doc on config management * unit tests for `include` on config.yaml
This commit is contained in:
parent
4bc06392db
commit
68e59824a3
13 changed files with 226 additions and 25 deletions
|
@ -0,0 +1,5 @@
|
|||
include:
|
||||
- included_models.yaml
|
||||
|
||||
litellm_settings:
|
||||
callbacks: ["prometheus"]
|
|
@ -0,0 +1,5 @@
|
|||
include:
|
||||
- non-existent-file.yaml
|
||||
|
||||
litellm_settings:
|
||||
callbacks: ["prometheus"]
|
|
@ -0,0 +1,6 @@
|
|||
include:
|
||||
- models_file_1.yaml
|
||||
- models_file_2.yaml
|
||||
|
||||
litellm_settings:
|
||||
callbacks: ["prometheus"]
|
|
@ -0,0 +1,4 @@
|
|||
model_list:
|
||||
- model_name: included-model
|
||||
litellm_params:
|
||||
model: gpt-4
|
|
@ -0,0 +1,4 @@
|
|||
model_list:
|
||||
- model_name: included-model-1
|
||||
litellm_params:
|
||||
model: gpt-4
|
|
@ -0,0 +1,4 @@
|
|||
model_list:
|
||||
- model_name: included-model-2
|
||||
litellm_params:
|
||||
model: gpt-3.5-turbo
|
|
@ -23,6 +23,8 @@ import logging
|
|||
|
||||
from litellm.proxy.proxy_server import ProxyConfig
|
||||
|
||||
INVALID_FILES = ["config_with_missing_include.yaml"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_basic_reading_configs_from_files():
|
||||
|
@ -38,6 +40,9 @@ async def test_basic_reading_configs_from_files():
|
|||
print(files)
|
||||
|
||||
for file in files:
|
||||
if file in INVALID_FILES: # these are intentionally invalid files
|
||||
continue
|
||||
print("reading file=", file)
|
||||
config_path = os.path.join(example_config_yaml_path, file)
|
||||
config = await proxy_config_instance.get_config(config_file_path=config_path)
|
||||
print(config)
|
||||
|
@ -115,3 +120,67 @@ async def test_read_config_file_with_os_environ_vars():
|
|||
os.environ[key] = _old_env_vars[key]
|
||||
else:
|
||||
del os.environ[key]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_basic_include_directive():
|
||||
"""
|
||||
Test that the include directive correctly loads and merges configs
|
||||
"""
|
||||
proxy_config_instance = ProxyConfig()
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
config_path = os.path.join(
|
||||
current_path, "example_config_yaml", "config_with_include.yaml"
|
||||
)
|
||||
|
||||
config = await proxy_config_instance.get_config(config_file_path=config_path)
|
||||
|
||||
# Verify the included model list was merged
|
||||
assert len(config["model_list"]) > 0
|
||||
assert any(
|
||||
model["model_name"] == "included-model" for model in config["model_list"]
|
||||
)
|
||||
|
||||
# Verify original config settings remain
|
||||
assert config["litellm_settings"]["callbacks"] == ["prometheus"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_missing_include_file():
|
||||
"""
|
||||
Test that a missing included file raises FileNotFoundError
|
||||
"""
|
||||
proxy_config_instance = ProxyConfig()
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
config_path = os.path.join(
|
||||
current_path, "example_config_yaml", "config_with_missing_include.yaml"
|
||||
)
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
await proxy_config_instance.get_config(config_file_path=config_path)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multiple_includes():
|
||||
"""
|
||||
Test that multiple files in the include list are all processed correctly
|
||||
"""
|
||||
proxy_config_instance = ProxyConfig()
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
config_path = os.path.join(
|
||||
current_path, "example_config_yaml", "config_with_multiple_includes.yaml"
|
||||
)
|
||||
|
||||
config = await proxy_config_instance.get_config(config_file_path=config_path)
|
||||
|
||||
# Verify models from both included files are present
|
||||
assert len(config["model_list"]) == 2
|
||||
assert any(
|
||||
model["model_name"] == "included-model-1" for model in config["model_list"]
|
||||
)
|
||||
assert any(
|
||||
model["model_name"] == "included-model-2" for model in config["model_list"]
|
||||
)
|
||||
|
||||
# Verify original config settings remain
|
||||
assert config["litellm_settings"]["callbacks"] == ["prometheus"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue