Skip to content

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

Python

fix: prevent duplicate Sources sections - prompt forbids model-written source lists and the renderer strips a trailing citations-only Sources/References block before appending its own

Murtaza Nasird054e8aa9469
diff --git a/src/services/inquire_agent.py b/src/services/inquire_agent.py
index 2926340c..b31442ff 100644
--- a/src/services/inquire_agent.py
+++ b/src/services/inquire_agent.py
@@ -579,9 +579,10 @@ moment. The link text must ALWAYS be the recording's exact title (plus " @ time"
never a date, a number, or other text — because the interface derives a numbered source list from \
it: citations render as compact numbered markers and the titles appear once at the end. For the \
same reason, avoid repeating a recording's title in the prose immediately around its citation. \
-When the user refers to a bare number ("what about 5", "open 3"), they mean that numbered citation \
-from your previous answer; the displayed numbering is included with each earlier answer in this \
-conversation — use it, never guess.
+Never write a "Sources" or "References" section yourself — the interface appends one \
+automatically; end your answer after the last point. When the user refers to a bare number \
+("what about 5", "open 3"), they mean that numbered citation from your previous answer; the \
+displayed numbering is included with each earlier answer in this conversation — use it, never guess.
- Order information from the most recent recordings first unless the question implies otherwise."""
diff --git a/templates/inquire.html b/templates/inquire.html
index 97a0f0fa..a7b02a25 100644
--- a/templates/inquire.html
+++ b/templates/inquire.html
@@ -985,6 +985,31 @@
// this mapping is sent back with the history.
message.sources = [...refs.entries()].map(([id, e]) => ({ n: e.n, recording_id: Number(id), title: e.title }));
}
+ // Strip a model-written trailing Sources/References
+ // section (the interface appends its own). Removed
+ // ONLY when everything after the heading is bare
+ // citation links — real prose is never dropped.
+ const topNodes = [...tpl.content.children];
+ for (let i = topNodes.length - 1; i >= 0; i--) {
+ const el = topNodes[i];
+ const headingish = /^H[1-6]$/.test(el.tagName) ||
+ (el.tagName === 'P' && el.children.length === 1 &&
+ el.firstElementChild && el.firstElementChild.tagName === 'STRONG' &&
+ el.firstElementChild.textContent.trim() === el.textContent.trim());
+ if (!headingish) continue;
+ if (!/^(sources?|references?|quellen|fuentes|fontes|источники|来源)\s*:?$/i.test(el.textContent.trim())) continue;
+ const tail = topNodes.slice(i + 1);
+ const onlyCitations = tail.every(node => {
+ const clone = node.cloneNode(true);
+ clone.querySelectorAll('a[href^="/recordings/"]').forEach(a => a.remove());
+ return clone.textContent.replace(/[\d\s.,;:()\[\]@–—-]+/g, '') === '';
+ });
+ if (onlyCitations) {
+ tail.forEach(node => node.remove());
+ el.remove();
+ }
+ break;
+ }
if (refs.size) {
const wrap = document.createElement('div');
wrap.className = 'citation-refs';