fix(api/core/app/segments): Allow to contains boolean value in object segment (#7047)

This commit is contained in:
-LAN- 2024-08-07 16:20:22 +08:00 committed by GitHub
parent 72c75b75cf
commit aad02113c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 21 deletions

View File

@ -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]

View File

@ -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

View File

@ -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():

View File

@ -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, {}],
},
)