From 4ce4927c0cf9af8d0c4b6319b155e244572db4e7 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 3 May 2024 17:56:39 -0700 Subject: [PATCH 1/2] Add test_engines_model_chat_completions --- litellm/tests/test_proxy_server.py | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/litellm/tests/test_proxy_server.py b/litellm/tests/test_proxy_server.py index 43a070556..c1965dc2a 100644 --- a/litellm/tests/test_proxy_server.py +++ b/litellm/tests/test_proxy_server.py @@ -160,7 +160,40 @@ def test_chat_completion(mock_acompletion, client_no_auth): pytest.fail(f"LiteLLM Proxy test failed. Exception - {str(e)}") -# Run the test +@mock_patch_acompletion() +def test_engines_model_chat_completions(mock_acompletion, client_no_auth): + global headers + try: + # Your test data + test_data = { + "model": "gpt-3.5-turbo", + "messages": [ + {"role": "user", "content": "hi"}, + ], + "max_tokens": 10, + } + + print("testing proxy server with chat completions") + response = client_no_auth.post("/engines/gpt-3.5-turbo/chat/completions", json=test_data) + mock_acompletion.assert_called_once_with( + model="gpt-3.5-turbo", + messages=[ + {"role": "user", "content": "hi"}, + ], + max_tokens=10, + litellm_call_id=mock.ANY, + litellm_logging_obj=mock.ANY, + request_timeout=mock.ANY, + specific_deployment=True, + metadata=mock.ANY, + proxy_server_request=mock.ANY, + ) + print(f"response - {response.text}") + assert response.status_code == 200 + result = response.json() + print(f"Received response: {result}") + except Exception as e: + pytest.fail(f"LiteLLM Proxy test failed. Exception - {str(e)}") @mock_patch_acompletion() From eb433bde863c750affcae4ac38517ba756ed9290 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 3 May 2024 17:57:30 -0700 Subject: [PATCH 2/2] Add route: "/engines/{model:path}/chat/completions" Without this, it results in: ```pytb Traceback (most recent call last): File "/Users/abramowi/Code/OpenSource/litellm/litellm/proxy/proxy_server.py", line 3836, in completion raise HTTPException( fastapi.exceptions.HTTPException: 400: {'error': 'completion: Invalid model name passed in model=gpt-3.5-turbo/chat'} ``` --- litellm/proxy/proxy_server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 55202fd16..bbeacded0 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -3456,6 +3456,11 @@ def model_list( dependencies=[Depends(user_api_key_auth)], tags=["chat/completions"], ) +@router.post( + "/engines/{model:path}/chat/completions", + dependencies=[Depends(user_api_key_auth)], + tags=["chat/completions"], +) @router.post( "/openai/deployments/{model:path}/chat/completions", dependencies=[Depends(user_api_key_auth)],