test(gemini): cover repeated transcription hints through proxy

This commit is contained in:
Rakshit Jain 2026-10-06 12:19:06 +08:00
parent 9a90a86d1d
commit d483d4fbf2
2 changed files with 76 additions and 1 deletions

View file

@ -11,9 +11,10 @@ import contextlib
import os
import sys
from pathlib import Path
from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional
from typing import Any, AsyncIterator, Callable, Dict, Final, Iterator, List, Optional
from unittest.mock import AsyncMock, MagicMock
import httpx
import pytest
# Repo root, anchored to this file (not CWD) so the path is correct no
@ -536,3 +537,41 @@ def reset_login_throttle(monkeypatch):
_drop_throttle_keys()
yield _drop_throttle_keys
_drop_throttle_keys()
@pytest.fixture
async def gemini_transcription_requests(monkeypatch: pytest.MonkeyPatch) -> AsyncIterator[list[httpx.Request]]:
import litellm
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
from litellm.proxy import proxy_server
requests: Final[list[httpx.Request]] = [] # mutable-ok: captures requests to the injected provider transport
def respond(request: httpx.Request) -> httpx.Response:
requests.append(request)
return httpx.Response(
200,
json={
"id": "test-interaction",
"status": "completed",
"steps": [{"type": "model_generation", "content": [{"type": "text", "text": "Hello world."}]}],
},
)
handler: Final = AsyncHTTPHandler(transport=httpx.MockTransport(respond))
router: Final = litellm.Router(
model_list=[
{
"model_name": "gemini-transcribe",
"litellm_params": {"model": "gemini/gemini-3.5-transcribe", "api_key": "test-key"},
}
],
num_retries=0,
default_litellm_params={"client": handler},
)
monkeypatch.setattr(proxy_server, "llm_router", router)
try:
yield requests
finally:
router.discard()
await handler.close()

View file

@ -10,12 +10,18 @@ Pins (PR2):
from __future__ import annotations
import io
import json
from collections.abc import Callable
from contextlib import AbstractContextManager
from typing import Final
from unittest.mock import AsyncMock, MagicMock
import httpx
import pytest
from fastapi.testclient import TestClient
from litellm.proxy import proxy_server
from litellm.proxy._types import UserAPIKeyAuth
from litellm.types.llms.openai import HttpxBinaryResponseContent
@ -254,3 +260,33 @@ def test_audio_transcription_error(client, auth_as, patched_transcription_error,
response = client.post(path, files=files, data=data)
assert response.status_code == 500
assert len(response.content) > 0
@pytest.mark.parametrize("path", ["/v1/audio/transcriptions", "/audio/transcriptions"])
def test_repeated_language_fields_reach_gemini_through_proxy(
client: TestClient,
auth_as: Callable[..., AbstractContextManager[UserAPIKeyAuth]],
gemini_transcription_requests: list[httpx.Request],
path: str,
) -> None:
with auth_as():
response: Final = client.post(
path,
files=[
("file", ("audio.wav", b"RIFF....WAVEfmt synthetic-audio", "audio/wav")),
("model", (None, "gemini-transcribe")),
("language", (None, "fr")),
("language_codes[]", (None, "en-US")),
("language_codes[]", (None, "es-ES")),
("timestamp_granularities[]", (None, "word")),
],
)
assert response.status_code == 200, response.text
assert response.json()["text"] == "Hello world."
assert len(gemini_transcription_requests) == 1
assert json.loads(gemini_transcription_requests[0].content)["generation_config"] == {
"transcription_config": {
"language_codes": ["en-US", "es-ES"],
"mode": {"type": "verbatim", "timestamp_granularities": ["word"], "diarization_mode": "speaker"},
}
}