@@ -1615,23 +1615,37 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp
1615
1615
)
1616
1616
);
1617
1617
});
1618
-
1619
- auto not_end = builder.add_rule (" not-end" ,
1620
- " [^<] | \" <\" [^|] | \" <|\" [^e] | \" <|e\" [^n] | \" <|en\" [^d] | \" <|end\" [^|] | \" <|end|\" [^>]" );
1621
- auto analysis = builder.add_rule (" analysis" ,
1622
- " \" <|channel|>analysis<|message|>\" ( " + not_end + " )* \" <|end|>\" " );
1623
-
1624
- auto recipient_in_role = builder.add_rule (" recipient_in_role" ,
1625
- " (" + analysis + " )?" + " \" <|start|>assistant\" ? \" to=functions.\" ( " +
1626
- string_join (tool_rules_recipient_in_role, " | " ) + " )"
1627
- );
1628
1618
1629
1619
auto recipient_in_channel = builder.add_rule (" recipient_in_channel" ,
1630
1620
channel + " \" to=functions.\" ( " +
1631
1621
string_join (tool_rules_recipient_in_channel, " | " ) + " )"
1632
1622
);
1633
1623
1634
- builder.add_rule (" root" , recipient_in_role + " | " + recipient_in_channel);
1624
+ if (data.grammar_lazy ) {
1625
+ auto recipient_in_role = builder.add_rule (" recipient_in_role" ,
1626
+ " \" <|start|>assistant\" ? \" to=functions.\" ( " +
1627
+ string_join (tool_rules_recipient_in_role, " | " ) + " )"
1628
+ );
1629
+
1630
+ builder.add_rule (" root" , recipient_in_role + " | " + recipient_in_channel);
1631
+ } else {
1632
+ auto not_end = builder.add_rule (" not-end" ,
1633
+ " [^<] | \" <\" [^|] | \" <|\" [^e] | \" <|e\" [^n] | \" <|en\" [^d] | \" <|end\" [^|] | \" <|end|\" [^>]" );
1634
+ auto analysis = builder.add_rule (" analysis" ,
1635
+ " \" <|channel|>analysis<|message|>\" ( " + not_end + " )* \" <|end|>\" " );
1636
+ auto commentary = builder.add_rule (" commentary" ,
1637
+ " \" <|channel|>commentary<|message|>\" ( " + not_end + " )* \" <|end|>\" " );
1638
+
1639
+ auto recipient_in_role = builder.add_rule (" recipient_in_role" ,
1640
+ " \" to=functions.\" ( " + string_join (tool_rules_recipient_in_role, " | " ) + " )"
1641
+ );
1642
+
1643
+ builder.add_rule (" root" ,
1644
+ " ( " + analysis + " \" <|start|>assistant\" )? " +
1645
+ " ( " + commentary + " \" <|start|>assistant\" )? " +
1646
+ " ( " + recipient_in_role + " | " + recipient_in_channel + " )"
1647
+ );
1648
+ }
1635
1649
1636
1650
// Trigger on tool calls that appear in the commentary channel
1637
1651
data.grammar_triggers .push_back ({
0 commit comments