Split by extracting array items from JSON content.
(self, inputs: List[Message])
| 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 | |
| 190 | def create_splitter( |
nothing calls this directly
no test coverage detected