Skip to content
Draft
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
15 changes: 8 additions & 7 deletions tests/e2e/logging/logging_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Literal

import pytest
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError

from e2e_config import POLL_INTERVAL, POLL_TIMEOUT
from e2e_gateway import Gateway, build_gateway
Expand Down Expand Up @@ -200,15 +200,16 @@ def costs_agree(expected: float, actual: float, *, rel_tol: float = 0.05) -> boo
return abs(expected - actual) <= max(1e-9, abs(expected) * rel_tol)


_JSON_OBJECT: TypeAdapter[dict[str, object]] = TypeAdapter(dict[str, object])


def completion_response_id(body: str) -> str | None:
"""SpendLogs.request_id is the chat completion body id, not x-litellm-call-id."""
if not body or body == "<streamed>":
return None
try:
parsed = json.loads(body)
except json.JSONDecodeError:
return None
if not isinstance(parsed, dict):
parsed = _JSON_OBJECT.validate_json(body)
except ValidationError:
return None
raw = parsed.get("id")
return raw if isinstance(raw, str) and raw else None
Expand Down Expand Up @@ -499,9 +500,9 @@ def list_langfuse_observations(
headers=creds.auth_headers,
params=LangfuseListParams(
limit=100,
trace_id=trace_id,
traceId=trace_id,
name=name,
from_start_time=from_start_time,
fromStartTime=from_start_time,
),
response_type=LangfuseObservationList,
timeout=30.0,
Expand Down
Loading