@@ -24,6 +24,7 @@ struct templates_params {
24
24
std::string grammar;
25
25
bool add_generation_prompt = true ;
26
26
bool extract_reasoning = true ;
27
+ json extra_context;
27
28
};
28
29
29
30
common_chat_tool_choice common_chat_tool_choice_parse_oaicompat (const std::string & tool_choice) {
@@ -1561,7 +1562,7 @@ static common_chat_msg common_chat_parse_hermes_2_pro(const std::string& input,
1561
1562
1562
1563
static common_chat_params common_chat_params_init_without_tools (const common_chat_template & tmpl, const struct templates_params & inputs) {
1563
1564
common_chat_params data;
1564
- data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt );
1565
+ data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt ,inputs. extra_context );
1565
1566
data.format = COMMON_CHAT_FORMAT_CONTENT_ONLY;
1566
1567
data.grammar_lazy = false ;
1567
1568
if (!inputs.json_schema .is_null ()) {
@@ -1591,6 +1592,13 @@ static common_chat_params common_chat_templates_apply_jinja(
1591
1592
params.extract_reasoning = inputs.extract_reasoning ;
1592
1593
params.tool_choice = inputs.tool_choice ;
1593
1594
params.grammar = inputs.grammar ;
1595
+
1596
+ for (auto el: inputs.chat_template_kwargs )
1597
+ {
1598
+ params.extra_context [el.first ] = json::parse (el.second );
1599
+ }
1600
+
1601
+
1594
1602
if (!inputs.json_schema .empty ()) {
1595
1603
params.json_schema = json::parse (inputs.json_schema );
1596
1604
}
0 commit comments