Merge e932375e56 into 8a98ba4582
This commit is contained in:
commit
1f410a2dc0
|
|
@ -3020,7 +3020,19 @@ static common_chat_params common_chat_templates_apply_jinja(
|
||||||
: *tmpls->template_default;
|
: *tmpls->template_default;
|
||||||
const auto & src = tmpl.source();
|
const auto & src = tmpl.source();
|
||||||
const auto & caps = tmpl.original_caps();
|
const auto & caps = tmpl.original_caps();
|
||||||
params.messages = common_chat_msgs_to_json_oaicompat(inputs.messages, /* concat_text= */ !tmpl.original_caps().requires_typed_content);
|
params.messages = common_chat_msgs_to_json_oaicompat(inputs.messages, /* concat_text= */ !caps.requires_typed_content);
|
||||||
|
|
||||||
|
// If template requires typed content, ensure all string contents are converted into json arrays
|
||||||
|
if (caps.requires_typed_content) {
|
||||||
|
for (auto & msg : params.messages) {
|
||||||
|
if (msg.contains("content") && msg.at("content").is_string()) {
|
||||||
|
const auto text = msg.at("content").get<std::string>();
|
||||||
|
json content_arr = json::array();
|
||||||
|
content_arr.push_back(json::object({ {"type", "text"}, {"text", text} }));
|
||||||
|
msg["content"] = std::move(content_arr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
params.add_generation_prompt = inputs.add_generation_prompt;
|
params.add_generation_prompt = inputs.add_generation_prompt;
|
||||||
params.tool_choice = inputs.tool_choice;
|
params.tool_choice = inputs.tool_choice;
|
||||||
params.reasoning_format = inputs.reasoning_format;
|
params.reasoning_format = inputs.reasoning_format;
|
||||||
|
|
|
||||||
|
|
@ -105,13 +105,19 @@ caps caps_get(jinja::program & prog) {
|
||||||
// tools
|
// tools
|
||||||
return json{nullptr};
|
return json{nullptr};
|
||||||
},
|
},
|
||||||
[&](bool, value & messages, value &) {
|
[&](bool success, value & messages, value &) {
|
||||||
auto & content = messages->at(0)->at("content");
|
auto & content = messages->at(0)->at("content");
|
||||||
caps_print_stats(content, "messages[0].content");
|
caps_print_stats(content, "messages[0].content");
|
||||||
if (has_op(content, "selectattr") || has_op(content, "array_access")) {
|
if (has_op(content, "selectattr") || has_op(content, "array_access")) {
|
||||||
// accessed as an array
|
// accessed as an array
|
||||||
result.requires_typed_content = true;
|
result.requires_typed_content = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the template uses content and fails with a string, it likely expects an array
|
||||||
|
if (!success && content->stats.used) {
|
||||||
|
JJ_DEBUG("%s", "Template failed with string content, likely expects typed content array");
|
||||||
|
result.requires_typed_content = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue