Fix generation prompt to chat template
Browse files- tokenizer_config.json +1 -1
tokenizer_config.json
CHANGED
@@ -2000,7 +2000,7 @@
|
|
2000 |
"<end_of_turn>"
|
2001 |
],
|
2002 |
"bos_token": "<bos>",
|
2003 |
-
"chat_template": "\n{%- macro render_json(d, indent=4) -%}\n{%- if d is string %}\n{{ '\"' + d + '\"' }}\n{%- elif d is mapping %}\n{%- for key, value in d.items() %}\n{%- if value is string %}\n{{ \" \" * indent + '\"' + key + '\": \"' + value + '\"' }}\n{%- elif value is mapping %}\n{{ \" \" * indent + '\"' + key + '\": {' }}\n{{ render_json(value, indent + 4) }}\n{{ \" \" * indent + \"}\" }}\n{%- elif value is sequence %}\n{{ \" \" * indent + '\"' + key + '\": [\n' }}\n{%- for item in value %}\n{{- \" \" * (indent + 4) + render_json(item, indent + 4) }}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{{ '\n' + \" \" * indent + \"]\" }}\n{%- else %}\n{{ \" \" * indent + '\"' + key + '\": ' + value|string }}\n{%- endif %}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{%- elif d is sequence %}\n{%- for item in d %}\n{{ \" \" * indent + render_json(item, indent + 4) }}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{%- else %}\n{{ \" \" * indent + d|string }}\n{%- endif %}\n{%- endmacro %}\n\n\n{#- This block checks system prompt and list of tools #}\n{%- if not add_generation_prompt is defined %}\n {%- set add_generation_prompt = false %}\n{%- endif %}\n{%- if messages[0][\"role\"] == \"system\" %}\n {%- set system_message = messages[0][\"content\"] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n {%- set system_message = \"\" %}\n{%- endif %}\n{%- if not tools is defined %}\n {%- set tools = none %}\n{%- endif %}\n{%- set user_messages = loop_messages | selectattr(\"role\", \"equalto\", \"user\") | list %}\n\n\n{#- This block checks for alternating user/model messages, skipping tool calling messages #}\n{%- set ns = namespace() %}\n{%- set ns.index = 0 %}\n{%- for message in loop_messages %}\n {%- if not (message.role == \"tool\" or message.role == \"tool_results\" or (message.tool_calls is defined and message.tool_calls is not none)) %}\n {%- if (message[\"role\"] == \"user\" or message[\"role\"] == \"function-response\") != (ns.index % 2 == 0) %}\n {{- raise_exception(\"After the optional system message, conversation roles must alternate user/model/user/model/... NB: 'function-call' is same as the 'model' and 'function-response' is same as the 'user'!\") }}\n {%- endif %}\n {%- set ns.index = ns.index + 1 %}\n {%- endif %}\n{%- endfor %}\n\n\n{#- This block format full dialogue messages #}\n{{- bos_token }}\n{
|
2004 |
"clean_up_tokenization_spaces": false,
|
2005 |
"eos_token": "<eos>",
|
2006 |
"model_max_length": 1000000000000000019884624838656,
|
|
|
2000 |
"<end_of_turn>"
|
2001 |
],
|
2002 |
"bos_token": "<bos>",
|
2003 |
+
"chat_template": "\n{%- macro render_json(d, indent=4) -%}\n{%- if d is string %}\n{{ '\"' + d + '\"' }}\n{%- elif d is mapping %}\n{%- for key, value in d.items() %}\n{%- if value is string %}\n{{ \" \" * indent + '\"' + key + '\": \"' + value + '\"' }}\n{%- elif value is mapping %}\n{{ \" \" * indent + '\"' + key + '\": {' }}\n{{ render_json(value, indent + 4) }}\n{{ \" \" * indent + \"}\" }}\n{%- elif value is sequence %}\n{{ \" \" * indent + '\"' + key + '\": [\n' }}\n{%- for item in value %}\n{{- \" \" * (indent + 4) + render_json(item, indent + 4) }}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{{ '\n' + \" \" * indent + \"]\" }}\n{%- else %}\n{{ \" \" * indent + '\"' + key + '\": ' + value|string }}\n{%- endif %}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{%- elif d is sequence %}\n{%- for item in d %}\n{{ \" \" * indent + render_json(item, indent + 4) }}\n{%- if not loop.last %},\n{% endif %}\n{%- endfor %}\n{%- else %}\n{{ \" \" * indent + d|string }}\n{%- endif %}\n{%- endmacro %}\n\n\n{#- This block checks system prompt and list of tools #}\n{%- if not add_generation_prompt is defined %}\n {%- set add_generation_prompt = false %}\n{%- endif %}\n{%- if messages[0][\"role\"] == \"system\" %}\n {%- set system_message = messages[0][\"content\"] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set loop_messages = messages %}\n {%- set system_message = \"\" %}\n{%- endif %}\n{%- if not tools is defined %}\n {%- set tools = none %}\n{%- endif %}\n{%- set user_messages = loop_messages | selectattr(\"role\", \"equalto\", \"user\") | list %}\n\n\n{#- This block checks for alternating user/model messages, skipping tool calling messages #}\n{%- set ns = namespace() %}\n{%- set ns.index = 0 %}\n{%- for message in loop_messages %}\n {%- if not (message.role == \"tool\" or message.role == \"tool_results\" or (message.tool_calls is defined and message.tool_calls is not none)) %}\n {%- if (message[\"role\"] == \"user\" or message[\"role\"] == \"function-response\") != (ns.index % 2 == 0) %}\n {{- raise_exception(\"After the optional system message, conversation roles must alternate user/model/user/model/... NB: 'function-call' is same as the 'model' and 'function-response' is same as the 'user'!\") }}\n {%- endif %}\n {%- set ns.index = ns.index + 1 %}\n {%- endif %}\n{%- endfor %}\n\n\n{#- This block format full dialogue messages #}\n{{- bos_token }}\n{{- \"<start_of_turn>user\" + '\n' + system_message}}\n{%- if tools is not none %}\n {%- for tool in tools %}\n {%- set tool = tool.function %}\n {{- '{\n' }}\n {{- render_json(tool, 4) }}\n {%- if not loop.last %}\n {{- \"\n},\n\" }}\n {%- else %}\n {{- \"\n}\n\" }}\n {% endif %}\n {%- endfor %}\n{%- else %}\n {{- '\n\n' }}\n{%- endif %}\n{{ loop_messages[0]['content'] + '<end_of_turn>\n' }}\n{%- for message in loop_messages[1:] %}\n {%- if message[\"role\"] == \"user\" %}\n {{- \"<start_of_turn>user\" + '\n' + message['content'] + '<end_of_turn>\n' }}\n {%- elif message[\"role\"] == \"model\" %}\n {{- \"<start_of_turn>model\" + '\n' + message['content'] + '<end_of_turn>\n' }}\n {%- elif message[\"role\"] == \"function-call\" %}\n {{- \"<start_of_turn>model\" + '\n' + \"Function call: \" + message['content'] + '<end_of_turn>\n' }}\n {%- elif message[\"role\"] == \"function-response\" %}\n {{- \"<start_of_turn>user\" + '\n' + \"Function response: \" + message['content'] + '<end_of_turn>\n' }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {%- if loop_messages[-1]['role'] == \"user\" or loop_messages[-1]['role'] == \"function-response\" %}\n{{ '<start_of_turn>model\n' }}\n {%- else %}\n {{- raise_exception(\"For add_generation_prompt=True, the last message role must be 'user' or 'function-response'.\") }}\n {%- endif %}\n{%- endif %}\n",
|
2004 |
"clean_up_tokenization_spaces": false,
|
2005 |
"eos_token": "<eos>",
|
2006 |
"model_max_length": 1000000000000000019884624838656,
|