-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asynchronous file upload (google.generativeai.upload_file
) and other blocking methods?
#564
Comments
The implementation of that upload function is kind of messy (see #327). When I was writing it there just didn't seem to be a clear way to simply make an async implementation. Am I reading this right? (Once 327 is fixed) we can make the implementation for
|
Either https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor or https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread can be used... Both makes methods blocking, but ngl the python SDK is quite messy to deal with and I'm not entirely sure if this is the correct way/workaround for making it async but it works
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Mark Daoust ***@***.***>
Sent: Thursday, October 3, 2024 8:00:09 AM
To: google-gemini/generative-ai-python ***@***.***>
Cc: WMCB Tech (marcusz) ***@***.***>; Author ***@***.***>
Subject: Re: [google-gemini/generative-ai-python] Asynchronous file upload (`google.generativeai.upload_file`) and other blocking methods? (Issue #564)
asyncio.to_thread, interesting. That's new to me.
The implementation of that upload function is kind of messy (see #327<#327>). When I was writing it there just didn't seem to be a clear way to simply make an async implementation.
Am I reading this right? (Once 327 is fixed) we can make the implementation for upload_file_async just:
async def upload_file_async(*args, **kwargs)
return await asyncio.to_thread(blocking_function, *args, **kwargs)
—
Reply to this email directly, view it on GitHub<#564 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A4QQBQM3OSFCXFIKOZXWRFLZZSCITAVCNFSM6AAAAABOTSP2SKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJQGA2DONJUGM>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I occasionally get the following error when using
|
Description of the feature request:
Currently
google.generativeai.upload_file
is a blocking function, it would be nice if there are async versions of these methods along with other I/O related methods likeget_file
anddelete_file
thoughupload_file
can be made asynchronous if uploading lets say 100mb of file.What problem are you trying to solve with this feature?
Adding asynchronous versions of upload file methods is good in applications where it is async-driven (e.g. Discord bots, web) which currently using this to utilize multimodal features can potentially block the entire script which is not good for such applications
Any other information you'd like to share?
Right now I'm using something like
asyncio.to_thread
to make it asynchronous, but offering a native async methods would be niceRight now there are only two async methods with this SDK are
generate_content
andsend_message
Although it would also be a good idea if adding async variant to SDK as well
The text was updated successfully, but these errors were encountered: