Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(fireworks): mock whisper transcription tests instead of live calls (#30391)

yuneng-jiang82d9f2788790
diff --git a/tests/llm_translation/test_fireworks_ai_translation.py b/tests/llm_translation/test_fireworks_ai_translation.py
index c4f15ac4c3e..4e5bef16b8c 100644
--- a/tests/llm_translation/test_fireworks_ai_translation.py
+++ b/tests/llm_translation/test_fireworks_ai_translation.py
@@ -70,6 +70,11 @@ def test_map_response_format():
assert result == {"response_format": response_format}
+_AUDIO_FILE_PATH = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)), "gettysburg.wav"
+)
+
+
class TestFireworksAIAudioTranscription(BaseLLMAudioTranscriptionTest):
def get_base_audio_transcription_call_args(self) -> dict:
return {
@@ -80,6 +85,60 @@ class TestFireworksAIAudioTranscription(BaseLLMAudioTranscriptionTest):
def get_custom_llm_provider(self) -> litellm.LlmProviders:
return litellm.LlmProviders.FIREWORKS_AI
+ def test_audio_transcription(self):
+ from unittest.mock import MagicMock
+
+ from openai.types.audio import Transcription
+
+ audio_file = open(_AUDIO_FILE_PATH, "rb")
+ mock_client = MagicMock()
+ mock_client.audio.transcriptions.create.return_value = Transcription(
+ text="four score and seven years ago"
+ )
+
+ transcript = transcription(
+ **self.get_base_audio_transcription_call_args(),
+ file=audio_file,
+ api_key="fw-test-key",
+ client=mock_client,
+ )
+
+ assert transcript.text == "four score and seven years ago"
+ sent = mock_client.audio.transcriptions.create.call_args.kwargs
+ assert sent["model"] == "whisper-v3"
+ assert sent["file"] is audio_file
+
+ @pytest.mark.asyncio
+ async def test_audio_transcription_async(self):
+ from unittest.mock import AsyncMock, MagicMock
+
+ from openai.types.audio import Transcription
+
+ audio_file = open(_AUDIO_FILE_PATH, "rb")
+ raw_response = MagicMock()
+ raw_response.headers = {}
+ raw_response.parse.return_value = Transcription(
+ text="four score and seven years ago"
+ )
+ mock_client = MagicMock()
+ mock_client.audio.transcriptions.with_raw_response.create = AsyncMock(
+ return_value=raw_response
+ )
+
+ transcript = await litellm.atranscription(
+ **self.get_base_audio_transcription_call_args(),
+ file=audio_file,
+ api_key="fw-test-key",
+ client=mock_client,
+ )
+
+ assert transcript.text == "four score and seven years ago"
+ sent = (
+ mock_client.audio.transcriptions.with_raw_response.create.call_args.kwargs
+ )
+ assert sent["model"] == "whisper-v3"
+ assert sent["file"] is audio_file
+
@pytest.mark.parametrize(
"disable_add_transform_inline_image_block",