MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / test_template_cpp

Function test_template_cpp

tests/test-jinja.cpp:1950–1981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1948}
1949
1950static void test_template_cpp(testing & t, const std::string & name, const std::string & tmpl, const json & vars, const std::string & expect) {
1951 t.test(name, [&tmpl, &vars, &expect](testing & t) {
1952 jinja::lexer lexer;
1953 auto lexer_res = lexer.tokenize(tmpl);
1954
1955 jinja::program ast = jinja::parse_from_tokens(lexer_res);
1956
1957 jinja::context ctx(tmpl);
1958 jinja::global_from_json(ctx, vars, true);
1959
1960 jinja::runtime runtime(ctx);
1961
1962 try {
1963 const jinja::value results = runtime.execute(ast);
1964 auto parts = runtime.gather_string_parts(results);
1965
1966 std::string rendered;
1967 for (const auto & part : parts->as_string().parts) {
1968 rendered += part.val;
1969 }
1970
1971 if (!t.assert_true("Template render mismatch", expect == rendered)) {
1972 t.log("Template: " + json(tmpl).dump());
1973 t.log("Expected: " + json(expect).dump());
1974 t.log("Actual : " + json(rendered).dump());
1975 }
1976 } catch (const jinja::not_implemented_exception & e) {
1977 // TODO @ngxson : remove this when the test framework supports skipping tests
1978 t.log("Skipped: " + std::string(e.what()));
1979 }
1980 });
1981}
1982
1983// keep this in-sync with https://github.com/huggingface/transformers/blob/main/src/transformers/utils/chat_template_utils.py
1984// note: we use SandboxedEnvironment instead of ImmutableSandboxedEnvironment to allow usage of in-place array methods like append() and pop()

Callers 1

test_templateFunction · 0.85

Calls 12

parse_from_tokensFunction · 0.85
global_from_jsonFunction · 0.85
stringClass · 0.85
gather_string_partsMethod · 0.80
assert_trueMethod · 0.80
dumpMethod · 0.80
testMethod · 0.45
tokenizeMethod · 0.45
executeMethod · 0.45
as_stringMethod · 0.45
logMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected