mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
162 lines
5.3 KiB
Python
162 lines
5.3 KiB
Python
# What is this?
|
|
## This tests the `get_optional_params_embeddings` function
|
|
import sys, os
|
|
import traceback
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
import io
|
|
|
|
import pytest
|
|
import litellm
|
|
from litellm import embedding
|
|
from litellm.utils import get_optional_params_embeddings, get_llm_provider
|
|
|
|
|
|
def test_vertex_projects():
|
|
litellm.drop_params = True
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="vertex_ai/textembedding-gecko"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
user="test-litellm-user-5",
|
|
dimensions=None,
|
|
encoding_format="base64",
|
|
custom_llm_provider=custom_llm_provider,
|
|
**{
|
|
"vertex_ai_project": "my-test-project",
|
|
"vertex_ai_location": "us-east-1",
|
|
},
|
|
)
|
|
|
|
print(f"received optional_params: {optional_params}")
|
|
|
|
assert "vertex_ai_project" in optional_params
|
|
assert "vertex_ai_location" in optional_params
|
|
|
|
|
|
# test_vertex_projects()
|
|
|
|
|
|
def test_bedrock_embed_v2_regular():
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="bedrock/amazon.titan-embed-text-v2:0"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=512,
|
|
custom_llm_provider=custom_llm_provider,
|
|
)
|
|
print(f"received optional_params: {optional_params}")
|
|
assert optional_params == {"dimensions": 512}
|
|
|
|
|
|
def test_bedrock_embed_v2_with_drop_params():
|
|
litellm.drop_params = True
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="bedrock/amazon.titan-embed-text-v2:0"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=512,
|
|
user="test-litellm-user-5",
|
|
encoding_format="base64",
|
|
custom_llm_provider=custom_llm_provider,
|
|
)
|
|
print(f"received optional_params: {optional_params}")
|
|
assert optional_params == {"dimensions": 512, "embeddingTypes": ["binary"]}
|
|
|
|
|
|
def test_openai_non_text_embedding_3_with_allowed_openai_params():
|
|
"""
|
|
Test that `dimensions` is allowed for non-text-embedding-3 OpenAI models
|
|
when `allowed_openai_params=["dimensions"]` is passed. Without this flag,
|
|
an UnsupportedParamsError would be raised.
|
|
"""
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=1024,
|
|
custom_llm_provider=custom_llm_provider,
|
|
allowed_openai_params=["dimensions"],
|
|
)
|
|
print(f"received optional_params: {optional_params}")
|
|
assert optional_params.get("dimensions") == 1024
|
|
|
|
|
|
def test_openai_non_text_embedding_3_without_allowed_openai_params_raises():
|
|
"""
|
|
Test that passing `dimensions` to a non-text-embedding-3 OpenAI model
|
|
without `allowed_openai_params` still raises UnsupportedParamsError.
|
|
"""
|
|
from litellm.exceptions import UnsupportedParamsError
|
|
|
|
# ensure global drop_params is off (other tests in this file flip it on)
|
|
prev_drop_params = litellm.drop_params
|
|
litellm.drop_params = False
|
|
try:
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="openai/nvidia/llama-3.2-nv-embedqa-1b-v2"
|
|
)
|
|
with pytest.raises(UnsupportedParamsError):
|
|
get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=1024,
|
|
custom_llm_provider=custom_llm_provider,
|
|
)
|
|
finally:
|
|
litellm.drop_params = prev_drop_params
|
|
|
|
|
|
def test_openai_non_text_embedding_3_drop_params_per_call():
|
|
"""
|
|
Regression for https://github.com/BerriAI/litellm/issues/26787
|
|
|
|
When drop_params=True is passed per-call, `dimensions` should be silently
|
|
stripped for a non-`text-embedding-3` OpenAI-provider model instead of
|
|
raising UnsupportedParamsError.
|
|
"""
|
|
prev_drop_params = litellm.drop_params
|
|
litellm.drop_params = False # ensure only per-call flag is in effect
|
|
try:
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="openai/Qwen/Qwen3-Embedding-0.6B"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=1024,
|
|
custom_llm_provider=custom_llm_provider,
|
|
drop_params=True,
|
|
)
|
|
print(f"received optional_params: {optional_params}")
|
|
assert "dimensions" not in optional_params
|
|
finally:
|
|
litellm.drop_params = prev_drop_params
|
|
|
|
|
|
def test_openai_non_text_embedding_3_drop_params_global():
|
|
"""
|
|
Regression for https://github.com/BerriAI/litellm/issues/26787
|
|
|
|
When `litellm.drop_params = True` is set globally, `dimensions` should be
|
|
silently stripped for a non-`text-embedding-3` OpenAI-provider model
|
|
instead of raising UnsupportedParamsError.
|
|
"""
|
|
prev_drop_params = litellm.drop_params
|
|
litellm.drop_params = True
|
|
try:
|
|
model, custom_llm_provider, _, _ = get_llm_provider(
|
|
model="openai/Qwen/Qwen3-Embedding-0.6B"
|
|
)
|
|
optional_params = get_optional_params_embeddings(
|
|
model=model,
|
|
dimensions=1024,
|
|
custom_llm_provider=custom_llm_provider,
|
|
)
|
|
print(f"received optional_params: {optional_params}")
|
|
assert "dimensions" not in optional_params
|
|
finally:
|
|
litellm.drop_params = prev_drop_params
|