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(utils.py): support non default params for audio transcription (#11212)

Krish Dholakia1995c7aad5d9
diff --git a/litellm/constants.py b/litellm/constants.py
index f1ed7380119..da9778922b4 100644
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@ -284,6 +284,12 @@ OPENAI_CHAT_COMPLETION_PARAMS = [
"web_search_options",
]
+OPENAI_TRANSCRIPTION_PARAMS = [
+ "language",
+ "response_format",
+ "timestamp_granularities",
+]
+
DEFAULT_CHAT_COMPLETION_PARAM_VALUES = {
"functions": None,
"function_call": None,
diff --git a/litellm/llms/base_llm/chat/transformation.py b/litellm/llms/base_llm/chat/transformation.py
index e69effabb23..a81375b980c 100644
--- a/litellm/llms/base_llm/chat/transformation.py
+++ b/litellm/llms/base_llm/chat/transformation.py
@@ -87,6 +87,7 @@ class BaseConfig(ABC):
for k, v in cls.__dict__.items()
if not k.startswith("__")
and not k.startswith("_abc")
+ and not k.startswith("_is_base_class")
and not isinstance(
v,
(
diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.py
index 907da5002f0..e03c4c93bd7 100644
--- a/litellm/llms/openai/chat/gpt_transformation.py
+++ b/litellm/llms/openai/chat/gpt_transformation.py
@@ -89,6 +89,9 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
- `top_p` (number or null): An alternative to sampling with temperature, used for nucleus sampling.
"""
+ # Add a class variable to track if this is the base class
+ _is_base_class = True
+
frequency_penalty: Optional[int] = None
function_call: Optional[Union[str, dict]] = None
functions: Optional[list] = None
@@ -120,6 +123,8 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
if key != "self" and value is not None:
setattr(self.__class__, key, value)
+ self.__class__._is_base_class = False
+
@classmethod
def get_config(cls):
return super().get_config()
@@ -406,11 +411,17 @@ class OpenAIGPTConfig(BaseLLMModelInfo, BaseConfig):
messages=messages, model=model, is_async=True
)
- return {
- "model": model,
- "messages": transformed_messages,
- **optional_params,
- }
+ if self.__class__._is_base_class:
+ return {
+ "model": model,
+ "messages": transformed_messages,
+ **optional_params,
+ }
+ else:
+ ## allow for any object specific behaviour to be handled
+ return self.transform_request(
+ model, messages, optional_params, litellm_params, headers
+ )
def _passed_in_tools(self, optional_params: dict) -> bool:
return optional_params.get("tools", None) is not None
diff --git a/litellm/main.py b/litellm/main.py
index a4081483441..64039f357b3 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -94,6 +94,7 @@ from litellm.utils import (
get_api_key,
get_llm_provider,
get_non_default_completion_params,
+ get_non_default_transcription_params,
get_optional_params_embeddings,
get_optional_params_image_gen,
get_optional_params_transcription,
@@ -987,7 +988,6 @@ def completion( # type: ignore # noqa: PLR0915
assistant_continue_message=assistant_continue_message,
)
######## end of unpacking kwargs ###########
- standard_openai_params = get_standard_openai_params(params=args)
non_default_params = get_non_default_completion_params(kwargs=kwargs)
litellm_params = {} # used to prevent unbound var errors
## PROMPT MANAGEMENT HOOKS ##
@@ -4731,8 +4731,8 @@ def transcription(
litellm_logging_obj: LiteLLMLoggingObj = kwargs.get("litellm_logging_obj") # type: ignore
extra_headers = kwargs.get("extra_headers", None)
kwargs.pop("tags", [])
+ non_default_params = get_non_default_transcription_params(kwargs)
- drop_params = kwargs.get("drop_params", None)
client: Optional[
Union[
openai.AsyncOpenAI,
@@ -4765,7 +4765,7 @@ def transcription(
timestamp_granularities=timestamp_granularities,
temperature=temperature,
custom_llm_provider=custom_llm_provider,
- drop_params=drop_params,
+ **non_default_params,
)
litellm_params_dict = get_litellm_params(**kwargs)
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml
index d6b3e450a3d..18784428003 100644
--- a/litellm/proxy/_new_secret_config.yaml
+++ b/litellm/proxy/_new_secret_config.yaml
@@ -10,4 +10,4 @@ model_list:
api_key: os.environ/OPENAI_API_KEY
litellm_settings:
- cache: true
+ cache: true
\ No newline at end of file
diff --git a/litellm/utils.py b/litellm/utils.py
index fe9300aab51..632f2151e0e 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -2155,15 +2155,17 @@ def _get_non_default_params(
def get_optional_params_transcription(
model: str,
+ custom_llm_provider: str,
language: Optional[str] = None,
prompt: Optional[str] = None,
response_format: Optional[str] = None,
temperature: Optional[int] = None,
timestamp_granularities: Optional[List[Literal["word", "segment"]]] = None,
- custom_llm_provider: Optional[str] = None,
drop_params: Optional[bool] = None,
**kwargs,
):
+ from litellm.constants import OPENAI_TRANSCRIPTION_PARAMS
+
# retrieve all parameters passed to the function
passed_params = locals()
custom_llm_provider = passed_params.pop("custom_llm_provider")
@@ -2229,9 +2231,14 @@ def get_optional_params_transcription(
model=model,
drop_params=drop_params if drop_params is not None else False,
)
- for k in passed_params.keys(): # pass additional kwargs without modification
- if k not in default_params.keys():
- optional_params[k] = passed_params[k]
+ optional_params = add_provider_specific_params_to_optional_params(
+ optional_params=optional_params,
+ passed_params=passed_params,
+ custom_llm_provider=custom_llm_provider,
+ openai_params=OPENAI_TRANSCRIPTION_PARAMS,
+ additional_drop_params=kwargs.get("additional_drop_params", None),
+ )
+
return optional_params
@@ -2767,6 +2774,9 @@ def pre_process_non_default_params(
non_default_params = add_provider_specific_params_to_optional_params(
optional_params=non_default_params,
passed_params=passed_params,
+ custom_llm_provider=custom_llm_provider,
+ openai_params=list(DEFAULT_CHAT_COMPLETION_PARAM_VALUES.keys()),
+ additional_drop_params=additional_drop_params,
)
if remove_sensitive_keys:
@@ -3634,6 +3644,33 @@ def get_optional_params( # noqa: PLR0915
else False
),
)
+ # if user passed in non-default kwargs for specific providers/models, pass them along
+ optional_params = add_provider_specific_params_to_optional_params(
+ optional_params=optional_params,
+ passed_params=passed_params,
+ custom_llm_provider=custom_llm_provider,
+ openai_params=list(DEFAULT_CHAT_COMPLETION_PARAM_VALUES.keys()),
+ additional_drop_params=additional_drop_params,
+ )
+ print_verbose(f"Final returned optional params: {optional_params}")
+ optional_params = _apply_openai_param_overrides(
+ optional_params=optional_params,
+ non_default_params=non_default_params,
+ allowed_openai_params=allowed_openai_params,
+ )
+ return optional_params
+
+
+def add_provider_specific_params_to_optional_params(
+ optional_params: dict,
+ passed_params: dict,
+ custom_llm_provider: str,
+ openai_params: List[str],
+ additional_drop_params: Optional[list] = None,
+) -> dict:
+ """
+ Add provider specific params to optional_params
+ """
if (
custom_llm_provider
in ["openai", "azure", "text-completion-openai"]
@@ -3648,7 +3685,7 @@ def get_optional_params( # noqa: PLR0915
):
extra_body = passed_params.pop("extra_body", {})
for k in passed_params.keys():
- if k not in DEFAULT_CHAT_COMPLETION_PARAM_VALUES.keys():
+ if k not in openai_params:
extra_body[k] = passed_params[k]
optional_params.setdefault("extra_body", {})
optional_params["extra_body"] = {
@@ -3660,28 +3697,9 @@ def get_optional_params( # noqa: PLR0915
extra_body=optional_params["extra_body"]
)
else:
- # if user passed in non-default kwargs for specific providers/models, pass them along
- optional_params = add_provider_specific_params_to_optional_params(
- optional_params=optional_params, passed_params=passed_params
- )
- print_verbose(f"Final returned optional params: {optional_params}")
- optional_params = _apply_openai_param_overrides(
- optional_params=optional_params,
- non_default_params=non_default_params,
- allowed_openai_params=allowed_openai_params,
- )
- return optional_params
-
-
-def add_provider_specific_params_to_optional_params(
- optional_params: dict, passed_params: dict
-) -> dict:
- """
- Add provider specific params to optional_params
- """
- for k in passed_params.keys():
- if k not in DEFAULT_CHAT_COMPLETION_PARAM_VALUES.keys():
- optional_params[k] = passed_params[k]
+ for k in passed_params.keys():
+ if k not in openai_params:
+ optional_params[k] = passed_params[k]
return optional_params
@@ -6905,6 +6923,14 @@ def get_non_default_completion_params(kwargs: dict) -> dict:
return non_default_params
+def get_non_default_transcription_params(kwargs: dict) -> dict:
+ from litellm.constants import OPENAI_TRANSCRIPTION_PARAMS
+
+ default_params = OPENAI_TRANSCRIPTION_PARAMS + all_litellm_params
+ non_default_params = {k: v for k, v in kwargs.items() if k not in default_params}
+ return non_default_params
+
+
def add_openai_metadata(metadata: dict) -> dict:
"""
Add metadata to openai optional parameters, excluding hidden params.
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion.json
index b2a2c83b51a..bede5753a2a 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion.json
@@ -62,7 +62,7 @@
"endTime": "2025-01-16T11:28:55.124353-08:00",
"completionStartTime": "2025-01-16T11:28:55.124353-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_complex_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_complex_metadata.json
index 9d30a82b8d2..1e60a0479b1 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_complex_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_complex_metadata.json
@@ -103,7 +103,7 @@
"endTime": "2025-01-22T09:27:51.702048-08:00",
"completionStartTime": "2025-01-22T09:27:51.702048-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_langfuse_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_langfuse_metadata.json
index 7c2fc6c5f35..a217a901285 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_langfuse_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_langfuse_metadata.json
@@ -81,7 +81,7 @@
"endTime": "2025-01-22T09:19:11.234200-08:00",
"completionStartTime": "2025-01-22T09:19:11.234200-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_no_choices.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_no_choices.json
index cb9f007c2d5..be21c297dcc 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_no_choices.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_no_choices.json
@@ -52,7 +52,7 @@
"endTime": "2025-02-06T16:23:27.644253-08:00",
"completionStartTime": "2025-02-06T16:23:27.644253-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 10,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_router.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_router.json
index e5059d873a0..021c2b1b73c 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_router.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_router.json
@@ -65,7 +65,8 @@
"model": "gpt-3.5-turbo",
"modelParameters": {
"stream": false,
- "max_retries": 0
+ "max_retries": 0,
+ "extra_body": "{}"
},
"usage": {
"input": 10,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags.json
index c4cbe1e68af..07fca9daafb 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags.json
@@ -71,7 +71,7 @@
"endTime": "2025-01-22T07:31:28.962389-08:00",
"completionStartTime": "2025-01-22T07:31:28.962389-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags_stream.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags_stream.json
index cd882af614d..d7003c3f99e 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags_stream.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_tags_stream.json
@@ -71,7 +71,7 @@
"endTime": "2025-01-22T08:38:26.015666-08:00",
"completionStartTime": "2025-01-22T08:38:26.015666-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata.json
index 5c8d5c5b88d..e8f01f6d723 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata.json
@@ -78,7 +78,7 @@
"endTime": "2025-01-22T09:59:39.365756-08:00",
"completionStartTime": "2025-01-22T09:59:39.365756-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata_2.json b/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata_2.json
index 4533262ef42..786fe20e7b4 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata_2.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/complex_metadata_2.json
@@ -70,7 +70,7 @@
"endTime": "2025-01-22T10:06:50.958374-08:00",
"completionStartTime": "2025-01-22T10:06:50.958374-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/empty_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/empty_metadata.json
index 39a88320bbf..69db4314f0f 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/empty_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/empty_metadata.json
@@ -64,7 +64,7 @@
"endTime": "2025-01-22T09:59:32.880691-08:00",
"completionStartTime": "2025-01-22T09:59:32.880691-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_function.json b/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_function.json
index e73ef0d9ed6..eae3134555e 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_function.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_function.json
@@ -64,7 +64,7 @@
"endTime": "2025-01-22T09:59:36.161959-08:00",
"completionStartTime": "2025-01-22T09:59:36.161959-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_lock.json b/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_lock.json
index 39a88320bbf..69db4314f0f 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_lock.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/metadata_with_lock.json
@@ -64,7 +64,7 @@
"endTime": "2025-01-22T09:59:32.880691-08:00",
"completionStartTime": "2025-01-22T09:59:32.880691-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/nested_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/nested_metadata.json
index efd3bbae323..c4fe594fa14 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/nested_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/nested_metadata.json
@@ -70,7 +70,7 @@
"endTime": "2025-01-22T09:55:28.853979-08:00",
"completionStartTime": "2025-01-22T09:55:28.853979-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata.json b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata.json
index 8cb1cced89d..d348ac50392 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata.json
@@ -70,7 +70,7 @@
"endTime": "2025-01-22T09:53:53.753431-08:00",
"completionStartTime": "2025-01-22T09:53:53.753431-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata2.json b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata2.json
index 0de688644b9..d5468d302c9 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata2.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata2.json
@@ -74,7 +74,7 @@
"endTime": "2025-01-22T09:56:35.476236-08:00",
"completionStartTime": "2025-01-22T09:56:35.476236-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata3.json b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata3.json
index f0ad3e9e712..1107766993a 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata3.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/simple_metadata3.json
@@ -78,7 +78,7 @@
"endTime": "2025-01-22T09:56:38.785762-08:00",
"completionStartTime": "2025-01-22T09:56:38.785762-08:00",
"model": "gpt-3.5-turbo",
- "modelParameters": {},
+ "modelParameters": {"extra_body": "{}"},
"usage": {
"input": 10,
"output": 20,
diff --git a/tests/test_litellm/llms/azure/chat/test_azure_chat_o_series_transformation.py b/tests/test_litellm/llms/azure/chat/test_azure_chat_o_series_transformation.py
new file mode 100644
index 00000000000..31c76c42599
--- /dev/null
+++ b/tests/test_litellm/llms/azure/chat/test_azure_chat_o_series_transformation.py
@@ -0,0 +1,30 @@
+import json
+import os
+import sys
+import traceback
+from typing import Callable, Optional
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+sys.path.insert(
+ 0, os.path.abspath("../../../../..")
+) # Adds the parent directory to the system path
+import litellm
+from litellm.llms.azure.chat.o_series_transformation import AzureOpenAIO1Config
+
+
+async def test_azure_chat_o_series_transformation():
+ provider_config = AzureOpenAIO1Config()
+ model = "o_series/web-interface-o1-mini"
+ messages = [{"role": "user", "content": "Hello, how are you?"}]
+ optional_params = {}
+ litellm_params = {}
+ headers = {}
+
+ response = await provider_config.async_transform_request(
+ model, messages, optional_params, litellm_params, headers
+ )
+ print(response)
+ assert response["model"] == "web-interface-o1-mini"
diff --git a/tests/litellm/llms/nebius/test_nebius_chat_transformation.py b/tests/test_litellm/llms/nebius/test_nebius_chat_transformation.py
similarity index 99%
rename from tests/litellm/llms/nebius/test_nebius_chat_transformation.py
rename to tests/test_litellm/llms/nebius/test_nebius_chat_transformation.py
index 9d32679c5e2..4cef9479619 100644
--- a/tests/litellm/llms/nebius/test_nebius_chat_transformation.py
+++ b/tests/test_litellm/llms/nebius/test_nebius_chat_transformation.py
@@ -13,6 +13,7 @@ sys.path.insert(
) # Adds the parent directory to the system path
import pytest
+
import litellm
from litellm import completion
from litellm.llms.nebius.chat.transformation import NebiusConfig
diff --git a/tests/litellm/llms/nebius/test_nebius_embedding_transformation.py b/tests/test_litellm/llms/nebius/test_nebius_embedding_transformation.py
similarity index 99%
rename from tests/litellm/llms/nebius/test_nebius_embedding_transformation.py
rename to tests/test_litellm/llms/nebius/test_nebius_embedding_transformation.py
index da34964bacb..88f79abbde6 100644
--- a/tests/litellm/llms/nebius/test_nebius_embedding_transformation.py
+++ b/tests/test_litellm/llms/nebius/test_nebius_embedding_transformation.py
@@ -1,6 +1,7 @@
-import litellm
from unittest.mock import patch
+import litellm
+
def mock_embedding_response(*args, **kwargs):
"""Mock response mimicking litellm.embedding output."""
diff --git a/tests/litellm/secrets_managers/test_secret_managers_main.py b/tests/test_litellm/secret_managers/test_secret_managers_main.py
similarity index 82%
rename from tests/litellm/secrets_managers/test_secret_managers_main.py
rename to tests/test_litellm/secret_managers/test_secret_managers_main.py
index 875e9f40fc2..159e41546df 100644
--- a/tests/litellm/secrets_managers/test_secret_managers_main.py
+++ b/tests/test_litellm/secret_managers/test_secret_managers_main.py
@@ -1,13 +1,16 @@
-import pytest
+import logging
import os
from unittest.mock import Mock, patch
+
+import pytest
+
from litellm.secret_managers.main import get_secret
-import logging
# Set up logging for debugging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
+
# Mock HTTPHandler and oidc_cache
class MockHTTPHandler:
def __init__(self, timeout):
@@ -19,13 +22,16 @@ class MockHTTPHandler:
def get(self, url, params=None, headers=None):
# Store params for audience verification
self.last_params = params
- logger.debug(f"MockHTTPHandler.get called with url={url}, params={params}, headers={headers}")
+ logger.debug(
+ f"MockHTTPHandler.get called with url={url}, params={params}, headers={headers}"
+ )
mock_response = Mock()
mock_response.status_code = self.status_code
mock_response.text = self.text
mock_response.json.return_value = self.json_data
return mock_response
+
@pytest.fixture
def mock_oidc_cache():
cache = Mock()
@@ -33,75 +39,83 @@ def mock_oidc_cache():
cache.set_cache = Mock()
return cache
+
@pytest.fixture
def mock_env():
with patch.dict(os.environ, {}, clear=True):
yield os.environ
-@patch('litellm.secret_managers.main.oidc_cache')
-@patch('litellm.secret_managers.main.HTTPHandler')
+
+@patch("litellm.secret_managers.main.oidc_cache")
+@patch("litellm.secret_managers.main.HTTPHandler")
def test_oidc_google_success(mock_http_handler, mock_oidc_cache):
mock_oidc_cache.get_cache.return_value = None
mock_handler = MockHTTPHandler(timeout=600.0)
mock_http_handler.return_value = mock_handler
secret_name = "oidc/google/[invalid url, do not cite]"
result = get_secret(secret_name)
-
+
assert result == "mocked_token"
assert mock_handler.last_params == {"audience": "[invalid url, do not cite]"}
mock_oidc_cache.set_cache.assert_called_once_with(
key=secret_name, value="mocked_token", ttl=3540
)
-@patch('litellm.secret_managers.main.oidc_cache')
+
+@patch("litellm.secret_managers.main.oidc_cache")
def test_oidc_google_cached(mock_oidc_cache):
mock_oidc_cache.get_cache.return_value = "cached_token"
-
+
secret_name = "oidc/google/[invalid url, do not cite]"
- with patch('litellm.HTTPHandler') as mock_http:
+ with patch("litellm.HTTPHandler") as mock_http:
result = get_secret(secret_name)
-
+
assert result == "cached_token", f"Expected cached token, got {result}"
mock_oidc_cache.get_cache.assert_called_with(key=secret_name)
mock_http.assert_not_called()
+
def test_oidc_google_failure(mock_oidc_cache):
mock_handler = MockHTTPHandler(timeout=600.0)
mock_handler.status_code = 400
-
- with patch('litellm.secret_managers.main.HTTPHandler', return_value=mock_handler):
+
+ with patch("litellm.secret_managers.main.HTTPHandler", return_value=mock_handler):
mock_oidc_cache.get_cache.return_value = None
secret_name = "oidc/google/https://example.com/api"
-
+
with pytest.raises(ValueError, match="Google OIDC provider failed"):
get_secret(secret_name)
-def test_oidc_circleci_success(mock_env):
- mock_env["CIRCLE_OIDC_TOKEN"] = "circleci_token"
-
+
+def test_oidc_circleci_success(monkeypatch):
+ monkeypatch.setenv("CIRCLE_OIDC_TOKEN", "circleci_token")
+
secret_name = "oidc/circleci/test-audience"
result = get_secret(secret_name)
-
+
assert result == "circleci_token"
-def test_oidc_circleci_failure():
+
+def test_oidc_circleci_failure(monkeypatch):
+ monkeypatch.delenv("CIRCLE_OIDC_TOKEN", raising=False)
secret_name = "oidc/circleci/test-audience"
-
+
with pytest.raises(ValueError, match="CIRCLE_OIDC_TOKEN not found in environment"):
get_secret(secret_name)
-@patch('litellm.secret_managers.main.oidc_cache')
-@patch('litellm.secret_managers.main.HTTPHandler')
+
+@patch("litellm.secret_managers.main.oidc_cache")
+@patch("litellm.secret_managers.main.HTTPHandler")
def test_oidc_github_success(mock_http_handler, mock_oidc_cache, mock_env):
mock_env["ACTIONS_ID_TOKEN_REQUEST_URL"] = "https://github.com/token"
mock_env["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = "github_token"
mock_oidc_cache.get_cache.return_value = None
mock_handler = MockHTTPHandler(timeout=600.0)
mock_http_handler.return_value = mock_handler
-
+
secret_name = "oidc/github/github-audience"
result = get_secret(secret_name)
-
+
assert result == "mocked_token", f"Expected token 'mocked_token', got {result}"
assert mock_handler.last_params == {"audience": "github-audience"}
logger.debug(f"set_cache call args: {mock_oidc_cache.set_cache.call_args}")
@@ -110,62 +124,74 @@ def test_oidc_github_success(mock_http_handler, mock_oidc_cache, mock_env):
key=secret_name, value="mocked_token", ttl=295
)
+
def test_oidc_github_missing_env():
secret_name = "oidc/github/github-audience"
-
- with pytest.raises(ValueError, match="ACTIONS_ID_TOKEN_REQUEST_URL or ACTIONS_ID_TOKEN_REQUEST_TOKEN not found in environment"):
+
+ with pytest.raises(
+ ValueError,
+ match="ACTIONS_ID_TOKEN_REQUEST_URL or ACTIONS_ID_TOKEN_REQUEST_TOKEN not found in environment",
+ ):
get_secret(secret_name)
+
def test_oidc_azure_file_success(mock_env, tmp_path):
token_file = tmp_path / "token.txt"
token_file.write_text("azure_token")
mock_env["AZURE_FEDERATED_TOKEN_FILE"] = str(token_file)
-
+
secret_name = "oidc/azure/azure-audience"
result = get_secret(secret_name)
-
+
assert result == "azure_token"
-@patch('litellm.secret_managers.main.get_azure_ad_token_provider')
+
+@patch("litellm.secret_managers.main.get_azure_ad_token_provider")
def test_oidc_azure_ad_token_success(mock_get_azure_ad_token_provider):
mock_token_provider = Mock(return_value="azure_ad_token")
mock_get_azure_ad_token_provider.return_value = mock_token_provider
secret_name = "oidc/azure/api://azure-audience"
result = get_secret(secret_name)
-
+
assert result == "azure_ad_token"
- mock_get_azure_ad_token_provider.assert_called_once_with(azure_scope="api://azure-audience")
+ mock_get_azure_ad_token_provider.assert_called_once_with(
+ azure_scope="api://azure-audience"
+ )
mock_token_provider.assert_called_once_with()
+
def test_oidc_file_success(tmp_path):
token_file = tmp_path / "token.txt"
token_file.write_text("file_token")
-
+
secret_name = f"oidc/file/{token_file}"
result = get_secret(secret_name)
-
+
assert result == "file_token"
+
def test_oidc_env_success(mock_env):
mock_env["CUSTOM_TOKEN"] = "env_token"
-
+
secret_name = "oidc/env/CUSTOM_TOKEN"
result = get_secret(secret_name)
-
+
assert result == "env_token"
+
def test_oidc_env_path_success(mock_env, tmp_path):
token_file = tmp_path / "token.txt"
token_file.write_text("env_path_token")
mock_env["TOKEN_PATH"] = str(token_file)
-
+
secret_name = "oidc/env_path/TOKEN_PATH"
result = get_secret(secret_name)
-
+
assert result == "env_path_token"
+
def test_unsupported_oidc_provider():
secret_name = "oidc/unsupported/unsupported-audience"
-
+
with pytest.raises(ValueError, match="Unsupported OIDC provider"):
- get_secret(secret_name)
\ No newline at end of file
+ get_secret(secret_name)
diff --git a/tests/litellm/types/test_types_utils.py b/tests/test_litellm/types/test_types_utils.py
similarity index 100%
rename from tests/litellm/types/test_types_utils.py
rename to tests/test_litellm/types/test_types_utils.py