]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : escape all U+2581 in a string (#2750)
authorGeorgi Gerganov <redacted>
Thu, 24 Aug 2023 09:26:01 +0000 (12:26 +0300)
committerGitHub <redacted>
Thu, 24 Aug 2023 09:26:01 +0000 (12:26 +0300)
llama.cpp

index 7cac8a1ce4b282b09d9dacfe90127d80fe34af6f..f5526e302e145af13c601daff92817f28d8d156e 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -3004,11 +3004,8 @@ static std::string llama_escape_whitespace(const std::string& text) {
     return result;
 }
 
-static std::string llama_unescape_whitespace(const std::string& word) {
-    if (word.length() >= 3 && word.substr(0, 3) == "\xe2\x96\x81") {
-        return std::string(" ") + word.substr(3);
-    }
-    return word;
+static void llama_unescape_whitespace(std::string & word) {
+    replace_all(word, "\xe2\x96\x81", " ");
 }
 
 struct llm_symbol {
@@ -5822,7 +5819,7 @@ int llama_token_to_str_with_model(const struct llama_model * model, llama_token
         if (llama_is_normal_token(model->vocab, token)) {
             std::string result = model->vocab.id_to_token[token].text;
             if (llama_vocab_get_type(model->vocab) == LLAMA_VOCAB_TYPE_SPM) {
-                result = llama_unescape_whitespace(result);
+                llama_unescape_whitespace(result);
             }
             if (length < (int) result.length()) {
                 return -result.length();