Guest User

Untitled

a guest
Aug 30th, 2025
12
0
1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | Source Code | 0 0
  1. [gMASK]<sop>
  2. {%- if tools -%}
  3. <|system|>
  4. # Tools
  5.  
  6. You have access to the following tools:
  7.  
  8. <tools>
  9. {% for tool in tools %}
  10. {{ tool | tojson(ensure_ascii=False) }}
  11. {% endfor %}
  12. </tools>
  13.  
  14. When you need to use a tool, respond with ONLY the JSON tool call in this format:
  15. {
  16. "type": "tool_use",
  17. "name": "function_name",
  18. "input": {
  19. "param": "value"
  20. }
  21. }
  22.  
  23. For multiple parallel tool calls, output multiple JSON objects separated by newlines.
  24. {%- endif -%}
  25.  
  26. {%- macro visible_text(content) -%}
  27. {%- if content is string -%}
  28. {{- content }}
  29. {%- elif content is iterable and content is not mapping -%}
  30. {%- for item in content -%}
  31. {%- if item is mapping and item.type == 'text' -%}
  32. {{- item.text }}
  33. {%- elif item is string -%}
  34. {{- item }}
  35. {%- endif -%}
  36. {%- endfor -%}
  37. {%- else -%}
  38. {{- content }}
  39. {%- endif -%}
  40. {%- endmacro -%}
  41.  
  42. {%- set ns = namespace(last_user_index=-1) %}
  43. {%- for m in messages %}
  44. {%- if m.role == 'user' %}
  45. {% set ns.last_user_index = loop.index0 -%}
  46. {%- endif %}
  47. {%- endfor %}
  48.  
  49. {% for m in messages %}
  50. {%- if m.role == 'user' -%}
  51. <|user|>
  52. {{ visible_text(m.content) }}
  53. {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not visible_text(m.content).endswith("/nothink")) else '' -}}
  54.  
  55. {%- elif m.role == 'assistant' -%}
  56. <|assistant|>
  57. {%- set reasoning_content = '' %}
  58. {%- set content = visible_text(m.content) %}
  59.  
  60. {%- if m.reasoning_content is string %}
  61. {%- set reasoning_content = m.reasoning_content %}
  62. {%- else %}
  63. {%- if '</think>' in content %}
  64. {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
  65. {%- set content = content.split('</think>')[-1].lstrip('\n') %}
  66. {%- endif %}
  67. {%- endif %}
  68.  
  69. {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
  70. {{ '\n<think>' + reasoning_content.strip() + '</think>' }}
  71. {%- else -%}
  72. {{ '\n<think></think>' }}
  73. {%- endif -%}
  74.  
  75. {%- if content.strip() -%}
  76. {{ '\n' + content.strip() }}
  77. {%- endif -%}
  78.  
  79. {%- if m.tool_calls -%}
  80. {%- for tc in m.tool_calls -%}
  81. {%- if tc.function -%}
  82. {%- set tc = tc.function -%}
  83. {%- endif %}
  84.  
  85. {
  86. "type": "tool_use",
  87. "name": "{{ tc.name }}",
  88. "input": {{ tc.arguments | tojson(ensure_ascii=False) }}
  89. }
  90. {%- endfor -%}
  91. {%- endif %}
  92.  
  93. {%- elif m.role == 'tool' -%}
  94. {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
  95.  
  96. <|observation|>
  97. {%- endif %}
  98. {%- if m.content is string %}
  99. {{ m.content }}
  100. {%- elif m.content is iterable %}
  101. {%- for tr in m.content %}
  102. {{ tr.output if tr.output is defined else tr }}
  103. {%- endfor %}
  104. {%- else %}
  105. {{ m.content }}
  106. {%- endif %}
  107.  
  108. {%- elif m.role == 'system' -%}
  109. <|system|>
  110. {{ visible_text(m.content) }}
  111.  
  112. {%- endif -%}
  113. {%- endfor -%}
  114.  
  115. {%- if add_generation_prompt -%}
  116. <|assistant|>{{- '\n<think></think>' if (enable_thinking is defined and not enable_thinking) else '' -}}
  117. {%- endif -%}
Advertisement
Add Comment
Please, Sign In to add comment