(feat) proxy: embeddings-add OpenAI exception mapping

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

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)}")