Skip to content

Commit

Permalink
Fix unclosed event loop (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiangning30 committed Aug 16, 2024
1 parent a8ae387 commit 17197d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lagent/actions/bing_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ def search(self, query: str, max_retry: int = 3) -> dict:

def _call_ddgs(self, query: str, **kwargs) -> dict:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
ddgs = DDGS(**kwargs)
response = ddgs.text(query.strip("'"), max_results=10)
return response
try:
asyncio.set_event_loop(loop)
ddgs = DDGS(**kwargs)
response = ddgs.text(query.strip("'"), max_results=10)
return response
finally:
loop.close()

def _parse_response(self, response: dict) -> dict:
raw_results = []
Expand Down

0 comments on commit 17197d0

Please sign in to comment.