generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

Unable to call aivoke with transport="rest".

Open kento996 opened this issue 1 year ago • 1 comments

Description of the bug:

When I set transport="rest" in ChatGoogleGenerativeAI, I can't use chain.ainvoke

def get_gemini_pro() -> BaseChatModel:

    return ChatGoogleGenerativeAI(model="gemini-1.5-pro-latest",
                                  temperature=0,
                                  convert_system_message_to_human=True,
                                  transport="rest")
async def invokeChain(code):
    llm=get_gemini_pro()
    chain=descriptionGenTemplate()|llm|CodeoutputStruction()
    res= await chain.ainvoke({"code":code})
    print(res)
if __name__ == '__main__':

    code="""
xxxxxxxxxxxxxxx
"""
    asyncio.run(invokeChain(code))

Executing the above code displays the following error:

Traceback (most recent call last):
  File "f:\code\pythonProject\Gemini_CWEs\codeExpansion.py", line 93, in <module>
    asyncio.run(invokeChain(code))
  File "E:\anaconda\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^

                               ......

  File "C:\Users\kento\AppData\Local\pypoetry\Cache\virtualenvs\gemini-cwes-rly_BX-h-py3.11\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?

No response

kento996 avatar Apr 02 '24 09:04 kento996

It might be that streaming with transport="rest" is broken.

Edit: No. Rest async streaming is broken.

MarkDaoust avatar Apr 10 '24 21:04 MarkDaoust

https://github.com/search?q=repo%3Agoogle-gemini%2Fgenerative-ai-python+%22Unexpected+type+of+call%22&type=issues

MarkDaoust avatar May 17 '24 23:05 MarkDaoust

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] avatar Jun 01 '24 01:06 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!

github-actions[bot] avatar Jun 16 '24 01:06 github-actions[bot]