Skip to content

feat: bare-list Whisper prompt with a 224-token budget (#53) - #58

Merged
DavidHruby1 merged 4 commits into
mainfrom
feat/whisper-prompt-budget
Nov 4, 2026
Merged

DavidHruby1 merged 4 commits into
mainfrom
feat/whisper-prompt-budget

Conversation

@DavidHruby1

Copy link
Copy Markdown
Owner

Closes #53. Stacked on #57 (#52) — this branch is based on feat/vocabulary-language-tags, so until #57 merges the diff also shows its commit. Merge #57 first.

Changes

  • Prompt shape — stt.build_whisper_prompt(terms) -> (prompt, omitted) sends a bare list like prior transcript text: PySide6, Qt, httpx. No Preferred spellings: header and no JSON quotes, so the prompt no longer pulls the transcript toward English. Terms containing a comma are kept as they are.
  • 224-token budget — WHISPER_PROMPT_TOKEN_BUDGET = 224, estimated without a tokenizer by estimate_prompt_tokens = ceil(UTF-8 bytes / 2). Terms are added whole in select_vocabulary order (language terms first, then All languages). The first term that doesn't fit ends the list, so the cut is deterministic.
  • Never silent — each dictation logs STT prompt: N terms sent, M omitted (token budget). Only the counts are logged, never the terms.
  • Settings — under "Send vocabulary to this provider" in STT → Advanced, a line shows Prompt for Czech: ~N / 224 tokens for the dialog's language. With Auto it counts only All-languages terms. When terms don't fit, a hush="warning" label says how many will be skipped. Both refresh when the vocabulary (add/edit/remove/row language) or the language changes.
  • Preset default — choosing the OpenAI or Groq STT preset turns on "Send vocabulary" for that role (primary/fallback). Custom and the local preset leave it alone. The AppConfig default stays False and saved configs are not migrated.
  • docs/IMPLEMENTATION.md updated (stt API, runtime behavior).

Decisions on the open questions

  • Divisor 2, not 3. When a prompt is too long, Whisper drops its start, which is where the language-specific terms go. So it's safer to overestimate. Mixed-case identifiers and Czech with diacritics also tokenize denser than 3 bytes/token. The budget still fits about 40–50 typical terms.
  • Preset auto-enable implemented as proposed.

Tests

  • New tests/test_whisper_prompt.py: prompt shape, empty selection → no prompt field, deterministic cut with language terms first, first non-fitting term stops the list, log shows counts without terms, settings estimate/warning and refresh, OpenAI/Groq presets enable the toggle while Custom/local don't change it.
  • tests/test_vocabulary_languages.py updated for the new prompt shape.
  • python -m unittest discover -s tests: 489 tests, OK. test_tray_menu…test_exit_during_initial_settings_stops_outer_event_loop sometimes fails on a timeout. It fails the same way on the base branch without this change.

DavidHruby1 and others added 4 commits November 4, 2026 10:05
- config: VocabularyTerm(term, language); normalize accepts terms, dicts and legacy
  strings, dedups by term across languages; select_vocabulary() picks the dictation's
  language terms then All-languages terms (primary subtag match)
- persistence: JSON array of {"term", "language"} objects; legacy string lists load as
  All languages and are rewritten on the next save
- stt/rewrite: both use the same select_vocabulary() pick for stt_language
- settings: Vocabulary tab is a Term | Language table with a per-row language combo
- docs and tests

Closes #52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- stt: build_whisper_prompt() renders the vocabulary as prior transcript text
  ("PySide6, Qt, httpx.") with no English header or quotes; terms are added whole
  in select_vocabulary order until WHISPER_PROMPT_TOKEN_BUDGET (224) by a
  conservative estimate, ceil(UTF-8 bytes / 2); the first term that does not fit
  ends the list
- stt: each dictation logs "STT prompt: N terms sent, M omitted (token budget)",
  counts only
- settings: STT Advanced shows the prompt estimate for the dialog's language and a
  warning with the skipped count; refreshes on vocabulary or language edits
- settings: choosing the OpenAI or Groq STT preset turns on "Send vocabulary" for
  that role; defaults and saved settings are unchanged
- docs and tests

Closes #53

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cument prompt budget in README

Terms in the vocabulary table are editable in place, which bypassed the
estimate/overflow refresh added for the Whisper prompt budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DavidHruby1 DavidHruby1 closed this Nov 4, 2026
@DavidHruby1 DavidHruby1 reopened this Nov 4, 2026
@DavidHruby1
DavidHruby1 merged commit d70f5a4 into main Nov 4, 2026
9 checks passed
DavidHruby1 added a commit that referenced this pull request Nov 4, 2026
DavidHruby1 added a commit that referenced this pull request Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slovník: Whisper prompt jako holý seznam + hlídání limitu 224 tokenů (4.2)

1 participant