mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
Snapshot corpus for the translation v2 differential gate: 19 OpenAI-format
request cases x {anthropic, bedrock converse, bedrock invoke} through the
real v1 transform_request path (get_optional_params, validate_environment
included), recorded provider responses through transform_response, SSE and
event-stream replays through CustomStreamWrapper plus the real decoders, and
both /v1/messages surfaces (anthropic<->openai adapter round-trip and the
native AnthropicMessagesConfig quirks: max_tokens pop, reasoning_effort
rewrite, advisor-block stripping). 89 canonical-JSON snapshots, deterministic
via frozen uuid/fastuuid/time, regenerated with --snapshot-update or
SNAPSHOT_UPDATE=1. Wired into CI as a job in test-unit-llm-providers.yml and
a make test-characterization target
30 lines
958 B
Python
30 lines
958 B
Python
"""Pin v1 response transforms: recorded provider JSON -> OpenAI ModelResponse."""
|
|
|
|
import pytest
|
|
|
|
from ._helpers import FIXTURES_DIR, assert_snapshot, load_json
|
|
from ._seams import PROVIDERS, run_response_transform
|
|
|
|
_MESSAGES = [{"role": "user", "content": "What is the capital of France?"}]
|
|
|
|
|
|
def _fixture_ids(provider_key: str) -> list:
|
|
return sorted(p.stem for p in (FIXTURES_DIR / "responses" / provider_key).glob("*.json"))
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"provider_key,fixture_id",
|
|
[
|
|
(p, f)
|
|
for p in sorted(PROVIDERS)
|
|
for f in _fixture_ids(p)
|
|
],
|
|
)
|
|
def test_response_transform(
|
|
provider_key: str, fixture_id: str, snapshot_update: bool
|
|
) -> None:
|
|
payload = load_json(FIXTURES_DIR / "responses" / provider_key / f"{fixture_id}.json")
|
|
result = run_response_transform(provider_key, payload, _MESSAGES)
|
|
assert_snapshot(
|
|
f"responses/{provider_key}/{fixture_id}.json", result, snapshot_update
|
|
)
|