MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / match_string

Function match_string

smallthinker/tests/test-chat.cpp:117–137  ·  view source on GitHub ↗

TODO: extract to common helper (copied from test-grammar-integration.cpp)

Source from the content-addressed store, hash-verified

115
116// TODO: extract to common helper (copied from test-grammar-integration.cpp)
117static bool match_string(const std::string & input, llama_grammar * grammar) {
118 const auto cpts = unicode_cpts_from_utf8(input);
119
120 auto & stacks_cur = llama_grammar_get_stacks(grammar);
121
122 for (const auto & cpt : cpts) {
123 llama_grammar_accept(grammar, cpt);
124
125 if (stacks_cur.empty()) {
126 // no stacks means that the grammar failed to match at this point
127 return false;
128 }
129 }
130
131 if (std::any_of(stacks_cur.begin(), stacks_cur.end(), [](const auto & stack) { return stack.empty(); })) {
132 // An empty stack means that the grammar has been completed
133 return true;
134 }
135
136 return false;
137}
138
139static std::string renormalize_json(const std::string & json_str) {
140 try {

Callers 1

test_templatesFunction · 0.70

Calls 5

unicode_cpts_from_utf8Function · 0.85
llama_grammar_acceptFunction · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected