How to call functions with chat models - Pretty Print
def pretty_print_conversation(messages): role_to_color = { 'system': 'red', 'user': 'green', 'assistant': 'blue', 'function': 'magenta', } for message in messages: if message['role'] == 'system': print(colored(f'system: {message['content']}
', role_to_color[message['role']])) elif message['role'] == 'user': print(colored(f'user: {message['content']}
', role_to_color[message['role']])) elif message['role'] == 'assistant' and message.get('function_call'): print(colored(f'assistant: {message['function_call']}
', role_to_color[message['role']])) elif message['role'] == 'assistant' and not message.get('function_call'): print(colored(f'assistant: {message['content']}
', role_to_color[message['role']])) elif message['role'] == 'function': print(colored(f'function ({message['name']}): {message['content']}
', role_to_color[message['role']]))