mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 18:19:11 +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)
|
return FloatSegment(value=value)
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
# TODO: Limit the depth of the object
|
# TODO: Limit the depth of the object
|
||||||
obj = {k: build_segment(v) for k, v in value.items()}
|
return ObjectSegment(value=value)
|
||||||
return ObjectSegment(value=obj)
|
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
# TODO: Limit the depth of the array
|
# TODO: Limit the depth of the array
|
||||||
elements = [build_segment(v) for v in value]
|
elements = [build_segment(v) for v in value]
|
||||||
|
@ -85,7 +85,7 @@ class FileSegment(Segment):
|
|||||||
|
|
||||||
class ObjectSegment(Segment):
|
class ObjectSegment(Segment):
|
||||||
value_type: SegmentType = SegmentType.OBJECT
|
value_type: SegmentType = SegmentType.OBJECT
|
||||||
value: Mapping[str, Segment]
|
value: Mapping[str, Any]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self) -> str:
|
def text(self) -> str:
|
||||||
@ -102,9 +102,6 @@ class ObjectSegment(Segment):
|
|||||||
# TODO: Use markdown code block
|
# TODO: Use markdown code block
|
||||||
return json.dumps(self.model_dump()['value'], ensure_ascii=False, indent=2)
|
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):
|
class ArraySegment(Segment):
|
||||||
@property
|
@property
|
||||||
|
@ -67,7 +67,7 @@ def test_build_a_object_variable_with_none_value():
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
assert isinstance(var, ObjectSegment)
|
assert isinstance(var, ObjectSegment)
|
||||||
assert isinstance(var.value['key1'], NoneSegment)
|
assert var.value['key1'] is None
|
||||||
|
|
||||||
|
|
||||||
def test_object_variable():
|
def test_object_variable():
|
||||||
|
@ -54,20 +54,10 @@ def test_object_variable_to_object():
|
|||||||
var = ObjectVariable(
|
var = ObjectVariable(
|
||||||
name='object',
|
name='object',
|
||||||
value={
|
value={
|
||||||
'key1': ObjectVariable(
|
'key1': {
|
||||||
name='object',
|
'key2': 'value2',
|
||||||
value={
|
|
||||||
'key2': StringVariable(name='key2', value='value2'),
|
|
||||||
},
|
},
|
||||||
),
|
'key2': ['value5_1', 42, {}],
|
||||||
'key2': ArrayAnyVariable(
|
|
||||||
name='array',
|
|
||||||
value=[
|
|
||||||
StringVariable(name='key5_1', value='value5_1'),
|
|
||||||
IntegerVariable(name='key5_2', value=42),
|
|
||||||
ObjectVariable(name='key5_3', value={}),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user