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
feat(utils.py): support global vertex ai safety settings param
Krrish Dholakia3c99ad19fa16
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 6c7529477f5..c7648ac07f0 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -339,6 +339,7 @@ api_version = Noneorganization = Noneproject = Noneconfig_path = None+vertex_ai_safety_settings: Optional[dict] = None####### COMPLETION MODELS ###################open_ai_chat_completion_models: List = []open_ai_text_completion_models: List = []diff --git a/litellm/tests/test_optional_params.py b/litellm/tests/test_optional_params.pyindex 2b6e07f63c9..7bda4f0a4d4 100644--- a/litellm/tests/test_optional_params.py+++ b/litellm/tests/test_optional_params.py@@ -19,7 +19,11 @@ from litellm.types.completion import (ChatCompletionSystemMessageParam,ChatCompletionUserMessageParam,)-from litellm.utils import get_optional_params, get_optional_params_embeddings+from litellm.utils import (+ get_optional_params,+ get_optional_params_embeddings,+ get_optional_params_image_gen,+)## get_optional_params_embeddings### Models: OpenAI, Azure, Bedrock@@ -430,7 +434,6 @@ def test_get_optional_params_image_gen():print(response)assert "aws_region_name" not in response-response = litellm.utils.get_optional_params_image_gen(aws_region_name="us-east-1", custom_llm_provider="bedrock")@@ -463,3 +466,36 @@ def test_get_optional_params_num_retries():print(f"mock_client.call_args: {mock_client.call_args}")assert mock_client.call_args.kwargs["max_retries"] == 10+++ "provider",+ [+ "vertex_ai",+ "vertex_ai_beta",+ ],+)+def test_vertex_safety_settings(provider):+ litellm.vertex_ai_safety_settings = [+ {+ "category": "HARM_CATEGORY_HARASSMENT",+ "threshold": "BLOCK_NONE",+ },+ {+ "category": "HARM_CATEGORY_HATE_SPEECH",+ "threshold": "BLOCK_NONE",+ },+ {+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",+ "threshold": "BLOCK_NONE",+ },+ {+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",+ "threshold": "BLOCK_NONE",+ },+ ]++ optional_params = get_optional_params(+ model="gemini-1.5-pro", custom_llm_provider=provider+ )+ assert len(optional_params) == 1diff --git a/litellm/utils.py b/litellm/utils.pyindex 0c15cae53e7..0e9e531e98a 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -3145,7 +3145,6 @@ def get_optional_params(or model in litellm.vertex_embedding_modelsor model in litellm.vertex_vision_models):- print_verbose(f"(start) INSIDE THE VERTEX AI OPTIONAL PARAM BLOCK")## check if unsupported param passed insupported_params = get_supported_openai_params(model=model, custom_llm_provider=custom_llm_provider@@ -3157,9 +3156,8 @@ def get_optional_params(optional_params=optional_params,)- print_verbose(- f"(end) INSIDE THE VERTEX AI OPTIONAL PARAM BLOCK - optional_params: {optional_params}"- )+ if litellm.vertex_ai_safety_settings is not None:+ optional_params["safety_settings"] = litellm.vertex_ai_safety_settingselif custom_llm_provider == "gemini":supported_params = get_supported_openai_params(model=model, custom_llm_provider=custom_llm_provider@@ -3170,7 +3168,7 @@ def get_optional_params(optional_params=optional_params,model=model,)- elif custom_llm_provider == "vertex_ai_beta" or custom_llm_provider == "gemini":+ elif custom_llm_provider == "vertex_ai_beta":supported_params = get_supported_openai_params(model=model, custom_llm_provider=custom_llm_provider)@@ -3185,6 +3183,8 @@ def get_optional_params(else False),)+ if litellm.vertex_ai_safety_settings is not None:+ optional_params["safety_settings"] = litellm.vertex_ai_safety_settingselif (custom_llm_provider == "vertex_ai" and model in litellm.vertex_anthropic_models):