-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt_store.py
More file actions
42 lines (32 loc) · 1.43 KB
/
Copy pathprompt_store.py
File metadata and controls
42 lines (32 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
prompt_store.py
---------------
Runtime-editable system prompt store.
The admin can update Sarah's personality/instructions via the dashboard.
Changes are persisted directly to the Supabase PostgreSQL database
(`system_config` table) so they survive Render's server restarts.
"""
import logging
from database import get_system_config, set_system_config, delete_system_config
logger = logging.getLogger(__name__)
_PROMPT_KEY = "system_prompt"
def get_active_prompt(default_prompt: str) -> str:
"""Return the override prompt from the database if it exists, otherwise the default."""
try:
content = get_system_config(_PROMPT_KEY)
if content:
logger.info("📝 [PROMPT] Using database-overridden system prompt.")
return content
except Exception as e:
logger.warning(f"⚠️ [PROMPT] Failed to read from DB: {e} — using default.")
return default_prompt
def save_prompt(new_prompt: str) -> None:
"""Persist a new prompt to the database."""
set_system_config(_PROMPT_KEY, new_prompt.strip())
logger.info(f"✅ [PROMPT] Saved new system prompt to DB ({len(new_prompt)} chars).")
def delete_prompt_override() -> bool:
"""Remove the override from the database, reverting to the code default."""
deleted = delete_system_config(_PROMPT_KEY)
if deleted:
logger.info("🗑️ [PROMPT] DB override removed — reverted to default prompt.")
return deleted