@@ -34,6 +34,7 @@ struct templates_params {
34
34
bool add_generation_prompt = true ;
35
35
bool extract_reasoning = true ;
36
36
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
37
+ json extra_context;
37
38
};
38
39
39
40
common_chat_tool_choice common_chat_tool_choice_parse_oaicompat (const std::string & tool_choice) {
@@ -1582,7 +1583,7 @@ static common_chat_msg common_chat_parse_hermes_2_pro(const std::string& input,
1582
1583
1583
1584
static common_chat_params common_chat_params_init_without_tools (const common_chat_template & tmpl, const struct templates_params & inputs) {
1584
1585
common_chat_params data;
1585
- data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt );
1586
+ data.prompt = apply (tmpl, inputs.messages , inputs.tools .empty () ? json () : inputs.tools , inputs.add_generation_prompt ,inputs. extra_context );
1586
1587
data.format = COMMON_CHAT_FORMAT_CONTENT_ONLY;
1587
1588
data.grammar_lazy = false ;
1588
1589
if (!inputs.json_schema .is_null ()) {
@@ -1613,6 +1614,12 @@ static common_chat_params common_chat_templates_apply_jinja(
1613
1614
params.tool_choice = inputs.tool_choice ;
1614
1615
params.grammar = inputs.grammar ;
1615
1616
params.now = inputs.now ;
1617
+
1618
+ for (auto el: inputs.chat_template_kwargs )
1619
+ {
1620
+ params.extra_context [el.first ] = json::parse (el.second );
1621
+ }
1622
+
1616
1623
if (!inputs.json_schema .empty ()) {
1617
1624
params.json_schema = json::parse (inputs.json_schema );
1618
1625
}
0 commit comments