fix test proxy exception mapping

This commit is contained in:
Ishaan Jaff 2024-08-15 08:52:28 -07:00
parent 58828403ea
commit c50a60004f
2 changed files with 18 additions and 4 deletions

View file

@ -25,6 +25,17 @@ else:
LitellmRouter = Any
ROUTE_ENDPOINT_MAPPING = {
"acompletion": "/chat/completions",
"atext_completion": "/completions",
"aembedding": "/embeddings",
"aimage_generation": "/image/generations",
"aspeech": "/audio/speech",
"atranscription": "/audio/transcriptions",
"amoderation": "/moderations",
}
async def route_request(
data: dict,
llm_router: Optional[LitellmRouter],
@ -94,10 +105,12 @@ async def route_request(
elif user_model is not None:
return getattr(litellm, f"{route_type}")(**data)
# if no route found then it's a bad request
route_name = ROUTE_ENDPOINT_MAPPING.get(route_type, route_type)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail={
"error": f"{route_type}: Invalid model name passed in model="
"error": f"{route_name}: Invalid model name passed in model="
+ data.get("model", "")
},
)

View file

@ -229,8 +229,9 @@ def test_chat_completion_exception_any_model(client):
)
assert isinstance(openai_exception, openai.BadRequestError)
_error_message = openai_exception.message
assert "chat_completion: Invalid model name passed in model=Lite-GPT-12" in str(
_error_message
assert (
"/chat/completions: Invalid model name passed in model=Lite-GPT-12"
in str(_error_message)
)
except Exception as e:
@ -259,7 +260,7 @@ def test_embedding_exception_any_model(client):
print("Exception raised=", openai_exception)
assert isinstance(openai_exception, openai.BadRequestError)
_error_message = openai_exception.message
assert "embeddings: Invalid model name passed in model=Lite-GPT-12" in str(
assert "/embeddings: Invalid model name passed in model=Lite-GPT-12" in str(
_error_message
)