LHC88 commited on
Commit
f13dda8
·
1 Parent(s): 23dd25f

updated chat_teplate. working openai ompatible parallel tool calls

Browse files
Files changed (1) hide show
  1. tokenizer_config.json +1 -1
tokenizer_config.json CHANGED
@@ -9007,7 +9007,7 @@
9007
  "<SPECIAL_999>"
9008
  ],
9009
  "bos_token": "<s>",
9010
- "chat_template": "{%- set default_system_message = 'You are AI.' -%}{{ bos_token }}\n{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set system_message = default_system_message %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{% if tools is not none and tools|length > 0 %}\n {%- set tool_str = tools|tojson -%}\n {%- set tool_instructions =\n '\\nYou can use multiple tools by responding with a JSON array like this: '\n ~ '[{\"name\": \"tool1\", \"parameters\": {\"p1\": \"val1\" }}, {\"name\": \"tool2\", \"parameters\": {\"p2\": \"val2\", \"p3\": 23}}] '\n ~ ' Your available tools are: '\n ~ '[AVAILABLE_TOOLS]'\n ~ tool_str\n ~ '[/AVAILABLE_TOOLS]\\n'\n -%}\n {%- set system_message = system_message ~ tool_instructions -%}\n{% endif %}\n{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }}\n{%- for message in loop_messages %}\n\n {%- if message['role'] == 'user' %}\n {{- '[INST]' + message['content'] + '[/INST]' }}\n\n {%- elif message['role'] == 'system' %}\n {{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }}\n\n {%- elif message['role'] == 'assistant' %}\n {%- if message.tool_calls is defined and message.tool_calls is not none -%}\n [TOOL_CALLS]\n {{ {\"tool_calls\": message.tool_calls}|tojson }}\n [/TOOL_CALLS]\n {%- elif message['content'] is defined and message['content'] is not none -%}\n {{- message['content'] + eos_token }}\n {%- endif %}\n\n {%- elif message['role'] == 'tool_calls' or message.tool_calls is defined %}\n {%- if message.tool_calls is defined %}\n {%- set tool_calls = message.tool_calls %}\n {%- else %}\n {%- set tool_calls = message.content %}\n {%- endif %}\n {{- \"[TOOL_CALLS] [\" }}\n {%- for tool_call in tool_calls %}\n {%- set out = tool_call.function|tojson %}\n {{- out[:-1] }}\n {%- if not tool_call.id is defined or tool_call.id|length < 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length >= 9!\" + tool_call.id) }}\n {%- endif %}\n {{- ', \"id\": \"' + tool_call.id + '\"}' }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- else %}\n {{- \"]\" + eos_token }}\n {%- endif %}\n {%- endfor %}\n\n {%- elif message[\"role\"] == \"tool\" %}\n {%- if message.content is defined and message.content.content is defined %}\n {%- set content = message.content.content %}\n {%- else %}\n {%- set content = message.content %}\n {%- endif %}\n {{- '[TOOL_RESULTS] {\"content\": ' + content|string + \", \" }}\n {%- if not message.tool_call_id is defined or message.tool_call_id|length < 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length >= 9!\" + message.tool_call_id) }}\n {%- endif %}\n {{- '\"call_id\": \"' + message.tool_call_id + '\"}[/TOOL_RESULTS]' }}\n\n {%- elif message[\"role\"] == \"assistant\" and message.content is defined and message.content is not none %}\n {{- message[\"content\"] + eos_token }}\n\n {%- elif message['role'] == 'tool' -%}\n [TOOL_CONTENT]\n {{ {\"tool_call_id\": message['tool_call_id'], \"tool_call\": message['content']}|tojson }}\n [/TOOL_CONTENT]\n\n {%- else %}\n {{- raise_exception('Only user, system, assistant, tool_call & tool roles are supported!') }}\n {%- endif %}\n{%- endfor %}\n",
9011
  "clean_up_tokenization_spaces": false,
9012
  "eos_token": "</s>",
9013
  "extra_special_tokens": {},
 
9007
  "<SPECIAL_999>"
9008
  ],
9009
  "bos_token": "<s>",
