caps : recheck typed content if template checks for string (#28511)
This commit is contained in:
@@ -117,6 +117,7 @@ caps caps_get(jinja::program & prog) {
|
|||||||
|
|
||||||
JJ_DEBUG("%s\n", ">>> Running capability check: typed content");
|
JJ_DEBUG("%s\n", ">>> Running capability check: typed content");
|
||||||
|
|
||||||
|
bool checks_for_string = false;
|
||||||
static const std::string content_marker = "STRING_MARKER";
|
static const std::string content_marker = "STRING_MARKER";
|
||||||
|
|
||||||
// case: typed content support
|
// case: typed content support
|
||||||
@@ -136,6 +137,10 @@ caps caps_get(jinja::program & prog) {
|
|||||||
[&](context &, bool success, value & messages, value &, const std::string & rendered) {
|
[&](context &, bool success, value & messages, value &, const std::string & rendered) {
|
||||||
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, "test_is_string")) {
|
||||||
|
// checked if content is string
|
||||||
|
checks_for_string = true;
|
||||||
|
}
|
||||||
bool used_as_array = has_op(content, "selectattr") || has_op(content, "array_access");
|
bool used_as_array = has_op(content, "selectattr") || has_op(content, "array_access");
|
||||||
if (used_as_array) {
|
if (used_as_array) {
|
||||||
// accessed as an array
|
// accessed as an array
|
||||||
@@ -151,6 +156,33 @@ caps caps_get(jinja::program & prog) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (checks_for_string) {
|
||||||
|
caps_try_execute(
|
||||||
|
prog,
|
||||||
|
[&]() {
|
||||||
|
// messages
|
||||||
|
return json::array({
|
||||||
|
{
|
||||||
|
{"role", "user"},
|
||||||
|
{"content", json::array({
|
||||||
|
})}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
nullptr, // ctx_fn
|
||||||
|
nullptr, // tools_fn
|
||||||
|
[&](context &, bool success, value & messages, value &, const std::string &) {
|
||||||
|
auto & content = messages->at(0)->at("content");
|
||||||
|
caps_print_stats(content, "messages[0].content");
|
||||||
|
bool used_as_array = has_op(content, "selectattr") || has_op(content, "array_access");
|
||||||
|
if (used_as_array && success) {
|
||||||
|
// accessed as an array
|
||||||
|
result.supports_typed_content = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
JJ_DEBUG("%s\n", ">>> Running capability check: system prompt");
|
JJ_DEBUG("%s\n", ">>> Running capability check: system prompt");
|
||||||
|
|
||||||
// case: system prompt support
|
// case: system prompt support
|
||||||
|
|||||||
@@ -412,12 +412,18 @@ value test_expression::execute_impl(context & ctx) {
|
|||||||
throw std::runtime_error("Invalid test expression");
|
throw std::runtime_error("Invalid test expression");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = builtins.find("test_is_" + test_id);
|
const std::string test_name = "test_is_" + test_id;
|
||||||
JJ_DEBUG("Test expression %s '%s' %s (using function 'test_is_%s')", operand->type().c_str(), test_id.c_str(), negate ? "(negate)" : "", test_id.c_str());
|
auto it = builtins.find(test_name);
|
||||||
|
JJ_DEBUG("Test expression %s '%s' %s (using function '%s')", operand->type().c_str(), test_id.c_str(), negate ? "(negate)" : "", test_name.c_str());
|
||||||
if (it == builtins.end()) {
|
if (it == builtins.end()) {
|
||||||
throw std::runtime_error("Unknown test '" + test_id + "'");
|
throw std::runtime_error("Unknown test '" + test_id + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.is_get_stats) {
|
||||||
|
value_t::stats_t::mark_used(input);
|
||||||
|
input->stats.ops.insert(test_name);
|
||||||
|
}
|
||||||
|
|
||||||
auto res = it->second(args);
|
auto res = it->second(args);
|
||||||
|
|
||||||
if (negate) {
|
if (negate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user