Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Surface user and admin default prompt variables on the upload form by mirroring the task-side priority chain
Murtaza Nasir8bd8d6423c99
diff --git a/docs/user-guide/settings.md b/docs/user-guide/settings.mdindex cdf37ffb..82486ba8 100644--- a/docs/user-guide/settings.md+++ b/docs/user-guide/settings.md@@ -221,7 +221,9 @@ Tag and folder custom prompts may contain `{{name}}` placeholders that are fille**Editing values after upload.** Stored variable values are not yet editable from the recording detail or reprocess modal. To change a value, re-upload the recording or wait for that capability in a future release.-**Where variables are surfaced.** The upload form scans the custom prompts on every selected tag and on the chosen folder, and renders an input for each `{{name}}` it finds. Variables in the user's personal default summary prompt and in the admin's default summary prompt are technically substituted at summarisation time but are not surfaced on the upload form: the form does not know which fallback prompt would win the priority chain. Account Settings warns when these prompts contain placeholders, recommending that templated content live on a tag or folder instead. The Tag Management form also warns when a tag is configured as a watch-folder (auto-process) tag and its prompt contains placeholders, since drop-folder ingest has no UI for users to fill values.+**Where variables are surfaced.** The upload form mirrors the same priority chain that the summarisation task uses to pick a prompt. The first non-empty layer wins and its variables become inputs on the form: selected tags first, then the selected folder, then your personal summary prompt, then the site default set by the admin. Lower layers are not scanned because their prompt would not run.++**Drop-folder ingest is the exception.** Recordings ingested through the auto-process watch directory bypass the upload form entirely, so any tag prompt with placeholders attached to such a recording silently substitutes to empty strings. Tag Management surfaces a warning when a tag is configured as a watch-folder tag and its custom prompt contains `{{...}}` placeholders. Either keep watch-folder tags variable-free, or reprocess after upload to fill the values.### ASR Defaultsdiff --git a/src/api/system.py b/src/api/system.pyindex ef589595..78efb9e1 100644--- a/src/api/system.py+++ b/src/api/system.py@@ -264,13 +264,22 @@ def get_config():# Get user's default transcription language if authenticateduser_transcription_language = ''+ user_summary_prompt = ''try:from flask_login import current_user- if current_user and current_user.is_authenticated and current_user.transcription_language:- user_transcription_language = current_user.transcription_language+ if current_user and current_user.is_authenticated:+ if current_user.transcription_language:+ user_transcription_language = current_user.transcription_language+ if current_user.summary_prompt:+ user_summary_prompt = current_user.summary_promptexcept:pass+ # Admin-defined default summary prompt. Used by the upload form to+ # surface `{{name}}` placeholders that would otherwise substitute to+ # empty strings on uploads that fall through to this prompt.+ admin_default_summary_prompt = SystemSetting.get_setting('admin_default_summary_prompt', '') or ''+return jsonify({'max_file_size_mb': max_file_size_mb,'recording_disclaimer': SystemSetting.get_setting('recording_disclaimer', ''),@@ -293,6 +302,8 @@ def get_config():'video_retention': VIDEO_RETENTION,'max_concurrent_uploads': MAX_CONCURRENT_UPLOADS,'user_transcription_language': user_transcription_language,+ 'user_summary_prompt': user_summary_prompt,+ 'admin_default_summary_prompt': admin_default_summary_prompt,'transcription_model_options': _get_transcription_model_options(),**chunking_info})diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex ead49453..e98814fb 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -389,6 +389,11 @@ document.addEventListener('DOMContentLoaded', async () => {// Advanced Options for ASRconst showAdvancedOptions = ref(false);const userTranscriptionLanguage = ref(''); // User's default from account settings+ // Personal and site-default summary prompts. Used by the upload+ // form to surface `{{variable}}` placeholders that would otherwise+ // substitute to empty strings.+ const userSummaryPrompt = ref('');+ const adminDefaultSummaryPrompt = ref('');const uploadLanguage = ref('');const uploadMinSpeakers = ref('');const uploadMaxSpeakers = ref('');@@ -656,24 +661,42 @@ document.addEventListener('DOMContentLoaded', async () => {}};- // Tags: scan custom_prompt of every selected tag.+ // Mirror the task-side priority chain so the inputs shown match+ // whichever prompt would actually be used at summarisation time:+ // tags (stack, highest priority) -> folder -> user default -> admin default+ // The first non-empty layer wins; lower-priority layers are not+ // scanned because their prompt would not run.++ let anyTagHasPrompt = false;if (Array.isArray(selectedTagIds.value) && Array.isArray(availableTags.value)) {for (const id of selectedTagIds.value) {const tag = availableTags.value.find(t => t.id === id);if (tag && tag.custom_prompt) {addVars(tag.custom_prompt, tag.name, 'tag');+ anyTagHasPrompt = true;}}}- // Folder: scan custom_prompt of the selected folder.- if (selectedFolderId.value && Array.isArray(availableFolders.value)) {+ let folderHasPrompt = false;+ if (!anyTagHasPrompt && selectedFolderId.value && Array.isArray(availableFolders.value)) {const folder = availableFolders.value.find(f => f.id === selectedFolderId.value);if (folder && folder.custom_prompt) {addVars(folder.custom_prompt, folder.name, 'folder');+ folderHasPrompt = true;}}+ let userPromptHasContent = false;+ if (!anyTagHasPrompt && !folderHasPrompt && userSummaryPrompt.value) {+ addVars(userSummaryPrompt.value, 'Your default prompt', 'user');+ userPromptHasContent = true;+ }++ if (!anyTagHasPrompt && !folderHasPrompt && !userPromptHasContent && adminDefaultSummaryPrompt.value) {+ addVars(adminDefaultSummaryPrompt.value, 'Site default prompt', 'admin');+ }+return Array.from(acc.values());});const isMobileDevice = computed(() => {@@ -2420,6 +2443,13 @@ document.addEventListener('DOMContentLoaded', async () => {uploadLanguage.value = config.user_transcription_language;}+ // Capture the user's personal summary prompt and the+ // site-wide admin default so the upload form can scan+ // them for `{{variable}}` placeholders when no tag /+ // folder prompt is active.+ userSummaryPrompt.value = config.user_summary_prompt || '';+ adminDefaultSummaryPrompt.value = config.admin_default_summary_prompt || '';+// Restore saved folder selection from localStorageif (foldersEnabled.value) {const savedFolder = localStorage.getItem('selectedFolder');diff --git a/templates/account.html b/templates/account.htmlindex d26e04b8..8edc2fa0 100644--- a/templates/account.html+++ b/templates/account.html@@ -702,14 +702,6 @@placeholder="Describe how you want your summaries structured. Leave blank to use the admin's default prompt."data-i18n-placeholder="customPrompts.promptPlaceholder"class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md shadow-sm focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm bg-[var(--bg-input)] text-[var(--text-primary)]">{{ current_user.summary_prompt or '' }}</textarea>- <!-- Warning when this prompt contains {{...}} placeholders. The upload form scans- selected tags and folders for variables, but not the user's personal default- prompt, so placeholders here would silently substitute to empty strings on- uploads that fall through to this prompt. -->- <div id="userSummaryPromptVariableWarning" class="hidden mt-2 flex items-start gap-2 p-2.5 bg-[var(--bg-warning-light)] border border-[var(--border-warning)] rounded-md text-xs text-[var(--text-warning-strong)]">- <i class="fas fa-exclamation-triangle mt-0.5"></i>- <span>This prompt contains <code>{{...}}</code> placeholders. The upload form does not surface variables from the personal default prompt, so values will substitute to empty strings on any upload that falls through to this prompt. Move the placeholders into a tag or folder custom prompt to have them filled in at upload time.</span>- </div><p class="text-xs text-[var(--text-light)] mt-2"><span data-i18n="customPrompts.promptDescription">This prompt will be used to generate summaries for your transcriptions. It overrides the admin's default prompt.</span></p>@@ -5302,28 +5294,16 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</cowarningEl.classList.toggle('hidden', !shouldShow);}- // User-level summary_prompt: warn when it contains {{...}} placeholders.- // The upload form does not surface variables from the personal default- // prompt, so they would silently substitute to empty strings.- function refreshUserSummaryPromptVariableWarning() {- const warningEl = document.getElementById('userSummaryPromptVariableWarning');- const promptEl = document.getElementById('summary_prompt_custom');- if (!warningEl || !promptEl) return;- warningEl.classList.toggle('hidden', !promptHasVariables(promptEl.value));- }-document.addEventListener('input', (e) => {- if (!e.target) return;- if (e.target.id === 'tagCustomPrompt') refreshTagAutoProcessVariableWarning();- if (e.target.id === 'summary_prompt_custom') refreshUserSummaryPromptVariableWarning();+ if (e.target && e.target.id === 'tagCustomPrompt') {+ refreshTagAutoProcessVariableWarning();+ }});document.addEventListener('change', (e) => {if (e.target && e.target.id === 'tagAutoProcess') {refreshTagAutoProcessVariableWarning();}});- // Initial render: account page may load with a saved value already in place.- refreshUserSummaryPromptVariableWarning();// Load folders from APIasync function loadFolders() {diff --git a/templates/admin.html b/templates/admin.htmlindex 2f5aa3eb..cdb7f31d 100644--- a/templates/admin.html+++ b/templates/admin.html@@ -806,15 +806,6 @@class="w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md focus:outline-none focus:ring-2 focus:ring-[var(--border-focus)] bg-[var(--bg-input)] text-[var(--text-primary)]":placeholder="t('form.summaryPromptPlaceholder')"></textarea>- <!-- Warning when the admin default contains {{...}} placeholders.- The upload form only surfaces variables from selected tags- and folders, not from the admin default, so users would not- know to fill them and the placeholders would silently- substitute to empty strings on every fresh upload. -->- <div v-if="adminDefaultPromptHasVariables" class="mt-2 flex items-start gap-2 p-2.5 bg-[var(--bg-warning-light)] border border-[var(--border-warning)] rounded-md text-xs text-[var(--text-warning-strong)]">- <i class="fas fa-exclamation-triangle mt-0.5"></i>- <span>This prompt contains <code>{{...}}</code> placeholders. The upload form does not surface variables from the admin default, so users will not be prompted to fill them and the placeholders will substitute to empty strings on uploads that fall through to this prompt. Move templated content into a tag or folder custom prompt so it is filled at upload time.</span>- </div></div><div class="flex justify-between items-center">@@ -2125,12 +2116,6 @@ Summarization Instructions:const promptSaveMessage = ref('');const promptSaveError = ref(false);const showFullPromptStructure = ref(false);- // True when the admin default contains {{...}} placeholders.- // Drives the inline warning under the textarea.- const adminDefaultPromptHasVariables = computed(() => {- const v = defaultSummaryPrompt.value;- return typeof v === 'string' && /\{\{\s*[A-Za-z_][A-Za-z0-9_]*\s*\}\}/.test(v);- });const originalDefaultPrompt = `Generate a comprehensive summary that includes the following sections:- **Key Issues Discussed**: A bulleted list of the main topics- **Key Decisions Made**: A bulleted list of any decisions reached@@ -3574,7 +3559,6 @@ Summarization Instructions:// Default Prompts statedefaultSummaryPrompt,- adminDefaultPromptHasVariables,isSavingPrompt,promptSaveMessage,promptSaveError,diff --git a/templates/components/upload-view.html b/templates/components/upload-view.htmlindex 4d93ec61..8a6427a9 100644--- a/templates/components/upload-view.html+++ b/templates/components/upload-view.html@@ -345,7 +345,12 @@<span class="ml-1 text-[10px] text-[var(--text-muted)] font-normal"><span v-for="(src, i) in variable.sources" :key="i"><span v-if="i > 0">, </span>- <i :class="src.type === 'folder' ? 'fas fa-folder' : 'fas fa-tag'" class="mr-0.5"></i>${ src.name }+ <i :class="{+ 'fas fa-folder': src.type === 'folder',+ 'fas fa-tag': src.type === 'tag',+ 'fas fa-user': src.type === 'user',+ 'fas fa-cog': src.type === 'admin'+ }" class="mr-0.5"></i>${ src.name }</span></span></label>