fix(api): Fix the issues that `None` content is written to the user accidentally

The `_save_multimodal_output_and_convert_result_to_markdown` should not yield
anything when `contents` is None. However, the lack of `return` statement
causing the fallback branch executed, resulting in `None` written to the user.
pull/17372/head
QuantumGhost 1 year ago
parent fc7498e227
commit 81c4428cf8

@ -80,7 +80,6 @@ from extensions.ext_database import db
from models.model import Conversation from models.model import Conversation
from models.provider import Provider, ProviderType from models.provider import Provider, ProviderType
from models.workflow import WorkflowNodeExecutionStatus from models.workflow import WorkflowNodeExecutionStatus
from .entities import ( from .entities import (
LLMNodeChatModelMessage, LLMNodeChatModelMessage,
LLMNodeCompletionModelPromptTemplate, LLMNodeCompletionModelPromptTemplate,
@ -1234,17 +1233,20 @@ class LLMNode(BaseNode[LLMNodeData]):
self, self,
contents: str | list[PromptMessageContentUnionTypes] | None, contents: str | list[PromptMessageContentUnionTypes] | None,
) -> Generator[str, None, None]: ) -> Generator[str, None, None]:
"""Convert intermediate prompt messages to strings, and yield it to the caller. """Convert intermediate prompt messages into strings and yield them to the caller.
If there are contents other than `TextPromptMessageContent`, it will be saved and If the messages contain non-textual content (e.g., multimedia like images or videos),
correspond markdown content will be yielded to the caller. it will be saved separately, and the corresponding Markdown representation will
be yielded to the caller.
""" """
# NOTE(QuantumGhost): This function should yield to the caller as soon as there is new # NOTE(QuantumGhost): This function should yield results to the caller immediately
# content or new content part available. It should avoid intermediate buffering. # whenever new content or partial content is available. Avoid any intermediate buffering
# It also should avoid yield empty string. (Yield from an empty list instead.) # of results. Additionally, do not yield empty strings; instead, yield from an empty list
# if necessary.
if contents is None: if contents is None:
yield from [] yield from []
return
if isinstance(contents, str): if isinstance(contents, str):
yield contents yield contents
elif isinstance(contents, list): elif isinstance(contents, list):

Loading…
Cancel
Save