MCPcopy
hub / github.com/idank/explainshell / finalize

Method finalize

explainshell/extraction/llm/extractor.py:330–366  ·  view source on GitHub ↗

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],
    )

Source from the content-addressed store, hash-verified

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,

Callers 1

_process_one_batchFunction · 0.45

Calls 7

_dump_failed_responseMethod · 0.95
_build_messagesMethod · 0.95
_finalizeMethod · 0.95
ExtractionStatsClass · 0.90
process_llm_resultFunction · 0.90
TokenUsageClass · 0.90
ChunkResultClass · 0.85

Tested by

no test coverage detected