From 36614145147602da92b9a0c10bf9009f36010907 Mon Sep 17 00:00:00 2001 From: VAliquo Date: Sat, 5 Oct 2024 22:44:15 -0400 Subject: [PATCH 1/2] [ADD] Command history --- navi.py | 2 +- navi_internal.py | 11 ++++++++++- navi_shell.py | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/navi.py b/navi.py index f004570..1fffe03 100644 --- a/navi.py +++ b/navi.py @@ -63,4 +63,4 @@ def get_parameters(input_str: str) -> list[str]: # Flatten the list and filter out empty strings parameters = [item for sublist in matches for item in sublist if item] - return parameters \ No newline at end of file + return parameters diff --git a/navi_internal.py b/navi_internal.py index 54e2635..8bf2073 100644 --- a/navi_internal.py +++ b/navi_internal.py @@ -9,6 +9,9 @@ import spacy import platform +from prompt_toolkit import PromptSession +from prompt_toolkit.history import FileHistory + from mods import mods @@ -21,6 +24,9 @@ class NaviApp: server: str = config.server port: int = config.port + script_dir = os.path.dirname(os.path.abspath(__file__)) + hist_file = os.path.join(script_dir, ".navi_history") + # NLP setup nlp: spacy.language.Language = spacy.load("en_core_web_sm") ruler: spacy.pipeline.EntityRuler = nlp.add_pipe("entity_ruler") @@ -34,6 +40,9 @@ def __new__(cls, *args, **kwargs): cls._instance = super(NaviApp, cls).__new__(cls, *args, **kwargs) return cls._instance + def setup_history(self) -> None: + self.session = PromptSession(history=FileHistory(self.hist_file)) + def get_user(self) -> str: return self.user @@ -145,7 +154,7 @@ def chat_with_navi(self) -> None: while True: # Get user input try: - user_message = input(f"\n{self.user}> ") + user_message = self.session.prompt(f"\n{self.user}> ") except EOFError: self.print_message("Encountered an unexpected end of input.") break diff --git a/navi_shell.py b/navi_shell.py index e338cf2..0526bfc 100644 --- a/navi_shell.py +++ b/navi_shell.py @@ -77,6 +77,7 @@ def main() -> None: navi_instance.setup_navi_vocab() navi_instance.set_user(user) navi_instance.clear_terminal() + navi_instance.setup_history() navi_instance.chat_with_navi() navi_instance.print_message(f"How can I help you {user}") except KeyboardInterrupt: From 2e8a37c4d5f63d8c90d019cb280575c5c6298bf4 Mon Sep 17 00:00:00 2001 From: VAliquo Date: Sat, 5 Oct 2024 22:47:56 -0400 Subject: [PATCH 2/2] [FIX] Missing install --- install/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/install/requirements.txt b/install/requirements.txt index 4638bda..0bba9d5 100644 --- a/install/requirements.txt +++ b/install/requirements.txt @@ -13,3 +13,4 @@ image hashcat mido psutil +prompt_toolkit==3.0.48