feat(managed_files.py): support deleting file from DB on delete

This commit is contained in:
Krrish Dholakia 2025-04-11 18:25:15 -07:00
parent 49fbe6d3d2
commit c2fbf74fb6

View file

@ -113,21 +113,22 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger):
async def delete_unified_file_id( async def delete_unified_file_id(
self, file_id: str, litellm_parent_otel_span: Optional[Span] = None self, file_id: str, litellm_parent_otel_span: Optional[Span] = None
) -> OpenAIFileObject: ) -> OpenAIFileObject:
key = f"litellm_proxy/{file_id}"
## get old value ## get old value
old_value = await self.internal_usage_cache.async_get_cache( initial_value = await self.prisma_client.db.litellm_managedfiletable.find_first(
key=key, where={"unified_file_id": file_id}
litellm_parent_otel_span=litellm_parent_otel_span,
) )
if old_value is None or not isinstance(old_value, OpenAIFileObject): if initial_value is None:
raise Exception(f"LiteLLM Managed File object with id={file_id} not found") raise Exception(f"LiteLLM Managed File object with id={file_id} not found")
## delete old value ## delete old value
await self.internal_usage_cache.async_set_cache( await self.internal_usage_cache.async_set_cache(
key=key, key=file_id,
value=None, value=None,
litellm_parent_otel_span=litellm_parent_otel_span, litellm_parent_otel_span=litellm_parent_otel_span,
) )
return old_value await self.prisma_client.db.litellm_managedfiletable.delete(
where={"unified_file_id": file_id}
)
return initial_value.file_object
async def async_pre_call_hook( async def async_pre_call_hook(
self, self,