Add /clipboard command
clipboard contents can be added as context in the conversation now.
This commit is contained in:
parent
0455b12d90
commit
f49142f04c
26
assistant.py
26
assistant.py
|
|
@ -48,6 +48,10 @@ def parse_commands(text):
|
||||||
global history
|
global history
|
||||||
history = [ system_prompt ]
|
history = [ system_prompt ]
|
||||||
return True
|
return True
|
||||||
|
case '/clipboard':
|
||||||
|
context_query = '\n\nThe following is context provided by the user:\n'
|
||||||
|
context_query += get_string_from_clipboard() + '\n'
|
||||||
|
return text.split('/clipboard ')[1] + context_query
|
||||||
case '/exit':
|
case '/exit':
|
||||||
exit()
|
exit()
|
||||||
return False
|
return False
|
||||||
|
|
@ -124,6 +128,12 @@ def copy_string_to_clipboard(string):
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def get_string_from_clipboard():
|
||||||
|
try:
|
||||||
|
result = pyperclip.paste()
|
||||||
|
except:
|
||||||
|
result = ''
|
||||||
|
return result
|
||||||
|
|
||||||
code_history = []
|
code_history = []
|
||||||
|
|
||||||
|
|
@ -176,18 +186,22 @@ def chat(message, stream=True):
|
||||||
|
|
||||||
def chat2(args, user_input, stream=True):
|
def chat2(args, user_input, stream=True):
|
||||||
global conversation
|
global conversation
|
||||||
if parse_commands(user_input):
|
command_result = parse_commands(user_input)
|
||||||
result = ''
|
if command_result:
|
||||||
elif args.reflect:
|
if type(command_result) == bool:
|
||||||
|
return ''
|
||||||
|
elif type(command_result) == str: # sometimes I want to change the user prompt with a command
|
||||||
|
user_input = command_result
|
||||||
|
|
||||||
|
if args.reflect:
|
||||||
print('assistant: ', end='')
|
print('assistant: ', end='')
|
||||||
result = reflection_mode(user_input, stream)
|
result = reflection_mode(user_input, stream)
|
||||||
else:
|
else:
|
||||||
print('assistant: ', end='')
|
print('assistant: ', end='')
|
||||||
result = chat(user_input, stream)
|
result = chat(user_input, stream)
|
||||||
|
|
||||||
if result != '':
|
conversation += 'user: ' + user_input + '\n'
|
||||||
conversation += 'user: ' + user_input + '\n'
|
conversation += 'assistant: ' + result + '\n'
|
||||||
conversation += 'assistant: ' + result + '\n'
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def highlightify_text(full_text):
|
def highlightify_text(full_text):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue