22
22
from google .generativeai import protos
23
23
from itertools import islice
24
24
from io import IOBase
25
+ import asyncio
25
26
26
27
from google .generativeai .types import file_types
27
28
@@ -87,6 +88,8 @@ def upload_file(
87
88
)
88
89
return file_types .File (response )
89
90
91
+ async def upload_file_async (* args , ** kwargs ):
92
+ return await asyncio .to_thread (upload_file , * args , ** kwargs )
90
93
91
94
def list_files (page_size = 100 ) -> Iterable [file_types .File ]:
92
95
"""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]:
96
99
for proto in response :
97
100
yield file_types .File (proto )
98
101
102
+ async def list_files_async (* args , ** kwargs ):
103
+ return await asyncio .to_thread (list_files , * args , ** kwargs )
99
104
100
105
def get_file (name : str ) -> file_types .File :
101
106
"""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:
104
109
client = get_default_file_client ()
105
110
return file_types .File (client .get_file (name = name ))
106
111
112
+ async def get_file_async (* args , ** kwargs ):
113
+ return await asyncio .to_thread (get_file , * args , ** kwargs )
107
114
108
115
def delete_file (name : str | file_types .File | protos .File ):
109
116
"""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):
114
121
request = protos .DeleteFileRequest (name = name )
115
122
client = get_default_file_client ()
116
123
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