mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
feat - show monthly spend reports
This commit is contained in:
parent
63e4176502
commit
09c064c94c
1 changed files with 17 additions and 19 deletions
|
@ -5415,50 +5415,48 @@ async def global_view_spend_tags(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _get_weekly_spend_reports():
|
async def _get_spend_report_for_time_range(
|
||||||
|
start_date: str,
|
||||||
|
end_date: str,
|
||||||
|
):
|
||||||
global prisma_client
|
global prisma_client
|
||||||
todays_date = datetime.now().date()
|
if prisma_client is None:
|
||||||
_week_before = todays_date - timedelta(days=7)
|
verbose_proxy_logger.error(
|
||||||
|
f"Database not connected. Connect a database to your proxy for weekly, monthly spend reports"
|
||||||
todays_date = todays_date.strftime("%Y-%m-%d")
|
)
|
||||||
_week_before = _week_before.strftime("%Y-%m-%d")
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
sql_query = """
|
sql_query = """
|
||||||
SELECT
|
SELECT
|
||||||
t.team_alias,
|
t.team_alias,
|
||||||
SUM(s.spend) AS total_spend,
|
SUM(s.spend) AS total_spend
|
||||||
s."startTime"::DATE AS log_date
|
|
||||||
FROM
|
FROM
|
||||||
"LiteLLM_SpendLogs" s
|
"LiteLLM_SpendLogs" s
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
"LiteLLM_TeamTable" t ON s.team_id = t.team_id
|
"LiteLLM_TeamTable" t ON s.team_id = t.team_id
|
||||||
WHERE
|
WHERE
|
||||||
s."startTime"::DATE BETWEEN $1::date AND $1::date
|
s."startTime"::DATE >= $1::date AND s."startTime"::DATE <= $2::date
|
||||||
GROUP BY
|
GROUP BY
|
||||||
t.team_alias,
|
t.team_alias
|
||||||
log_date
|
|
||||||
ORDER BY
|
ORDER BY
|
||||||
total_spend DESC;
|
total_spend DESC;
|
||||||
"""
|
"""
|
||||||
response = await prisma_client.db.query_raw(
|
response = await prisma_client.db.query_raw(sql_query, start_date, end_date)
|
||||||
sql_query, todays_date, _week_before
|
|
||||||
)
|
|
||||||
|
|
||||||
# get spend per tag for today
|
# get spend per tag for today
|
||||||
sql_query = """
|
sql_query = """
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_array_elements_text(request_tags) AS individual_request_tag,
|
jsonb_array_elements_text(request_tags) AS individual_request_tag,
|
||||||
"startTime"::DATE AS log_date,
|
|
||||||
SUM(spend) AS total_spend
|
SUM(spend) AS total_spend
|
||||||
FROM "LiteLLM_SpendLogs"
|
FROM "LiteLLM_SpendLogs"
|
||||||
WHERE "startTime"::DATE BETWEEN $1::date AND $1::date
|
WHERE "startTime"::DATE >= $1::date AND "startTime"::DATE <= $2::date
|
||||||
GROUP BY individual_request_tag, log_date;
|
GROUP BY individual_request_tag
|
||||||
|
ORDER BY total_spend DESC;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
spend_per_tag = await prisma_client.db.query_raw(
|
spend_per_tag = await prisma_client.db.query_raw(
|
||||||
sql_query, todays_date, _week_before
|
sql_query, start_date, end_date
|
||||||
)
|
)
|
||||||
|
|
||||||
return response, spend_per_tag
|
return response, spend_per_tag
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue