Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ With `--llm-reduce`, batch mode emits one final
`{"type":"reduce","model","prompts","output"}` record after the per-source
`result` records — the aggregate prompt(s) run once over every result, with the
output printed to stdout (the progress table is routed to stderr so stdout stays
clean for piping). `--llm-reduce` is repeatable, each prompt running on the
previous one's output; for a single source it extends the `--llm` chain over
that transcript.
clean for piping; the global `-q`/`--quiet` drops that table entirely). `--llm-reduce`
is repeatable, each prompt running on the previous one's output; for a single
source it extends the `--llm` chain over that transcript.

`assembly eval` takes the same `--llm`/`--llm-reduce` flags but emits one JSON
object per dataset (not NDJSON; a single dataset is therefore one object):
Expand Down
12 changes: 9 additions & 3 deletions aai_cli/app/transcribe/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,22 @@ def _render_table(items: list[_Item]) -> Table:


@contextmanager
def _progress_table(items: list[_Item], *, json_mode: bool, reduce_active: bool) -> Generator[None]:
def _progress_table(
items: list[_Item], *, json_mode: bool, reduce_active: bool, quiet: bool
) -> Generator[None]:
"""Render the batch as a live-updating table (human mode).

Rich renders nothing while running on a non-interactive console and prints the
final frame once on stop, so piped/agent runs still get the result table. JSON
mode skips Rich entirely — NDJSON per source is the output. When a --llm-reduce
step will print the aggregate to stdout, the table goes to stderr so stdout
carries only the reduce result.

``--quiet`` drops the table only when it's stderr progress chrome (the
--llm-reduce case); without --llm-reduce the table *is* the run's stdout result,
so it's left alone — quiet silences chrome, not the output a script came for.
"""
if json_mode:
if json_mode or (quiet and reduce_active):
yield
return
console = output.error_console if reduce_active else output.console
Expand Down Expand Up @@ -380,7 +386,7 @@ def run_batch(
"""
items = [_Item(source) for source in sources]
reduce_active = bool(transform.reduce_prompts)
with _progress_table(items, json_mode=json_mode, reduce_active=reduce_active):
with _progress_table(items, json_mode=json_mode, reduce_active=reduce_active, quiet=quiet):
_drain(
api_key,
items,
Expand Down
56 changes: 56 additions & 0 deletions tests/test_transcribe_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,62 @@ def test_batch_reduce_routes_table_to_stderr(mocker, monkeypatch, capsys):
assert "https://a" in err


def test_quiet_drops_the_reduce_progress_table_but_keeps_the_result(mocker, monkeypatch, capsys):
"""--quiet silences the stderr progress chrome; stdout still carries the reduce."""
import assemblyai as aai

_auth()
monkeypatch.setattr(
_TRANSCRIBE, lambda api_key, audio, *, config: _fake_transcript(mocker, audio)
)
monkeypatch.setattr(
transcribe_batch.llm,
"run_chain",
lambda api_key, prompts, *, transcript_text, model, max_tokens: "AGGREGATE",
)
transform = transcribe_run.TransformOptions(
prompts=[], model="m", max_tokens=10, reduce_prompts=["summarize"]
)
transcribe_batch.run_batch(
"sk_live",
["https://a"],
transcription_config=aai.TranscriptionConfig(),
concurrency=1,
force=False,
transform=transform,
json_mode=False,
quiet=True,
)
out, err = capsys.readouterr()
assert "AGGREGATE" in out # the data a script came for survives --quiet
assert "https://a" not in err # the progress table chrome is gone


def test_quiet_keeps_the_non_reduce_table_since_it_is_the_result(mocker, monkeypatch, capsys):
"""Without --llm-reduce the table is the run's stdout output, so --quiet leaves it."""
import assemblyai as aai

_auth()
monkeypatch.setattr(
_TRANSCRIBE, lambda api_key, audio, *, config: _fake_transcript(mocker, audio)
)
transform = transcribe_run.TransformOptions(
prompts=[], model="m", max_tokens=10, reduce_prompts=[]
)
transcribe_batch.run_batch(
"sk_live",
["https://a"],
transcription_config=aai.TranscriptionConfig(),
concurrency=1,
force=False,
transform=transform,
json_mode=False,
quiet=True,
)
out, _ = capsys.readouterr()
assert "https://a" in out # the result table still renders to stdout


def test_batch_reduce_skips_when_nothing_to_reduce(mocker, monkeypatch, capsys):
"""An all-empty batch result must not fire a (billable) reduce call."""
import assemblyai as aai
Expand Down
Loading