mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-20 04:39:00 +08:00
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>
This commit is contained in:
@ -435,7 +435,7 @@ async def mindmap():
|
|||||||
kb_ids.extend(req["kb_ids"])
|
kb_ids.extend(req["kb_ids"])
|
||||||
kb_ids = list(set(kb_ids))
|
kb_ids = list(set(kb_ids))
|
||||||
|
|
||||||
mind_map = gen_mindmap(req["question"], kb_ids, search_app.get("tenant_id", current_user.id), search_config)
|
mind_map = await gen_mindmap(req["question"], kb_ids, search_app.get("tenant_id", current_user.id), search_config)
|
||||||
if "error" in mind_map:
|
if "error" in mind_map:
|
||||||
return server_error_response(Exception(mind_map["error"]))
|
return server_error_response(Exception(mind_map["error"]))
|
||||||
return get_json_result(data=mind_map)
|
return get_json_result(data=mind_map)
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
import asyncio
|
|
||||||
import binascii
|
import binascii
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@ -887,7 +886,7 @@ async def async_ask(question, kb_ids, tenant_id, chat_llm_name=None, search_conf
|
|||||||
yield decorate_answer(answer)
|
yield decorate_answer(answer)
|
||||||
|
|
||||||
|
|
||||||
def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
|
async def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
|
||||||
meta_data_filter = search_config.get("meta_data_filter", {})
|
meta_data_filter = search_config.get("meta_data_filter", {})
|
||||||
doc_ids = search_config.get("doc_ids", [])
|
doc_ids = search_config.get("doc_ids", [])
|
||||||
rerank_id = search_config.get("rerank_id", "")
|
rerank_id = search_config.get("rerank_id", "")
|
||||||
@ -931,5 +930,5 @@ def gen_mindmap(question, kb_ids, tenant_id, search_config={}):
|
|||||||
rank_feature=label_question(question, kbs),
|
rank_feature=label_question(question, kbs),
|
||||||
)
|
)
|
||||||
mindmap = MindMapExtractor(chat_mdl)
|
mindmap = MindMapExtractor(chat_mdl)
|
||||||
mind_map = asyncio.run(mindmap([c["content_with_weight"] for c in ranks["chunks"]]))
|
mind_map = await mindmap([c["content_with_weight"] for c in ranks["chunks"]])
|
||||||
return mind_map.output
|
return mind_map.output
|
||||||
|
|||||||
Reference in New Issue
Block a user