Skip to content

Commit

Permalink
Accept partial file names (google-gemini#386)
Browse files Browse the repository at this point in the history
Adds prefix files/ if not present

Change-Id: Iac5c4d0934620f2462cf15ae519474b0ce7908da
  • Loading branch information
mayureshagashe2105 authored Jun 14, 2024
1 parent 23b81d7 commit 419a7ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions google/generativeai/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ def list_files(page_size=100) -> Iterable[file_types.File]:
yield file_types.File(proto)


def get_file(name) -> file_types.File:
def get_file(name: str) -> file_types.File:
"""Calls the API to retrieve a specified file using a supported file service."""
if "/" not in name:
name = f"files/{name}"
client = get_default_file_client()
return file_types.File(client.get_file(name=name))


def delete_file(name):
def delete_file(name: str | file_types.File | protos.File):
"""Calls the API to permanently delete a specified file using a supported file service."""
if isinstance(name, (file_types.File, protos.File)):
name = name.name
elif "/" not in name:
name = f"files/{name}"
request = protos.DeleteFileRequest(name=name)
client = get_default_file_client()
client.delete_file(request=request)

0 comments on commit 419a7ce

Please sign in to comment.