diff --git a/lib/openai/functs.py b/lib/openai/functs.py index d787e63..548f876 100644 --- a/lib/openai/functs.py +++ b/lib/openai/functs.py @@ -26,5 +26,9 @@ function_description = [ }, "required": ["message"] } + }, + { + "name": "end_chat", + "description": "Close the chat connection with the user. The assistant is allowed to close the connection at any point if it desires to.", } ] diff --git a/lib/openai/talk.py b/lib/openai/talk.py index 007b32d..386c306 100644 --- a/lib/openai/talk.py +++ b/lib/openai/talk.py @@ -11,6 +11,8 @@ def func_talk(response: ChatCompletion): function_arguments = function_call.arguments try: j = json.loads(function_arguments) + if 'message' in j.get('message'): + print(response) return j.get('message') except json.decoder.JSONDecodeError: # Sometimes the AI doesn't do JSON. diff --git a/run.py b/run.py index 35ab2da..ddddeae 100755 --- a/run.py +++ b/run.py @@ -28,7 +28,7 @@ signal.signal(signal.SIGINT, signal_handler) client = OpenAI(api_key=OPENAI_KEY) temp_name = 'Sakura' -character_card = load_personality('Sakura', 'a shy girl', 'a desktop computer') +character_card = load_personality('Sakura', 'a shy girl', 'a desktop computer', 'Use Japanese emoticons.') context: list[dict[str, str]] = [character_card] @@ -64,6 +64,9 @@ def main(): context.append({'role': 'assistant', 'content': response_text}) print(colored(response_text, 'blue') + '\n') break + elif function_name == 'end_chat': + print(colored('The AI has terminated the connection.', 'red', attrs=['bold'])) + sys.exit(1) print(f'Executing {function_name}("{function_arguments}")' + '\n')