MCPcopy Index your code
hub / github.com/appdevforall/CodeOnTheGo / match_string

Function match_string

subprojects/llama.cpp/tests/test-chat.cpp:122–142  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 1

test_templatesFunction · 0.70

Calls 5

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

Tested by

no test coverage detected