2
## Tests `litellm.transcription` endpoint. Outside litellm module b/c of audio file used in testing (it's ~700kb).
6
import aiohttp, traceback
7
from openai import AsyncOpenAI
9
from typing import Optional
10
from dotenv import load_dotenv
12
# Get the current directory of the file being run
13
pwd = os.path.dirname(os.path.realpath(__file__))
16
file_path = os.path.join(pwd, "gettysburg.wav")
18
audio_file = open(file_path, "rb")
23
0, os.path.abspath("../")
24
) # Adds the parent directory to the system path
26
from litellm import Router
29
def test_transcription():
30
transcript = litellm.transcription(
34
print(f"transcript: {transcript.model_dump()}")
35
print(f"transcript: {transcript._hidden_params}")
41
def test_transcription_azure():
42
litellm.set_verbose = True
43
transcript = litellm.transcription(
44
model="azure/azure-whisper",
46
api_base="https://my-endpoint-europe-berri-992.openai.azure.com/",
47
api_key=os.getenv("AZURE_EUROPE_API_KEY"),
48
api_version="2024-02-15-preview",
51
print(f"transcript: {transcript}")
52
assert transcript.text is not None
53
assert isinstance(transcript.text, str)
56
# test_transcription_azure()
60
async def test_transcription_async_azure():
61
transcript = await litellm.atranscription(
62
model="azure/azure-whisper",
64
api_base="https://my-endpoint-europe-berri-992.openai.azure.com/",
65
api_key=os.getenv("AZURE_EUROPE_API_KEY"),
66
api_version="2024-02-15-preview",
69
assert transcript.text is not None
70
assert isinstance(transcript.text, str)
73
# asyncio.run(test_transcription_async_azure())
77
async def test_transcription_async_openai():
78
transcript = await litellm.atranscription(
83
assert transcript.text is not None
84
assert isinstance(transcript.text, str)
88
async def test_transcription_on_router():
89
litellm.set_verbose = True
90
print("\n Testing async transcription on router\n")
94
"model_name": "whisper",
100
"model_name": "whisper",
102
"model": "azure/azure-whisper",
103
"api_base": "https://my-endpoint-europe-berri-992.openai.azure.com/",
104
"api_key": os.getenv("AZURE_EUROPE_API_KEY"),
105
"api_version": "2024-02-15-preview",
110
router = Router(model_list=model_list)
111
response = await router.atranscription(
116
except Exception as e:
117
traceback.print_exc()
118
pytest.fail(f"Error occurred: {e}")