Merge pull request #329 from SuanmoSuanyangTechnology/fix/workflow-stream
fix(workflow): fix streaming output parsing errors and improve file-type output handling
This commit is contained in:
@@ -667,6 +667,15 @@ class BaseNode(ABC):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_model_output(content) -> str:
|
def process_model_output(content) -> str:
|
||||||
if isinstance(content, dict):
|
result = ""
|
||||||
return content.get("text")
|
if isinstance(content, list):
|
||||||
return content
|
for msg in content:
|
||||||
|
if isinstance(msg, dict):
|
||||||
|
result += msg.get("text")
|
||||||
|
elif isinstance(msg, str):
|
||||||
|
result += msg
|
||||||
|
elif isinstance(content, dict):
|
||||||
|
result = content.get("text")
|
||||||
|
elif isinstance(content, str):
|
||||||
|
return content
|
||||||
|
return result
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from typing import Any, TypeVar, Type, Generic
|
|||||||
|
|
||||||
from deprecated import deprecated
|
from deprecated import deprecated
|
||||||
|
|
||||||
from app.core.workflow.variable.base_variable import BaseVariable, VariableType, FileObject
|
from app.core.workflow.variable.base_variable import BaseVariable, VariableType, FileObject, FileType
|
||||||
|
|
||||||
T = TypeVar("T", bound=BaseVariable)
|
T = TypeVar("T", bound=BaseVariable)
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ class FileVariable(BaseVariable):
|
|||||||
raise TypeError(f"Value must be a FileObject - {type(value)}:{value}")
|
raise TypeError(f"Value must be a FileObject - {type(value)}:{value}")
|
||||||
|
|
||||||
def to_literal(self) -> str:
|
def to_literal(self) -> str:
|
||||||
return str(self.value.model_dump())
|
return f'{"!"if self.value.type == FileType.IMAGE else ""}[file]({self.value.url})'
|
||||||
|
|
||||||
def get_value(self) -> Any:
|
def get_value(self) -> Any:
|
||||||
return self.value.model_dump()
|
return self.value.model_dump()
|
||||||
|
|||||||
@@ -460,21 +460,8 @@ class WorkflowService:
|
|||||||
input_data = {"message": payload.message, "variables": payload.variables,
|
input_data = {"message": payload.message, "variables": payload.variables,
|
||||||
"conversation_id": payload.conversation_id, "files": files}
|
"conversation_id": payload.conversation_id, "files": files}
|
||||||
|
|
||||||
# 转换 user_id 为 UUID
|
|
||||||
triggered_by_uuid = None
|
|
||||||
if payload.user_id:
|
|
||||||
try:
|
|
||||||
triggered_by_uuid = uuid.UUID(payload.user_id)
|
|
||||||
except (ValueError, AttributeError):
|
|
||||||
logger.warning(f"无效的 user_id 格式: {payload.user_id}")
|
|
||||||
|
|
||||||
# 转换 conversation_id 为 UUID
|
# 转换 conversation_id 为 UUID
|
||||||
conversation_id_uuid = None
|
conversation_id_uuid = uuid.UUID(payload.conversation_id) if payload.conversation_id else None
|
||||||
if payload.conversation_id:
|
|
||||||
try:
|
|
||||||
conversation_id_uuid = uuid.UUID(payload.conversation_id)
|
|
||||||
except (ValueError, AttributeError):
|
|
||||||
logger.warning(f"无效的 conversation_id 格式: {payload.conversation_id}")
|
|
||||||
|
|
||||||
# 2. 创建执行记录
|
# 2. 创建执行记录
|
||||||
execution = self.create_execution(
|
execution = self.create_execution(
|
||||||
@@ -661,21 +648,8 @@ class WorkflowService:
|
|||||||
input_data = {"message": payload.message, "variables": payload.variables,
|
input_data = {"message": payload.message, "variables": payload.variables,
|
||||||
"conversation_id": payload.conversation_id, "files": files}
|
"conversation_id": payload.conversation_id, "files": files}
|
||||||
|
|
||||||
# 转换 user_id 为 UUID
|
|
||||||
triggered_by_uuid = None
|
|
||||||
if payload.user_id:
|
|
||||||
try:
|
|
||||||
triggered_by_uuid = uuid.UUID(payload.user_id)
|
|
||||||
except (ValueError, AttributeError):
|
|
||||||
logger.warning(f"无效的 user_id 格式: {payload.user_id}")
|
|
||||||
|
|
||||||
# 转换 conversation_id 为 UUID
|
# 转换 conversation_id 为 UUID
|
||||||
conversation_id_uuid = None
|
conversation_id_uuid = uuid.UUID(payload.conversation_id) if payload.conversation_id else None
|
||||||
if payload.conversation_id:
|
|
||||||
try:
|
|
||||||
conversation_id_uuid = uuid.UUID(payload.conversation_id)
|
|
||||||
except (ValueError, AttributeError):
|
|
||||||
logger.warning(f"无效的 conversation_id 格式: {payload.conversation_id}")
|
|
||||||
|
|
||||||
# 2. 创建执行记录
|
# 2. 创建执行记录
|
||||||
execution = self.create_execution(
|
execution = self.create_execution(
|
||||||
|
|||||||
Reference in New Issue
Block a user