Skip to content

Commit 0b9e196

Browse files
committed
add test for transcriptions
1 parent a5fd61b commit 0b9e196

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import os
2+
3+
import pytest
4+
5+
from together.client import Together
6+
from together.types.audio_speech import (
7+
AudioTranscriptionResponse,
8+
AudioTranscriptionVerboseResponse,
9+
)
10+
11+
12+
class TestTogetherTranscriptions:
13+
@pytest.fixture
14+
def sync_together_client(self) -> Together:
15+
"""
16+
Initialize object with API key from environment
17+
"""
18+
TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
19+
return Together(api_key=TOGETHER_API_KEY)
20+
21+
def test_basic_transcription_url(self, sync_together_client):
22+
"""
23+
Test basic transcription with URL audio file
24+
"""
25+
audio_url = "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
26+
27+
response = sync_together_client.audio.transcriptions.create(
28+
file=audio_url, model="openai/whisper-large-v3"
29+
)
30+
31+
assert isinstance(response, AudioTranscriptionResponse)
32+
assert isinstance(response.text, str)
33+
assert len(response.text) > 0
34+
35+
def test_transcription_with_language(self, sync_together_client):
36+
"""
37+
Test transcription with language parameter
38+
"""
39+
audio_url = "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
40+
41+
response = sync_together_client.audio.transcriptions.create(
42+
file=audio_url, model="openai/whisper-large-v3", language="en"
43+
)
44+
45+
assert isinstance(response, AudioTranscriptionResponse)
46+
assert isinstance(response.text, str)
47+
assert len(response.text) > 0
48+
49+
def test_transcription_verbose_json(self, sync_together_client):
50+
"""
51+
Test transcription with verbose JSON format and timestamps
52+
"""
53+
audio_url = "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
54+
55+
response = sync_together_client.audio.transcriptions.create(
56+
file=audio_url,
57+
model="openai/whisper-large-v3",
58+
response_format="verbose_json",
59+
timestamp_granularities="segment",
60+
)
61+
62+
assert isinstance(response, AudioTranscriptionVerboseResponse)
63+
assert isinstance(response.text, str)
64+
assert len(response.text) > 0
65+
assert hasattr(response, "segments")
66+
67+
def test_transcription_with_temperature(self, sync_together_client):
68+
"""
69+
Test transcription with temperature parameter
70+
"""
71+
audio_url = "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
72+
73+
response = sync_together_client.audio.transcriptions.create(
74+
file=audio_url, model="openai/whisper-large-v3", temperature=0.2
75+
)
76+
77+
assert isinstance(response, AudioTranscriptionResponse)
78+
assert isinstance(response.text, str)
79+
assert len(response.text) > 0
80+
81+
def test_transcription_missing_file(self, sync_together_client):
82+
"""
83+
Test transcription with missing file parameter
84+
"""
85+
with pytest.raises(TypeError):
86+
sync_together_client.audio.transcriptions.create(
87+
model="openai/whisper-large-v3"
88+
)
89+
90+
def test_transcription_missing_model(self, sync_together_client):
91+
"""
92+
Test transcription with missing model parameter - should use default model
93+
"""
94+
audio_url = "https://raw.githubusercontent.com/yuekaizhang/Triton-ASR-Client/main/datasets/mini_en/wav/1221-135766-0002.wav"
95+
96+
response = sync_together_client.audio.transcriptions.create(file=audio_url)
97+
98+
assert isinstance(response, AudioTranscriptionResponse)
99+
assert isinstance(response.text, str)
100+
assert len(response.text) > 0

0 commit comments

Comments
 (0)