Skip to content

Commit 16cf750

Browse files
Updated files.py to include asyncio
1 parent f0a4ef9 commit 16cf750

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

google/generativeai/files.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def upload_file(
8888
)
8989
return file_types.File(response)
9090

91+
9192
async def upload_file_async(*args, **kwargs):
92-
return await asyncio.to_thread(upload_file, *args, **kwargs)
93+
return await asyncio.to_thread(upload_file, *args, **kwargs)
94+
9395

9496
def list_files(page_size=100) -> Iterable[file_types.File]:
9597
"""Calls the API to list files using a supported file service."""
@@ -99,19 +101,23 @@ def list_files(page_size=100) -> Iterable[file_types.File]:
99101
for proto in response:
100102
yield file_types.File(proto)
101103

104+
102105
async def list_files_async(*args, **kwargs):
103106
return await asyncio.to_thread(list_files, *args, **kwargs)
104107

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

116+
112117
async def get_file_async(*args, **kwargs):
113118
return await asyncio.to_thread(get_file, *args, **kwargs)
114119

120+
115121
def delete_file(name: str | file_types.File | protos.File):
116122
"""Calls the API to permanently delete a specified file using a supported file service."""
117123
if isinstance(name, (file_types.File, protos.File)):
@@ -122,5 +128,6 @@ def delete_file(name: str | file_types.File | protos.File):
122128
client = get_default_file_client()
123129
client.delete_file(request=request)
124130

131+
125132
async def delete_file_async(*args, **kwargs):
126-
return await asyncio.to_thread(get_file, *args, **kwargs)
133+
return await asyncio.to_thread(get_file, *args, **kwargs)

0 commit comments

Comments
 (0)