Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

-LAN-75e6576c6750
diff --git a/api/core/app/segments/segments.py b/api/core/app/segments/segments.py
index e6bf6cc3a38..afd383880f0 100644
--- a/api/core/app/segments/segments.py
+++ b/api/core/app/segments/segments.py
@@ -34,12 +34,6 @@ class Segment(BaseModel):
return str(self.value)
def to_object(self) -> Any:
- if isinstance(self.value, Segment):
- return self.value.to_object()
- if isinstance(self.value, list):
- return [v.to_object() for v in self.value]
- if isinstance(self.value, dict):
- return {k: v.to_object() for k, v in self.value.items()}
return self.value
diff --git a/api/core/app/segments/variables.py b/api/core/app/segments/variables.py
index b020914d84b..5edaccc4d6c 100644
--- a/api/core/app/segments/variables.py
+++ b/api/core/app/segments/variables.py
@@ -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