Skip to content

Commit a40710e

Browse files
authored
Add upper filter (to support inclusionAI/Ling-Coder-lite) (google#58)
* Add upper filter * Test inclusionAI/Ling-Coder-lite template
1 parent cbbd303 commit a40710e

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

include/minja/minja.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,14 +2618,18 @@ inline std::shared_ptr<Context> Context::builtins() {
26182618
auto & text = args.at("text");
26192619
return text.is_null() ? text : Value(strip(text.get<std::string>()));
26202620
}));
2621-
globals.set("lower", simple_function("lower", { "text" }, [](const std::shared_ptr<Context> &, Value & args) {
2622-
auto text = args.at("text");
2623-
if (text.is_null()) return text;
2624-
std::string res;
2625-
auto str = text.get<std::string>();
2626-
std::transform(str.begin(), str.end(), std::back_inserter(res), ::tolower);
2627-
return Value(res);
2628-
}));
2621+
auto char_transform_function = [](const std::string & name, const std::function<char(char)> & fn) {
2622+
return simple_function(name, { "text" }, [=](const std::shared_ptr<Context> &, Value & args) {
2623+
auto text = args.at("text");
2624+
if (text.is_null()) return text;
2625+
std::string res;
2626+
auto str = text.get<std::string>();
2627+
std::transform(str.begin(), str.end(), std::back_inserter(res), fn);
2628+
return Value(res);
2629+
});
2630+
};
2631+
globals.set("lower", char_transform_function("lower", ::tolower));
2632+
globals.set("upper", char_transform_function("upper", ::toupper));
26292633
globals.set("default", Value::callable([=](const std::shared_ptr<Context> &, ArgumentsValue & args) {
26302634
args.expectArgs("default", {2, 3}, {0, 1});
26312635
auto & value = args.args[0];

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ set(MODEL_IDS
137137
huihui-ai/Qwen2.5-14B-Instruct-1M-abliterated
138138
ibm-granite/granite-3.1-8b-instruct
139139
Ihor/Text2Graph-R1-Qwen2.5-0.5b
140+
inclusionAI/Ling-Coder-lite
140141
indischepartij/MiniCPM-3B-OpenHermes-2.5-v2
141142
Infinigence/Megrez-3B-Instruct
142143
inflatebot/MN-12B-Mag-Mell-R1

tests/test-syntax.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ TEST(SyntaxTest, SimpleCases) {
8888
EXPECT_EQ(
8989
"ok",
9090
render("{# Hey\nHo #}{#- Multiline...\nComments! -#}{{ 'ok' }}{# yo #}", {}, {}));
91-
91+
9292
EXPECT_EQ(
9393
" b",
9494
render(R"( {% set _ = 1 %} {% set _ = 2 %}b)", {}, lstrip_trim_blocks));
@@ -130,6 +130,9 @@ TEST(SyntaxTest, SimpleCases) {
130130
EXPECT_EQ(
131131
"abc",
132132
render("{{ 'AbC' | lower }}", {}, {}));
133+
EXPECT_EQ(
134+
"ME",
135+
render("{{ 'me' | upper }}", {}, {}));
133136
EXPECT_EQ(
134137
"the default1",
135138
render("{{ foo | default('the default') }}{{ 1 | default('nope') }}", {}, {}));

0 commit comments

Comments
 (0)