(feat) proxy: embeddings-add OpenAI exception mapping

This commit is contained in:
ishaan-jaff 2023-12-15 14:02:24 +05:30
parent a325321bc6
commit e3cb7ba6ba
2 changed files with 40 additions and 4 deletions

View file

@ -1115,7 +1115,19 @@ async def embeddings(request: Request, user_api_key_dict: UserAPIKeyAuth = Depen
except Exception as e:
await proxy_logging_obj.post_call_failure_hook(user_api_key_dict=user_api_key_dict, original_exception=e)
traceback.print_exc()
if isinstance(e, HTTPException):
raise e
else:
error_traceback = traceback.format_exc()
error_msg = f"{str(e)}\n\n{error_traceback}"
try:
status = e.status_code # type: ignore
except:
status = 500
raise HTTPException(
status_code=status,
detail=error_msg
)
#### KEY MANAGEMENT ####

View file

@ -73,12 +73,12 @@ def test_chat_completion_exception_azure(client):
# raise openai.BadRequestError
# chat/completions openai
def test_exception_openai_bad_model(client):
try:
# Your test data
test_data = {
"model": "openai/GPT-12",
"model": "azure/GPT-12",
"messages": [
{
"role": "user",
@ -99,7 +99,7 @@ def test_exception_openai_bad_model(client):
except Exception as e:
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
# chat/completions any model
def test_chat_completion_exception_any_model(client):
try:
# Your test data
@ -125,3 +125,27 @@ def test_chat_completion_exception_any_model(client):
except Exception as e:
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")
# embeddings any model
def test_embedding_exception_any_model(client):
try:
# Your test data
test_data = {
"model": "Lite-GPT-12",
"input": ["hi"]
}
response = client.post("/embeddings", json=test_data)
print("Response from proxy=", response)
# make an openai client to call _make_status_error_from_response
openai_client = openai.OpenAI(api_key="anything")
openai_exception = openai_client._make_status_error_from_response(response=response)
print("Exception raised=", openai_exception)
assert isinstance(openai_exception, openai.NotFoundError)
except Exception as e:
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")