mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-17 20:29:47 +00:00
delete file if underlying goes missing
This commit is contained in:
parent
ccea70349e
commit
a03c4b5d0a
1 changed files with 8 additions and 3 deletions
|
|
@ -21,12 +21,15 @@ from llama_stack.apis.files import (
|
||||||
OpenAIFilePurpose,
|
OpenAIFilePurpose,
|
||||||
)
|
)
|
||||||
from llama_stack.core.datatypes import AccessRule
|
from llama_stack.core.datatypes import AccessRule
|
||||||
|
from llama_stack.log import get_logger
|
||||||
from llama_stack.providers.utils.sqlstore.api import ColumnDefinition, ColumnType
|
from llama_stack.providers.utils.sqlstore.api import ColumnDefinition, ColumnType
|
||||||
from llama_stack.providers.utils.sqlstore.authorized_sqlstore import AuthorizedSqlStore
|
from llama_stack.providers.utils.sqlstore.authorized_sqlstore import AuthorizedSqlStore
|
||||||
from llama_stack.providers.utils.sqlstore.sqlstore import sqlstore_impl
|
from llama_stack.providers.utils.sqlstore.sqlstore import sqlstore_impl
|
||||||
|
|
||||||
from .config import LocalfsFilesImplConfig
|
from .config import LocalfsFilesImplConfig
|
||||||
|
|
||||||
|
logger = get_logger(name=__name__, category="files")
|
||||||
|
|
||||||
|
|
||||||
class LocalfsFilesImpl(Files):
|
class LocalfsFilesImpl(Files):
|
||||||
def __init__(self, config: LocalfsFilesImplConfig, policy: list[AccessRule]) -> None:
|
def __init__(self, config: LocalfsFilesImplConfig, policy: list[AccessRule]) -> None:
|
||||||
|
|
@ -195,12 +198,14 @@ class LocalfsFilesImpl(Files):
|
||||||
# Read file content
|
# Read file content
|
||||||
file_obj, file_path = await self._lookup_file_id(file_id)
|
file_obj, file_path = await self._lookup_file_id(file_id)
|
||||||
|
|
||||||
with open(file_path, "rb") as f: # this may fail and result in 500 Internal Server Error
|
if not file_path.exists():
|
||||||
content = f.read()
|
logger.warning(f"File '{file_id}'s underlying '{file_path}' is missing, deleting metadata.")
|
||||||
|
await self.openai_delete_file(file_id)
|
||||||
|
raise ResourceNotFoundError(file_id, "File", "client.files.list()")
|
||||||
|
|
||||||
# Return as binary response with appropriate content type
|
# Return as binary response with appropriate content type
|
||||||
return Response(
|
return Response(
|
||||||
content=content,
|
content=file_path.read_bytes(),
|
||||||
media_type="application/octet-stream",
|
media_type="application/octet-stream",
|
||||||
headers={"Content-Disposition": f'attachment; filename="{file_obj.filename}"'},
|
headers={"Content-Disposition": f'attachment; filename="{file_obj.filename}"'},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue