]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
common/chat : preserve media markers for typed-content templates (#22634)
authorAldehir Rojas <redacted>
Thu, 7 May 2026 17:50:56 +0000 (12:50 -0500)
committerGitHub <redacted>
Thu, 7 May 2026 17:50:56 +0000 (12:50 -0500)
common/chat.cpp
common/chat.h

index 5364a6e0174944bf52b46937778ff66ab99bbcce..70b9f5dc2c5893ba57a1bb0a65d31f52f4cca0f5 100644 (file)
@@ -80,7 +80,7 @@ json common_chat_msg::to_json_oaicompat(bool concat_typed_text) const {
     if (!content.empty()) {
         jmsg["content"] = content;
     } else if (!content_parts.empty()) {
-        if (concat_typed_text) {
+        if (concat_typed_text || contains_media()) {
             std::string text;
             bool last_was_media_marker = false;
             // join parts with newline, do not add newline before or after media markers
index 01a47b383bf32abe98d7f23af9e2fe28e223329e..054f5ffe777f5d6d6632c78c204fea7837ec9638 100644 (file)
@@ -94,6 +94,15 @@ struct common_chat_msg {
                tool_name.empty() && tool_call_id.empty();
     }
 
+    bool contains_media() const {
+        for (const auto & part : content_parts) {
+            if (part.type == "media_marker") {
+                return true;
+            }
+        }
+        return false;
+    }
+
     void set_tool_call_ids(std::vector<std::string> &           ids_cache,
                            const std::function<std::string()> & gen_tool_call_id) {
         for (auto i = 0u; i < tool_calls.size(); i++) {