Summarize streams with real progress: adapters reassemble SSE/NDJSON deltas and report 0-99% as tokens arrive
This commit is contained in:
parent
cd1b08fda0
commit
7fa99e8291
8 changed files with 246 additions and 42 deletions
|
|
@ -38,6 +38,30 @@ def build_user_message(transcript: str, title: str | None,
|
|||
return msg
|
||||
|
||||
|
||||
# Rough typical length of a summary JSON reply. The stream cannot know the
|
||||
# model's final size, so progress is an estimate that crawls toward 99 and
|
||||
# the job sets 100 on success — honest "almost there", never a fake jump.
|
||||
EST_OUTPUT_CHARS = 1200
|
||||
|
||||
|
||||
def make_progress_ticker(on_progress):
|
||||
"""Wrap an optional on_progress callback into a feed(n_chars) sink.
|
||||
|
||||
Reports a clamped 0..99 estimate from streamed output size. Silent
|
||||
no-op when the caller has no callback; failures never disturb the
|
||||
summary itself."""
|
||||
if on_progress is None:
|
||||
return lambda n_chars: None
|
||||
|
||||
def feed(n_chars: int) -> None:
|
||||
try: # noqa: SIM105 — swallow deliberately: progress is display state
|
||||
on_progress(min(99, n_chars * 100 // EST_OUTPUT_CHARS))
|
||||
except Exception: # display state only
|
||||
pass
|
||||
|
||||
return feed
|
||||
|
||||
|
||||
def parse_summary(data: object, model: str) -> SummaryResult:
|
||||
if not isinstance(data, dict):
|
||||
return SummaryResult(model=model)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue