mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* test(e2e): move audio and realtime tests off OpenAI model ids with shutdown dates * test(e2e): move langfuse completion, image, and vertex realtime ids off dated models * test(e2e): register the weather tool in the first realtime session update and read Langfuse v2 flattened attributes * test(e2e): expect the OCR upload's file summary in the Langfuse generation input The OCR upload route has sent the uploaded file, not a data URL, since the native OCR route, and the generation input summarizes that form as the mime type and file name. The broken Langfuse lookup hid the stale data URL expectation * test(e2e): move the image generation test off gpt-image-1-mini gpt-image-1-mini has a 2026-12-01 deprecation_date, so the image generation e2e would start failing that day. gpt-image-2.5-flare has no date and already serves the Langfuse image tests * test(e2e): use gpt-image-2.6-flare and check every n=2 choice reaches Langfuse OpenAI names gpt-image-2.6-flare as the successor of gpt-image-1-mini, so the image tests use it. The n=2 completions test now needs one logged message per choice, since both choices repeat the same text and a single logged message used to pass --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
import json
|
|
from typing import Final
|
|
|
|
import pytest
|
|
from pydantic import JsonValue
|
|
|
|
from logging_client import LangfuseObservation, is_otel_v2_generation, observation_spend
|
|
|
|
|
|
@pytest.mark.parametrize("encoded", [False, True])
|
|
@pytest.mark.parametrize("cost", [0.0, 0.000023])
|
|
def test_observation_preserves_v2_content_usage_and_cost(encoded: bool, cost: float) -> None:
|
|
content: Final[JsonValue] = [{"role": "user", "content": "unique-request-marker"}]
|
|
output: Final[JsonValue] = [{"role": "assistant", "content": "response"}]
|
|
metadata: Final[JsonValue] = {
|
|
"attributes": {
|
|
"langfuse.observation.type": "generation",
|
|
"litellm.metadata.user_api_key_alias": "test-key-alias",
|
|
}
|
|
}
|
|
usage: Final[JsonValue] = {"input": 17, "output": 3}
|
|
observation: Final = LangfuseObservation.model_validate(
|
|
{
|
|
"id": "observation",
|
|
"input": json.dumps(content) if encoded else content,
|
|
"output": json.dumps(output) if encoded else output,
|
|
"metadata": json.dumps(metadata) if encoded else metadata,
|
|
"usageDetails": usage,
|
|
"totalCost": cost,
|
|
}
|
|
)
|
|
|
|
assert observation.input == content
|
|
assert observation.output == output
|
|
assert observation.usage_details == usage
|
|
assert observation_spend(observation) == cost
|
|
assert is_otel_v2_generation(observation, key_alias="test-key-alias")
|
|
assert not is_otel_v2_generation(observation, key_alias="another-key")
|
|
|
|
|
|
def test_otel_v2_generation_matches_metadata_flattened_by_the_v2_observations_api() -> None:
|
|
observation: Final = LangfuseObservation.model_validate(
|
|
{
|
|
"id": "observation",
|
|
"metadata": {
|
|
"scope.name": "litellm",
|
|
"attributes.langfuse.observation.type": "generation",
|
|
"attributes.litellm.metadata.user_api_key_alias": "test-key-alias",
|
|
"attributes.gen_ai.usage.input_tokens": 17,
|
|
},
|
|
}
|
|
)
|
|
|
|
assert is_otel_v2_generation(observation, key_alias="test-key-alias")
|
|
assert not is_otel_v2_generation(observation, key_alias="another-key")
|
|
|
|
|
|
def test_observation_preserves_plain_text_and_legacy_cost() -> None:
|
|
cost: Final = 0.000031
|
|
observation: Final = LangfuseObservation.model_validate(
|
|
{"id": "observation", "input": "plain prompt", "output": "plain reply", "calculatedTotalCost": cost}
|
|
)
|
|
|
|
assert observation.input == "plain prompt"
|
|
assert observation.output == "plain reply"
|
|
assert observation_spend(observation) == cost
|