fix agent string parsing, minor changes

This commit is contained in:
Cyberes 2024-01-20 16:27:17 -07:00
parent cec1fadab8
commit 3db40a65fe
2 changed files with 13 additions and 6 deletions

View File

@ -10,12 +10,14 @@ def func_talk(response: ChatCompletion):
if function_name == 'talk':
function_arguments = function_call.arguments
try:
j = json.loads(function_arguments)
if 'message' in j.get('message'):
print(response)
j = json.loads(escape_json_string(function_arguments))
return j.get('message')
except json.decoder.JSONDecodeError:
# Sometimes the AI doesn't do JSON.
return function_arguments
else:
print('THE AI DID NOT CALL A FUNCTION IN TALK:', response)
def escape_json_string(s):
return s.replace("\\", "\\\\")

11
run.py
View File

@ -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')
while True:
next_input = str(input('> '))
try:
next_input = str(input('> '))
except EOFError:
print('Exit')
sys.exit(0)
print('')
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.'})
response = client.chat.completions.create(
model="gpt-4",
model="gpt-4-1106-preview", # TODO: config
messages=temp_context,
functions=function_description,
temperature=0.7
@ -65,10 +69,11 @@ def main():
print(colored(response_text, 'blue') + '\n')
break
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']))
sys.exit(1)
print(f'Executing {function_name}("{function_arguments}")' + '\n')
print(f'{function_name}("{function_arguments}")' + '\n')
if function_name != 'run_bash':
context.append({'role': 'system', 'content': f'"{function_name}" is not a valid function.'})