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

Function find_partial_stop_string

examples/server/server.cpp:238–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238static size_t find_partial_stop_string(const std::string &stop,
239 const std::string &text)
240{
241 if (!text.empty() && !stop.empty())
242 {
243 const char text_last_char = text.back();
244 for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--)
245 {
246 if (stop[char_index] == text_last_char)
247 {
248 const std::string current_partial = stop.substr(0, char_index + 1);
249 if (ends_with(text, current_partial))
250 {
251 return text.size() - char_index - 1;
252 }
253 }
254 }
255 }
256 return std::string::npos;
257}
258
259// TODO: reuse llama_detokenize
260template <class Iter>

Callers 1

find_stopping_stringsMethod · 0.85

Calls 4

ends_withFunction · 0.85
substrMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected