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

Method split

runtime/node/splitter.py:158–187  ·  view source on GitHub ↗

Split by extracting array items from JSON content.

(self, inputs: List[Message])

Source from the content-addressed store, hash-verified

156 return [current]
157
158 def split(self, inputs: List[Message]) -> List[List[Message]]:
159 """Split by extracting array items from JSON content."""
160 units: List[List[Message]] = []
161
162 for msg in inputs:
163 text = msg.text_content()
164
165 # Try to parse as JSON
166 try:
167 data = json.loads(text)
168 items = self._extract_array(data)
169
170 for item in items:
171 if isinstance(item, (dict, list)):
172 content = json.dumps(item, ensure_ascii=False)
173 else:
174 content = str(item)
175
176 unit_msg = Message(
177 role=msg.role,
178 content=content,
179 metadata={**msg.metadata, "split_source": "json_path"},
180 )
181 units.append([unit_msg])
182
183 except json.JSONDecodeError:
184 # If not valid JSON, treat as single unit
185 units.append([msg])
186
187 return units if units else [[msg] for msg in inputs]
188
189
190def create_splitter(

Callers

nothing calls this directly

Calls 3

_extract_arrayMethod · 0.95
MessageClass · 0.90
text_contentMethod · 0.80

Tested by

no test coverage detected