Add /clipboard command
clipboard contents can be added as context in the conversation now.
This commit is contained in:
parent
0455b12d90
commit
f49142f04c
22
assistant.py
22
assistant.py
|
|
@ -48,6 +48,10 @@ def parse_commands(text):
|
|||
global history
|
||||
history = [ system_prompt ]
|
||||
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':
|
||||
exit()
|
||||
return False
|
||||
|
|
@ -124,6 +128,12 @@ def copy_string_to_clipboard(string):
|
|||
except:
|
||||
return
|
||||
|
||||
def get_string_from_clipboard():
|
||||
try:
|
||||
result = pyperclip.paste()
|
||||
except:
|
||||
result = ''
|
||||
return result
|
||||
|
||||
code_history = []
|
||||
|
||||
|
|
@ -176,16 +186,20 @@ def chat(message, stream=True):
|
|||
|
||||
def chat2(args, user_input, stream=True):
|
||||
global conversation
|
||||
if parse_commands(user_input):
|
||||
result = ''
|
||||
elif args.reflect:
|
||||
command_result = parse_commands(user_input)
|
||||
if command_result:
|
||||
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='')
|
||||
result = reflection_mode(user_input, stream)
|
||||
else:
|
||||
print('assistant: ', end='')
|
||||
result = chat(user_input, stream)
|
||||
|
||||
if result != '':
|
||||
conversation += 'user: ' + user_input + '\n'
|
||||
conversation += 'assistant: ' + result + '\n'
|
||||
return result
|
||||
|
|
|
|||
Loading…
Reference in a new issue