mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
fix: inline citations click issue
This commit is contained in:
parent
7dd5c957cf
commit
53f1caf91f
3 changed files with 19 additions and 27 deletions
|
|
@ -18,6 +18,13 @@
|
||||||
let selectedCitation: any = null;
|
let selectedCitation: any = null;
|
||||||
let isCollapsibleOpen = false;
|
let isCollapsibleOpen = false;
|
||||||
|
|
||||||
|
export const showSourceModal = (sourceIdx) => {
|
||||||
|
if (citations[sourceIdx]) {
|
||||||
|
selectedCitation = citations[sourceIdx];
|
||||||
|
showCitationModal = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function calculateShowRelevance(sources: any[]) {
|
function calculateShowRelevance(sources: any[]) {
|
||||||
const distances = sources.flatMap((citation) => citation.distances ?? []);
|
const distances = sources.flatMap((citation) => citation.distances ?? []);
|
||||||
const inRange = distances.filter((d) => d !== undefined && d >= -1 && d <= 1).length;
|
const inRange = distances.filter((d) => d !== undefined && d >= -1 && d <= 1).length;
|
||||||
|
|
|
||||||
|
|
@ -139,15 +139,15 @@
|
||||||
{preview}
|
{preview}
|
||||||
{done}
|
{done}
|
||||||
{topPadding}
|
{topPadding}
|
||||||
sourceIds={(sources ?? []).reduce((acc, s) => {
|
sourceIds={(sources ?? []).reduce((acc, source) => {
|
||||||
let ids = [];
|
let ids = [];
|
||||||
s.document.forEach((document, index) => {
|
source.document.forEach((document, index) => {
|
||||||
if (model?.info?.meta?.capabilities?.citations == false) {
|
if (model?.info?.meta?.capabilities?.citations == false) {
|
||||||
ids.push('N/A');
|
ids.push('N/A');
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadata = s.metadata?.[index];
|
const metadata = source.metadata?.[index];
|
||||||
const id = metadata?.source ?? 'N/A';
|
const id = metadata?.source ?? 'N/A';
|
||||||
|
|
||||||
if (metadata?.name) {
|
if (metadata?.name) {
|
||||||
|
|
@ -158,7 +158,7 @@
|
||||||
if (id.startsWith('http://') || id.startsWith('https://')) {
|
if (id.startsWith('http://') || id.startsWith('https://')) {
|
||||||
ids.push(id);
|
ids.push(id);
|
||||||
} else {
|
} else {
|
||||||
ids.push(s?.source?.name ?? id);
|
ids.push(source?.source?.name ?? id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ids;
|
return ids;
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@
|
||||||
export let readOnly = false;
|
export let readOnly = false;
|
||||||
export let topPadding = false;
|
export let topPadding = false;
|
||||||
|
|
||||||
|
let citationsElement: HTMLDivElement;
|
||||||
let buttonsContainerElement: HTMLDivElement;
|
let buttonsContainerElement: HTMLDivElement;
|
||||||
let showDeleteConfirm = false;
|
let showDeleteConfirm = false;
|
||||||
|
|
||||||
|
|
@ -820,29 +821,9 @@
|
||||||
}}
|
}}
|
||||||
onSourceClick={async (id, idx) => {
|
onSourceClick={async (id, idx) => {
|
||||||
console.log(id, idx);
|
console.log(id, idx);
|
||||||
let sourceButton = document.getElementById(`source-${message.id}-${idx}`);
|
|
||||||
const sourcesCollapsible = document.getElementById(
|
|
||||||
`collapsible-${message.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sourceButton) {
|
if (citationsElement) {
|
||||||
sourceButton.click();
|
citationsElement?.showSourceModal(idx - 1);
|
||||||
} else if (sourcesCollapsible) {
|
|
||||||
// Open sources collapsible so we can click the source button
|
|
||||||
sourcesCollapsible
|
|
||||||
.querySelector('div:first-child')
|
|
||||||
.dispatchEvent(new PointerEvent('pointerup', {}));
|
|
||||||
|
|
||||||
// Wait for next frame to ensure DOM updates
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
requestAnimationFrame(resolve);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Try clicking the source button again
|
|
||||||
sourceButton = document.getElementById(`source-${message.id}-${idx}`);
|
|
||||||
sourceButton && sourceButton.click();
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onAddMessages={({ modelId, parentId, messages }) => {
|
onAddMessages={({ modelId, parentId, messages }) => {
|
||||||
|
|
@ -863,7 +844,11 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if (message?.sources || message?.citations) && (model?.info?.meta?.capabilities?.citations ?? true)}
|
{#if (message?.sources || message?.citations) && (model?.info?.meta?.capabilities?.citations ?? true)}
|
||||||
<Citations id={message?.id} sources={message?.sources ?? message?.citations} />
|
<Citations
|
||||||
|
bind:this={citationsElement}
|
||||||
|
id={message?.id}
|
||||||
|
sources={message?.sources ?? message?.citations}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if message.code_executions}
|
{#if message.code_executions}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue