Made assistant history persist with cache file
This commit is contained in:
parent
2237293e16
commit
d946938b3d
16
assistant.py
16
assistant.py
|
|
@ -9,15 +9,27 @@ import pygments
|
||||||
from pygments.lexers import get_lexer_by_name, guess_lexer
|
from pygments.lexers import get_lexer_by_name, guess_lexer
|
||||||
from pygments.formatters import TerminalFormatter
|
from pygments.formatters import TerminalFormatter
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
server = 'localhost:11434'
|
server = 'localhost:11434'
|
||||||
model = 'gemma3:12b'
|
model = 'gemma3:12b'
|
||||||
reasoning_model='deepseek-r1:14b'
|
reasoning_model='deepseek-r1:14b'
|
||||||
temp = 0.2
|
temp = 0.2
|
||||||
|
|
||||||
|
|
||||||
pattern = r'```[a-z]*\n[\s\S]*?\n```'
|
pattern = r'```[a-z]*\n[\s\S]*?\n```'
|
||||||
line_pattern = r'`[a-z]*[\s\S]*?`'
|
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'):
|
def save_conversation(filename='conversation.md'):
|
||||||
# check if filename already exists and increment filename if so
|
# check if filename already exists and increment filename if so
|
||||||
if not filename.endswith('.md'):
|
if not filename.endswith('.md'):
|
||||||
|
|
@ -48,6 +60,7 @@ def parse_commands(text):
|
||||||
case '/clear':
|
case '/clear':
|
||||||
global history
|
global history
|
||||||
history = [ system_prompt ]
|
history = [ system_prompt ]
|
||||||
|
save_history(history, history_path)
|
||||||
return True
|
return True
|
||||||
case '/clipboard':
|
case '/clipboard':
|
||||||
context_query = '\n\nThe following is context provided by the user:\n'
|
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)
|
user_input = arg_follow_up(args)
|
||||||
result = chat2(args, user_input)
|
result = chat2(args, user_input)
|
||||||
exit()
|
exit()
|
||||||
|
global history
|
||||||
|
history = load_history(history_path)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
user_input = input('> ')
|
user_input = input('> ')
|
||||||
|
|
@ -331,6 +346,7 @@ def handle_non_piped_input(args):
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
result = chat2(args, user_input)
|
result = chat2(args, user_input)
|
||||||
|
save_history(history, history_path)
|
||||||
|
|
||||||
client = None
|
client = None
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue