Skip to content

Commit

Permalink
Merge pull request #99 from SaintsSec/vincent/history2
Browse files Browse the repository at this point in the history
[ADD] Command history
  • Loading branch information
AlexKollar authored Oct 6, 2024
2 parents a13eada + 2e8a37c commit 18ef682
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions install/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ image
hashcat
mido
psutil
prompt_toolkit==3.0.48
2 changes: 1 addition & 1 deletion navi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return parameters
11 changes: 10 additions & 1 deletion navi_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import spacy
import platform

from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory

from mods import mods


Expand All @@ -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")
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions navi_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 18ef682

Please sign in to comment.