9010
+ "chat_template": "{%- set default_system_message = 'You are AI.' -%}{{ bos_token }}\n{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set system_message = default_system_message %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{%- set user_messages = loop_messages | selectattr(\"role\", \"equalto\", \"user\") | list %}\n\n{% if tools is not none and tools|length > 0 %}\n {%- set tool_instructions =\n 'Use the available tools appropriately to fulfill your instructions and achieve your goals by returning a JSON array pre-pended with `[TOOL_CALLS]` like this: '\n ~ '[TOOL_CALLS][{\"name\": \"tool1\", \"arguments\": {\"p1\": \"val1\"}}, {\"name\": \"tool2\", \"arguments\": {\"p2\": \"val2\", \"p3\": 23}}] '\n ~ 'Your available tools are: '\n -%}\n\n {# Build out the tool list however you want #}\n {%- set tool_instructions = tool_instructions ~ '[AVAILABLE_TOOLS]' %}\n {%- for tool in tools %}\n {%- if not loop.first %}, {% endif %}\n {%- set tool_definition = tool.function %}\n {%- set tool_instructions = tool_instructions ~ '{\"type\":\"function\",\"function\":{' %}\n {%- for key, val in tool_definition.items() if key != \"return\" %}\n {%- if not loop.first %}, {% endif %}\n {%- if val is string %}\n {%- set tool_instructions = tool_instructions ~ '\"' ~ key ~ '\":\"' ~ val ~ '\"' %}\n {%- else %}\n {%- set tool_instructions = tool_instructions ~ '\"' ~ key ~ '\":' ~ (val|tojson) %}\n {%- endif %}\n {%- endfor %}\n {%- set tool_instructions = tool_instructions ~ '}}' %}\n {%- endfor %}\n {%- set tool_instructions = tool_instructions ~ '[/AVAILABLE_TOOLS]\\n' %}\n\n {%- set system_message = system_message ~ tool_instructions -%}\n{% endif %}\n{{ '[SYSTEM_PROMPT]' ~ system_message ~ '[/SYSTEM_PROMPT]' }}\n\n{%- for message in loop_messages %}\n {%- if message['role'] == 'user' %}\n {{- '[INST]' + message['content'] + '[/INST]' }}\n\n {%- elif message['role'] == 'system' %}\n {{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }}\n\n {%- elif message['role'] == 'assistant' %}\n {%- if message.tool_calls is defined and message.tool_calls is not none and message.tool_calls|length > 0 -%}\n [TOOL_CALLS][{{ message.tool_calls|tojson }}]\n {%- elif message['content'] is defined and message['content'] is not none -%}\n {{- message['content'] + eos_token }}\n {%- endif %}\n\n {%- elif message['role'] == 'tool_calls' or message.tool_calls is defined %}\n {%- if message.tool_calls is defined %}\n {%- set tool_calls = message.tool_calls %}\n {%- else %}\n {%- set tool_calls = message.content %}\n {%- endif %}\n {{- \"[TOOL_CALLS] [\" }}\n {%- for tool_call in tool_calls %}\n {%- set out = tool_call.function|tojson %}\n {{- out[:-1] }}\n {%- if not tool_call.id is defined or tool_call.id|length < 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length >= 9!\" + tool_call.id) }}\n {%- endif %}\n {{- ', \"id\": \"' + tool_call.id + '\"}' }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- else %}\n {{- \"]\" + eos_token }}\n {%- endif %}\n {%- endfor %}\n\n {%- elif message[\"role\"] == \"tool\" %}\n {%- if message.content is defined and message.content.content is defined %}\n {%- set content = message.content.content %}\n {%- else %}\n {%- set content = message.content %}\n {%- endif %}\n {{- '[TOOL_RESULTS] {\"content\": ' + content|string + \", \" }}\n {%- if not message.tool_call_id is defined or message.tool_call_id|length < 9 %}\n {{- raise_exception(\"Tool call IDs should be alphanumeric strings with length >= 9!\" + message.tool_call_id) }}\n {%- endif %}\n {{- '\"call_id\": \"' + message.tool_call_id + '\"}[/TOOL_RESULTS]' }}\n\n {%- elif message[\"role\"] == \"assistant\" and message.content is defined and message.content is not none %}\n {{- message[\"content\"] + eos_token }}\n\n {%- elif message['role'] == 'tool' -%}\n [TOOL_CONTENT]\n {{ {\"tool_call_id\": message['tool_call_id'], \"tool_call\": message['content']}|tojson }}\n [/TOOL_CONTENT]\n\n {%- else %}\n {{- raise_exception('Only user, system, assistant, tool_call & tool roles are supported!') }}\n {%- endif %}\n{%- endfor %}\n",
9011
  "clean_up_tokenization_spaces": false,
9012
  "eos_token": "</s>",
9013
  "extra_special_tokens": {},