Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Command history #99

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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