fix agent string parsing, minor changes
This commit is contained in:
parent
cec1fadab8
commit
3db40a65fe
|
@ -10,12 +10,14 @@ def func_talk(response: ChatCompletion):
|
||||||
if function_name == 'talk':
|
if function_name == 'talk':
|
||||||
function_arguments = function_call.arguments
|
function_arguments = function_call.arguments
|
||||||
try:
|
try:
|
||||||
j = json.loads(function_arguments)
|
j = json.loads(escape_json_string(function_arguments))
|
||||||
if 'message' in j.get('message'):
|
|
||||||
print(response)
|
|
||||||
return j.get('message')
|
return j.get('message')
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
# Sometimes the AI doesn't do JSON.
|
# Sometimes the AI doesn't do JSON.
|
||||||
return function_arguments
|
return function_arguments
|
||||||
else:
|
else:
|
||||||
print('THE AI DID NOT CALL A FUNCTION IN TALK:', response)
|
print('THE AI DID NOT CALL A FUNCTION IN TALK:', response)
|
||||||
|
|
||||||
|
|
||||||
|
def escape_json_string(s):
|
||||||
|
return s.replace("\\", "\\\\")
|
||||||
|
|
9
run.py
9
run.py
|
@ -37,7 +37,11 @@ def main():
|
||||||
print(colored(f'System Management Intelligence Interface', 'green', attrs=['bold']) + ' ' + colored(temp_name, 'green', attrs=['bold', 'underline']) + colored(' on ', 'green', attrs=['bold']) + colored(socket.gethostname(), 'green', attrs=['bold', 'underline']) + '\n')
|
print(colored(f'System Management Intelligence Interface', 'green', attrs=['bold']) + ' ' + colored(temp_name, 'green', attrs=['bold', 'underline']) + colored(' on ', 'green', attrs=['bold']) + colored(socket.gethostname(), 'green', attrs=['bold', 'underline']) + '\n')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
next_input = str(input('> '))
|
next_input = str(input('> '))
|
||||||
|
except EOFError:
|
||||||
|
print('Exit')
|
||||||
|
sys.exit(0)
|
||||||
print('')
|
print('')
|
||||||
context.append({'role': 'user', 'content': next_input})
|
context.append({'role': 'user', 'content': next_input})
|
||||||
|
|
||||||
|
@ -49,7 +53,7 @@ def main():
|
||||||
temp_context.append({'role': 'system', 'content': 'Run another command or call "talk" to communicate with the user.'})
|
temp_context.append({'role': 'system', 'content': 'Run another command or call "talk" to communicate with the user.'})
|
||||||
|
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="gpt-4",
|
model="gpt-4-1106-preview", # TODO: config
|
||||||
messages=temp_context,
|
messages=temp_context,
|
||||||
functions=function_description,
|
functions=function_description,
|
||||||
temperature=0.7
|
temperature=0.7
|
||||||
|
@ -65,10 +69,11 @@ def main():
|
||||||
print(colored(response_text, 'blue') + '\n')
|
print(colored(response_text, 'blue') + '\n')
|
||||||
break
|
break
|
||||||
elif function_name == 'end_chat':
|
elif function_name == 'end_chat':
|
||||||
|
# TODO: add a config arg to control whether or not the AI is allowed to do this.
|
||||||
print(colored('The AI has terminated the connection.', 'red', attrs=['bold']))
|
print(colored('The AI has terminated the connection.', 'red', attrs=['bold']))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(f'Executing {function_name}("{function_arguments}")' + '\n')
|
print(f'{function_name}("{function_arguments}")' + '\n')
|
||||||
|
|
||||||
if function_name != 'run_bash':
|
if function_name != 'run_bash':
|
||||||
context.append({'role': 'system', 'content': f'"{function_name}" is not a valid function.'})
|
context.append({'role': 'system', 'content': f'"{function_name}" is not a valid function.'})
|
||||||
|
|
Reference in New Issue