DiTy commited on
Commit
b16e16c
1 Parent(s): 6ad5274

Fix chat template with system message

Browse files
Files changed (2) hide show
  1. README.md +7 -7
  2. tokenizer_config.json +1 -1
README.md CHANGED
@@ -1,17 +1,17 @@
1
  ---
2
- library_name: transformers
3
- tags:
4
- - conversational
5
- - gemma2
6
- - function-calling
7
- - trl
8
- license: apache-2.0
9
  base_model: google/gemma-2-9b-it
10
  datasets:
11
  - DiTy/function-calling
12
  language:
13
  - en
 
 
14
  pipeline_tag: text-generation
 
 
 
 
 
15
  ---
16
 
17
  # DiTy/gemma-2-9b-it-function-calling-GGUF
 
1
  ---
 
 
 
 
 
 
 
2
  base_model: google/gemma-2-9b-it
3
  datasets:
4
  - DiTy/function-calling
5
  language:
6
  - en
7
+ library_name: transformers
8
+ license: apache-2.0
9
  pipeline_tag: text-generation
10
+ tags:
11
+ - conversational
12
+ - gemma2
13
+ - function-calling
14
+ - trl
15
  ---
16
 
17
  # DiTy/gemma-2-9b-it-function-calling-GGUF
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{{- \"<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,
 
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 (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{%- endfor %}\n\n\n{#- This block format full dialogue messages #}\n{{- bos_token }}\n{{- \"<start_of_turn>user\" + '\n' }}\n{%- if system_message != \"\" %}\n {{- system_message }}\n{%- endif %}\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 {%- elif system_message != \"\" %}\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\n",
2004
  "clean_up_tokenization_spaces": false,
2005
  "eos_token": "<eos>",
2006
  "model_max_length": 1000000000000000019884624838656,