Widget:ChatBox: Unterschied zwischen den Versionen
Aus MediaWiki
Alex (Diskussion | Beiträge) Create ChatBox widget for multi-turn RAG chat |
Alex (Diskussion | Beiträge) Fix source list rendering: match API fields (score/url/content) |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 313: | Zeile 313: | ||
html += '<div class="chat-sources-list" id="' + listId + '">'; | html += '<div class="chat-sources-list" id="' + listId + '">'; | ||
sources.forEach(function(s) { | sources.forEach(function(s) { | ||
var pct = Math.round((s. | var pct = Math.round((s.score || 0) * 100); | ||
var | var url = s.url || ''; | ||
var title = ''; | |||
if (url) { | |||
var seg = url.split('/').pop(); | |||
try { seg = decodeURIComponent(seg); } catch (e) {} | |||
title = seg.replace(/_/g, ' '); | |||
} | |||
html += '<div class="chat-source-item">' | html += '<div class="chat-source-item">' | ||
+ '<h5><a href="' + | + '<h5><a href="' + escapeHtml(url) + '">' + escapeHtml(title) + '</a></h5>' | ||
+ '<p class="chat-source-snippet">' + escapeHtml(truncate(s. | + '<p class="chat-source-snippet">' + escapeHtml(truncate(s.content || '', 150)) + '</p>' | ||
+ '<div class="chat-source-meta">Relevanz: ' + pct + '% | + '<div class="chat-source-meta">Relevanz: ' + pct + '% · ' + escapeHtml(s.source || '') + '</div>' | ||
+ '</div>'; | + '</div>'; | ||
}); | }); | ||
| Zeile 339: | Zeile 345: | ||
if (remaining > 0) { | if (remaining > 0) { | ||
statusEl.textContent = remaining + ' R\u00fcckfrage' + (remaining !== 1 ? 'n' : '') + ' verbleibend'; | statusEl.textContent = remaining + ' R\u00fcckfrage' + (remaining !== 1 ? 'n' : '') + ' verbleibend'; | ||
} else if (remaining === 0 | } else if (remaining === 0) { if (conversationId) { | ||
statusEl.textContent = 'Keine R\u00fcckfragen mehr m\u00f6glich'; | statusEl.textContent = 'Keine R\u00fcckfragen mehr m\u00f6glich'; | ||
input.disabled = true; | input.disabled = true; | ||
sendBtn.disabled = true; | sendBtn.disabled = true; | ||
input.placeholder = 'Starte eine neue Unterhaltung'; | input.placeholder = 'Starte eine neue Unterhaltung'; | ||
} | } } | ||
newBtn.className = conversationId ? 'visible' : ''; | newBtn.className = conversationId ? 'visible' : ''; | ||
} | } | ||