The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Litellm dev 12 19 2024 p2 (#7315)
Krish Dholakia4c7a3931b7af
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yamlindex e2b562bfc15..4d9879c37a1 100644--- a/litellm/proxy/_new_secret_config.yaml+++ b/litellm/proxy/_new_secret_config.yaml@@ -20,5 +20,9 @@ model_list:api_version: "2024-05-01-preview"litellm_settings:- success_callback: ["langsmith"]- num_retries: 0\ No newline at end of file+ default_team_settings:+ - team_id: c91e32bb-0f2a-4aa1-86c4-307ca2e03ea3+ success_callback: ["langfuse"]+ failure_callback: ["langfuse"]+ langfuse_public_key: my-fake-key+ langfuse_secret: my-fake-secretdiff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 3c5f2ef4d55..024bd953057 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -1354,6 +1354,19 @@ class ProxyConfig:config[key] = get_secret(value)return config+ def _get_team_config(self, team_id: str, all_teams_config: List[Dict]) -> Dict:+ team_config: dict = {}+ for team in all_teams_config:+ if "team_id" not in team:+ raise Exception(f"team_id missing from team: {team}")+ if team_id == team["team_id"]:+ team_config = team+ break+ for k, v in team_config.items():+ if isinstance(v, str) and v.startswith("os.environ/"):+ team_config[k] = get_secret(v)+ return team_config+async def load_team_config(self, team_id: str):"""- for a given team id@@ -1366,18 +1379,11 @@ class ProxyConfig:## LITELLM MODULE SETTINGS (e.g. litellm.drop_params=True,..)litellm_settings = config.get("litellm_settings", {})all_teams_config = litellm_settings.get("default_team_settings", None)- team_config: dict = {}if all_teams_config is None:- return team_config- for team in all_teams_config:- if "team_id" not in team:- raise Exception(f"team_id missing from team: {team}")- if team_id == team["team_id"]:- team_config = team- break- for k, v in team_config.items():- if isinstance(v, str) and v.startswith("os.environ/"):- team_config[k] = get_secret(v)+ return {}+ team_config = self._get_team_config(+ team_id=team_id, all_teams_config=all_teams_config+ )return team_configdef _init_cache(@@ -1452,9 +1458,12 @@ class ProxyConfig:config = self._check_for_os_environ_vars(config=config)- self.config = config+ self.update_config_state(config=config)return config+ def update_config_state(self, config: dict):+ self.config = config+async def load_config( # noqa: PLR0915self, router: Optional[litellm.Router], config_file_path: str):@@ -2272,6 +2281,24 @@ class ProxyConfig:pass_through_endpoints=general_settings["pass_through_endpoints"])+ def _update_config_fields(+ self,+ current_config: dict,+ param_name: str,+ db_param_value: Any,+ ) -> dict:+ if isinstance(current_config[param_name], dict):+ # if dict exists (e.g. litellm_settings),+ # go through each key and value,+ # and update if new value is not None/empty dict+ for key, value in db_param_value.items():+ if value:+ current_config[param_name][key] = value+ else:+ current_config[param_name] = db_param_value++ return current_config+async def _update_config_from_db(self,prisma_client: PrismaClient,@@ -2311,10 +2338,11 @@ class ProxyConfig:if param_name is not None and param_value is not None:# check if param_name is already in the configif param_name in config:- if isinstance(config[param_name], dict):- config[param_name].update(param_value)- else:- config[param_name] = param_value+ config = self._update_config_fields(+ current_config=config,+ param_name=param_name,+ db_param_value=param_value,+ )else:# if it's not in the config - then add itconfig[param_name] = param_valuediff --git a/tests/llm_translation/test_optional_params.py b/tests/llm_translation/test_optional_params.pyindex bfd5ee2a476..341484595c9 100644--- a/tests/llm_translation/test_optional_params.py+++ b/tests/llm_translation/test_optional_params.py@@ -502,6 +502,20 @@ def test_dynamic_drop_additional_params(drop_params):pass+def test_dynamic_drop_additional_params_stream_options():+ """+ Make a call to vertex ai, dropping 'stream_options' specifically+ """+ optional_params = litellm.utils.get_optional_params(+ model="mistral-large-2411@001",+ custom_llm_provider="vertex_ai",+ stream_options={"include_usage": True},+ additional_drop_params=["stream_options"],+ )++ assert "stream_options" not in optional_params++def test_dynamic_drop_additional_params_e2e():with patch("litellm.llms.custom_httpx.http_handler.HTTPHandler.post", new=MagicMock()diff --git a/tests/local_testing/test_router.py b/tests/local_testing/test_router.pyindex 6a91ee507c0..829447ad385 100644--- a/tests/local_testing/test_router.py+++ b/tests/local_testing/test_router.py@@ -2220,22 +2220,6 @@ def test_router_cooldown_api_connection_error():except litellm.APIConnectionError:pass- try:- router.completion(- model="gemini-1.5-pro",- messages=[{"role": "admin", "content": "Fail on this!"}],- )- except litellm.APIConnectionError:- pass-- try:- router.completion(- model="gemini-1.5-pro",- messages=[{"role": "admin", "content": "Fail on this!"}],- )- except litellm.APIConnectionError:- pass-def test_router_correctly_reraise_error():"""diff --git a/tests/proxy_unit_tests/test_proxy_utils.py b/tests/proxy_unit_tests/test_proxy_utils.pyindex 5ebff141a97..2648c748fbc 100644--- a/tests/proxy_unit_tests/test_proxy_utils.py+++ b/tests/proxy_unit_tests/test_proxy_utils.py@@ -934,3 +934,45 @@ def test_get_team_models():model_access_groups=model_access_groups,)assert result == ["gpt-4o", "gpt-3.5-turbo", "gpt-4o-mini"]+++def test_update_config_fields():+ from litellm.proxy.proxy_server import ProxyConfig++ proxy_config = ProxyConfig()++ args = {+ "current_config": {+ "litellm_settings": {+ "default_team_settings": [+ {+ "team_id": "c91e32bb-0f2a-4aa1-86c4-307ca2e03ea3",+ "success_callback": ["langfuse"],+ "failure_callback": ["langfuse"],+ "langfuse_public_key": "my-fake-key",+ "langfuse_secret": "my-fake-secret",+ }+ ]+ },+ },+ "param_name": "litellm_settings",+ "db_param_value": {+ "telemetry": False,+ "drop_params": True,+ "num_retries": 5,+ "request_timeout": 600,+ "success_callback": ["langfuse"],+ "default_team_settings": [],+ "context_window_fallbacks": [{"gpt-3.5-turbo": ["gpt-3.5-turbo-large"]}],+ },+ }+ updated_config = proxy_config._update_config_fields(**args)++ all_team_config = updated_config["litellm_settings"]["default_team_settings"]++ # check if team id config returned+ team_config = proxy_config._get_team_config(+ team_id="c91e32bb-0f2a-4aa1-86c4-307ca2e03ea3", all_teams_config=all_team_config+ )+ assert team_config["langfuse_public_key"] == "my-fake-key"+ assert team_config["langfuse_secret"] == "my-fake-secret"