diff --git a/assistant.py b/assistant.py index 8efedba..8062309 100755 --- a/assistant.py +++ b/assistant.py @@ -9,15 +9,27 @@ import pygments from pygments.lexers import get_lexer_by_name, guess_lexer from pygments.formatters import TerminalFormatter import os +import json server = 'localhost:11434' model = 'gemma3:12b' reasoning_model='deepseek-r1:14b' temp = 0.2 + pattern = r'```[a-z]*\n[\s\S]*?\n```' line_pattern = r'`[a-z]*[\s\S]*?`' +history_path = os.environ.get('HOME') + '/.cache/ai-assistant.history' + +def save_history(data, path): + with open(path, 'w+') as f: + json.dump(data, f) + +def load_history(path): + with open(path, 'r') as f: + return json.load(f) + def save_conversation(filename='conversation.md'): # check if filename already exists and increment filename if so if not filename.endswith('.md'): @@ -48,6 +60,7 @@ def parse_commands(text): case '/clear': global history history = [ system_prompt ] + save_history(history, history_path) return True case '/clipboard': context_query = '\n\nThe following is context provided by the user:\n' @@ -323,6 +336,8 @@ def handle_non_piped_input(args): user_input = arg_follow_up(args) result = chat2(args, user_input) exit() + global history + history = load_history(history_path) while True: try: user_input = input('> ') @@ -331,6 +346,7 @@ def handle_non_piped_input(args): exit() else: result = chat2(args, user_input) + save_history(history, history_path) client = None