refactor(api/core/app/segments): implement to_object in ObjectVariable and ArrayVariable. (#6671)

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN-
2024-07-25 17:06:38 +08:00
committed by GitHub
parent 0b4c26578e
commit 75e6576c67
2 changed files with 6 additions and 6 deletions

View File

@@ -56,6 +56,9 @@ class ObjectVariable(Variable):
# 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 ArrayVariable(Variable):
value_type: SegmentType = SegmentType.ARRAY
@@ -65,6 +68,9 @@ class ArrayVariable(Variable):
def markdown(self) -> str:
return '\n'.join(['- ' + item.markdown for item in self.value])
def to_object(self):
return [v.to_object() for v in self.value]
class FileVariable(Variable):
value_type: SegmentType = SegmentType.FILE