From edef33abb22867f92b5903c7f22597fcbb6205b4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 28 Nov 2024 20:17:37 -0800 Subject: [PATCH] test_audio_speech_router --- .../local_testing/test_router_client_init.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/local_testing/test_router_client_init.py b/tests/local_testing/test_router_client_init.py index 978562409..777dd289c 100644 --- a/tests/local_testing/test_router_client_init.py +++ b/tests/local_testing/test_router_client_init.py @@ -20,6 +20,7 @@ sys.path.insert( ) # Adds the parent directory to the system path import litellm from litellm import APIConnectionError, Router +from unittest.mock import ANY async def test_router_init(): @@ -213,3 +214,45 @@ def test_router_init_azure_service_principal_with_secret_with_environment_variab # asyncio.run(test_router_init()) + + +@pytest.mark.asyncio +async def test_audio_speech_router(): + + from litellm import Router + + litellm.set_verbose = True + + model_list = [ + { + "model_name": "tts", + "litellm_params": { + "model": "azure/azure-tts", + "api_base": os.getenv("AZURE_SWEDEN_API_BASE"), + "api_key": os.getenv("AZURE_SWEDEN_API_KEY"), + }, + }, + ] + + _router = Router(model_list=model_list) + + expected_openai_client = _router._get_client( + deployment=_router.model_list[0], + kwargs={}, + client_type="async", + ) + + with patch("litellm.aspeech") as mock_aspeech: + await _router.aspeech( + model="tts", + voice="alloy", + input="the quick brown fox jumped over the lazy dogs", + ) + + print( + "litellm.aspeech was called with kwargs = ", mock_aspeech.call_args.kwargs + ) + + # Get the actual client that was passed + client_passed_in_request = mock_aspeech.call_args.kwargs["client"] + assert client_passed_in_request == expected_openai_client