Finalize extraction from batch responses. Used by run_batch after collecting provider results. The returned stats carry ``chunks`` and ``plain_text_len``; token counts are tracked at the batch level by the runner.
(
self,
gz_path: str,
prepared: PreparedFile,
responses: list[str],
)
| 328 | ) |
| 329 | |
| 330 | def finalize( |
| 331 | self, |
| 332 | gz_path: str, |
| 333 | prepared: PreparedFile, |
| 334 | responses: list[str], |
| 335 | ) -> ExtractionResult: |
| 336 | """Finalize extraction from batch responses. |
| 337 | |
| 338 | Used by run_batch after collecting provider results. The returned |
| 339 | stats carry ``chunks`` and ``plain_text_len``; token counts are |
| 340 | tracked at the batch level by the runner. |
| 341 | """ |
| 342 | all_chunk_data: list[ChunkResult] = [] |
| 343 | stats = ExtractionStats( |
| 344 | chunks=prepared.n_chunks, |
| 345 | plain_text_len=prepared.plain_text_len, |
| 346 | ) |
| 347 | |
| 348 | for chunk_idx, response_text in enumerate(responses): |
| 349 | try: |
| 350 | chunk_data, raw = process_llm_result(response_text) |
| 351 | except ExtractionError as e: |
| 352 | if e.raw_response: |
| 353 | self._dump_failed_response(gz_path, chunk_idx, e.raw_response) |
| 354 | raise |
| 355 | |
| 356 | messages = self._build_messages(prepared.requests[chunk_idx]) |
| 357 | all_chunk_data.append( |
| 358 | ChunkResult( |
| 359 | data=chunk_data, |
| 360 | messages=messages, |
| 361 | raw_response=raw, |
| 362 | usage=TokenUsage(0, 0), |
| 363 | ) |
| 364 | ) |
| 365 | |
| 366 | return self._finalize(gz_path, prepared, all_chunk_data, stats) |
| 367 | |
| 368 | def _finalize( |
| 369 | self, |
no test coverage detected