Compare commits

..

No commits in common. "0455b12d9076271b60c220cfa64802faebd8a6f4" and "f6ec5cde2e215e2d7ce62f5ad200180f1cb9ce29" have entirely different histories.

View file

@ -8,7 +8,7 @@ import argparse
import pygments import pygments
from pygments.lexers import get_lexer_by_name from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter from pygments.formatters import TerminalFormatter
import os
server = 'localhost:11434' server = 'localhost:11434'
model = 'llama3.1:8b-instruct-q8_0' model = 'llama3.1:8b-instruct-q8_0'
@ -17,42 +17,6 @@ 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]*?`'
def save_conversation(filename='conversation.md'):
# check if filename already exists and increment filename if so
if not filename.endswith('.md'):
filename += '.md'
base, extension = os.path.splitext(filename)
i = 1
while os.path.exists(filename):
filename = f"{base}_{i}{extension}"
i += 1
# save conversation to filename
global conversation
with open(filename, 'w') as f:
f.write(conversation)
def parse_commands(text):
# See if user wrote any commands here
# returns bool: True if command was executed, False if not
# importantly, the command doesn't need to execute succesfully for it to return True
tokens = text.split(' ')
match tokens[0]:
case '/save':
if len(tokens) > 1:
save_conversation(tokens[1])
else:
save_conversation()
return True
case '/clear':
global history
history = [ system_prompt ]
return True
case '/exit':
exit()
return False
def highlight_code(language_name, code): def highlight_code(language_name, code):
# Check if the language is specified in the first line # Check if the language is specified in the first line
lexer_name = language_name lexer_name = language_name
@ -127,11 +91,9 @@ def copy_string_to_clipboard(string):
code_history = [] code_history = []
system_prompt = {"role": "system", "content": "You are a helpful, smart, kind, and efficient AI assistant. You always fulfill the user's requests accurately and concisely."} history = [
{"role": "system", "content": "You are a helpful, smart, kind, and efficient AI assistant. You always fulfill the user's requests accurately and concisely."},
history = [ system_prompt ] ]
conversation = ""
def chat(message, stream=True): def chat(message, stream=True):
history.append({"role": "user", "content": message}) history.append({"role": "user", "content": message})
@ -175,19 +137,10 @@ def chat(message, stream=True):
return result return result
def chat2(args, user_input, stream=True): def chat2(args, user_input, stream=True):
global conversation if args.reflect:
if parse_commands(user_input):
result = ''
elif args.reflect:
print('assistant: ', end='')
result = reflection_mode(user_input, stream) result = reflection_mode(user_input, stream)
else: else:
print('assistant: ', end='')
result = chat(user_input, stream) result = chat(user_input, stream)
if result != '':
conversation += 'user: ' + user_input + '\n'
conversation += 'assistant: ' + result + '\n'
return result return result
def highlightify_text(full_text): def highlightify_text(full_text):