Skip to content

While using the "ChatGoogleGenerativeAI" class getting error object GenerateContentResponse can't be used in 'await' expression #791

Open
@chetanrudrakar

Description

@chetanrudrakar

While using the "ChatGoogleGenerativeAI" class getting error object GenerateContentResponse can't be used in 'await' expression
Issue Description :
While utilizing the ChatGoogleGenerativeAI class, I encountered a TypeError indicating that the object GenerateContentResponse cannot be used within an await expression. This error arises when attempting to invoke asynchronous methods such as ainvoke or astream on the ChatGoogleGenerativeAI instance.

Steps to Reproduce:

Initialize the ChatGoogleGenerativeAI class with the appropriate parameters, including the model and API key and transport set to rest.
Observe the TypeError indicating that GenerateContentResponse cannot be used in an await expression.
ERROR [agent] ❌ Result failed 1/3 times:
object GenerateContentResponse can't be used in 'await' expression
Note : I am using this class with the browser-use Agent class to perform a task. Can anyone help me with this, Please refer the below code for reference.

async def script_validation():
task = (
‘Important : I am UI Automation tester validating the tasks’
‘Open website https://www.google.co.in/’
)
gemini_api_key = os.environ[“GEMINI_API_KEY”]
llm = ChatGoogleGenerativeAI(model=‘gemini-2.0-flash’, api_key=SecretStr(gemini_api_key), transport=“rest”)
agent = Agent(task=task, llm=llm, use_vision=True)
result = await agent.run()

asyncio.run(script_validation())

Can anyone please help ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions