-
Notifications
You must be signed in to change notification settings - Fork 464
Async Function Support for Tools Parameter in GenerativeModel #632
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Thanks! Note we do need you to sign the CLA before we can move the PR farther along. |
appreciate it! yeah i saw the notification, signed it rightaway🫡 |
Hi! This is to remind that i have signed The CLA Form |
Thanks for the reminder! I'll review today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I don't think this works yet.
I think there are two ways to fix this:
.1
I think we need to have the two types, sync and async, and then here (in the async function handler) we need to check the type of the callable and await
it, or not:
Or .2
await
it or not... the other option is use asyncio.to_thread
to make all functions awaitable in the async
function handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is probably insufficiently tested (to begin with, my fault, not yours), can you add a test, or try this out in a colab notebook and share that?
You should be able to install from your branch using pip install git+https://github.com/somwrks/generative-ai-python/tree/main
yes i agree with the first approach, i was essentially working with my project which is basically a discord bot working with different agents to automate actions. That is where i found this bug or thing that it won't allow async functions to work well. I'll update the changes and create another request from google collab with demo example aswellas my main project which is significantly larger. Does that sound good? |
approached this with different approach of handling async and sync functions in the beginning by checking the type and then running a separate nesting async loop function for each tool
Added 6 test cases for each connected async and sync functions simultaneously
Result-
|
Hey! i was wondering, what do you think of this? |
When will this asynchronous update pull request be included in the release? |
Mark, Can you review the changes and confirm too? |
Thanks for the ping. I'll try and merge it this week. |
Hi Mark! Any Updates? |
Description of the change
This change implements proper async function handling in the
GenerativeModel
class by modifying theCallableFunctionDeclaration
andFunctionLibrary
classes. The implementation adds support for detecting and properly awaiting async functions when they are passed as tools, resolving runtime errors related to unhandled coroutines.Key modifications include:
inspect.iscoroutinefunction()
CallableFunctionDeclaration.__call__
FunctionLibrary
Motivation
The current implementation fails to properly handle async functions when passed as tools to the GenerativeModel, resulting in runtime errors such as "coroutine was never awaited" and incorrect protobuf message conversion. This change is required to enable developers to use async functions with the GenerativeModel's tools parameter, allowing integration with asynchronous APIs and services.
Type of change
Bug fix, Feature Request
Checklist
git pull --rebase upstream main
).