mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-27 09:46:24 +02:00
replace rag llm factory with llamaindex custom llm
This commit is contained in:
parent
4712b2136b
commit
9fe9a4a2d1
9 changed files with 87 additions and 142 deletions
22
metagpt/utils/async_helper.py
Normal file
22
metagpt/utils/async_helper.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import asyncio
|
||||
import threading
|
||||
from typing import Any
|
||||
|
||||
|
||||
def run_coroutine_in_new_loop(coroutine) -> Any:
|
||||
"""Runs a coroutine in a new, separate event loop on a different thread.
|
||||
|
||||
This function is useful when try to execute an async function within a sync function, but encounter the error `RuntimeError: This event loop is already running`.
|
||||
"""
|
||||
new_loop = asyncio.new_event_loop()
|
||||
t = threading.Thread(target=lambda: new_loop.run_forever())
|
||||
t.start()
|
||||
|
||||
future = asyncio.run_coroutine_threadsafe(coroutine, new_loop)
|
||||
|
||||
try:
|
||||
return future.result()
|
||||
finally:
|
||||
new_loop.call_soon_threadsafe(new_loop.stop)
|
||||
t.join()
|
||||
new_loop.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue