Skip to content

Commit

Permalink
Fix some async problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Dec 13, 2024
1 parent 470bd9e commit 47358b3
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/main/askai/tui/askai_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ''}"
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 47358b3

Please sign in to comment.