mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test(embedding): align local_testing OpenAI encoding_format default
Made-with: Cursor
This commit is contained in:
parent
8473b70dd8
commit
a1f0823393
1 changed files with 8 additions and 22 deletions
|
|
@ -1257,22 +1257,13 @@ def test_jina_ai_img_embeddings(input_data, expected_payload_input):
|
|||
assert sent_data["input"] == expected_payload_input
|
||||
|
||||
|
||||
def test_encoding_format_none_not_omitted_from_openai_sdk():
|
||||
def test_encoding_format_defaults_to_float_for_openai_sdk(monkeypatch):
|
||||
"""
|
||||
Test that encoding_format=None is explicitly sent to OpenAI SDK.
|
||||
When encoding_format is not provided, LiteLLM sends `float` for OpenAI-path embeddings.
|
||||
|
||||
This test verifies that when encoding_format is not provided by the user,
|
||||
liteLLM explicitly sets it to None rather than omitting it. This prevents
|
||||
the OpenAI SDK from adding its default value of 'base64'.
|
||||
|
||||
Without this fix:
|
||||
- OpenAI SDK adds encoding_format='base64' as default when parameter is missing
|
||||
- This causes issues with providers that don't support encoding_format (like Gemini)
|
||||
|
||||
With this fix:
|
||||
- encoding_format=None is explicitly passed
|
||||
- OpenAI SDK respects the explicit None and doesn't add defaults
|
||||
Optional global override: `LITELLM_DEFAULT_EMBEDDING_ENCODING_FORMAT`.
|
||||
"""
|
||||
monkeypatch.delenv("LITELLM_DEFAULT_EMBEDDING_ENCODING_FORMAT", raising=False)
|
||||
with patch(
|
||||
"litellm.llms.openai.openai.OpenAIChatCompletion._get_openai_client"
|
||||
) as mock_get_client:
|
||||
|
|
@ -1310,17 +1301,12 @@ def test_encoding_format_none_not_omitted_from_openai_sdk():
|
|||
|
||||
call_kwargs = call_args[1] # Get kwargs
|
||||
|
||||
# The key assertion: encoding_format should be in the request with value None
|
||||
# This prevents OpenAI SDK from adding its default 'base64' value
|
||||
assert "encoding_format" in call_kwargs, (
|
||||
"encoding_format should be explicitly passed to OpenAI SDK "
|
||||
"(even if None) to prevent SDK from adding default value"
|
||||
)
|
||||
assert "encoding_format" in call_kwargs
|
||||
assert (
|
||||
call_kwargs["encoding_format"] is None
|
||||
), "encoding_format should be None when not provided by user"
|
||||
call_kwargs["encoding_format"] == "float"
|
||||
), "encoding_format should default to float when not provided by user"
|
||||
|
||||
print("✅ PASS: encoding_format=None is correctly passed to OpenAI SDK")
|
||||
print("✅ PASS: encoding_format='float' is correctly passed to OpenAI SDK")
|
||||
|
||||
|
||||
def test_encoding_format_explicit_value_preserved():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue