Skip to content

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]

fix: fix model param mapping

Krrish Dholakiadefd6025131f
diff --git a/litellm/llms/featherless_ai/chat/transformation.py b/litellm/llms/featherless_ai/chat/transformation.py
index aac887d7357..96702cf886e 100644
--- a/litellm/llms/featherless_ai/chat/transformation.py
+++ b/litellm/llms/featherless_ai/chat/transformation.py
@@ -26,7 +26,6 @@ class FeatherlessAIConfig(OpenAIGPTConfig):
tool_choice: Optional[str] = None
tools: Optional[list] = None
-
def __init__(
self,
frequency_penalty: Optional[int] = None,
@@ -66,9 +65,6 @@ class FeatherlessAIConfig(OpenAIGPTConfig):
"stop",
"temperature",
"top_p",
- "response_format",
- "tool_choice",
- "tools"
]
def map_openai_params(
@@ -125,8 +121,8 @@ class FeatherlessAIConfig(OpenAIGPTConfig):
) -> dict:
if not api_key:
raise ValueError("Missing Featherless AI API Key")
-
+
headers["Authorization"] = f"Bearer {api_key}"
headers["Content-Type"] = "application/json"
-
+
return headers
diff --git a/litellm/llms/sambanova/chat.py b/litellm/llms/sambanova/chat.py
index 3eda4d0bbfe..57a39ec8bbc 100644
--- a/litellm/llms/sambanova/chat.py
+++ b/litellm/llms/sambanova/chat.py
@@ -26,7 +26,7 @@ class SambanovaConfig(OpenAIGPTConfig):
tool_choice: Optional[str] = None
response_format: Optional[dict] = None
tools: Optional[list] = None
-
+
def __init__(
self,
max_tokens: Optional[int] = None,
@@ -54,8 +54,10 @@ class SambanovaConfig(OpenAIGPTConfig):
Get the supported OpenAI params for the given model
"""
+ from litellm.utils import supports_function_calling
- return [
+ params = [
+ "max_completion_tokens",
"max_tokens",
"response_format",
"stop",
@@ -64,11 +66,15 @@ class SambanovaConfig(OpenAIGPTConfig):
"temperature",
"top_p",
"top_k",
- "tool_choice",
- "tools",
- "parallel_tool_calls"
]
+ if supports_function_calling(model, custom_llm_provider="sambanova"):
+ params.append("tools")
+ params.append("tool_choice")
+ params.append("parallel_tool_calls")
+
+ return params
+
def map_openai_params(
self,
non_default_params: dict,
@@ -85,4 +91,4 @@ class SambanovaConfig(OpenAIGPTConfig):
optional_params["max_tokens"] = value
elif param in supported_openai_params:
optional_params[param] = value
- return optional_params
\ No newline at end of file
+ return optional_params
diff --git a/tests/litellm/test_utils.py b/tests/litellm/test_utils.py
index 12fd42bfb90..f8fe4bd90d9 100644
--- a/tests/litellm/test_utils.py
+++ b/tests/litellm/test_utils.py
@@ -11,7 +11,12 @@ sys.path.insert(
) # Adds the parent directory to the system path
import litellm
-from litellm.utils import get_optional_params_image_gen
+from litellm.types.utils import LlmProviders
+from litellm.utils import (
+ ProviderConfigManager,
+ get_llm_provider,
+ get_optional_params_image_gen,
+)
# Adds the parent directory to the system path
@@ -473,7 +478,8 @@ def test_aaamodel_prices_and_context_window_json_is_valid():
},
}
- prod_json = "./model_prices_and_context_window.json"
+ # prod_json = "./model_prices_and_context_window.json"
+ prod_json = "../../model_prices_and_context_window.json"
with open(prod_json, "r") as model_prices_file:
actual_json = json.load(model_prices_file)
assert isinstance(actual_json, dict)
@@ -518,3 +524,172 @@ def test_openai_models_in_model_info():
assert (
len(violated_models) == 0
), f"The following models should support pdf input: {violated_models}"
+
+
+def test_supports_tool_choice_simple_tests():
+ """
+ simple sanity checks
+ """
+ assert litellm.utils.supports_tool_choice(model="gpt-4o") == True
+ assert (
+ litellm.utils.supports_tool_choice(
+ model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0"
+ )
+ == True
+ )
+ assert (
+ litellm.utils.supports_tool_choice(
+ model="anthropic.claude-3-sonnet-20240229-v1:0"
+ )
+ is True
+ )
+
+ assert (
+ litellm.utils.supports_tool_choice(
+ model="anthropic.claude-3-sonnet-20240229-v1:0",
+ custom_llm_provider="bedrock_converse",
+ )
+ is True
+ )
+
+ assert (
+ litellm.utils.supports_tool_choice(model="us.amazon.nova-micro-v1:0") is False
+ )
+ assert (
+ litellm.utils.supports_tool_choice(model="bedrock/us.amazon.nova-micro-v1:0")
+ is False
+ )
+ assert (
+ litellm.utils.supports_tool_choice(
+ model="us.amazon.nova-micro-v1:0", custom_llm_provider="bedrock_converse"
+ )
+ is False
+ )
+
+ assert litellm.utils.supports_tool_choice(model="perplexity/sonar") is False
+
+
+def test_check_provider_match():
+ """
+ Test the _check_provider_match function for various provider scenarios
+ """
+ # Test bedrock and bedrock_converse cases
+ model_info = {"litellm_provider": "bedrock"}
+ assert litellm.utils._check_provider_match(model_info, "bedrock") is True
+ assert litellm.utils._check_provider_match(model_info, "bedrock_converse") is True
+
+ # Test bedrock_converse provider
+ model_info = {"litellm_provider": "bedrock_converse"}
+ assert litellm.utils._check_provider_match(model_info, "bedrock") is True
+ assert litellm.utils._check_provider_match(model_info, "bedrock_converse") is True
+
+ # Test non-matching provider
+ model_info = {"litellm_provider": "bedrock"}
+ assert litellm.utils._check_provider_match(model_info, "openai") is False
+
+
+# Models that should be skipped during testing
+OLD_PROVIDERS = ["aleph_alpha", "palm"]
+SKIP_MODELS = [
+ "azure/mistral",
+ "azure/command-r",
+ "jamba",
+ "deepinfra",
+ "mistral.",
+ "groq/llama-guard-3-8b",
+ "groq/gemma2-9b-it",
+]
+
+# Bedrock models to block - organized by type
+BEDROCK_REGIONS = ["ap-northeast-1", "eu-central-1", "us-east-1", "us-west-2"]
+BEDROCK_COMMITMENTS = ["1-month-commitment", "6-month-commitment"]
+BEDROCK_MODELS = {
+ "anthropic.claude-v1",
+ "anthropic.claude-v2",
+ "anthropic.claude-v2:1",
+ "anthropic.claude-instant-v1",
+}
+
+# Generate block_list dynamically
+block_list = set()
+for region in BEDROCK_REGIONS:
+ for commitment in BEDROCK_COMMITMENTS:
+ for model in BEDROCK_MODELS:
+ block_list.add(f"bedrock/{region}/{commitment}/{model}")
+ block_list.add(f"bedrock/{region}/{model}")
+
+# Add Cohere models
+for commitment in BEDROCK_COMMITMENTS:
+ block_list.add(f"bedrock/*/{commitment}/cohere.command-text-v14")
+ block_list.add(f"bedrock/*/{commitment}/cohere.command-light-text-v14")
+
+print("block_list", block_list)
+
+
+async def test_supports_tool_choice():
+ """
+ Test that litellm.utils.supports_tool_choice() returns the correct value
+ for all models in model_prices_and_context_window.json.
+
+ The test:
+ 1. Loads model pricing data
+ 2. Iterates through each model
+ 3. Checks if tool_choice support matches the model's supported parameters
+ """
+ # Load model prices
+ litellm._turn_on_debug()
+ path = "../../model_prices_and_context_window.json"
+ # path = "./model_prices_and_context_window.json"
+ with open(path, "r") as f:
+ model_prices = json.load(f)
+ litellm.model_cost = model_prices
+ config_manager = ProviderConfigManager()
+
+ for model_name, model_info in model_prices.items():
+ print(f"testing model: {model_name}")
+
+ # Skip certain models
+ if (
+ model_name == "sample_spec"
+ or model_info.get("mode") != "chat"
+ or any(skip in model_name for skip in SKIP_MODELS)
+ or any(provider in model_name for provider in OLD_PROVIDERS)
+ or model_info["litellm_provider"] in OLD_PROVIDERS
+ or model_name in block_list
+ or "azure/eu" in model_name
+ or "azure/us" in model_name
+ or "codestral" in model_name
+ or "o1" in model_name
+ or "o3" in model_name
+ or "mistral" in model_name
+ ):
+ continue
+
+ try:
+ model, provider, _, _ = get_llm_provider(model=model_name)
+ except Exception as e:
+ print(f"\033[91mERROR for {model_name}: {e}\033[0m")
+ continue
+
+ # Get provider config and supported params
+ print("LLM provider", provider)
+ provider_enum = LlmProviders(provider)
+ config = config_manager.get_provider_chat_config(model, provider_enum)
+ print("config", config)
+
+ if config:
+ supported_params = config.get_supported_openai_params(model)
+ print("supported_params", supported_params)
+ else:
+ raise Exception(f"No config found for {model_name}, provider: {provider}")
+
+ # Check tool_choice support
+ supports_tool_choice_result = litellm.utils.supports_tool_choice(
+ model=model_name, custom_llm_provider=provider
+ )
+ tool_choice_in_params = "tool_choice" in supported_params
+
+ assert (
+ supports_tool_choice_result == tool_choice_in_params
+ ), f"Tool choice support mismatch for {model_name}. supports_tool_choice() returned: {supports_tool_choice_result}, tool_choice in supported params: {tool_choice_in_params}\nConfig: {config}"
diff --git a/tests/litellm_utils_tests/test_supports_tool_choice.py b/tests/litellm_utils_tests/test_supports_tool_choice.py
deleted file mode 100644
index ac4eb1fe92d..00000000000
--- a/tests/litellm_utils_tests/test_supports_tool_choice.py
+++ /dev/null
@@ -1,171 +0,0 @@
-import json
-import os
-import sys
-from unittest.mock import patch
-import pytest
-
-# Add parent directory to system path
-sys.path.insert(0, os.path.abspath("../.."))
-
-import litellm
-from litellm.utils import get_llm_provider, ProviderConfigManager, _check_provider_match
-from litellm import LlmProviders
-
-
-def test_supports_tool_choice_simple_tests():
- """
- simple sanity checks
- """
- assert litellm.utils.supports_tool_choice(model="gpt-4o") == True
- assert (
- litellm.utils.supports_tool_choice(
- model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0"
- )
- == True
- )
- assert (
- litellm.utils.supports_tool_choice(
- model="anthropic.claude-3-sonnet-20240229-v1:0"
- )
- is True
- )
-
- assert (
- litellm.utils.supports_tool_choice(
- model="anthropic.claude-3-sonnet-20240229-v1:0",
- custom_llm_provider="bedrock_converse",
- )
- is True
- )
-
- assert (
- litellm.utils.supports_tool_choice(model="us.amazon.nova-micro-v1:0") is False
- )
- assert (
- litellm.utils.supports_tool_choice(model="bedrock/us.amazon.nova-micro-v1:0")
- is False
- )
- assert (
- litellm.utils.supports_tool_choice(
- model="us.amazon.nova-micro-v1:0", custom_llm_provider="bedrock_converse"
- )
- is False
- )
-
- assert litellm.utils.supports_tool_choice(model="perplexity/sonar") is False
-
-
-def test_check_provider_match():
- """
- Test the _check_provider_match function for various provider scenarios
- """
- # Test bedrock and bedrock_converse cases
- model_info = {"litellm_provider": "bedrock"}
- assert litellm.utils._check_provider_match(model_info, "bedrock") is True
- assert litellm.utils._check_provider_match(model_info, "bedrock_converse") is True
-
- # Test bedrock_converse provider
- model_info = {"litellm_provider": "bedrock_converse"}
- assert litellm.utils._check_provider_match(model_info, "bedrock") is True
- assert litellm.utils._check_provider_match(model_info, "bedrock_converse") is True
-
- # Test non-matching provider
- model_info = {"litellm_provider": "bedrock"}
- assert litellm.utils._check_provider_match(model_info, "openai") is False
-
-
-# Models that should be skipped during testing
-OLD_PROVIDERS = ["aleph_alpha", "palm"]
-SKIP_MODELS = ["azure/mistral", "azure/command-r", "jamba", "deepinfra", "mistral.", "groq/llama-guard-3-8b", "groq/gemma2-9b-it"]
-
-# Bedrock models to block - organized by type
-BEDROCK_REGIONS = ["ap-northeast-1", "eu-central-1", "us-east-1", "us-west-2"]
-BEDROCK_COMMITMENTS = ["1-month-commitment", "6-month-commitment"]
-BEDROCK_MODELS = {
- "anthropic.claude-v1",
- "anthropic.claude-v2",
- "anthropic.claude-v2:1",
- "anthropic.claude-instant-v1",
-}
-
-# Generate block_list dynamically
-block_list = set()
-for region in BEDROCK_REGIONS:
- for commitment in BEDROCK_COMMITMENTS:
- for model in BEDROCK_MODELS:
- block_list.add(f"bedrock/{region}/{commitment}/{model}")
- block_list.add(f"bedrock/{region}/{model}")
-
-# Add Cohere models
-for commitment in BEDROCK_COMMITMENTS:
- block_list.add(f"bedrock/*/{commitment}/cohere.command-text-v14")
- block_list.add(f"bedrock/*/{commitment}/cohere.command-light-text-v14")
-
-print("block_list", block_list)
-
-
-async def test_supports_tool_choice():
- """
- Test that litellm.utils.supports_tool_choice() returns the correct value
- for all models in model_prices_and_context_window.json.
-
- The test:
- 1. Loads model pricing data
- 2. Iterates through each model
- 3. Checks if tool_choice support matches the model's supported parameters
- """
- # Load model prices
- litellm._turn_on_debug()
- # path = "../../model_prices_and_context_window.json"
- path = "./model_prices_and_context_window.json"
- with open(path, "r") as f:
- model_prices = json.load(f)
- litellm.model_cost = model_prices
- config_manager = ProviderConfigManager()
-
- for model_name, model_info in model_prices.items():
- print(f"testing model: {model_name}")
-
- # Skip certain models
- if (
- model_name == "sample_spec"
- or model_info.get("mode") != "chat"
- or any(skip in model_name for skip in SKIP_MODELS)
- or any(provider in model_name for provider in OLD_PROVIDERS)
- or model_info["litellm_provider"] in OLD_PROVIDERS
- or model_name in block_list
- or "azure/eu" in model_name
- or "azure/us" in model_name
- or "codestral" in model_name
- or "o1" in model_name
- or "o3" in model_name
- or "mistral" in model_name
- ):
- continue
-
- try:
- model, provider, _, _ = get_llm_provider(model=model_name)
- except Exception as e:
- print(f"\033[91mERROR for {model_name}: {e}\033[0m")
- continue
-
- # Get provider config and supported params
- print("LLM provider", provider)
- provider_enum = LlmProviders(provider)
- config = config_manager.get_provider_chat_config(model, provider_enum)
- if config:
- supported_params = config.get_supported_openai_params(model)
- print("supported_params", supported_params)
- else:
- raise Exception(f"No config found for {model_name}, provider: {provider}")
-
- # Check tool_choice support
- supports_tool_choice_result = litellm.utils.supports_tool_choice(
- model=model_name, custom_llm_provider=provider
- )
- tool_choice_in_params = "tool_choice" in supported_params
-
- assert supports_tool_choice_result == tool_choice_in_params, (
- f"Tool choice support mismatch for {model_name}. supports_tool_choice() returned: {supports_tool_choice_result}, tool_choice in supported params: {tool_choice_in_params}"
- )