From 26a5d85869e88db9b7988ec8c5d79a9d23b33c90 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 30 Apr 2024 15:41:16 -0700 Subject: [PATCH] fix - backend return exceptions --- litellm/proxy/proxy_server.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index b3132d2c64..37c943636c 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7624,10 +7624,28 @@ async def model_metrics_exceptions( WHERE "startTime" >= $1::timestamp AND "endTime" <= $2::timestamp GROUP BY model_group, api_base, exception_type ORDER BY num_exceptions DESC - LIMIT 50; + LIMIT 200; """ db_response = await prisma_client.db.query_raw(sql_query, startTime, endTime) response: List[dict] = [] + for model_data in db_response: + model = model_data.get("model_group", "") + api_base = model_data.get("api_base", "") + exception_type = model_data.get("exception_type", "") + num_exceptions = model_data.get("num_exceptions", 0) + + response.append( + { + "model_group": model + "-" + api_base, + "exception_type": exception_type, + "num_exceptions": num_exceptions, + } + ) + + # sort all entries in descending order based on num_exceptions + + response.sort(key=lambda x: x["num_exceptions"], reverse=True) + return response