litellm/tests/llm_translation/base_audio_transcription_unit_tests.py
yuneng-jiang 6a0d03914c
test: drop the cwd-relative sys.path.insert calls from the test suite (#37802)
* test: drop the cwd-relative sys.path.insert calls from the test suite

TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.

Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.

Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.

* test: drop the duplicate imports the sys.path sweep exposed to F811

* test(pre-call-utils): restore the os import the new bedrock tests need
2026-08-22 09:25:58 -07:00

100 lines
3.5 KiB
Python

import httpx
import json
import pytest
from typing import Any, Dict, List
from unittest.mock import MagicMock, Mock, patch
import os
from litellm._uuid import uuid
import litellm
from litellm import transcription
from litellm.litellm_core_utils.get_supported_openai_params import (
get_supported_openai_params,
)
from litellm.llms.base_llm.audio_transcription.transformation import (
BaseAudioTranscriptionConfig,
)
from litellm.utils import ProviderConfigManager
from abc import ABC, abstractmethod
pwd = os.path.dirname(os.path.realpath(__file__))
print(pwd)
file_path = os.path.join(pwd, "gettysburg.wav")
audio_file = open(file_path, "rb")
class BaseLLMAudioTranscriptionTest(ABC):
@abstractmethod
def get_base_audio_transcription_call_args(self) -> dict:
"""Must return the base audio transcription call args"""
pass
@abstractmethod
def get_custom_llm_provider(self) -> litellm.LlmProviders:
"""Must return the custom llm provider"""
pass
def test_audio_transcription(self):
"""
Test that the audio transcription is translated correctly.
"""
litellm.set_verbose = True
transcription_call_args = self.get_base_audio_transcription_call_args()
transcript = transcription(**transcription_call_args, file=audio_file)
print(f"transcript: {transcript.model_dump()}")
print(f"transcript hidden params: {transcript._hidden_params}")
assert transcript.text is not None
@pytest.mark.asyncio
async def test_audio_transcription_async(self):
"""
Test that the audio transcription is translated correctly.
"""
litellm.set_verbose = True
litellm._turn_on_debug()
AUDIO_FILE = open(file_path, "rb")
transcription_call_args = self.get_base_audio_transcription_call_args()
transcript = await litellm.atranscription(
**transcription_call_args, file=AUDIO_FILE
)
print(f"transcript: {transcript.model_dump()}")
print(f"transcript hidden params: {transcript._hidden_params}")
assert transcript.text is not None
def test_audio_transcription_optional_params(self):
"""
Test that the audio transcription is translated correctly.
"""
transcription_args = self.get_base_audio_transcription_call_args()
model = transcription_args["model"]
custom_llm_provider = self.get_custom_llm_provider()
optional_params = get_supported_openai_params(
model=model,
custom_llm_provider=custom_llm_provider.value,
request_type="transcription",
)
print(f"optional_params: {optional_params}")
assert optional_params is not None
assert (
"max_completion_tokens" not in optional_params
) # assert default chat completion response not returned
def test_audio_transcription_config(self):
"""
Test that the audio transcription config is implemented and correctly instrumented.
"""
transcription_args = self.get_base_audio_transcription_call_args()
model = transcription_args["model"]
custom_llm_provider = self.get_custom_llm_provider()
config = ProviderConfigManager.get_provider_audio_transcription_config(
model=model,
provider=custom_llm_provider,
)
print(f"config: {config}")
assert config is not None
assert isinstance(config, BaseAudioTranscriptionConfig)