mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
fix - viewing model metrics
This commit is contained in:
parent
ace3b02d97
commit
0c464f7f61
1 changed files with 43 additions and 25 deletions
|
@ -7620,39 +7620,57 @@ async def model_metrics_exceptions(
|
||||||
startTime = startTime or datetime.now() - timedelta(days=30)
|
startTime = startTime or datetime.now() - timedelta(days=30)
|
||||||
endTime = endTime or datetime.now()
|
endTime = endTime or datetime.now()
|
||||||
|
|
||||||
|
"""
|
||||||
|
"""
|
||||||
sql_query = """
|
sql_query = """
|
||||||
SELECT model_group, api_base, exception_type, COUNT(*) AS num_exceptions
|
WITH cte AS (
|
||||||
|
SELECT
|
||||||
|
CASE WHEN api_base = '' THEN litellm_model_name ELSE CONCAT(litellm_model_name, '-', api_base) END AS combined_model_api_base,
|
||||||
|
exception_type,
|
||||||
|
COUNT(*) AS num_exceptions
|
||||||
FROM "LiteLLM_ErrorLogs"
|
FROM "LiteLLM_ErrorLogs"
|
||||||
WHERE "startTime" >= $1::timestamp AND "endTime" <= $2::timestamp
|
WHERE "startTime" >= $1::timestamp AND "endTime" <= $2::timestamp
|
||||||
GROUP BY model_group, api_base, exception_type
|
GROUP BY combined_model_api_base, exception_type
|
||||||
ORDER BY num_exceptions DESC
|
)
|
||||||
|
SELECT
|
||||||
|
combined_model_api_base,
|
||||||
|
COUNT(*) AS total_exceptions,
|
||||||
|
json_object_agg(exception_type, num_exceptions) AS exception_counts
|
||||||
|
FROM cte
|
||||||
|
GROUP BY combined_model_api_base
|
||||||
|
ORDER BY total_exceptions DESC
|
||||||
LIMIT 200;
|
LIMIT 200;
|
||||||
"""
|
"""
|
||||||
db_response = await prisma_client.db.query_raw(sql_query, startTime, endTime)
|
db_response = await prisma_client.db.query_raw(sql_query, startTime, endTime)
|
||||||
response: List[dict] = []
|
response: List[dict] = []
|
||||||
exception_types = set()
|
exception_types = set()
|
||||||
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)
|
|
||||||
exception_types.add(exception_type)
|
|
||||||
|
|
||||||
response.append(
|
"""
|
||||||
|
Return Data
|
||||||
{
|
{
|
||||||
"model_group": model + "-" + api_base,
|
"combined_model_api_base": "gpt-3.5-turbo-https://api.openai.com/v1/,
|
||||||
exception_type: num_exceptions,
|
"total_exceptions": 5,
|
||||||
"num_exceptions": num_exceptions,
|
"BadRequestException": 5,
|
||||||
|
"TimeoutException": 2
|
||||||
}
|
}
|
||||||
)
|
"""
|
||||||
|
|
||||||
# sort all entries in descending order based on num_exceptions
|
if db_response is not None:
|
||||||
response = sorted(response, key=lambda x: x["num_exceptions"], reverse=True)
|
# loop through all models
|
||||||
|
for model_data in db_response:
|
||||||
return {
|
model = model_data.get("combined_model_api_base", "")
|
||||||
"data": response,
|
total_exceptions = model_data.get("total_exceptions", 0)
|
||||||
"exception_types": list(exception_types),
|
exception_counts = model_data.get("exception_counts", {})
|
||||||
|
curr_row = {
|
||||||
|
"model": model,
|
||||||
|
"total_exceptions": total_exceptions,
|
||||||
}
|
}
|
||||||
|
curr_row.update(exception_counts)
|
||||||
|
response.append(curr_row)
|
||||||
|
for k, v in exception_counts.items():
|
||||||
|
exception_types.add(k)
|
||||||
|
|
||||||
|
return {"data": response, "exception_types": list(exception_types)}
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue