Skip to content

Commit

Permalink
k
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodanswer committed Nov 12, 2024
1 parent e706891 commit a20206c
Show file tree
Hide file tree
Showing 7 changed files with 1,369 additions and 945 deletions.
36 changes: 36 additions & 0 deletions backend/danswer/server/query_and_chat/chat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fastapi import APIRouter
from fastapi import Depends
from fastapi import HTTPException
from fastapi import Query
from fastapi import Request
from fastapi import Response
from fastapi import UploadFile
Expand Down Expand Up @@ -672,6 +673,41 @@ def upload_files_for_chat(
}


class FileRequest(BaseModel):
file_id: str


@router.get("/chat/file")
def get_other_chat_file(
file_id: str = Query(..., alias="file_id"),
db_session: Session = Depends(get_session),
_: User | None = Depends(current_user),
) -> Response:
file_store = get_default_file_store(db_session)

content = file_store.read_file(file_id, mode="b")

# Determine the media type based on the file extension
file_extension = file_id.split(".")[-1].lower()
if file_extension in ["md", "markdown"]:
media_type = "text/markdown"
elif file_extension in ["pdf"]:
media_type = "application/pdf"
elif file_extension in ["docx"]:
media_type = (
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
else:
# Default to 'application/octet-stream' for unknown types
media_type = "application/octet-stream"
print(file_extension)

# Read the content of the BytesIO object
content_bytes = content.getvalue()

return Response(content=content_bytes, media_type=media_type)


@router.get("/file/{file_id}")
def fetch_chat_file(
file_id: str,
Expand Down
Loading

0 comments on commit a20206c

Please sign in to comment.