@@ -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) {
@@ -1563,7 +1564,7 @@ static common_chat_msg common_chat_parse_hermes_2_pro(const std::string& input,
1563
1564
1564
1565
static common_chat_params common_chat_params_init_without_tools (const common_chat_template & tmpl, const struct templates_params & inputs) {
1565
1566
common_chat_params data;
1566
- data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt );
1567
+ data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt ,inputs. extra_context );
1567
1568
data.format = COMMON_CHAT_FORMAT_CONTENT_ONLY;
1568
1569
data.grammar_lazy = false ;
1569
1570
if (!inputs.json_schema .is_null ()) {
@@ -1593,6 +1594,13 @@ static common_chat_params common_chat_templates_apply_jinja(
1593
1594
params.extract_reasoning = inputs.extract_reasoning ;
1594
1595
params.tool_choice = inputs.tool_choice ;
1595
1596
params.grammar = inputs.grammar ;
1597
+
1598
+ for (auto el: inputs.chat_template_kwargs )
1599
+ {
1600
+ params.extra_context [el.first ] = json::parse (el.second );
1601
+ }
1602
+
1603
+
1596
1604
if (!inputs.json_schema .empty ()) {
1597
1605
params.json_schema = json::parse (inputs.json_schema );
1598
1606
}
0 commit comments