mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
Forwarding mode forwarded everything to Python with no native app behind it, and standalone mode built its own, so the two modes could not share a layer. The gateway now builds one native app in main.rs and serves it in both modes. Standalone serves it on its own listener. In front of Python, gateway-forward takes it as any tower Service together with `admit`, never as an axum Router, and composes the two itself, so no request Python answers passes through a native layer. `admit` is the only thing that decides who answers, and x-litellm-gateway names who did. `admit` is a value built from the config and called per request. It judges a request by its route, POST /v1/messages, and its caller, the master key. One that passes is answered by the native app, and Python never sees it. This is the happy path only. The config's settings and the request's headers and body are not judged yet, so a setting or parameter only Python honors is served natively until a later change adds those judges. A gateway that loaded no config refuses every request with reason configuration. x-litellm-gateway now names which check refused, as configuration, route or credential. In front of Python the native app is built from the config file Python runs with. The supervisor resolves the local YAML file by Python's own precedence, which is CONFIG_FILE_PATH, else --config, and none when LITELLM_CONFIG_BUCKET_NAME moves the config to a bucket. It passes the path as LITELLM_FORWARD_CONFIG, and the gateway loads it the way standalone mode does. With no local file the config is empty. A file the gateway cannot load, or a config the native app cannot be built from, is logged as an error and also leaves the config empty with every request refused, because the gateway exiting would stop Python with it. Config stored in the database is not read yet. Forwarding mode now builds the same AppState and verifies the same license as standalone. The new process module reads the environment once and picks the mode, replacing settings.rs. NON_LLM_CONNECTION_TIMEOUT is read the way Python's get_env_int reads it, so a blank or unparsable value no longer stops the gateway, and Python with it, in forwarding mode. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
import os
|
|
from pathlib import Path
|
|
from typing import Final
|
|
|
|
import pytest
|
|
|
|
from litellm.proxy.rust_forward.server import local_config_path
|
|
|
|
|
|
@pytest.fixture
|
|
def config_file(tmp_path: Path) -> str:
|
|
path: Final = tmp_path / "config.yaml"
|
|
path.write_text("model_list: []\n")
|
|
return str(path)
|
|
|
|
|
|
def test_the_cli_config_file_is_the_one_python_loads(config_file: str) -> None:
|
|
assert local_config_path(config_file, {}) == config_file
|
|
|
|
|
|
def test_a_relative_cli_path_is_handed_over_absolute(config_file: str, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.chdir(os.path.dirname(config_file))
|
|
handed_over: Final = local_config_path("config.yaml", {})
|
|
assert handed_over is not None
|
|
assert os.path.isabs(handed_over)
|
|
assert os.path.samefile(handed_over, config_file)
|
|
|
|
|
|
def test_config_file_path_wins_over_the_cli_flag(tmp_path: Path, config_file: str) -> None:
|
|
from_environment: Final = tmp_path / "from_environment.yml"
|
|
from_environment.write_text("model_list: []\n")
|
|
assert local_config_path(config_file, {"CONFIG_FILE_PATH": str(from_environment)}) == str(from_environment)
|
|
|
|
|
|
def test_config_file_path_that_names_no_file_hides_the_cli_flag(tmp_path: Path, config_file: str) -> None:
|
|
assert local_config_path(config_file, {"CONFIG_FILE_PATH": str(tmp_path / "missing.yaml")}) is None
|
|
|
|
|
|
def test_a_config_kept_in_a_bucket_is_not_a_local_file(config_file: str) -> None:
|
|
assert local_config_path(config_file, {"LITELLM_CONFIG_BUCKET_NAME": "configs"}) is None
|
|
|
|
|
|
def test_a_file_that_is_not_yaml_is_not_loaded(tmp_path: Path) -> None:
|
|
not_yaml: Final = tmp_path / "config.json"
|
|
not_yaml.write_text("{}")
|
|
assert local_config_path(str(not_yaml), {}) is None
|
|
|
|
|
|
def test_no_config_anywhere_hands_over_nothing() -> None:
|
|
assert local_config_path(None, {}) is None
|