mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
fix create view - MonthlyGlobalSpendPerUserPerKey
This commit is contained in:
parent
06d538de10
commit
38890a731d
1 changed files with 27 additions and 1 deletions
|
@ -969,11 +969,12 @@ class PrismaClient:
|
||||||
'Last30dKeysBySpend',
|
'Last30dKeysBySpend',
|
||||||
'Last30dModelsBySpend',
|
'Last30dModelsBySpend',
|
||||||
'MonthlyGlobalSpendPerKey',
|
'MonthlyGlobalSpendPerKey',
|
||||||
|
'MonthlyGlobalSpendPerUserPerKey',
|
||||||
'Last30dTopEndUsersSpend'
|
'Last30dTopEndUsersSpend'
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
if ret[0]["sum"] == 6:
|
if ret[0]["sum"] == 7:
|
||||||
print("All necessary views exist!") # noqa
|
print("All necessary views exist!") # noqa
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -1097,6 +1098,31 @@ class PrismaClient:
|
||||||
await self.db.execute_raw(query=sql_query)
|
await self.db.execute_raw(query=sql_query)
|
||||||
|
|
||||||
print("MonthlyGlobalSpendPerKey Created!") # noqa
|
print("MonthlyGlobalSpendPerKey Created!") # noqa
|
||||||
|
try:
|
||||||
|
await self.db.query_raw(
|
||||||
|
"""SELECT 1 FROM "MonthlyGlobalSpendPerUserPerKey" LIMIT 1"""
|
||||||
|
)
|
||||||
|
print("MonthlyGlobalSpendPerUserPerKey Exists!") # noqa
|
||||||
|
except Exception as e:
|
||||||
|
sql_query = """
|
||||||
|
CREATE OR REPLACE VIEW "MonthlyGlobalSpendPerUserPerKey" AS
|
||||||
|
SELECT
|
||||||
|
DATE("startTime") AS date,
|
||||||
|
SUM("spend") AS spend,
|
||||||
|
api_key as api_key,
|
||||||
|
"user" as "user"
|
||||||
|
FROM
|
||||||
|
"LiteLLM_SpendLogs"
|
||||||
|
WHERE
|
||||||
|
"startTime" >= (CURRENT_DATE - INTERVAL '20 days')
|
||||||
|
GROUP BY
|
||||||
|
DATE("startTime"),
|
||||||
|
"user",
|
||||||
|
api_key;
|
||||||
|
"""
|
||||||
|
await self.db.execute_raw(query=sql_query)
|
||||||
|
|
||||||
|
print("MonthlyGlobalSpendPerUserPerKey Created!") # noqa
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.db.query_raw(
|
await self.db.query_raw(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue