Browse Source

Merge branch 'feat/rag-2' of https://github.com/langgenius/dify into feat/rag-2

tags/2.0.0-beta.1
twwu 1 month ago
parent
commit
495324b85b

+ 6
- 4
api/core/workflow/nodes/code/code_node.py View File

elif output_config.type == SegmentType.NUMBER: elif output_config.type == SegmentType.NUMBER:
# check if number available # check if number available
value = result.get(output_name) value = result.get(output_name)
if not isinstance(value, (int, float, None)):
if value is not None and not isinstance(value, (int, float)):
raise OutputValidationError( raise OutputValidationError(
f"Output {prefix}{dot}{output_name} is not a number," f"Output {prefix}{dot}{output_name} is not a number,"
f" got {type(result.get(output_name))} instead." f" got {type(result.get(output_name))} instead."


elif output_config.type == SegmentType.STRING: elif output_config.type == SegmentType.STRING:
# check if string available # check if string available
value = result.get("output_name")
value = result.get(output_name)
if value is not None and not isinstance(value, str): if value is not None and not isinstance(value, str):
raise OutputValidationError(f"Output value `{value}` is not string")
raise OutputValidationError(
f"Output {prefix}{dot}{output_name} must be a string, got {type(value).__name__} instead"
)
transformed_result[output_name] = self._check_string( transformed_result[output_name] = self._check_string(
value=value, value=value,
variable=f"{prefix}{dot}{output_name}", variable=f"{prefix}{dot}{output_name}",
) )
else: else:
for i, inner_value in enumerate(value): for i, inner_value in enumerate(value):
if not isinstance(inner_value, bool | None):
if inner_value is not None and not isinstance(inner_value, bool):
raise OutputValidationError( raise OutputValidationError(
f"Output {prefix}{dot}{output_name}[{i}] is not a boolean," f"Output {prefix}{dot}{output_name}[{i}] is not a boolean,"
f" got {type(inner_value)} instead." f" got {type(inner_value)} instead."

+ 1
- 1
api/tests/integration_tests/workflow/nodes/test_code.py View File

result = node._run() result = node._run()
assert isinstance(result, NodeRunResult) assert isinstance(result, NodeRunResult)
assert result.status == WorkflowNodeExecutionStatus.FAILED assert result.status == WorkflowNodeExecutionStatus.FAILED
assert result.error == "Output variable `result` must be a string"
assert result.error == "Output result must be a string, got int instead"




def test_execute_code_output_validator_depth(): def test_execute_code_output_validator_depth():

Loading…
Cancel
Save