{{ '' -}} {%- if custom_tools is defined %} {%- set tools = custom_tools %} {%- endif %} {%- if not tools is defined %} {%- set tools = none %} {%- endif %} {#- Extract system message #} {% set ns = namespace(system_prompt='') -%} {%- if messages[0]['role'] == 'system' %} {%- if messages[0]['content'] is string %} {%- set ns.system_prompt = messages[0]['content']|trim %} {%- else %} {%- set ns.system_prompt = messages[0]['content'][0]['text']|trim %} {%- endif %} {%- set messages = messages[1:] %} {%- else %} {%- if tools is not none %} {%- set ns.system_prompt = "You are a helpful assistant created by Minimax based on MiniMax-M1 model." %} {%- else %} {%- set ns.system_prompt = "You are a helpful assistant created by Minimax based on MiniMax-M1 model." %} {%- endif %} {%- endif %} {#- System message #} {%- if ns.system_prompt != '' %} {{ 'system ai_setting=assistant\n' + ns.system_prompt + '\n' -}} {%- endif %} {#- Tools configuration #} {%- if tools is not none %} {{ 'system tool_setting=tools\nYou are provided with these tools:\n\n' -}} {%- for tool in tools %} {{ tool | tojson ~ '\n' -}} {%- endfor %} {{ '\n\nIf you need to call tools, please respond with XML tags, and provide tool-name and json-object of arguments, following the format below:\n\n{"name": , "arguments": }\n...\n\n' -}} {%- endif %} {#- Process messages #} {%- for message in messages %} {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %} {%- if message['role'] == 'user' %} {{ 'user name=user\n' -}} {%- if message['content'] is string %} {{ message['content']|trim -}} {%- else %} {%- for content in message['content'] %} {%- if content['type'] == 'text' %} {{ content['text']|trim -}} {%- endif %} {%- endfor %} {%- endif %} {{ '\n' -}} {%- elif message['role'] == 'assistant' %} {{ 'ai name=assistant\n' -}} {%- if message['content'] is string %} {{ message['content']|trim -}} {%- else %} {%- for content in message['content'] | selectattr('type', 'equalto', 'text') %} {{ content['text']|trim -}} {%- endfor %} {%- endif %} {{ '\n' -}} {%- endif %} {%- elif 'tool_calls' in message %} {{ 'ai name=assistant\n\n' -}} {%- for tool_call in message.tool_calls %} {{ '{"name": "' + tool_call.function.name + '", "arguments": ' + tool_call.function.arguments | tojson + '}\n' -}} {%- endfor %} {{ '\n' -}} {%- elif message.role == "tool" or message.role == "ipython" %} {{ 'tool name=tools\n' -}} {%- if message.content is string %} {{ 'tool result: ' + message.content + '\n\n' -}} {%- else %} {%- for content in message['content'] %} {%- if content['type'] == 'text' %} {{ 'tool result: ' + content['text'] + '\n\n' -}} {%- elif content.get('name') %} {{ 'tool name: ' + content['name'] + '\ntool result: ' + content['text'] + '\n\n' -}} {%- endif %} {%- endfor %} {%- endif %} {{ '\n' -}} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{ 'ai name=assistant\n' -}} {%- endif %}