Merge branch 'main' into fix/chore-fix

This commit is contained in:
Yeuoly
2024-11-08 13:47:24 +08:00
53 changed files with 1132 additions and 157 deletions

View File

@ -69,7 +69,7 @@ class BaseNode(Generic[GenericNodeData]):
try:
result = self._run()
except Exception as e:
logger.error(f"Node {self.node_id} failed to run: {e}")
logger.exception(f"Node {self.node_id} failed to run: {e}")
result = NodeRunResult(
status=WorkflowNodeExecutionStatus.FAILED,
error=str(e),

View File

@ -97,15 +97,6 @@ class Executor:
headers = self.variable_pool.convert_template(self.node_data.headers).text
self.headers = _plain_text_to_dict(headers)
body = self.node_data.body
if body is None:
return
if "content-type" not in (k.lower() for k in self.headers) and body.type in BODY_TYPE_TO_CONTENT_TYPE:
self.headers["Content-Type"] = BODY_TYPE_TO_CONTENT_TYPE[body.type]
if body.type == "form-data":
self.boundary = f"----WebKitFormBoundary{_generate_random_string(16)}"
self.headers["Content-Type"] = f"multipart/form-data; boundary={self.boundary}"
def _init_body(self):
body = self.node_data.body
if body is not None:
@ -154,9 +145,8 @@ class Executor:
for k, v in files.items()
if v.related_id is not None
}
self.data = form_data
self.files = files
self.files = files or None
def _assembling_headers(self) -> dict[str, Any]:
authorization = deepcopy(self.auth)
@ -217,6 +207,7 @@ class Executor:
"timeout": (self.timeout.connect, self.timeout.read, self.timeout.write),
"follow_redirects": True,
}
# request_args = {k: v for k, v in request_args.items() if v is not None}
response = getattr(ssrf_proxy, self.method)(**request_args)
return response
@ -244,6 +235,13 @@ class Executor:
raw += f"Host: {url_parts.netloc}\r\n"
headers = self._assembling_headers()
body = self.node_data.body
boundary = f"----WebKitFormBoundary{_generate_random_string(16)}"
if body:
if "content-type" not in (k.lower() for k in self.headers) and body.type in BODY_TYPE_TO_CONTENT_TYPE:
headers["Content-Type"] = BODY_TYPE_TO_CONTENT_TYPE[body.type]
if body.type == "form-data":
headers["Content-Type"] = f"multipart/form-data; boundary={boundary}"
for k, v in headers.items():
if self.auth.type == "api-key":
authorization_header = "Authorization"
@ -256,7 +254,6 @@ class Executor:
body = ""
if self.files:
boundary = self.boundary
for k, v in self.files.items():
body += f"--{boundary}\r\n"
body += f'Content-Disposition: form-data; name="{k}"\r\n\r\n'
@ -271,7 +268,6 @@ class Executor:
elif self.data and self.node_data.body.type == "x-www-form-urlencoded":
body = urlencode(self.data)
elif self.data and self.node_data.body.type == "form-data":
boundary = self.boundary
for key, value in self.data.items():
body += f"--{boundary}\r\n"
body += f'Content-Disposition: form-data; name="{key}"\r\n\r\n'

View File

@ -14,6 +14,7 @@ from core.model_runtime.entities import (
PromptMessage,
PromptMessageContentType,
TextPromptMessageContent,
VideoPromptMessageContent,
)
from core.model_runtime.entities.llm_entities import LLMResult, LLMUsage
from core.model_runtime.entities.model_entities import ModelType
@ -560,7 +561,9 @@ class LLMNode(BaseNode[LLMNodeData]):
# cuz vision detail is related to the configuration from FileUpload feature.
content_item.detail = vision_detail
prompt_message_content.append(content_item)
elif isinstance(content_item, TextPromptMessageContent | AudioPromptMessageContent):
elif isinstance(
content_item, TextPromptMessageContent | AudioPromptMessageContent | VideoPromptMessageContent
):
prompt_message_content.append(content_item)
if len(prompt_message_content) > 1:

View File

@ -127,7 +127,7 @@ class QuestionClassifierNode(LLMNode):
category_id = category_id_result
except OutputParserError:
logging.error(f"Failed to parse result text: {result_text}")
logging.exception(f"Failed to parse result text: {result_text}")
try:
process_data = {
"model_mode": model_config.mode,