CoolFace
Modelpublic

PYTHAI/Kimi-K2.7-Code-fork

sourceHugging Faceotherupdated 12d agoView on Hugging Face
0likes22downloads
chat_template.jinja62 linesDownload Raw Back to root
1{%- macro render_content(msg) -%}2    {%- set c = msg.get('content') -%}3    {%- if c is string -%}4      {{ c }}5    {%- elif c is not none -%}6      {% for content in c -%}7        {% if content['type'] == 'image' or content['type'] == 'image_url' -%}8          <|media_begin|>image<|media_content|><|media_pad|><|media_end|>9        {% elif content['type'] == 'video' or content['type']== 'video_url'-%}10          <|kimi_k25_video_placeholder|>11        {% else -%}12          {{ content['text'] }}13        {%- endif -%}14      {%- endfor -%}15    {%- endif -%}16{%- endmacro -%}17{% macro set_roles(message) -%}18  {%- set role_name =  message.get('name') or  message['role'] -%}19  {%- if message['role'] == 'user' -%}20    <|im_user|>{{role_name}}<|im_middle|>21  {%- elif message['role'] == 'assistant' -%}22    <|im_assistant|>{{role_name}}<|im_middle|>23  {%- else -%}24    <|im_system|>{{role_name}}<|im_middle|>25  {%- endif -%}26{%- endmacro -%}27{%- macro render_toolcalls(message) -%}28  <|tool_calls_section_begin|>29  {%- for tool_call in message['tool_calls'] -%}30    {%- set formatted_id = tool_call['id'] -%}31    <|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|>32  {%- endfor -%}33  <|tool_calls_section_end|>34{%- endmacro -%}35{%- if tools -%}36  {%- if tools_ts_str -%}37    <|im_system|>tool_declare<|im_middle|>{{ tools_ts_str }}<|im_end|>38  {%- else -%}39    <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>40  {%- endif -%}41{%- endif -%}42{%- for message in messages -%}43  {{set_roles(message)}}44  {%- if message['role'] == 'assistant' -%}45    {%- set rc = message.get('reasoning', message.get('reasoning_content', '')) -%}46    <think>{{rc}}</think>{{render_content(message)}}47    {%- if message.get('tool_calls') -%}48      {{render_toolcalls(message)}}49    {%- endif -%}50  {%- elif message['role'] == 'tool' -%}51    {%- set tool_call_id = message.tool_call_id -%}52    ## Return of {{ tool_call_id }}53{{render_content(message)}}54  {%- elif message['content'] is not none -%}55    {{render_content(message)}}56  {%- endif -%}57  <|im_end|>58{%- endfor -%}59{%- if add_generation_prompt -%}60  <|im_assistant|>assistant<|im_middle|><think>61{%- endif -%}62