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

Async chat using rest transport results in Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'> #203

Closed
holymode opened this issue Feb 9, 2024 · 11 comments
Labels
component:python sdk Issue/PR related to Python SDK type:bug Something isn't working

Comments

@holymode
Copy link

holymode commented Feb 9, 2024

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:

Traceback (most recent call last):
  File "C:\Users\tobia\Desktop\py\g3rb-bot\test.py", line 258, in <module>
    test = asyncio.run(generate_response_with_text("Hello"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-bot\test.py", line 256, in generate_response_with_text
    return await chat.send_message_async(message_text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-bot\venv\Lib\site-packages\google\generativeai\generative_models.py", line 410, in send_message_async
    response = await self.model.generate_content_async(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-bot\venv\Lib\site-packages\google\generativeai\generative_models.py", line 275, in generate_content_async
    response = await self._async_client.generate_content(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-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\tobia\Desktop\py\g3rb-bot\venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 231, in retry_wrapped_func
    return await retry_target(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-bot\venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 161, in retry_target
    _retry_error_helper(
  File "C:\Users\tobia\Desktop\py\g3rb-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\tobia\Desktop\py\g3rb-bot\venv\Lib\site-packages\google\api_core\retry\retry_unary_async.py", line 155, in retry_target
    return await target()
           ^^^^^^^^^^^^^^
  File "C:\Users\tobia\Desktop\py\g3rb-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'>

Actual vs expected behavior:

No response

Any other information you'd like to share?

Using the latest version of the lib.

@holymode holymode added component:python sdk Issue/PR related to Python SDK type:bug Something isn't working labels Feb 9, 2024
@LukeSamkharadze
Copy link

+1

@LukeSamkharadze
Copy link

@MarkDaoust

@Andy963
Copy link
Contributor

Andy963 commented Mar 14, 2024

@holymode @LukeSamkharadze this should be fixed by #229, try to updated to version 0.4.1

@P1nk-L0rD
Copy link

Still getting same error if using transport="rest" and generate_content_async
TypeError: Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'>

google-generativeai==0.4.1

@Andy963
Copy link
Contributor

Andy963 commented Apr 1, 2024

Still getting same error if using transport="rest" and generate_content_async TypeError: Unexpected type of call <class 'google.ai.generativelanguage_v1beta.types.generative_service.GenerateContentResponse'>

google-generativeai==0.4.1
@P1nk-L0rD
Please provide a minimal reproducible example ,so that we can better understand and address your issue.

@P1nk-L0rD
Copy link

P1nk-L0rD commented Apr 1, 2024

Please provide a minimal reproducible example ,so that we can better understand and address your issue.
@Andy963

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'>

@Andy963
Copy link
Contributor

Andy963 commented Apr 2, 2024

@P1nk-L0rD yes,there are some problem with the rest transport, you can try "grpc_asyncio" in this condition

@LukeSamkharadze
Copy link

Any updates on this?

@adrienbanse
Copy link

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?

@markmcd
Copy link
Member

markmcd commented Sep 11, 2024

@markmcd
Copy link
Member

markmcd commented Sep 11, 2024

We'll track this in #499

@markmcd markmcd closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
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 type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants