浏览代码

Added a check to ensure the input `text` is a string before proceeding with parsing (#22809)

Co-authored-by: -LAN- <laipz8200@outlook.com>
tags/1.7.0
crazywoola 3 个月前
父节点
当前提交
60c37fe492
没有帐户链接到提交者的电子邮件

+ 2
- 1
api/core/llm_generator/llm_generator.py 查看文件

@@ -114,7 +114,8 @@ class LLMGenerator:
),
)

questions = output_parser.parse(cast(str, response.message.content))
text_content = response.message.get_text_content()
questions = output_parser.parse(text_content) if text_content else []
except InvokeError:
questions = []
except Exception:

+ 0
- 1
api/core/llm_generator/output_parser/suggested_questions_after_answer.py 查看文件

@@ -15,5 +15,4 @@ class SuggestedQuestionsAfterAnswerOutputParser:
json_obj = json.loads(action_match.group(0).strip())
else:
json_obj = []

return json_obj

+ 17
- 0
api/core/model_runtime/entities/message_entities.py 查看文件

@@ -156,6 +156,23 @@ class PromptMessage(ABC, BaseModel):
"""
return not self.content

def get_text_content(self) -> str:
"""
Get text content from prompt message.

:return: Text content as string, empty string if no text content
"""
if isinstance(self.content, str):
return self.content
elif isinstance(self.content, list):
text_parts = []
for item in self.content:
if isinstance(item, TextPromptMessageContent):
text_parts.append(item.data)
return "".join(text_parts)
else:
return ""

@field_validator("content", mode="before")
@classmethod
def validate_content(cls, v):

+ 7
- 1
api/core/workflow/nodes/tool/tool_node.py 查看文件

@@ -317,7 +317,13 @@ class ToolNode(BaseNode):
elif message.type == ToolInvokeMessage.MessageType.FILE:
assert message.meta is not None
assert isinstance(message.meta, dict)
assert "file" in message.meta and isinstance(message.meta["file"], File)
# Validate that meta contains a 'file' key
if "file" not in message.meta:
raise ToolNodeError("File message is missing 'file' key in meta")

# Validate that the file is an instance of File
if not isinstance(message.meta["file"], File):
raise ToolNodeError(f"Expected File object but got {type(message.meta['file']).__name__}")
files.append(message.meta["file"])
elif message.type == ToolInvokeMessage.MessageType.LOG:
assert isinstance(message.message, ToolInvokeMessage.LogMessage)

正在加载...
取消
保存