mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix(router.py): check if azure returns 'content_filter' response + fallback available -> fallback
Exception maps azure content filter response exceptions
This commit is contained in:
parent
f814f24d9d
commit
2c7a80d08d
8 changed files with 100 additions and 70 deletions
|
@ -1,8 +1,12 @@
|
|||
#### What this tests ####
|
||||
# This tests calling router with fallback models
|
||||
|
||||
import sys, os, time
|
||||
import traceback, asyncio
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(
|
||||
|
@ -762,9 +766,11 @@ def test_ausage_based_routing_fallbacks():
|
|||
# The Request should fail azure/gpt-4-fast. Then fallback -> "azure/gpt-4-basic" -> "openai-gpt-4"
|
||||
# It should work with "openai-gpt-4"
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import litellm
|
||||
from litellm import Router
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
@ -1112,9 +1118,19 @@ async def test_client_side_fallbacks_list(sync_mode):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("sync_mode", [True, False])
|
||||
@pytest.mark.parametrize("content_filter_response_exception", [True, False])
|
||||
@pytest.mark.asyncio
|
||||
async def test_router_content_policy_fallbacks(sync_mode):
|
||||
async def test_router_content_policy_fallbacks(
|
||||
sync_mode, content_filter_response_exception
|
||||
):
|
||||
os.environ["LITELLM_LOG"] = "DEBUG"
|
||||
|
||||
if content_filter_response_exception:
|
||||
mock_response = Exception("content filtering policy")
|
||||
else:
|
||||
mock_response = litellm.ModelResponse(
|
||||
choices=[litellm.Choices(finish_reason="content_filter")]
|
||||
)
|
||||
router = Router(
|
||||
model_list=[
|
||||
{
|
||||
|
@ -1122,13 +1138,13 @@ async def test_router_content_policy_fallbacks(sync_mode):
|
|||
"litellm_params": {
|
||||
"model": "claude-2",
|
||||
"api_key": "",
|
||||
"mock_response": Exception("content filtering policy"),
|
||||
"mock_response": mock_response,
|
||||
},
|
||||
},
|
||||
{
|
||||
"model_name": "my-fallback-model",
|
||||
"litellm_params": {
|
||||
"model": "claude-2",
|
||||
"model": "openai/my-fake-model",
|
||||
"api_key": "",
|
||||
"mock_response": "This works!",
|
||||
},
|
||||
|
@ -1165,3 +1181,5 @@ async def test_router_content_policy_fallbacks(sync_mode):
|
|||
model="claude-2",
|
||||
messages=[{"role": "user", "content": "Hey, how's it going?"}],
|
||||
)
|
||||
|
||||
assert response.model == "my-fake-model"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue