diff --git a/src/main/askai/core/askai.py b/src/main/askai/core/askai.py index 53de7fc1..a9cc97d8 100644 --- a/src/main/askai/core/askai.py +++ b/src/main/askai/core/askai.py @@ -41,7 +41,7 @@ from askai.core.processors.ai_processor import AIProcessor from askai.core.support.chat_context import ChatContext from askai.core.support.shared_instances import shared -from askai.core.support.utilities import read_stdin +from askai.core.support.utilities import read_stdin, display_text from askai.exception.exceptions import * from askai.tui.app_icons import AppIcons @@ -131,9 +131,10 @@ def abort(self, signals: Any, frame: Any) -> None: log.warning(f"User interrupted: signals: {signals} frame: {frame}") self._abort_count += 1 if self._abort_count > 1: - log.warning(f"User aborted. Exiting!") - sys.exit(ExitStatus.ABORTED) - events.abort.emit(message="User interrupted") + display_text(f"%RED%\n{msg.terminate_requested('User aborted [ctrl+c]')}%NC%", markdown=False) + log.warning(f"User aborted. Exiting…") + self._abort() + events.abort.emit(message="User interrupted [ctrl+c]") threading.Timer(1, lambda: setattr(self, '_abort_count', 0)).start() terminal.restore() diff --git a/src/main/askai/core/askai_messages.py b/src/main/askai/core/askai_messages.py index 01a6f230..240d54e2 100644 --- a/src/main/askai/core/askai_messages.py +++ b/src/main/askai/core/askai_messages.py @@ -257,10 +257,10 @@ def quote_exceeded(self) -> str: ) def interruption_requested(self, reason: str) -> str: - return f"AI has interrupted the execution => {reason}" + return f" Interrupting execution => {reason}…" def terminate_requested(self, reason: str) -> str: - return f"AI has terminated the execution => {reason}" + return f" Terminating execution => {reason}…" assert (msg := AskAiMessages().INSTANCE) is not None diff --git a/src/main/askai/core/processors/splitter/splitter_executor.py b/src/main/askai/core/processors/splitter/splitter_executor.py index 5098753d..ace20528 100644 --- a/src/main/askai/core/processors/splitter/splitter_executor.py +++ b/src/main/askai/core/processors/splitter/splitter_executor.py @@ -25,6 +25,7 @@ from askai.core.askai_configs import configs from askai.core.askai_events import AskAiEvents, ASKAI_BUS_NAME, ABORT_EVENT +from askai.core.askai_messages import msg from askai.core.enums.acc_color import AccColor from askai.core.processors.splitter.splitter_pipeline import SplitterPipeline from askai.core.processors.splitter.splitter_states import States @@ -44,19 +45,21 @@ def __init__(self, query: str): def pipeline(self) -> SplitterPipeline: return self._pipeline - def display(self, text: str) -> None: + def display(self, text: str, force: bool = False) -> None: """Display a debug message if debugging mode is active. :param text: The debug message to display + :param force: Force displaying the message regardless of the debug flag. """ - if is_debugging(): + if force or is_debugging(): text_formatter.console.print(Text.from_markup(text)) def interrupt(self, ev: Event) -> None: """Interrupt the active execution pipeline. :param ev: The interruption event, """ - self._interrupted = True - self.display(f"[red] Execution interrupted => {ev.args.message} ![/red]") + if self.is_alive(): + self.display(f"[red]{msg.interruption_requested(ev.args.message)} ![/red]", True) + self._interrupted = True def run(self) -> None: """Execute the splitter pipeline.""" @@ -66,11 +69,11 @@ def run(self) -> None: self.pipeline.track_previous() if 1 < configs.max_router_retries < 1 + self.pipeline.failures[self.pipeline.state.value]: self.display( - f"\n[red] Max retries exceeded: {configs.max_agent_retries}[/red]\n") + f"\n[red] Max retries exceeded: {configs.max_agent_retries}[/red]\n", True) break if 1 < configs.max_iteractions < 1 + self.pipeline.iteractions: self.display( - f"\n[red] Max iteractions exceeded: {configs.max_iteractions}[/red]\n") + f"\n[red] Max iteractions exceeded: {configs.max_iteractions}[/red]\n", True) break match self.pipeline.state: case States.STARTUP: @@ -109,7 +112,7 @@ def run(self) -> None: self.pipeline.ev_final_answer() case _: self.display( - f"[red] Error: Machine halted before complete!({self.pipeline.state})[/red]") + f"[red] Error: Machine halted before complete!({self.pipeline.state})[/red]", True) break execution_status: bool = self.pipeline.previous != self.pipeline.state @@ -137,4 +140,4 @@ def run(self) -> None: if final_state != States.COMPLETE: retries: int = self.pipeline.failures[self.pipeline.state.value] - self.display(f" Failed to generate a response after {retries} retries") + self.display(f" Failed to generate a response after {retries} retries", True)