chatglm.jinja 629 B

123456789101112131415161718
  1. {%- set counter = namespace(index=0) -%}
  2. {%- for message in messages -%}
  3. {%- if message['role'] == 'user' -%}
  4. {{- '[Round ' + counter.index|string + ']\n问:' + message['content'] -}}
  5. {%- set counter.index = counter.index + 1 -%}
  6. {%- endif -%}
  7. {%- if message['role'] == 'assistant' -%}
  8. {{- '\n答:' + message['content'] -}}
  9. {%- if (loop.last and add_generation_prompt) or not loop.last -%}
  10. {{- '\n' -}}
  11. {%- endif -%}
  12. {%- endif -%}
  13. {%- endfor -%}
  14. {%- if add_generation_prompt and messages[-1]['role'] != 'assistant' -%}
  15. {{- '\n答:' -}}
  16. {%- endif -%}