Another fix for Kimi-K2 chat template.

This commit is contained in:
hksdpc255 2025-11-21 14:29:51 +11:00 committed by GitHub
parent f519483d52
commit e0eda17d42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 12 deletions

View File

@ -36,12 +36,8 @@
{%- if message['role'] == 'assistant' and message.get('tool_calls') -%} {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
{{render_content(message)}}<|tool_calls_section_begin|> {{render_content(message)}}<|tool_calls_section_begin|>
{%- for tool_call in message['tool_calls'] -%} {%- for tool_call in message['tool_calls'] -%}
{%- if tool_call['id'] is defined -%} {%- set formatted_id = 'functions.' + tool_call['function']['name'] + ':' + (tool_call_counter.value | string) -%}
{%- set formatted_id = tool_call['id'] -%} {%- set tool_call_counter.value = tool_call_counter.value + 1 -%}
{%- else -%}
{%- set formatted_id = 'functions.' + tool_call['function']['name'] + ':' + (tool_call_counter.value | string) -%}
{%- set tool_call_counter.value = tool_call_counter.value + 1 -%}
{%- endif -%}
{%- set _ = tool_response_queue.ids.append(formatted_id) -%} {%- set _ = tool_response_queue.ids.append(formatted_id) -%}
<|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|> <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
{%- endfor -%} {%- endfor -%}

View File

@ -30,12 +30,8 @@
{%- macro render_toolcalls(message) -%} {%- macro render_toolcalls(message) -%}
<|tool_calls_section_begin|> <|tool_calls_section_begin|>
{%- for tool_call in message['tool_calls'] -%} {%- for tool_call in message['tool_calls'] -%}
{%- if tool_call['id'] is defined -%} {%- set formatted_id = 'functions.' + tool_call['function']['name'] + ':' + (tool_call_counter.value | string) -%}
{%- set formatted_id = tool_call['id'] -%} {%- set tool_call_counter.value = tool_call_counter.value + 1 -%}
{%- else -%}
{%- set formatted_id = 'functions.' + tool_call['function']['name'] + ':' + (tool_call_counter.value | string) -%}
{%- set tool_call_counter.value = tool_call_counter.value + 1 -%}
{%- endif -%}
{%- set _ = tool_response_queue.ids.append(formatted_id) -%} {%- set _ = tool_response_queue.ids.append(formatted_id) -%}
<|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|> <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
{%- endfor -%} {%- endfor -%}