Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
aef2a514
"git@developer.sourcefind.cn:modelzoo/resnet50_tensorflow.git" did not exist on "77080ad11f016e5365d28d0681cc4c0a95a7061f"
Commit
aef2a514
authored
May 06, 2024
by
Timothy J. Baek
Browse files
refac: citation rendering
parent
64ed0d10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
31 deletions
+45
-31
src/lib/components/chat/Messages/CitationsModal.svelte
src/lib/components/chat/Messages/CitationsModal.svelte
+3
-4
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+42
-27
No files found.
src/lib/components/chat/Messages/CitationsModal.svelte
View file @
aef2a514
...
@@ -5,12 +5,11 @@
...
@@ -5,12 +5,11 @@
const i18n = getContext('i18n');
const i18n = getContext('i18n');
export let show = false;
export let show = false;
export let citation
: any[]
;
export let citation;
let mergedDocuments = [];
let mergedDocuments = [];
onMount(async () => {
$: if (citation) {
// Merge the document with its metadata
mergedDocuments = citation.document?.map((c, i) => {
mergedDocuments = citation.document?.map((c, i) => {
return {
return {
source: citation.source,
source: citation.source,
...
@@ -18,7 +17,7 @@
...
@@ -18,7 +17,7 @@
metadata: citation.metadata?.[i]
metadata: citation.metadata?.[i]
};
};
});
});
}
);
}
</script>
</script>
<Modal size="lg" bind:show>
<Modal size="lg" bind:show>
...
...
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
aef2a514
...
@@ -66,8 +66,8 @@
...
@@ -66,8 +66,8 @@
let showRateComment = false;
let showRateComment = false;
// Backend returns a list of citations per collection, we flatten it to citations per source
let showCitationModal = false;
let
c
itation
s
=
{}
;
let
selectedC
itation =
null
;
$: tokens = marked.lexer(sanitizeResponseContent(message.content));
$: tokens = marked.lexer(sanitizeResponseContent(message.content));
...
@@ -134,24 +134,6 @@
...
@@ -134,24 +134,6 @@
allowHTML: true
allowHTML: true
});
});
}
}
if (message.citations) {
message.citations.forEach((citation) => {
citation.document.forEach((document, index) => {
const metadata = citation.metadata?.[index];
const source = citation?.source?.name ?? metadata?.source ?? 'N/A';
citations[source] = citations[source] || {
source: citation.source,
document: [],
metadata: []
};
citations[source].document.push(document);
citations[source].metadata.push(metadata);
});
});
}
};
};
const renderLatex = () => {
const renderLatex = () => {
...
@@ -346,6 +328,8 @@
...
@@ -346,6 +328,8 @@
});
});
</script>
</script>
<CitationsModal bind:show={showCitationModal} citation={selectedCitation} />
{#key message.id}
{#key message.id}
<div class=" flex w-full message-{message.id}" id="message-{message.id}">
<div class=" flex w-full message-{message.id}" id="message-{message.id}">
<ProfileImage
<ProfileImage
...
@@ -467,13 +451,43 @@
...
@@ -467,13 +451,43 @@
</div>
</div>
</div>
</div>
{#if Object.keys(citations).length > 0}
<!-- if (message.citations) {
<hr class=" dark:border-gray-800" />
citations = message.citations.forEach((citation) => {
citation.document.forEach((document, index) => {
const metadata = citation.metadata?.[index];
const source = citation?.source?.name ?? metadata?.source ?? 'N/A';
citations[source] = citations[source] || {
source: citation.source,
document: [],
metadata: []
};
citations[source].document.push(document);
citations[source].metadata.push(metadata);
});
});
} -->
{#if message.citations}
<hr class=" dark:border-gray-800" />
<div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
<div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
{#each Object.keys(citations) as source, idx}
{#each message.citations.reduce((acc, citation) => {
<CitationsModal bind:show={citations[source].show} citation={citations[source]} />
citation.document.forEach((document, index) => {
const metadata = citation.metadata?.[index];
const id = metadata?.source ?? 'N/A';
const existingSource = acc.find((item) => item.id === id);
if (existingSource) {
existingSource.document.push(document);
existingSource.metadata.push(metadata);
} else {
acc.push( { id: id, source: citation?.source, document: [document], metadata: metadata ? [metadata] : [] } );
}
});
return acc;
}, []) as citation, idx}
<div class="flex gap-1 text-xs font-semibold">
<div class="flex gap-1 text-xs font-semibold">
<div>
<div>
[{idx + 1}]
[{idx + 1}]
...
@@ -482,10 +496,11 @@
...
@@ -482,10 +496,11 @@
<button
<button
class="dark:text-gray-500 underline"
class="dark:text-gray-500 underline"
on:click={() => {
on:click={() => {
citations[source].show = !citations[source].show;
showCitationModal = true;
selectedCitation = citation;
}}
}}
>
>
{citation
s[source]
.source.name}
{citation.source.name}
</button>
</button>
</div>
</div>
{/each}
{/each}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment