mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix: test error
This commit is contained in:
parent
d6cd50dfdb
commit
8dd04c4eee
1 changed files with 25 additions and 30 deletions
|
|
@ -1128,38 +1128,31 @@ def test_anthropic_disable_url_suffix_env_var():
|
|||
from unittest.mock import patch, MagicMock
|
||||
import os
|
||||
from litellm import completion
|
||||
from litellm.llms.anthropic.chat.handler import AnthropicLLM
|
||||
|
||||
# Test with environment variable disabled (default behavior)
|
||||
with patch.dict(os.environ, {"ANTHROPIC_API_BASE": "https://api.example.com"}):
|
||||
with patch.object(AnthropicLLM, "__init__", return_value=None) as mock_init:
|
||||
with patch.object(AnthropicLLM, "completion") as mock_completion:
|
||||
mock_completion.return_value = MagicMock()
|
||||
|
||||
# Mock the initialization to capture api_base
|
||||
actual_api_base = None
|
||||
def capture_init(self, **kwargs):
|
||||
nonlocal actual_api_base
|
||||
actual_api_base = kwargs.get("api_base")
|
||||
|
||||
with patch("litellm.main.anthropic_chat_completions") as mock_anthropic:
|
||||
def capture_completion(**kwargs):
|
||||
nonlocal actual_api_base
|
||||
actual_api_base = kwargs.get("api_base")
|
||||
return MagicMock()
|
||||
|
||||
mock_anthropic.completion = capture_completion
|
||||
|
||||
# This should append /v1/messages
|
||||
completion(
|
||||
model="anthropic/claude-3-sonnet",
|
||||
messages=[{"role": "user", "content": "test"}],
|
||||
api_key="test-key"
|
||||
)
|
||||
|
||||
# Verify the api_base has /v1/messages appended
|
||||
assert actual_api_base.endswith("/v1/messages")
|
||||
assert actual_api_base == "https://api.example.com/v1/messages"
|
||||
actual_api_base = None
|
||||
|
||||
with patch("litellm.main.anthropic_chat_completions") as mock_anthropic:
|
||||
def capture_completion(**kwargs):
|
||||
nonlocal actual_api_base
|
||||
actual_api_base = kwargs.get("api_base")
|
||||
mock_response = MagicMock()
|
||||
mock_response.choices = [MagicMock()]
|
||||
return mock_response
|
||||
|
||||
mock_anthropic.completion = capture_completion
|
||||
|
||||
# This should append /v1/messages
|
||||
completion(
|
||||
model="anthropic/claude-3-sonnet",
|
||||
messages=[{"role": "user", "content": "test"}],
|
||||
api_key="test-key"
|
||||
)
|
||||
|
||||
# Verify the api_base has /v1/messages appended
|
||||
assert actual_api_base.endswith("/v1/messages")
|
||||
assert actual_api_base == "https://api.example.com/v1/messages"
|
||||
|
||||
# Test with environment variable enabled
|
||||
with patch.dict(os.environ, {
|
||||
|
|
@ -1172,7 +1165,9 @@ def test_anthropic_disable_url_suffix_env_var():
|
|||
def capture_completion(**kwargs):
|
||||
nonlocal actual_api_base
|
||||
actual_api_base = kwargs.get("api_base")
|
||||
return MagicMock()
|
||||
mock_response = MagicMock()
|
||||
mock_response.choices = [MagicMock()]
|
||||
return mock_response
|
||||
|
||||
mock_anthropic.completion = capture_completion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue