Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Consolidate the default summary prompt into one constant (was copy-pasted in 4 places)

Murtaza Nasir5728e9ed2e87
diff --git a/src/api/auth.py b/src/api/auth.py
index fa41425e..8d16c234 100644
--- a/src/api/auth.py
+++ b/src/api/auth.py
@@ -632,11 +632,9 @@ def account():
if admin_default_prompt:
default_summary_prompt_text = admin_default_prompt
else:
- # Fallback to hardcoded default if admin hasn't set one
- default_summary_prompt_text = """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
-- **Action Items**: A bulleted list of tasks assigned, including who is responsible if mentioned"""
+ # Fallback to the shipped default if admin hasn't set one.
+ from src.config.prompts import DEFAULT_SUMMARY_PROMPT
+ default_summary_prompt_text = DEFAULT_SUMMARY_PROMPT
asr_diarize_locked = 'ASR_DIARIZE' in os.environ
ASR_DIARIZE = os.environ.get('ASR_DIARIZE', 'false').lower() == 'true'
diff --git a/src/config/prompts.py b/src/config/prompts.py
new file mode 100644
index 00000000..c5e198b8
--- /dev/null
+++ b/src/config/prompts.py
@@ -0,0 +1,16 @@
+"""Default prompt templates — single source of truth.
+
+Kept dependency-free (no app/model imports) so both ``src/init_db.py`` (which
+seeds the admin setting on a fresh database) and ``src/tasks/processing.py``
+(which uses it as a runtime fallback) can import it cheaply without circular
+imports. Previously this text was copy-pasted in three places and could drift;
+change it here only.
+"""
+
+# The summary prompt a fresh install ships with, and the fallback used at
+# summarization time when no per-recording / tag / folder / user / admin prompt
+# is set. To change the shipped default, edit this string.
+DEFAULT_SUMMARY_PROMPT = """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
+- **Action Items**: A bulleted list of tasks assigned, including who is responsible if mentioned"""
diff --git a/src/init_db.py b/src/init_db.py
index 41093b0b..5e7d016c 100644
--- a/src/init_db.py
+++ b/src/init_db.py
@@ -665,13 +665,10 @@ def initialize_database(app):
app.logger.info("Initialized default asr_timeout_seconds setting")
if not SystemSetting.query.filter_by(key='admin_default_summary_prompt').first():
- default_prompt = """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
-- **Action Items**: A bulleted list of tasks assigned, including who is responsible if mentioned"""
+ from src.config.prompts import DEFAULT_SUMMARY_PROMPT
SystemSetting.set_setting(
key='admin_default_summary_prompt',
- value=default_prompt,
+ value=DEFAULT_SUMMARY_PROMPT,
description='Default summarization prompt used when users have not set their own prompt. This serves as the base prompt for all users.',
setting_type='string'
)
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index a40d98d5..371ba0f9 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -571,11 +571,9 @@ def generate_summary_only_task(app_context, recording_id, custom_prompt_override
current_app.logger.info(f"Using admin default prompt for recording {recording_id}")
summarization_instructions = admin_default_prompt
else:
- # Fallback to hardcoded default if admin hasn't set one
- summarization_instructions = """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
-- **Action Items**: A bulleted list of tasks assigned, including who is responsible if mentioned"""
+ # Fallback to the shipped default if admin hasn't set one.
+ from src.config.prompts import DEFAULT_SUMMARY_PROMPT
+ summarization_instructions = DEFAULT_SUMMARY_PROMPT
current_app.logger.info(f"Using hardcoded default prompt for recording {recording_id}")
# Append the user's per-run additions on top of the resolved default
@@ -2366,10 +2364,8 @@ def generate_incognito_summary(transcription_text, user=None):
if admin_default_prompt:
summarization_instructions = admin_default_prompt
else:
- summarization_instructions = """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
-- **Action Items**: A bulleted list of tasks assigned, including who is responsible if mentioned"""
+ from src.config.prompts import DEFAULT_SUMMARY_PROMPT
+ summarization_instructions = DEFAULT_SUMMARY_PROMPT
# Build messages
system_message_content = "You are an AI assistant that generates comprehensive summaries for meeting transcripts. Respond only with the summary in Markdown format."
diff --git a/tests/test_default_summary_prompt.py b/tests/test_default_summary_prompt.py
new file mode 100644
index 00000000..c8b52bf3
--- /dev/null
+++ b/tests/test_default_summary_prompt.py
@@ -0,0 +1,43 @@
+"""Guards for the consolidated default summary prompt.
+
+The default summary prompt used to be copy-pasted in four places (init_db seed,
+two processing.py fallbacks, the account-page render). They now all reference
+src.config.prompts.DEFAULT_SUMMARY_PROMPT. These tests make sure the constant
+stays meaningful and that a fresh database seeds exactly that value, so the
+single source of truth can't silently drift from what installs actually get.
+"""
+
+import sys
+import os
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from src.config.prompts import DEFAULT_SUMMARY_PROMPT
+
+
+def test_default_summary_prompt_is_meaningful():
+ """The constant must be non-trivial markdown with the expected sections, so
+ an accidental empty/garbled edit is caught."""
+ assert isinstance(DEFAULT_SUMMARY_PROMPT, str)
+ assert DEFAULT_SUMMARY_PROMPT.strip(), "default summary prompt must not be empty"
+ for section in ("Key Issues Discussed", "Key Decisions Made", "Action Items"):
+ assert section in DEFAULT_SUMMARY_PROMPT, f"missing expected section: {section}"
+
+
+def test_fresh_install_seeds_the_constant():
+ """initialize_database (run once by conftest) must seed
+ admin_default_summary_prompt with exactly the shared constant — i.e. a fresh
+ install ships the constant, not a stale hardcoded copy."""
+ from src.app import app
+ from src.models import SystemSetting
+
+ with app.app_context():
+ seeded = SystemSetting.get_setting('admin_default_summary_prompt', None)
+ assert seeded == DEFAULT_SUMMARY_PROMPT, (
+ "the seeded admin_default_summary_prompt drifted from "
+ "src.config.prompts.DEFAULT_SUMMARY_PROMPT"
+ )
+
+
+if __name__ == "__main__":
+ sys.exit(__import__("pytest").main([__file__, "-q"]))