Skip to content

Commit 74eb894

Browse files
N0bodycanKevinHuSh
andauthored
Fix RuntimeError: asyncio.run() cannot be called from a running event loop when calling mindmap endpoint. (#11880)
### What problem does this PR solve? Fix RuntimeError when calling mindmap endpoint by converting `gen_mindmap()` to async function and using `await` instead of `asyncio.run()`. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
1 parent 34d29d7 commit 74eb894

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

api/apps/conversation_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ async def mindmap():
435435
kb_ids.extend(req["kb_ids"])
436436
kb_ids = list(set(kb_ids))
437437

438-
mind_map = gen_mindmap(req["question"], kb_ids, search_app.get("tenant_id", current_user.id), search_config)
438+
mind_map = await gen_mindmap(req["question"], kb_ids, search_app.get("tenant_id", current_user.id), search_config)
439439
if "error" in mind_map:
440440
return server_error_response(Exception(mind_map["error"]))
441441
return get_json_result(data=mind_map)

api/db/services/dialog_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
import asyncio
1716
import binascii
1817
import logging
1918
import re
@@ -887,7 +886,7 @@ def decorate_answer(answer):
887886
yield decorate_answer(answer)
888887

889888

890-
def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
889+
async def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
891890
meta_data_filter = search_config.get("meta_data_filter", {})
892891
doc_ids = search_config.get("doc_ids", [])
893892
rerank_id = search_config.get("rerank_id", "")
@@ -931,5 +930,5 @@ def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
931930
rank_feature=label_question(question, kbs),
932931
)
933932
mindmap = MindMapExtractor(chat_mdl)
934-
mind_map = asyncio.run(mindmap([c["content_with_weight"] for c in ranks["chunks"]]))
933+
mind_map = await mindmap([c["content_with_weight"] for c in ranks["chunks"]])
935934
return mind_map.output

0 commit comments

Comments
 (0)