mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
test_bedrock_error_handling_returns_actual_error
This commit is contained in:
parent
e17636d4a6
commit
51f1907e98
1 changed files with 54 additions and 2 deletions
|
|
@ -18,12 +18,12 @@ import litellm
|
|||
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
|
||||
BaseOpenAIPassThroughHandler,
|
||||
RouteChecks,
|
||||
bedrock_llm_proxy_route,
|
||||
create_pass_through_route,
|
||||
llm_passthrough_factory_proxy_route,
|
||||
vllm_proxy_route,
|
||||
vertex_discovery_proxy_route,
|
||||
vertex_proxy_route,
|
||||
bedrock_llm_proxy_route,
|
||||
vllm_proxy_route,
|
||||
)
|
||||
from litellm.types.passthrough_endpoints.vertex_ai import VertexPassThroughCredentials
|
||||
|
||||
|
|
@ -996,6 +996,58 @@ class TestBedrockLLMProxyRoute:
|
|||
assert call_kwargs["model"] == "anthropic.claude-3-sonnet-20240229-v1:0"
|
||||
assert result == "success"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bedrock_error_handling_returns_actual_error(self):
|
||||
"""
|
||||
Test that when Bedrock API returns an error, it is properly propagated to the user
|
||||
instead of being returned as a generic "Internal Server Error".
|
||||
"""
|
||||
from fastapi import HTTPException
|
||||
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
|
||||
handle_bedrock_passthrough_router_model,
|
||||
)
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.method = "POST"
|
||||
mock_request.headers = {"content-type": "application/json"}
|
||||
mock_request.query_params = {}
|
||||
|
||||
mock_request_body = {
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [{"textaaa": "Hello"}]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
bedrock_error_message = '{"message":"ContentBlock object at messages.0.content.0 must set one of the following keys: text, image, toolUse, toolResult, document, video."}'
|
||||
|
||||
mock_llm_router = Mock()
|
||||
mock_llm_router.allm_passthrough_route = AsyncMock(
|
||||
side_effect=BaseLLMException(
|
||||
status_code=400,
|
||||
message=bedrock_error_message
|
||||
)
|
||||
)
|
||||
|
||||
endpoint = "model/test-model/converse"
|
||||
model = "test-model"
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await handle_bedrock_passthrough_router_model(
|
||||
model=model,
|
||||
endpoint=endpoint,
|
||||
request=mock_request,
|
||||
request_body=mock_request_body,
|
||||
llm_router=mock_llm_router,
|
||||
)
|
||||
|
||||
assert exc_info.value.status_code == 400
|
||||
assert "ContentBlock object at messages.0.content.0 must set one of the following keys" in str(exc_info.value.detail)
|
||||
|
||||
|
||||
class TestLLMPassthroughFactoryProxyRoute:
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue