fix: preserve inline image for chatflow messages (#37455)

This commit is contained in:
Yunlu Wen 2026-06-15 15:37:24 +08:00 committed by GitHub
parent 3eaa534e99
commit 4b15b0e6a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 8 deletions

View File

@ -1,6 +1,5 @@
import json
import logging
import re
import time
from collections.abc import Callable, Generator, Mapping
from contextlib import contextmanager
@ -1010,11 +1009,7 @@ class AdvancedChatAppGenerateTaskPipeline(GraphRuntimeStateSupport):
if message.status == MessageStatus.PAUSED:
message.status = MessageStatus.NORMAL
# If there are assistant files, remove markdown image links from answer
answer_text = self._task_state.answer
if self._recorded_files:
# Remove markdown image links since we're storing files separately
answer_text = re.sub(r"!\[.*?\]\(.*?\)", "", answer_text).strip()
message.answer = answer_text
message.updated_at = naive_utc_now()

View File

@ -562,7 +562,7 @@ class TestAdvancedChatGenerateTaskPipeline:
assert list(pipeline._handle_human_input_form_timeout_event(timeout_event)) == ["timeout"]
assert persisted == ["saved"]
def test_save_message_strips_markdown_and_sets_usage(self):
def test_save_message_preserves_full_answer_and_sets_usage(self):
pipeline = _make_pipeline()
pipeline._recorded_files = [
{
@ -572,7 +572,8 @@ class TestAdvancedChatGenerateTaskPipeline:
"related_id": "file-id",
}
]
pipeline._task_state.answer = "![img](url) hello"
# The answer is stored verbatim; markdown image links are never stripped.
pipeline._task_state.answer = "![img](http://example.com/file.png) hello ![inline](http://llm.com/img.jpg)"
pipeline._task_state.is_streaming_response = True
pipeline._task_state.first_token_time = pipeline._base_task_pipeline.start_at + 0.1
pipeline._task_state.last_token_time = pipeline._base_task_pipeline.start_at + 0.2
@ -614,7 +615,7 @@ class TestAdvancedChatGenerateTaskPipeline:
pipeline._save_message(session=_Session(), graph_runtime_state=graph_runtime_state)
assert message.status == MessageStatus.NORMAL
assert message.answer == "hello"
assert message.answer == "![img](http://example.com/file.png) hello ![inline](http://llm.com/img.jpg)"
assert message.message_metadata
def test_handle_stop_event_saves_message_for_moderation(self, monkeypatch: pytest.MonkeyPatch):