Support for structured output

#7
by s-yanev - opened
Files changed (1) hide show
  1. chat_template.jinja +24 -2
chat_template.jinja CHANGED
@@ -1,5 +1,5 @@
1
  [gMASK]<sop>
2
- {%- if tools -%}
3
  <|system|>
4
  # Tools
5
 
@@ -78,7 +78,29 @@ For each function call, output the function name and arguments within the follow
78
  <tool_response>{{ tr.output if tr.output is defined else tr }}</tool_response>{% endfor -%}
79
  {% endif -%}
80
  {%- elif m.role == 'system' -%}
81
- <|system|>{{ visible_text(m.content) }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  {%- endif -%}
83
  {%- endfor -%}
84
  {%- if add_generation_prompt -%}
 
1
  [gMASK]<sop>
2
+ {%- if tools and not (structured_output is defined and structured_output.enabled) -%}
3
  <|system|>
4
  # Tools
5
 
 
78
  <tool_response>{{ tr.output if tr.output is defined else tr }}</tool_response>{% endfor -%}
79
  {% endif -%}
80
  {%- elif m.role == 'system' -%}
81
+ <|system|>
82
+ {%- if structured_output is defined and structured_output.enabled and loop.index0 == 0 -%}
83
+ # Structured Output
84
+
85
+ You are a structured output engine.
86
+
87
+ Output ONLY valid JSON. Follow the JSON schema exactly.
88
+
89
+ Do not output:
90
+ - markdown
91
+ - prose
92
+ - explanations
93
+ - XML
94
+ - comments
95
+ - chain-of-thought
96
+
97
+ JSON Schema:
98
+ {{ structured_output.schema | tojson(indent=2) }}
99
+
100
+ {{ visible_text(m.content) }}
101
+ {%- else -%}
102
+ {{ visible_text(m.content) }}
103
+ {%- endif -%}
104
  {%- endif -%}
105
  {%- endfor -%}
106
  {%- if add_generation_prompt -%}