From 907200d737a40021f41119f238e1c727ba332990 Mon Sep 17 00:00:00 2001 From: CyanFalse Date: Sun, 8 Mar 2026 16:29:49 +0800 Subject: [PATCH] fix some problem 1. remove inline in base64_decode 2. edit the validation in image_embedding 3. revert find_precomputed and find_chunk --- tools/server/server-common.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index bbfebd6488..8af2215611 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -166,7 +166,7 @@ static inline bool is_base64(uint8_t c) { return (isalnum(c) || (c == '+') || (c == '/')); } -inline raw_buffer base64_decode(const std::string & encoded_string) { +raw_buffer base64_decode(const std::string & encoded_string) { int i = 0; int j = 0; int in_ = 0; @@ -414,13 +414,14 @@ void server_tokens::keep_first(size_t n) { // make sure we never remove tokens in the middle of an image // note that the case where we keep a full image at the end is allowed: // tokens[n - 1] == LLAMA_TOKEN_NULL && tokens[n] != LLAMA_TOKEN_NULL - if (tokens[n - 1] == LLAMA_TOKEN_NULL && tokens[n] == LLAMA_TOKEN_NULL) { - find_chunk(n - 1); // will throw an error if the token is not begin-of-chunk - } - if (has_precomputed) { + if (has_precomputed) { //if it is precomputed, we only need to check if the previous token is precomputed. find_precomputed(n - 1); // must be find_precomputed but not find_chunk.beacause it knows more than mtmd chunk - } } + else if (tokens[n - 1] == LLAMA_TOKEN_NULL && tokens[n] == LLAMA_TOKEN_NULL) { + find_chunk(n - 1); // will throw an error if the token is not begin-of-chunk + } + + } } // remove all image chunks that are not used anymore for (auto it = map_idx_to_media.begin(); it != map_idx_to_media.end(); ) { @@ -1148,8 +1149,14 @@ json oaicompat_chat_params_parse( } else if (type=="image_embedding" || type=="image_embedding_b64"){ json emb_data = json_value(p, type, json::object()); - if (!(emb_data.contains("embedding")||emb_data.contains("embedding_b64")) || !emb_data.contains("n_tokens") || !emb_data.contains("n_embd")) { - throw std::invalid_argument(type + " must contain 'embedding', 'n_tokens', and 'n_embd'"); + if (!emb_data.contains("n_tokens") || !emb_data.contains("n_embd")) { + throw std::invalid_argument(type + " must contain 'n_tokens', and 'n_embd'"); + } + if(type=="image_embedding" && !emb_data.contains("embedding")) { + throw std::invalid_argument(type + " must contain 'embedding'"); + } + if(type=="image_embedding_b64" && !emb_data.contains("embedding_b64")) { + throw std::invalid_argument(type + " must contain 'embedding_b64'"); } server_precomputed_image img;