diff --git a/google/generativeai/files.py b/google/generativeai/files.py index 4028d37f7..0e8a8ed27 100644 --- a/google/generativeai/files.py +++ b/google/generativeai/files.py @@ -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)