Skip to content

Add JSON exact match test for vLLM embeddings - #22180

Merged
Sameerlite merged 1 commit into
mainfrom
litellm_fix_vllm_test
Feb 26, 2026
Merged

Add JSON exact match test for vLLM embeddings#22180
Sameerlite merged 1 commit into
mainfrom
litellm_fix_vllm_test

Conversation

@Sameerlite

Copy link
Copy Markdown
Contributor

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

@vercel

vercel Bot commented Feb 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Building Building Preview, Comment Feb 26, 2026 11:20am

Request Review

@greptile-apps

greptile-apps Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a test that verifies the HTTP request body sent to a vLLM embedding endpoint when using litellm.aembedding() with the hosted_vllm/ provider prefix. It confirms that the hosted_vllm/ prefix is correctly stripped from the model name and that no unexpected fields (like encoding_format) are included in the request.

  • Adds test_langfuse_logging_vllm_embedding which mocks AsyncHTTPHandler.post and asserts the request body matches a JSON fixture
  • Adds embedding_with_vllm.json fixture file with the expected request body ({"model": "BAAI/bge-small-en-v1.5", "input": ["Hello from litellm!"]})
  • The test mechanics are correct — the client parameter properly flows through to the HTTP call site, and the mock correctly captures the request body
  • Concern: The test is placed in test_langfuse_e2e_test.py but doesn't test any Langfuse logging behavior — it only validates the vLLM request body. It would be better placed in a vLLM-specific test file
  • The PR checklist requirement for a test in tests/litellm/ is not met

Confidence Score: 3/5

  • This PR is safe to merge — it only adds test code with no production changes — but has organizational concerns.
  • The test logic itself is correct and well-constructed, but it's misplaced in the Langfuse e2e test file rather than a vLLM-specific test location. The PR also doesn't include a test in the required tests/litellm/ directory per the contribution checklist. No production code is modified, so there's no risk of regression.
  • tests/logging_callback_tests/test_langfuse_e2e_test.py — test is functional but placed in the wrong file, should be in a vLLM-specific test location

Important Files Changed

Filename Overview
tests/logging_callback_tests/test_langfuse_e2e_test.py Adds a new test for vLLM embedding request body validation. Test logic is sound, but it's misplaced in the Langfuse e2e test file since it doesn't test any Langfuse behavior.
tests/logging_callback_tests/langfuse_expected_request_body/embedding_with_vllm.json Simple JSON fixture with expected vLLM embedding request body. Content correctly matches the output of HostedVLLMEmbeddingConfig.transform_embedding_request().

Sequence Diagram

sequenceDiagram
    participant Test as test_langfuse_logging_vllm_embedding
    participant LiteLLM as litellm.aembedding()
    participant Embedding as embedding() in main.py
    participant Handler as BaseLLMHTTPHandler
    participant Mock as AsyncHTTPHandler (mocked .post)

    Test->>LiteLLM: aembedding(model="hosted_vllm/BAAI/bge-small-en-v1.5", client=mock)
    LiteLLM->>Embedding: embedding(..., aembedding=True)
    Embedding->>Handler: base_llm_http_handler.embedding(client=mock)
    Handler->>Handler: transform_embedding_request() strips "hosted_vllm/" prefix
    Handler-->>LiteLLM: returns coroutine (aembedding=True)
    LiteLLM->>Mock: await mock.post(json={"model": "BAAI/bge-small-en-v1.5", "input": [...]})
    Mock-->>LiteLLM: httpx.Response(200, embedding data)
    LiteLLM-->>Test: EmbeddingResponse
    Test->>Test: assert mock.post.call_args.kwargs["json"] == expected fixture
Loading

Last reviewed commit: 1a3d4c8

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +452 to +500
async def test_langfuse_logging_vllm_embedding(self, mock_setup):
"""
Test that the request sent to the vllm embedding endpoint is correct.

Verifies the request body matches the expected JSON fixture,
including that the hosted_vllm/ prefix is stripped from the model name
and that no unexpected fields (e.g. encoding_format) are included.
"""
setup = mock_setup

vllm_response_data = {
"object": "list",
"data": [{"object": "embedding", "index": 0, "embedding": [0.1, 0.2, 0.3]}],
"model": "BAAI/bge-small-en-v1.5",
"usage": {"prompt_tokens": 10, "total_tokens": 10},
}
mock_vllm_response = httpx.Response(
status_code=200,
json=vllm_response_data,
)

mock_async_client = AsyncHTTPHandler()
mock_async_client.post = AsyncMock(return_value=mock_vllm_response)

with patch("httpx.Client.post", setup["mock_post"]):
await litellm.aembedding(
model="hosted_vllm/BAAI/bge-small-en-v1.5",
input=["Hello from litellm!"],
api_base="http://my-fake-vllm.com/v1",
metadata={"trace_id": setup["trace_id"]},
client=mock_async_client,
)

# Verify the request sent to vllm matches the expected JSON fixture
assert mock_async_client.post.call_count == 1
actual_vllm_request = mock_async_client.post.call_args.kwargs["json"]

pwd = os.path.dirname(os.path.realpath(__file__))
expected_body_path = os.path.join(
pwd, "langfuse_expected_request_body", "embedding_with_vllm.json"
)
with open(expected_body_path, "r") as f:
expected_vllm_request = json.load(f)

assert actual_vllm_request == expected_vllm_request, (
f"vllm request body mismatch:\n"
f"actual: {json.dumps(actual_vllm_request, indent=2)}\n"
f"expected: {json.dumps(expected_vllm_request, indent=2)}"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test placed in wrong test file

This test verifies the HTTP request body sent to the vLLM embedding endpoint (model name stripping, absence of encoding_format), but it doesn't verify any Langfuse logging behavior. Placing it in test_langfuse_e2e_test.py is misleading — it uses the mock_setup fixture only for its mock_post to stub out Langfuse's httpx.Client.post, but the actual assertions are entirely about the vLLM request body.

Consider moving this test to a vLLM-specific test file (e.g., under tests/llm_translation/ or a dedicated vLLM embedding test). This would also decouple it from the Langfuse mock_setup fixture, which sets up Langfuse-specific state (litellm.success_callback = ["langfuse"], trace IDs) that this test doesn't need.

Additionally, the PR checklist requires at least one test in the tests/litellm/ directory, which is not satisfied.

Context Used: Rule from dashboard - What: Ensure that any PR claiming to fix an issue includes evidence that the issue is resolved, such... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2/5 only because location is wrong

@Sameerlite
Sameerlite merged commit 16d6c27 into main Feb 26, 2026
82 of 93 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_fix_vllm_test branch March 26, 2026 22:29
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
Add JSON exact match test for vLLM embeddings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant