mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
(feat) proxy - track cost for user_ids that do not exist
This commit is contained in:
parent
6c6c2facad
commit
f4aef679c9
1 changed files with 22 additions and 1 deletions
|
@ -530,7 +530,11 @@ class PrismaClient:
|
||||||
where={"token": token}, # type: ignore
|
where={"token": token}, # type: ignore
|
||||||
data={**db_data}, # type: ignore
|
data={**db_data}, # type: ignore
|
||||||
)
|
)
|
||||||
print_verbose("\033[91m" + f"DB write succeeded {response}" + "\033[0m")
|
print_verbose(
|
||||||
|
"\033[91m"
|
||||||
|
+ f"DB Token Table update succeeded {response}"
|
||||||
|
+ "\033[0m"
|
||||||
|
)
|
||||||
return {"token": token, "data": db_data}
|
return {"token": token, "data": db_data}
|
||||||
elif user_id is not None:
|
elif user_id is not None:
|
||||||
"""
|
"""
|
||||||
|
@ -540,6 +544,23 @@ class PrismaClient:
|
||||||
where={"user_id": user_id}, # type: ignore
|
where={"user_id": user_id}, # type: ignore
|
||||||
data={**db_data}, # type: ignore
|
data={**db_data}, # type: ignore
|
||||||
)
|
)
|
||||||
|
if update_user_row is None:
|
||||||
|
# if the provided user does not exist, STILL Track this!
|
||||||
|
# make a new user with {"user_id": user_id, "spend": data['spend']}
|
||||||
|
|
||||||
|
db_data["user_id"] = user_id
|
||||||
|
update_user_row = await self.db.litellm_usertable.upsert(
|
||||||
|
where={"user_id": user_id}, # type: ignore
|
||||||
|
data={
|
||||||
|
"create": {**db_data}, # type: ignore
|
||||||
|
"update": {}, # don't do anything if it already exists
|
||||||
|
},
|
||||||
|
)
|
||||||
|
print_verbose(
|
||||||
|
"\033[91m"
|
||||||
|
+ f"DB User Table - update succeeded {update_user_row}"
|
||||||
|
+ "\033[0m"
|
||||||
|
)
|
||||||
return {"user_id": user_id, "data": db_data}
|
return {"user_id": user_id, "data": db_data}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue