Guest User

dsv4flash.jinja

a guest
Jul 23rd, 2026
17
0
27 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. {%- if not add_generation_prompt is defined -%}
  2. {%- set add_generation_prompt = false -%}
  3. {%- endif -%}
  4. {%- if not thinking is defined -%}
  5. {%- if enable_thinking is defined -%}
  6. {%- set thinking = enable_thinking -%}
  7. {%- else -%}
  8. {%- set thinking = false -%}
  9. {%- endif -%}
  10. {%- endif -%}
  11. {%- set dsml_token = '|DSML|' -%}
  12. {%- set thinking_start_token = '<think>' -%}
  13. {%- set thinking_end_token = '</think>' -%}
  14. {%- set tools_header = '## Tools\n\nYou have access to a set of tools to help answer the user\'s question. You can invoke tools by writing a "<' + dsml_token + 'tool_calls>" block like the following:\n\n<' + dsml_token + 'tool_calls>\n<' + dsml_token + 'invoke name="$TOOL_NAME">\n<' + dsml_token + 'parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</' + dsml_token + 'parameter>\n...\n</' + dsml_token + 'invoke>\n<' + dsml_token + 'invoke name="$TOOL_NAME2">\n...\n</' + dsml_token + 'invoke>\n</' + dsml_token + 'tool_calls>\n\nString parameters should be specified as is and set `string="true"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string="false"`.\n\nIf thinking_mode is enabled (triggered by ' + thinking_start_token + '), you MUST output your complete reasoning inside ' + thinking_start_token + '...' + thinking_end_token + ' BEFORE any tool calls or final response.\n\nOtherwise, output directly after ' + thinking_end_token + ' with tool calls or final response.\n\n### Available Tool Schemas\n\n' -%}
  15. {%- set tools_footer = '\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.\n' -%}
  16. {%- set ns = namespace(system_prompt='', is_first_sp=true) -%}
  17. {%- for message in messages -%}
  18. {%- if message['role'] == 'system' -%}
  19. {%- if ns.is_first_sp -%}
  20. {%- set ns.system_prompt = ns.system_prompt + (message['content'] or '') -%}
  21. {%- set ns.is_first_sp = false -%}
  22. {%- else -%}
  23. {%- set ns.system_prompt = ns.system_prompt + '\n\n' + (message['content'] or '') -%}
  24. {%- endif -%}
  25. {%- endif -%}
  26. {%- endfor -%}
  27. {%- if tools is defined and tools -%}
  28. {%- set ts = namespace(schemas='') -%}
  29. {%- for tool in tools -%}
  30. {%- if tool['type'] == 'function' -%}
  31. {%- set ts.schemas = ts.schemas + (tool['function'] | tojson) + '\n' -%}
  32. {%- endif -%}
  33. {%- endfor -%}
  34. {%- if ns.system_prompt -%}
  35. {%- set ns.system_prompt = ns.system_prompt + '\n\n' + tools_header + ts.schemas + tools_footer -%}
  36. {%- else -%}
  37. {%- set ns.system_prompt = tools_header + ts.schemas + tools_footer -%}
  38. {%- endif -%}
  39. {%- endif -%}
  40. {{- bos_token -}}
  41. {{- ns.system_prompt -}}
  42. {%- set last_user_idx = namespace(value=-1) -%}
  43. {%- for message in messages -%}
  44. {%- if message['role'] == 'user' or message['role'] == 'developer' or message['role'] == 'tool' -%}
  45. {%- set last_user_idx.value = loop.index0 -%}
  46. {%- endif -%}
  47. {%- endfor -%}
  48. {%- set state = namespace(in_user=false) -%}
  49. {%- for message in messages -%}
  50. {%- if message['role'] == 'user' or message['role'] == 'developer' -%}
  51. {%- if state.in_user -%}
  52. {{- '\n\n' -}}
  53. {%- else -%}
  54. {{- '<|User|>' -}}
  55. {%- set state.in_user = true -%}
  56. {%- endif -%}
  57. {{- message['content'] or '' -}}
  58. {%- elif message['role'] == 'tool' -%}
  59. {%- if state.in_user -%}
  60. {{- '\n\n' -}}
  61. {%- else -%}
  62. {{- '<|User|>' -}}
  63. {%- set state.in_user = true -%}
  64. {%- endif -%}
  65. {{- '<tool_result>' + (message['content'] or '') + '</tool_result>' -}}
  66. {%- elif message['role'] == 'assistant' -%}
  67. {%- set state.in_user = false -%}
  68. {{- '<|Assistant|>' -}}
  69. {%- set is_after_last_user = loop.index0 > last_user_idx.value -%}
  70. {%- if is_after_last_user and thinking -%}
  71. {{- thinking_start_token -}}
  72. {%- if message['reasoning_content'] is defined and message['reasoning_content'] -%}
  73. {{- message['reasoning_content'] -}}
  74. {%- endif -%}
  75. {{- thinking_end_token -}}
  76. {%- else -%}
  77. {{- thinking_end_token -}}
  78. {%- endif -%}
  79. {%- if message['content'] is defined and message['content'] -%}
  80. {{- message['content'] -}}
  81. {%- endif -%}
  82. {%- if message['tool_calls'] -%}
  83. {{- '\n\n<' + dsml_token + 'tool_calls>\n' -}}
  84. {%- for tool in message['tool_calls'] -%}
  85. {%- set func = tool['function'] -%}
  86. {{- '<' + dsml_token + 'invoke name="' + func['name'] + '">\n' -}}
  87. {%- set args = func['arguments'] -%}
  88. {%- if args is string -%}
  89. {%- set args = args | from_json -%}
  90. {%- endif -%}
  91. {%- for key, val in args.items() -%}
  92. {%- if val is string -%}
  93. {{- '<' + dsml_token + 'parameter name="' + key + '" string="true">' + val + '</' + dsml_token + 'parameter>\n' -}}
  94. {%- else -%}
  95. {{- '<' + dsml_token + 'parameter name="' + key + '" string="false">' + (val | tojson) + '</' + dsml_token + 'parameter>\n' -}}
  96. {%- endif -%}
  97. {%- endfor -%}
  98. {{- '</' + dsml_token + 'invoke>\n' -}}
  99. {%- endfor -%}
  100. {{- '</' + dsml_token + 'tool_calls>' -}}
  101. {%- endif -%}
  102. {{- '<|end▁of▁sentence|>' -}}
  103. {%- endif -%}
  104. {%- endfor -%}
  105. {%- if add_generation_prompt -%}
  106. {{- '<|Assistant|>' -}}
  107. {%- if thinking -%}
  108. {{- thinking_start_token -}}
  109. {%- else -%}
  110. {{- thinking_end_token -}}
  111. {%- endif -%}
  112. {%- endif -%}
Add Comment
Please, Sign In to add comment