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
4c6567c4
"vscode:/vscode.git/clone" did not exist on "7785af9de2cc5dc94f157d7d0640c142b2f60eaa"
Commit
4c6567c4
authored
May 06, 2024
by
Jun Siang Cheah
Committed by
Timothy J. Baek
May 06, 2024
Browse files
feat: group citations by source
parent
c3425f3b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
src/lib/components/chat/Messages/CitationsModal.svelte
src/lib/components/chat/Messages/CitationsModal.svelte
+0
-2
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+32
-5
No files found.
src/lib/components/chat/Messages/CitationsModal.svelte
View file @
4c6567c4
...
...
@@ -49,7 +49,6 @@
<div class="flex flex-col w-full px-5 py-4 dark:text-gray-200 overflow-y-scroll max-h-[22rem]">
{#each mergedDocuments as document}
<!-- Source from document.metadata.source -->
<div class="flex flex-col w-full">
<div class="text-lg font-medium dark:text-gray-300">
{$i18n.t('Source')}
...
...
@@ -58,7 +57,6 @@
{document.metadata?.source ?? $i18n.t('No source available')}
</div>
</div>
<!-- Content from document.document.content -->
<div class="flex flex-col w-full">
<div class="text-lg font-medium dark:text-gray-300">
{$i18n.t('Content')}
...
...
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
4c6567c4
...
...
@@ -67,6 +67,8 @@
let showRateComment = false;
let showCitations = {};
// Backend returns a list of citations per collection, we flatten it to citations per source
let flattenedCitations = {};
$: tokens = marked.lexer(sanitizeResponseContent(message.content));
...
...
@@ -133,6 +135,28 @@
allowHTML: true
});
}
if (message.citations) {
for (const citation of message.citations) {
const zipped = (citation?.document ?? []).map(function (document, index) {
return [document, citation.metadata?.[index]];
});
for (const [document, metadata] of zipped) {
const source = metadata?.source ?? 'N/A';
if (source in flattenedCitations) {
flattenedCitations[source].document.push(document);
flattenedCitations[source].metadata.push(metadata);
} else {
flattenedCitations[source] = {
document: [document],
metadata: [metadata]
};
}
}
}
console.log(flattenedCitations);
console.log(Object.keys(flattenedCitations));
}
};
const renderLatex = () => {
...
...
@@ -363,16 +387,19 @@
{/each}
</div>
{/if}
{#if
message.c
itations}
{#if
flattenedC
itations}
<div class="my-2.5 w-full flex overflow-x-auto gap-2 flex-wrap">
{#each
message.c
itations as
citation
}
{#each
[...Object.keys(flattenedC
itations
)]
as
source
}
<div>
<CitationsModal bind:show={showCitations[citation]} {citation} />
<CitationsModal
bind:show={showCitations[source]}
citation={flattenedCitations[source]}
/>
<button
class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none text-left"
type="button"
on:click={() => {
showCitations[
citation
] = !showCitations[
citation
];
showCitations[
source
] = !showCitations[
source
];
}}
>
<div class="p-2.5 bg-red-400 text-white rounded-lg">
...
...
@@ -395,7 +422,7 @@
<div class="flex flex-col justify-center -space-y-0.5">
<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
{
citation.metadata?.[0]?.source ?? 'N/A'
}
{
source
}
</div>
<div class=" text-gray-500 text-sm">{$i18n.t('Document')}</div>
...
...
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