Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"model": "BAAI/bge-small-en-v1.5",
"input": ["Hello from litellm!"]
}
58 changes: 56 additions & 2 deletions tests/logging_callback_tests/test_langfuse_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import logging
import os
import sys
from typing import Any, Optional
from unittest.mock import MagicMock, patch
import threading
from typing import Any, Optional
from unittest.mock import AsyncMock, MagicMock, patch

import httpx

logging.basicConfig(level=logging.DEBUG)
sys.path.insert(0, os.path.abspath("../.."))

import litellm
from litellm import completion
from litellm.caching import InMemoryCache
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler

litellm.num_retries = 3
litellm.success_callback = ["langfuse"]
Expand Down Expand Up @@ -445,6 +448,57 @@ async def test_langfuse_logging_completion_with_vertex_llm_response(
setup["mock_post"], "completion_with_vertex_call.json", setup["trace_id"]
)

@pytest.mark.asyncio
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)}"
)
Comment on lines +452 to +500

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


@pytest.mark.asyncio
async def test_langfuse_logging_with_router(self, mock_setup):
"""Test Langfuse logging with router"""
Expand Down
Loading