Skip to content
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

Open
zavocc opened this issue Sep 21, 2024 · 4 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:feature request New feature request/enhancement

Comments

@zavocc
Copy link

zavocc commented Sep 21, 2024

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 like get_file and delete_file though upload_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 nice

Right now there are only two async methods with this SDK are generate_content and send_message
Although it would also be a good idea if adding async variant to SDK as well

@manojssmk manojssmk added type:feature request New feature request/enhancement status:triaged Issue/PR triaged to the corresponding sub-team component:python sdk Issue/PR related to Python SDK labels Sep 23, 2024
@MarkDaoust
Copy link
Collaborator

asyncio.to_thread, interesting. That's new to me.

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 upload_file_async just:

async def upload_file_async(*args, **kwargs)
  return await asyncio.to_thread(blocking_function, *args, **kwargs)

@zavocc
Copy link
Author

zavocc commented Oct 3, 2024 via email

@MarkDaoust
Copy link
Collaborator

MarkDaoust commented Oct 29, 2024

#586

@gokturkDev
Copy link

I occasionally get the following error when using asyncio.to_thread
I tried hard to diagnose what exactly is triggering this but in vain, it sometimes works and sometimes breaks for the same image.
Eventually mitigated it with a retry mechanism.
Posting this because it might be related @MarkDaoust

 Encountered error: 503 IOCP/Socket: Connection reset (An existing connection was forcibly closed by the remote host.

 -- 10054

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:triaged Issue/PR triaged to the corresponding sub-team type:feature request New feature request/enhancement
Projects
None yet
Development

No branches or pull requests

4 participants