{% for message in messages %}{% if message['role'] == 'system' %}{{ 'system ai_setting=assistant\n' + message['content'][0]['text'] + '\n'}}{% elif message['role'] == 'user' %}{{ 'user name=user\n' + message['content'][0]['text'] + '\n'}}{% elif message['role'] == 'assistant' %}{{ 'ai name=assistant\n' }}{% for content in message['content'] | selectattr('type', 'equalto', 'text') %}{% generation %}{{ content['text'] }}{% endgeneration %}{% endfor %}{{ '\n' }}{% elif message['role'] == 'function' %}{{ 'system function_response=functions\n' + '{"name": "' + message['name'] + '", "response": ' + message['content'][0]['text'] + '}' + '\n'}}{% endif %}{% endfor %}{% if tools %}{% for function in tools %}{{ 'system function_setting=functions\n' + function | tojson + '\n'}}{% endfor %}{% endif %}{% if add_generation_prompt %}{{ 'ai name=assistant\n' }}{% endif %}