mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge b680be2705 into e9b1c11098
This commit is contained in:
commit
2cfa3479ef
2 changed files with 26 additions and 11 deletions
|
|
@ -336,7 +336,7 @@ class ProxyInitializationHelpers:
|
|||
api_base = f"http://{host}:{port}"
|
||||
if isinstance(test, str):
|
||||
api_base = test
|
||||
else:
|
||||
elif test is not True:
|
||||
raise ValueError("Invalid test value")
|
||||
client: Final = openai.OpenAI(api_key="My API Key", base_url=api_base)
|
||||
|
||||
|
|
|
|||
|
|
@ -184,7 +184,16 @@ class TestProxyInitializationHelpers:
|
|||
@patch("openai.OpenAI")
|
||||
@patch("click.echo")
|
||||
@patch("builtins.print")
|
||||
def test_run_test_chat_completion(self, mock_print, mock_echo, mock_openai):
|
||||
@pytest.mark.parametrize(
|
||||
("test_value", "expected_base_url"),
|
||||
[
|
||||
(True, "http://localhost:8000"),
|
||||
("http://test-url", "http://test-url"),
|
||||
],
|
||||
)
|
||||
def test_run_test_chat_completion(
|
||||
self, mock_print, mock_echo, mock_openai, test_value, expected_base_url
|
||||
):
|
||||
# Setup
|
||||
mock_client = MagicMock()
|
||||
mock_openai.return_value = mock_client
|
||||
|
|
@ -200,21 +209,27 @@ class TestProxyInitializationHelpers:
|
|||
]
|
||||
|
||||
# Execute
|
||||
with pytest.raises(ValueError, match="Invalid test value"):
|
||||
ProxyInitializationHelpers._run_test_chat_completion(
|
||||
"localhost", 8000, "gpt-3.5-turbo", True
|
||||
)
|
||||
|
||||
# Test with valid string test value
|
||||
ProxyInitializationHelpers._run_test_chat_completion(
|
||||
"localhost", 8000, "gpt-3.5-turbo", "http://test-url"
|
||||
"localhost", 8000, "gpt-3.5-turbo", test_value
|
||||
)
|
||||
|
||||
# Assert
|
||||
mock_openai.assert_called_once_with(
|
||||
api_key="My API Key", base_url="http://test-url"
|
||||
api_key="My API Key", base_url=expected_base_url
|
||||
)
|
||||
mock_client.chat.completions.create.assert_called()
|
||||
assert mock_client.chat.completions.create.call_count == 2
|
||||
mock_client.completions.create.assert_called_once_with(
|
||||
model="gpt-3.5-turbo", prompt="this is a test request, write a short poem"
|
||||
)
|
||||
|
||||
@patch("openai.OpenAI")
|
||||
def test_run_test_chat_completion_rejects_false(self, mock_openai):
|
||||
with pytest.raises(ValueError, match="Invalid test value"):
|
||||
ProxyInitializationHelpers._run_test_chat_completion(
|
||||
"localhost", 8000, "gpt-3.5-turbo", False
|
||||
)
|
||||
|
||||
mock_openai.assert_not_called()
|
||||
|
||||
def test_get_default_unvicorn_init_args(self):
|
||||
# Test without log_config
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue