File size: 824 Bytes
5669b22 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import threading
class InterruptManager:
def __init__(self, llm):
self.llm = llm
self._continue_exec_flag = threading.Event()
self._continue_exec_flag.set()
EXEC_FLAG_CHECK_TIMEOUT = 5
def interrupt(self, heard_sentence: str = "") -> None:
self._continue_exec_flag.clear()
self.llm.handle_interrupt(heard_sentence)
def interrupt_post_processing(self) -> None:
self._continue_exec_flag.set()
def wait_continue_flag(self):
return self._continue_exec_flag.wait(self.EXEC_FLAG_CHECK_TIMEOUT)
def in_interrupt(self):
# if not self._continue_exec_flag.is_set():
# raise InterruptedError("Conversation chain interrupted: checked")
return not self._continue_exec_flag.is_set()
|