Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/minja/minja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,13 @@ static std::string strip(const std::string & s) {
return s.substr(start, end - start + 1);
}

static std::string capitalize(const std::string & s) {
if (s.empty()) return s;
auto result = s;
result[0] = std::toupper(result[0]);
return result;
}

static std::string html_escape(const std::string & s) {
std::string result;
result.reserve(s.size());
Expand Down Expand Up @@ -1462,6 +1469,9 @@ class MethodCallExpr : public Expression {
if (method->get_name() == "strip") {
vargs.expectArgs("strip method", {0, 0}, {0, 0});
return Value(strip(str));
} else if (method->get_name() == "capitalize") {
vargs.expectArgs("capitalize method", {0, 0}, {0, 0});
return Value(capitalize(str));
} else if (method->get_name() == "endswith") {
vargs.expectArgs("endswith method", {1, 1}, {0, 0});
auto suffix = vargs.args[0].get<std::string>();
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(MODEL_IDS
databricks/dbrx-instruct # Gated
google/gemma-2-2b-it # Gated
google/gemma-7b-it # Gated
BEE-spoke-data/tFINE-900m-instruct-orpo
MiniMaxAI/MiniMax-Text-01
indischepartij/MiniCPM-3B-OpenHermes-2.5-v2
mattshumer/Reflection-Llama-3.1-70B
Expand Down
4 changes: 4 additions & 0 deletions tests/test-syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ TEST(SyntaxTest, SimpleCases) {
return testing::Throws<std::runtime_error>(Property(&std::runtime_error::what, testing::HasSubstr(expected_substr)));
};

EXPECT_EQ(
"Ok",
render("{{ 'ok'.capitalize() }}", {}, {}));

EXPECT_EQ(
"ok",
render("{# Hey\nHo #}{#- Multiline...\nComments! -#}{{ 'ok' }}{# yo #}", {}, {}));
Expand Down