]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
fix stop regression (#11543)
authorOlivier Chafik <redacted>
Fri, 31 Jan 2025 13:48:31 +0000 (13:48 +0000)
committerGitHub <redacted>
Fri, 31 Jan 2025 13:48:31 +0000 (13:48 +0000)
examples/server/utils.hpp

index 70bd6a42cb60811ebd835c0d8c063d5cce866c50..94e189457a2fb607d82ba5d0344d062362d4955d 100644 (file)
@@ -484,13 +484,14 @@ static bool ends_with(const std::string & str, const std::string & suffix) {
 
 static size_t find_partial_stop_string(const std::string &stop, const std::string &text) {
     if (!text.empty() && !stop.empty()) {
-        auto it = std::find(stop.rbegin(), stop.rend(), text.back());
-        while (it != stop.rend()) {
-            size_t length = std::distance(it, stop.rend());
-            if (text.length() >= length && 0 == text.compare(text.length() - length, length, stop)) {
-                return text.length() - length;
+        const char text_last_char = text.back();
+        for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--) {
+            if (stop[char_index] == text_last_char) {
+                const std::string current_partial = stop.substr(0, char_index + 1);
+                if (ends_with(text, current_partial)) {
+                    return text.size() - char_index - 1;
+                }
             }
-            it = std::find(std::next(it), stop.rend(), text.back());
         }
     }