@@ -921,14 +921,15 @@ async def test_bedrock_llm_proxy_route_regular_model(self):
921
921
class TestLLMPassthroughFactoryProxyRoute :
922
922
@pytest .mark .asyncio
923
923
async def test_llm_passthrough_factory_proxy_route_success (self ):
924
+ from litellm .types .utils import LlmProviders
924
925
mock_request = MagicMock (spec = Request )
925
926
mock_request .method = "POST"
926
927
mock_request .json = AsyncMock (return_value = {"stream" : False })
927
928
mock_fastapi_response = MagicMock (spec = Response )
928
929
mock_user_api_key_dict = MagicMock ()
929
930
930
931
with patch (
931
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints .ProviderConfigManager.get_provider_model_info"
932
+ "litellm.utils .ProviderConfigManager.get_provider_model_info"
932
933
) as mock_get_provider , patch (
933
934
"litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.passthrough_endpoint_router.get_credentials"
934
935
) as mock_get_creds , patch (
@@ -937,16 +938,16 @@ async def test_llm_passthrough_factory_proxy_route_success(self):
937
938
mock_provider_config = MagicMock ()
938
939
mock_provider_config .get_api_base .return_value = "https://example.com/v1"
939
940
mock_provider_config .validate_environment .return_value = {
940
- "Authorization " : "Bearer test-key "
941
+ "x-api-key " : "dummy "
941
942
}
942
943
mock_get_provider .return_value = mock_provider_config
943
- mock_get_creds .return_value = "test-api-key "
944
+ mock_get_creds .return_value = "dummy "
944
945
945
946
mock_endpoint_func = AsyncMock (return_value = "success" )
946
947
mock_create_route .return_value = mock_endpoint_func
947
948
948
949
result = await llm_passthrough_factory_proxy_route (
949
- custom_llm_provider = "custom_provider" ,
950
+ custom_llm_provider = LlmProviders . VLLM ,
950
951
endpoint = "/chat/completions" ,
951
952
request = mock_request ,
952
953
fastapi_response = mock_fastapi_response ,
@@ -955,96 +956,79 @@ async def test_llm_passthrough_factory_proxy_route_success(self):
955
956
956
957
assert result == "success"
957
958
mock_get_provider .assert_called_once_with (
958
- provider = litellm .LlmProviders ("custom_provider" ), model = None
959
+ provider = litellm .LlmProviders (LlmProviders . VLLM ), model = None
959
960
)
960
961
mock_get_creds .assert_called_once_with (
961
- custom_llm_provider = "custom_provider" , region_name = None
962
+ custom_llm_provider = LlmProviders . VLLM , region_name = None
962
963
)
963
964
mock_create_route .assert_called_once_with (
964
965
endpoint = "/chat/completions" ,
965
966
target = "https://example.com/v1/chat/completions" ,
966
- custom_headers = {"Authorization " : "Bearer test-key " },
967
+ custom_headers = {"x-api-key " : "dummy " },
967
968
)
968
969
mock_endpoint_func .assert_awaited_once ()
969
970
970
971
971
972
class TestVLLMProxyRoute :
972
973
@pytest .mark .asyncio
973
- async def test_vllm_proxy_route_with_router_model (self ):
974
+ @patch (
975
+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body" ,
976
+ return_value = {"model" : "router-model" , "stream" : False },
977
+ )
978
+ @patch (
979
+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model" ,
980
+ return_value = True ,
981
+ )
982
+ @patch ("litellm.proxy.proxy_server.llm_router" )
983
+ async def test_vllm_proxy_route_with_router_model (
984
+ self , mock_llm_router , mock_is_router , mock_get_body
985
+ ):
974
986
mock_request = MagicMock (spec = Request )
975
987
mock_request .method = "POST"
976
988
mock_request .headers = {"content-type" : "application/json" }
977
989
mock_request .query_params = {}
978
-
979
990
mock_fastapi_response = MagicMock (spec = Response )
980
991
mock_user_api_key_dict = MagicMock ()
992
+ mock_llm_router .allm_passthrough_route = AsyncMock (
993
+ return_value = httpx .Response (200 , json = {"response" : "success" })
994
+ )
981
995
982
- with patch (
983
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body" ,
984
- return_value = {"model" : "router-model" , "stream" : False },
985
- ), patch (
986
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model" ,
987
- return_value = True ,
988
- ) as mock_is_router , patch (
989
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.llm_router"
990
- ) as mock_llm_router :
991
- mock_llm_router .allm_passthrough_route = AsyncMock ()
992
- mock_response = httpx .Response (200 , json = {"response" : "success" })
993
- mock_llm_router .allm_passthrough_route .return_value = mock_response
994
-
995
- await vllm_proxy_route (
996
- endpoint = "/chat/completions" ,
997
- request = mock_request ,
998
- fastapi_response = mock_fastapi_response ,
999
- user_api_key_dict = mock_user_api_key_dict ,
1000
- )
996
+ await vllm_proxy_route (
997
+ endpoint = "/chat/completions" ,
998
+ request = mock_request ,
999
+ fastapi_response = mock_fastapi_response ,
1000
+ user_api_key_dict = mock_user_api_key_dict ,
1001
+ )
1001
1002
1002
- mock_is_router .assert_called_once ()
1003
- mock_llm_router .allm_passthrough_route .assert_awaited_once_with (
1004
- model = "router-model" ,
1005
- method = "POST" ,
1006
- endpoint = "/chat/completions" ,
1007
- request_query_params = {},
1008
- request_headers = {"content-type" : "application/json" },
1009
- stream = False ,
1010
- content = None ,
1011
- data = None ,
1012
- files = None ,
1013
- json = {"model" : "router-model" , "stream" : False },
1014
- params = None ,
1015
- headers = None ,
1016
- cookies = None ,
1017
- )
1003
+ mock_is_router .assert_called_once ()
1004
+ mock_llm_router .allm_passthrough_route .assert_awaited_once ()
1018
1005
1019
1006
@pytest .mark .asyncio
1020
- async def test_vllm_proxy_route_fallback_to_factory (self ):
1007
+ @patch (
1008
+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body" ,
1009
+ return_value = {"model" : "other-model" },
1010
+ )
1011
+ @patch (
1012
+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model" ,
1013
+ return_value = False ,
1014
+ )
1015
+ @patch (
1016
+ "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.llm_passthrough_factory_proxy_route"
1017
+ )
1018
+ async def test_vllm_proxy_route_fallback_to_factory (
1019
+ self , mock_factory_route , mock_is_router , mock_get_body
1020
+ ):
1021
1021
mock_request = MagicMock (spec = Request )
1022
1022
mock_fastapi_response = MagicMock (spec = Response )
1023
1023
mock_user_api_key_dict = MagicMock ()
1024
+ mock_factory_route .return_value = "factory_success"
1024
1025
1025
- with patch (
1026
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.get_request_body" ,
1027
- return_value = {"model" : "other-model" },
1028
- ), patch (
1029
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.is_passthrough_request_using_router_model" ,
1030
- return_value = False ,
1031
- ), patch (
1032
- "litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints.llm_passthrough_factory_proxy_route"
1033
- ) as mock_factory_route :
1034
- mock_factory_route .return_value = "factory_success"
1035
-
1036
- result = await vllm_proxy_route (
1037
- endpoint = "/chat/completions" ,
1038
- request = mock_request ,
1039
- fastapi_response = mock_fastapi_response ,
1040
- user_api_key_dict = mock_user_api_key_dict ,
1041
- )
1026
+ result = await vllm_proxy_route (
1027
+ endpoint = "/chat/completions" ,
1028
+ request = mock_request ,
1029
+ fastapi_response = mock_fastapi_response ,
1030
+ user_api_key_dict = mock_user_api_key_dict ,
1031
+ )
1042
1032
1043
- assert result == "factory_success"
1044
- mock_factory_route .assert_awaited_once_with (
1045
- endpoint = "/chat/completions" ,
1046
- request = mock_request ,
1047
- fastapi_response = mock_fastapi_response ,
1048
- user_api_key_dict = mock_user_api_key_dict ,
1049
- custom_llm_provider = "vllm" ,
1050
- )
1033
+ assert result == "factory_success"
1034
+ mock_factory_route .assert_awaited_once ()
0 commit comments