Skip to content

Commit f0a4ef9

Browse files
Updated files.py to include asyncio
1 parent 8f77cc6 commit f0a4ef9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

google/generativeai/files.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from google.generativeai import protos
2323
from itertools import islice
2424
from io import IOBase
25+
import asyncio
2526

2627
from google.generativeai.types import file_types
2728

@@ -87,6 +88,8 @@ def upload_file(
8788
)
8889
return file_types.File(response)
8990

91+
async def upload_file_async(*args, **kwargs):
92+
return await asyncio.to_thread(upload_file, *args, **kwargs)
9093

9194
def list_files(page_size=100) -> Iterable[file_types.File]:
9295
"""Calls the API to list files using a supported file service."""
@@ -96,6 +99,8 @@ def list_files(page_size=100) -> Iterable[file_types.File]:
9699
for proto in response:
97100
yield file_types.File(proto)
98101

102+
async def list_files_async(*args, **kwargs):
103+
return await asyncio.to_thread(list_files, *args, **kwargs)
99104

100105
def get_file(name: str) -> file_types.File:
101106
"""Calls the API to retrieve a specified file using a supported file service."""
@@ -104,6 +109,8 @@ def get_file(name: str) -> file_types.File:
104109
client = get_default_file_client()
105110
return file_types.File(client.get_file(name=name))
106111

112+
async def get_file_async(*args, **kwargs):
113+
return await asyncio.to_thread(get_file, *args, **kwargs)
107114

108115
def delete_file(name: str | file_types.File | protos.File):
109116
"""Calls the API to permanently delete a specified file using a supported file service."""
@@ -114,3 +121,6 @@ def delete_file(name: str | file_types.File | protos.File):
114121
request = protos.DeleteFileRequest(name=name)
115122
client = get_default_file_client()
116123
client.delete_file(request=request)
124+
125+
async def delete_file_async(*args, **kwargs):
126+
return await asyncio.to_thread(get_file, *args, **kwargs)

0 commit comments

Comments
 (0)