-
Notifications
You must be signed in to change notification settings - Fork 324
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
Async chat using rest transport results in Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'> #203
Comments
+1 |
@holymode @LukeSamkharadze this should be fixed by #229, try to updated to version 0.4.1 |
Still getting same error if using transport="rest" and generate_content_async google-generativeai==0.4.1 |
|
Code: import asyncio
import google.generativeai as genai
async def ask_gemini(question: str):
genai.configure(api_key=api_key, transport="rest")
model = genai.GenerativeModel('gemini-pro')
response = await model.generate_content_async(question)
return response.text
print(asyncio.run(ask_gemini("What is your name?"))) Exception: Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\Gemini_bot\check_gemini.py", line 14, in <module>
print(asyncio.run(ask_gemini("What is your name?")))
File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Users\user\PycharmProjects\Gemini_bot\check_gemini.py", line 10, in ask_gemini
response = await model.generate_content_async(question)
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\generativeai\generative_models.py", line 269, in generate_content_async
response = await self._async_client.generate_content(
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\async_client.py", line 354, in generate_content
response = await rpc(
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\api_core\retry\retry_unary_async.py", line 230, in retry_wrapped_func
return await retry_target(
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\api_core\retry\retry_unary_async.py", line 160, in retry_target
_retry_error_helper(
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\api_core\retry\retry_unary_async.py", line 155, in retry_target
return await target()
File "C:\Users\user\PycharmProjects\Gemini_bot\venv\lib\site-packages\google\api_core\grpc_helpers_async.py", line 187, in error_remapped_callable
raise TypeError("Unexpected type of call %s" % type(call))
TypeError: Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'> |
@P1nk-L0rD yes,there are some problem with the rest transport, you can try "grpc_asyncio" in this condition |
Any updates on this? |
This error is still unsolved for generativeai == 0.7.0 (latest to this date), which prevents for recording cassettes for async test, any update or workaround? |
We'll track this in #499 |
Description of the bug:
When using the rest transport with async chat method it will result in
Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'>
.Using sync function however works fine.
Changing to default transport also works fine with async method.
Traceback:
Actual vs expected behavior:
No response
Any other information you'd like to share?
Using the latest version of the lib.
The text was updated successfully, but these errors were encountered: