From 47358b3496fc68b7ccb8884ebe9b8206ca004f62 Mon Sep 17 00:00:00 2001 From: Hugo Saporetti Junior Date: Fri, 13 Dec 2024 15:21:09 -0300 Subject: [PATCH] Fix some async problems --- src/main/askai/tui/askai_app.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/askai/tui/askai_app.py b/src/main/askai/tui/askai_app.py index 051a5db0..aeb95179 100644 --- a/src/main/askai/tui/askai_app.py +++ b/src/main/askai/tui/askai_app.py @@ -95,9 +95,7 @@ def __init__( mode: RouterMode, ): super().__init__() - self._askai: AskAi = AskAi( - speak, debug, cacheable, tempo, engine_name, model_name, mode - ) + self._askai: AskAi = AskAi(speak, debug, cacheable, tempo, engine_name, model_name, mode) self._re_render: bool = True self._display_buffer: list[str] = list() self._startup() @@ -156,7 +154,7 @@ def input_actions(self): return self.query_one(InputActions) @property - def suggester(self) -> InputSuggester: + def suggester(self) -> Optional[InputSuggester]: """Get the Input Suggester.""" return self.line_input.suggester @@ -209,9 +207,7 @@ async def action_forward(self) -> None: def action_toggle_table_of_contents(self) -> None: """Toggles display of the table of contents.""" - self.md_console.show_table_of_contents = ( - not self.md_console.show_table_of_contents - ) + self.md_console.show_table_of_contents = not self.md_console.show_table_of_contents def check_action(self, action: str, _) -> Optional[bool]: """Check if a specific action can be performed. @@ -253,9 +249,7 @@ def action_clear(self, overwrite: bool = True) -> None: :param overwrite: Whether to overwrite the existing content in the console (default is True). """ is_new: bool = not file_is_not_empty(str(self.console_path)) or overwrite - with open( - self.console_path, "w" if overwrite else "a", encoding=Charset.UTF_8.val - ) as f_console: + with open(self.console_path, "w" if overwrite else "a", encoding=Charset.UTF_8.val) as f_console: f_console.write( f"{'---' + os.linesep * 2 if not is_new else ''}" f"{'# ' + now(DATE_FORMAT) + os.linesep * 2 if is_new else ''}" @@ -278,7 +272,7 @@ async def action_assistive(self) -> None: self.ask_and_reply("/assistive") @work(thread=True) - async def action_ptt(self) -> None: + def action_ptt(self) -> None: """Handle the Push-To-Talk (PTT) action for Speech-To-Text (STT) input. This method allows the user to use Push-To-Talk as an input method, converting spoken words into text. """ @@ -320,9 +314,7 @@ async def _write_markdown(self) -> None: if (text := self._display_buffer.pop(0)) == prev_text: continue prev_text = text - final_text: str = text_formatter.beautify( - f"{ensure_endswith(text, os.linesep * 2)}" - ) + final_text: str = text_formatter.beautify(f"{ensure_endswith(text, os.linesep * 2)}") f_console.write(final_text) f_console.flush() self._re_render = True @@ -359,9 +351,7 @@ def _reply_error(self, reply: AIReply) -> None: log.error(reply.message) self.display_text(f"{shared.nickname_md} Error: {reply.message}") if configs.is_speak and reply.is_speakable: - self.engine.text_to_speech( - f"Error: {reply.message}", f"{shared.nickname_md} " - ) + self.engine.text_to_speech(f"Error: {reply.message}", f"{shared.nickname_md} ") def display_text(self, markdown_text: str) -> None: """Send the text to the Markdown console. @@ -435,7 +425,7 @@ def _startup(self) -> None: log.info("AskAI is ready to use!") @work(thread=True) - async def _setup(self) -> None: + def _setup(self) -> None: """Setup the TUI controls.""" player.start_delay() self.splash.set_class(True, "-hidden")