mirror of https://github.com/langgenius/dify.git
fix(api): Fix variable truncation for `list[File]` value in output mapping (#26133)
This commit is contained in:
parent
2913d17fe2
commit
96a0b9991e
|
|
@ -262,6 +262,14 @@ class VariableTruncator:
|
||||||
target_length = self._array_element_limit
|
target_length = self._array_element_limit
|
||||||
|
|
||||||
for i, item in enumerate(value):
|
for i, item in enumerate(value):
|
||||||
|
# Dirty fix:
|
||||||
|
# The output of `Start` node may contain list of `File` elements,
|
||||||
|
# causing `AssertionError` while invoking `_truncate_json_primitives`.
|
||||||
|
#
|
||||||
|
# This check ensures that `list[File]` are handled separately
|
||||||
|
if isinstance(item, File):
|
||||||
|
truncated_value.append(item)
|
||||||
|
continue
|
||||||
if i >= target_length:
|
if i >= target_length:
|
||||||
return _PartResult(truncated_value, used_size, True)
|
return _PartResult(truncated_value, used_size, True)
|
||||||
if i > 0:
|
if i > 0:
|
||||||
|
|
|
||||||
|
|
@ -588,3 +588,11 @@ class TestIntegrationScenarios:
|
||||||
if isinstance(result.result, ObjectSegment):
|
if isinstance(result.result, ObjectSegment):
|
||||||
result_size = truncator.calculate_json_size(result.result.value)
|
result_size = truncator.calculate_json_size(result.result.value)
|
||||||
assert result_size <= original_size
|
assert result_size <= original_size
|
||||||
|
|
||||||
|
def test_file_and_array_file_variable_mapping(self, file):
|
||||||
|
truncator = VariableTruncator(string_length_limit=30, array_element_limit=3, max_size_bytes=300)
|
||||||
|
|
||||||
|
mapping = {"array_file": [file]}
|
||||||
|
truncated_mapping, truncated = truncator.truncate_variable_mapping(mapping)
|
||||||
|
assert truncated is False
|
||||||
|
assert truncated_mapping == mapping
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue