(feat) proxy - save model access requests

This commit is contained in:
ishaan-jaff 2024-02-19 16:35:20 -08:00
parent 54e9b5b99a
commit a13565dd95
4 changed files with 82 additions and 1 deletions

View file

@ -696,7 +696,9 @@ class PrismaClient:
on_backoff=on_backoff, # specifying the function to call on backoff
)
async def insert_data(
self, data: dict, table_name: Literal["user", "key", "config", "spend", "team"]
self,
data: dict,
table_name: Literal["user", "key", "config", "spend", "team", "model_request"],
):
"""
Add a key to the database. If it already exists, do nothing.
@ -778,6 +780,17 @@ class PrismaClient:
)
verbose_proxy_logger.info(f"Data Inserted into Spend Table")
return new_spend_row
elif table_name == "model_request":
db_data = self.jsonify_object(data=data)
new_model_request_row = await self.db.litellm_modelrequests.upsert(
where={"request_id": data["request_id"]},
data={
"create": {**db_data}, # type: ignore
"update": {}, # don't do anything if it already exists
},
)
verbose_proxy_logger.info(f"Data Inserted into Model Request Table")
return new_model_request_row
except Exception as e:
print_verbose(f"LiteLLM Prisma Client Exception: {e}")