mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
use view for getting tag usage on ui
This commit is contained in:
parent
4626c5a365
commit
43acf6d08f
1 changed files with 17 additions and 28 deletions
|
@ -47,17 +47,14 @@ async def ui_get_spend_by_tags(
|
||||||
if tags_list is None or (isinstance(tags_list, list) and "all-tags" in tags_list):
|
if tags_list is None or (isinstance(tags_list, list) and "all-tags" in tags_list):
|
||||||
# Get spend for all tags
|
# Get spend for all tags
|
||||||
sql_query = """
|
sql_query = """
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_array_elements_text(request_tags) AS individual_request_tag,
|
individual_request_tag,
|
||||||
DATE(s."startTime") AS spend_date,
|
spend_date,
|
||||||
COUNT(*) AS log_count,
|
log_count,
|
||||||
SUM(spend) AS total_spend
|
total_spend
|
||||||
FROM "LiteLLM_SpendLogs" s
|
FROM DailyTagSpend
|
||||||
WHERE
|
WHERE spend_date >= $1::date AND spend_date <= $2::date
|
||||||
DATE(s."startTime") >= $1::date
|
ORDER BY total_spend DESC;
|
||||||
AND DATE(s."startTime") <= $2::date
|
|
||||||
GROUP BY individual_request_tag, spend_date
|
|
||||||
ORDER BY total_spend DESC;
|
|
||||||
"""
|
"""
|
||||||
response = await prisma_client.db.query_raw(
|
response = await prisma_client.db.query_raw(
|
||||||
sql_query,
|
sql_query,
|
||||||
|
@ -67,23 +64,15 @@ async def ui_get_spend_by_tags(
|
||||||
else:
|
else:
|
||||||
# filter by tags list
|
# filter by tags list
|
||||||
sql_query = """
|
sql_query = """
|
||||||
SELECT
|
SELECT
|
||||||
individual_request_tag,
|
individual_request_tag,
|
||||||
COUNT(*) AS log_count,
|
SUM(log_count) AS log_count,
|
||||||
SUM(spend) AS total_spend
|
SUM(total_spend) AS total_spend
|
||||||
FROM (
|
FROM DailyTagSpend
|
||||||
SELECT
|
WHERE spend_date >= $1::date AND spend_date <= $2::date
|
||||||
jsonb_array_elements_text(request_tags) AS individual_request_tag,
|
AND individual_request_tag = ANY($3::text[])
|
||||||
DATE(s."startTime") AS spend_date,
|
GROUP BY individual_request_tag
|
||||||
spend
|
ORDER BY total_spend DESC;
|
||||||
FROM "LiteLLM_SpendLogs" s
|
|
||||||
WHERE
|
|
||||||
DATE(s."startTime") >= $1::date
|
|
||||||
AND DATE(s."startTime") <= $2::date
|
|
||||||
) AS subquery
|
|
||||||
WHERE individual_request_tag = ANY($3::text[])
|
|
||||||
GROUP BY individual_request_tag
|
|
||||||
ORDER BY total_spend DESC;
|
|
||||||
"""
|
"""
|
||||||
response = await prisma_client.db.query_raw(
|
response = await prisma_client.db.query_raw(
|
||||||
sql_query,
|
sql_query,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue