Skip to content

Commit

Permalink
Add support for google slides (#2083)
Browse files Browse the repository at this point in the history
* add support for google slides

* remove log + account for dead code

* squash
  • Loading branch information
pablonyx authored Aug 9, 2024
1 parent b230082 commit 7bfa997
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions backend/danswer/connectors/google_drive/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,24 +306,29 @@ def get_all_files_batched(

def extract_text(file: dict[str, str], service: discovery.Resource) -> str:
mime_type = file["mimeType"]

if mime_type not in set(item.value for item in GDriveMimeType):
# Unsupported file types can still have a title, finding this way is still useful
return UNSUPPORTED_FILE_TYPE_CONTENT

if mime_type == GDriveMimeType.DOC.value:
return (
service.files()
.export(fileId=file["id"], mimeType="text/plain")
.execute()
.decode("utf-8")
)
elif mime_type == GDriveMimeType.SPREADSHEET.value:
return (
if mime_type in [
GDriveMimeType.DOC.value,
GDriveMimeType.PPT.value,
GDriveMimeType.SPREADSHEET.value,
]:
export_mime_type = "text/plain"
if mime_type == GDriveMimeType.SPREADSHEET.value:
export_mime_type = "text/csv"
elif mime_type == GDriveMimeType.PPT.value:
export_mime_type = "text/plain"

response = (
service.files()
.export(fileId=file["id"], mimeType="text/csv")
.export(fileId=file["id"], mimeType=export_mime_type)
.execute()
.decode("utf-8")
)
return response.decode("utf-8")

elif mime_type == GDriveMimeType.WORD_DOC.value:
response = service.files().get_media(fileId=file["id"]).execute()
return docx_to_text(file=io.BytesIO(response))
Expand All @@ -333,9 +338,6 @@ def extract_text(file: dict[str, str], service: discovery.Resource) -> str:
elif mime_type == GDriveMimeType.POWERPOINT.value:
response = service.files().get_media(fileId=file["id"]).execute()
return pptx_to_text(file=io.BytesIO(response))
elif mime_type == GDriveMimeType.PPT.value:
response = service.files().get_media(fileId=file["id"]).execute()
return pptx_to_text(file=io.BytesIO(response))

return UNSUPPORTED_FILE_TYPE_CONTENT

Expand Down

0 comments on commit 7bfa997

Please sign in to comment.