Release 4.3 introduces breaking changes in downstream apps when ran as async
tdj28 opened this issue · comments
Moving from 4.2 to 4.3 results in this error in CrewAI, for example: joaomdmoura/crewAI#193
RuntimeError: Cannot run the event loop while another loop is running
Quick update, it appears to only happen when the search call is being called in an async function, unable to replicate with a normal function.
Error does not occur here:
from langchain_community.tools import DuckDuckGoSearchRun
search = DuckDuckGoSearchRun()
print(search.run("Obama's first name?"))
does occur here:
from langchain_community.tools import DuckDuckGoSearchRun
import asyncio
async def main():
search = DuckDuckGoSearchRun()
print(search.run("Obama's first name?"))
asyncio.run(main())
This is the proper way to call this async:
from langchain_community.tools import DuckDuckGoSearchRun
import asyncio
async def main():
search = DuckDuckGoSearchRun()
result = await asyncio.to_thread(search.run, "Obama's first name?")
print(result)
asyncio.run(main())
Which is partially documented in the README. I'll close this issue as this does not look like a bug in the code, but it will be a breaking change (from 4.2 to 4.3) for users who prior used async without properly awaiting, but the error is theirs. Hopefully this issue will help anyone else experiencing this.
The right way to use AsyncDDGS in asynchronous code.
Fixed in v4.4