MCPcopy
hub / github.com/OpenBMB/ChatDev / _extract_array

Method _extract_array

runtime/node/splitter.py:132–156  ·  view source on GitHub ↗

Extract array from data using simple dot notation path.

(self, data: Any)

Source from the content-addressed store, hash-verified

130 self.json_path = json_path
131
132 def _extract_array(self, data: Any) -> List[Any]:
133 """Extract array from data using simple dot notation path."""
134 if not self.json_path:
135 if isinstance(data, list):
136 return data
137 return [data]
138
139 parts = self.json_path.split(".")
140 current = data
141
142 for part in parts:
143 if isinstance(current, dict):
144 current = current.get(part)
145 elif isinstance(current, list) and part.isdigit():
146 idx = int(part)
147 current = current[idx] if idx < len(current) else None
148 else:
149 return []
150
151 if current is None:
152 return []
153
154 if isinstance(current, list):
155 return current
156 return [current]
157
158 def split(self, inputs: List[Message]) -> List[List[Message]]:
159 """Split by extracting array items from JSON content."""

Callers 1

splitMethod · 0.95

Calls 2

splitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected