mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-02 11:18:19 +08:00
fix(api/core/app/segments): Allow to contains boolean value in object segment (#7047)
This commit is contained in:
parent
72c75b75cf
commit
aad02113c6
@ -75,8 +75,7 @@ def build_segment(value: Any, /) -> Segment:
|
||||
return FloatSegment(value=value)
|
||||
if isinstance(value, dict):
|
||||
# TODO: Limit the depth of the object
|
||||
obj = {k: build_segment(v) for k, v in value.items()}
|
||||
return ObjectSegment(value=obj)
|
||||
return ObjectSegment(value=value)
|
||||
if isinstance(value, list):
|
||||
# TODO: Limit the depth of the array
|
||||
elements = [build_segment(v) for v in value]
|
||||
|
@ -85,7 +85,7 @@ class FileSegment(Segment):
|
||||
|
||||
class ObjectSegment(Segment):
|
||||
value_type: SegmentType = SegmentType.OBJECT
|
||||
value: Mapping[str, Segment]
|
||||
value: Mapping[str, Any]
|
||||
|
||||
@property
|
||||
def text(self) -> str:
|
||||
@ -102,9 +102,6 @@ class ObjectSegment(Segment):
|
||||
# TODO: Use markdown code block
|
||||
return json.dumps(self.model_dump()['value'], ensure_ascii=False, indent=2)
|
||||
|
||||
def to_object(self):
|
||||
return {k: v.to_object() for k, v in self.value.items()}
|
||||
|
||||
|
||||
class ArraySegment(Segment):
|
||||
@property
|
||||
|
@ -67,7 +67,7 @@ def test_build_a_object_variable_with_none_value():
|
||||
}
|
||||
)
|
||||
assert isinstance(var, ObjectSegment)
|
||||
assert isinstance(var.value['key1'], NoneSegment)
|
||||
assert var.value['key1'] is None
|
||||
|
||||
|
||||
def test_object_variable():
|
||||
|
@ -54,20 +54,10 @@ def test_object_variable_to_object():
|
||||
var = ObjectVariable(
|
||||
name='object',
|
||||
value={
|
||||
'key1': ObjectVariable(
|
||||
name='object',
|
||||
value={
|
||||
'key2': StringVariable(name='key2', value='value2'),
|
||||
},
|
||||
),
|
||||
'key2': ArrayAnyVariable(
|
||||
name='array',
|
||||
value=[
|
||||
StringVariable(name='key5_1', value='value5_1'),
|
||||
IntegerVariable(name='key5_2', value=42),
|
||||
ObjectVariable(name='key5_3', value={}),
|
||||
],
|
||||
),
|
||||
'key1': {
|
||||
'key2': 'value2',
|
||||
},
|
||||
'key2': ['value5_1', 42, {}],
|
||||
},
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user