Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add append vs replace mode for tag and custom prompts in the reprocess summary modal
Murtaza Nasird93dc2143596
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex 2c8b9368..c14eab2c 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -1188,13 +1188,20 @@ def reprocess_summary(recording_id):if client is None:return jsonify({'error': 'Summary service is not available (OpenRouter client not configured)'}), 503- # Get custom prompt from request if provided+ # Get custom prompt + mode from request if provideddata = request.get_json() or {}custom_prompt = data.get('custom_prompt', '').strip() if data.get('custom_prompt') else None+ prompt_mode = (data.get('prompt_mode') or 'replace').strip().lower()+ if prompt_mode not in ('replace', 'append'):+ prompt_mode = 'replace'+ custom_prompt_append = bool(custom_prompt) and prompt_mode == 'append'# Debug loggingif custom_prompt:- current_app.logger.info(f"Received custom prompt override for recording {recording_id} (length: {len(custom_prompt)})")+ current_app.logger.info(+ f"Received custom prompt override for recording {recording_id} "+ f"(mode={prompt_mode}, length={len(custom_prompt)})"+ )else:current_app.logger.info(f"No custom prompt override provided for recording {recording_id}, will use default priority")@@ -1212,6 +1219,7 @@ def reprocess_summary(recording_id):# Queue summary generation jobjob_params = {'custom_prompt': custom_prompt,+ 'custom_prompt_append': custom_prompt_append,'user_id': current_user.id}job_queue.enqueue(diff --git a/src/services/job_queue.py b/src/services/job_queue.pyindex 794e0de3..ef14c74f 100644--- a/src/services/job_queue.py+++ b/src/services/job_queue.py@@ -449,6 +449,7 @@ class FairJobQueue:current_app._get_current_object().app_context(),recording.id,custom_prompt_override=params.get('custom_prompt'),+ custom_prompt_append=params.get('custom_prompt_append', False),user_id=params.get('user_id'))diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 7ff0ed29..0a1af761 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -464,6 +464,7 @@ document.addEventListener('DOMContentLoaded', async () => {const summaryReprocessPromptSource = ref('default');const summaryReprocessSelectedTagId = ref('');const summaryReprocessCustomPrompt = ref('');+ const summaryReprocessPromptMode = ref('append'); // 'append' | 'replace'const speakerMap = ref({});const speakerColorMap = ref({}); // Stable mapping of speaker ID → color classconst modalSpeakers = ref([]);@@ -727,7 +728,7 @@ document.addEventListener('DOMContentLoaded', async () => {userShares, isLoadingShares, copiedShareId,shareToDelete, showShareDeleteModal, recordingToDelete, recordingToReset,reprocessType, reprocessRecording, isAutoIdentifying, asrReprocessOptions,- summaryReprocessPromptSource, summaryReprocessSelectedTagId, summaryReprocessCustomPrompt,+ summaryReprocessPromptSource, summaryReprocessSelectedTagId, summaryReprocessCustomPrompt, summaryReprocessPromptMode,speakerMap, speakerColorMap, modalSpeakers, speakerDisplayMap, regenerateSummaryAfterSpeakerUpdate, speakerSuggestions,loadingSuggestions, activeSpeakerInput, voiceSuggestions, loadingVoiceSuggestions,diff --git a/static/js/modules/composables/reprocess.js b/static/js/modules/composables/reprocess.jsindex 9b5edb89..cd04a4ee 100644--- a/static/js/modules/composables/reprocess.js+++ b/static/js/modules/composables/reprocess.js@@ -13,6 +13,7 @@ export function useReprocess(state, utils) {reprocessRecording, recordingToReset, selectedRecording,recordings, asrReprocessOptions, summaryReprocessPromptSource,summaryReprocessSelectedTagId, summaryReprocessCustomPrompt,+ summaryReprocessPromptMode,availableTags, processingProgress, processingMessage,currentlyProcessingFile, uploadQueue, userTranscriptionLanguage,showCustomizeSummaryModal, customizeSummaryPrompt, customizeSummaryMode@@ -130,7 +131,8 @@ export function useReprocess(state, utils) {recordingId,summaryReprocessPromptSource.value,summaryReprocessSelectedTagId.value,- summaryReprocessCustomPrompt.value+ summaryReprocessCustomPrompt.value,+ summaryReprocessPromptMode.value);}};@@ -191,7 +193,7 @@ export function useReprocess(state, utils) {// Summary Reprocessing// =========================================- const reprocessSummary = async (recordingId, promptSource, selectedTagId, customPrompt) => {+ const reprocessSummary = async (recordingId, promptSource, selectedTagId, customPrompt, promptMode) => {if (!recordingId) {setGlobalError('No recording ID provided for reprocessing.');return;@@ -200,14 +202,17 @@ export function useReprocess(state, utils) {try {const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');const requestBody = { reprocess_summary: true };+ const mode = promptMode === 'append' ? 'append' : 'replace';if (promptSource === 'tag' && selectedTagId) {const selectedTag = availableTags.value.find(t => t.id == selectedTagId);if (selectedTag && selectedTag.custom_prompt) {requestBody.custom_prompt = selectedTag.custom_prompt;+ requestBody.prompt_mode = mode;}} else if (promptSource === 'custom' && customPrompt) {requestBody.custom_prompt = customPrompt;+ requestBody.prompt_mode = mode;}const response = await fetch(`/recording/${recordingId}/reprocess_summary`, {diff --git a/templates/modals/reprocess-modal.html b/templates/modals/reprocess-modal.htmlindex 37357364..6203c12b 100644--- a/templates/modals/reprocess-modal.html+++ b/templates/modals/reprocess-modal.html@@ -143,6 +143,29 @@<textarea id="reprocess-custom-prompt" v-model="summaryReprocessCustomPrompt" rows="4" 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)] text-sm bg-[var(--bg-input)] text-[var(--text-primary)]" placeholder="Enter your custom summarization instructions..."></textarea></div>+ <!-- Apply mode toggle for tag and custom prompt sources -->+ <div v-if="summaryReprocessPromptSource === 'tag' || summaryReprocessPromptSource === 'custom'">+ <label class="block text-sm font-medium text-[var(--text-muted)] mb-2">Apply mode</label>+ <div class="grid grid-cols-2 gap-2 p-1 bg-[var(--bg-tertiary)] border border-[var(--border-secondary)] rounded-md">+ <label+ :class="['flex items-start gap-2 p-2 rounded cursor-pointer transition-colors', summaryReprocessPromptMode === 'append' ? 'bg-[var(--bg-secondary)] border border-[var(--border-accent)] shadow-sm' : 'border border-transparent hover:bg-[var(--bg-secondary)]']">+ <input type="radio" v-model="summaryReprocessPromptMode" value="append" class="mt-0.5 h-4 w-4 text-[var(--text-accent)] border-[var(--border-secondary)] focus:ring-[var(--border-focus)]">+ <span class="flex-1">+ <span class="block text-sm font-medium text-[var(--text-primary)]">Append</span>+ <span class="block text-xs text-[var(--text-muted)] mt-0.5">Use the default prompt and add this as extra context.</span>+ </span>+ </label>+ <label+ :class="['flex items-start gap-2 p-2 rounded cursor-pointer transition-colors', summaryReprocessPromptMode === 'replace' ? 'bg-[var(--bg-secondary)] border border-[var(--border-accent)] shadow-sm' : 'border border-transparent hover:bg-[var(--bg-secondary)]']">+ <input type="radio" v-model="summaryReprocessPromptMode" value="replace" class="mt-0.5 h-4 w-4 text-[var(--text-accent)] border-[var(--border-secondary)] focus:ring-[var(--border-focus)]">+ <span class="flex-1">+ <span class="block text-sm font-medium text-[var(--text-primary)]">Replace</span>+ <span class="block text-xs text-[var(--text-muted)] mt-0.5">Use only this text as the summarisation instructions.</span>+ </span>+ </label>+ </div>+ </div>+<!-- Info message when no tags with custom prompts exist --><div v-if="summaryReprocessPromptSource === 'tag' && tagsWithCustomPrompts.length === 0" class="text-xs text-[var(--text-muted)] italic">No tags with custom prompts available. Create tags with custom prompts in the Account Settings.