{ "chat_template": "{{ bos_token }}\n{%- if messages[0]['role'] == 'system' -%}\n {%- if messages[0]['content'] is string -%}\n {%- set first_user_prefix = messages[0]['content'] + '\n\n' -%}\n {%- else -%}\n {%- set first_user_prefix = messages[0]['content'][0]['text'] + '\n\n' -%}\n {%- endif -%}\n {%- set loop_messages = messages[1:] -%}\n{%- else -%}\n {%- set first_user_prefix = \"\" -%}\n {%- set loop_messages = messages -%}\n{%- endif -%}\n{%- if not tools is defined %}\n {%- set tools = none %}\n{%- endif %}\n{%- for message in loop_messages | rejectattr(\"role\", \"equalto\", \"tool\") | selectattr(\"tool_calls\", \"undefined\") -%}\n {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}\n {{ raise_exception(\"Conversation roles must alternate user/assistant/user/assistant/...\") }}\n {%- endif -%}\n{%- endfor -%}\n{%- for message in loop_messages -%}\n {%- if (message['role'] == 'assistant') -%}\n {%- set role = \"model\" -%}\n {%- elif (message['role'] == 'tool') -%}\n {%- set role = \"user\" -%}\n {%- else -%}\n {%- set role = message['role'] -%}\n {%- endif -%}\n {{ '' + role + '\n' -}}\n {%- if loop.first -%}\n {{ first_user_prefix }}\n {%- if tools is not none -%}\n {{- \"You have access to the following tools to help respond to the user. To call tools, please respond with a python list of the calls. DO NOT USE MARKDOWN SYNTAX.\n\" }}\n {{- 'Respond in the format [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)] \n' }}\n {{- \"Do not use variables.\n\n\" }}\n {%- for t in tools -%}\n {{- t | tojson(indent=4) }}\n {{- \"\n\n\" }}\n {%- endfor -%}\n {%- endif -%}\n {%- endif -%}\n\n {%- if 'tool_calls' in message -%}\n {{- '[' -}}\n {%- for tool_call in message.tool_calls -%}\n {%- if tool_call.function is defined -%}\n {%- set tool_call = tool_call.function -%}\n {%- endif -%}\n {{- tool_call.name + '(' -}}\n {%- for param in tool_call.arguments -%}\n {{- param + '=' -}}\n {{- \"%sr\" | format(tool_call.arguments[param]) -}}\n {%- if not loop.last -%}, {% endif -%}\n {%- endfor -%}\n {{- ')' -}}\n {%- if not loop.last -%},{%- endif -%}\n {%- endfor -%}\n {{- ']' -}}\n {%- endif -%}\n\n {%- if (message['role'] == 'tool') -%}\n {{ '\n' -}}\n {%- endif -%}\n {%- if message['content'] is string -%}\n {{ message['content'] | trim }}\n {%- elif message['content'] is iterable -%}\n {%- for item in message['content'] -%}\n {%- if item['type'] == 'image' -%}\n {{ '' }}\n {%- elif item['type'] == 'text' -%}\n {{ item['text'] | trim }}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{ raise_exception(\"Invalid content type\") }}\n {%- endif -%}\n {%- if (message['role'] == 'tool') -%}\n {{ '' -}}\n {%- endif -%}\n {{ '\n' }}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{'model\n'}}\n{%- endif -%}\n" }