From 01fceb29f558d591d957997c893d78dd3c5b4b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Sch=C3=BCller?= Date: Tue, 19 Nov 2024 10:36:21 +0100 Subject: [PATCH] Fix asyncio loop issue in combination with enable_input event --- nemoguardrails/cli/chat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nemoguardrails/cli/chat.py b/nemoguardrails/cli/chat.py index 3485dfd09..c48997319 100644 --- a/nemoguardrails/cli/chat.py +++ b/nemoguardrails/cli/chat.py @@ -30,7 +30,7 @@ from nemoguardrails.logging import verbose from nemoguardrails.logging.verbose import console from nemoguardrails.streaming import StreamingHandler -from nemoguardrails.utils import new_event_dict, new_uuid +from nemoguardrails.utils import get_or_create_event_loop, new_event_dict, new_uuid os.environ["TOKENIZERS_PARALLELISM"] = "false" @@ -662,6 +662,7 @@ def run_chat( ) elif rails_config.colang_version == "2.x": rails_app = LLMRails(rails_config, verbose=verbose) - asyncio.run(_run_chat_v2_x(rails_app)) + loop = get_or_create_event_loop() + loop.run_until_complete(_run_chat_v2_x(rails_app)) else: raise Exception(f"Invalid colang version: {rails_config.colang_version}")