mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 02:34:29 +00:00
* add initial test for assembly ai * start using PassthroughEndpointRouter * migrate to lllm passthrough endpoints * add assembly ai as a known provider * fix PassthroughEndpointRouter * fix set_pass_through_credentials * working EU request to assembly ai pass through endpoint * add e2e test assembly * test_assemblyai_routes_with_bad_api_key * clean up pass through endpoint router * e2e testing for assembly ai pass through * test assembly ai e2e testing * delete assembly ai models * fix code quality * ui working assembly ai api base flow * fix install assembly ai * update model call details with kwargs for pass through logging * fix tracking assembly ai model in response * _handle_assemblyai_passthrough_logging * fix test_initialize_deployment_for_pass_through_unsupported_provider * TestPassthroughEndpointRouter * _get_assembly_transcript * fix assembly ai pt logging tests * fix assemblyai_proxy_route * fix _get_assembly_region_from_url
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
"""
|
|
This test ensures that the proxy can passthrough requests to assemblyai
|
|
"""
|
|
|
|
import pytest
|
|
import assemblyai as aai
|
|
import aiohttp
|
|
import asyncio
|
|
import time
|
|
|
|
TEST_MASTER_KEY = "sk-1234"
|
|
TEST_BASE_URL = "http://0.0.0.0:4000/assemblyai"
|
|
|
|
|
|
def test_assemblyai_basic_transcribe():
|
|
print("making basic transcribe request to assemblyai passthrough")
|
|
|
|
# Replace with your API key
|
|
aai.settings.api_key = f"Bearer {TEST_MASTER_KEY}"
|
|
aai.settings.base_url = TEST_BASE_URL
|
|
|
|
# URL of the file to transcribe
|
|
FILE_URL = "https://assembly.ai/wildfires.mp3"
|
|
|
|
# You can also transcribe a local file by passing in a file path
|
|
# FILE_URL = './path/to/file.mp3'
|
|
|
|
transcriber = aai.Transcriber()
|
|
transcript = transcriber.transcribe(FILE_URL)
|
|
print(transcript)
|
|
print(transcript.id)
|
|
if transcript.id:
|
|
transcript.delete_by_id(transcript.id)
|
|
else:
|
|
pytest.fail("Failed to get transcript id")
|
|
|
|
if transcript.status == aai.TranscriptStatus.error:
|
|
print(transcript.error)
|
|
pytest.fail(f"Failed to transcribe file error: {transcript.error}")
|
|
else:
|
|
print(transcript.text)
|
|
|
|
|
|
async def generate_key(calling_key: str) -> str:
|
|
"""Helper function to generate a new API key"""
|
|
url = "http://0.0.0.0:4000/key/generate"
|
|
headers = {
|
|
"Authorization": f"Bearer {calling_key}",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.post(url, headers=headers, json={}) as response:
|
|
if response.status == 200:
|
|
data = await response.json()
|
|
return data.get("key")
|
|
raise Exception(f"Failed to generate key: {response.status}")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_assemblyai_transcribe_with_non_admin_key():
|
|
# Generate a non-admin key using the helper
|
|
non_admin_key = await generate_key(TEST_MASTER_KEY)
|
|
print(f"Generated non-admin key: {non_admin_key}")
|
|
|
|
# Use the non-admin key to transcribe
|
|
# Replace with your API key
|
|
aai.settings.api_key = f"Bearer {non_admin_key}"
|
|
aai.settings.base_url = TEST_BASE_URL
|
|
|
|
# URL of the file to transcribe
|
|
FILE_URL = "https://assembly.ai/wildfires.mp3"
|
|
|
|
# You can also transcribe a local file by passing in a file path
|
|
# FILE_URL = './path/to/file.mp3'
|
|
|
|
request_start_time = time.time()
|
|
|
|
transcriber = aai.Transcriber()
|
|
transcript = transcriber.transcribe(FILE_URL)
|
|
print(transcript)
|
|
print(transcript.id)
|
|
if transcript.id:
|
|
transcript.delete_by_id(transcript.id)
|
|
else:
|
|
pytest.fail("Failed to get transcript id")
|
|
|
|
if transcript.status == aai.TranscriptStatus.error:
|
|
print(transcript.error)
|
|
pytest.fail(f"Failed to transcribe file error: {transcript.error}")
|
|
else:
|
|
print(transcript.text)
|
|
|
|
request_end_time = time.time()
|
|
print(f"Request took {request_end_time - request_start_time} seconds")
|