Commit 7538dc05 authored by Jun Siang Cheah's avatar Jun Siang Cheah
Browse files

feat: use url as source name for citations

parent 77928ae1
...@@ -453,6 +453,11 @@ ...@@ -453,6 +453,11 @@
citation.document.forEach((document, index) => { citation.document.forEach((document, index) => {
const metadata = citation.metadata?.[index]; const metadata = citation.metadata?.[index];
const id = metadata?.source ?? 'N/A'; const id = metadata?.source ?? 'N/A';
let source = citation?.source;
// Check if ID looks like a URL
if (id.startsWith('http://') || id.startsWith('https://')) {
source = { name: id };
}
const existingSource = acc.find((item) => item.id === id); const existingSource = acc.find((item) => item.id === id);
...@@ -460,7 +465,7 @@ ...@@ -460,7 +465,7 @@
existingSource.document.push(document); existingSource.document.push(document);
existingSource.metadata.push(metadata); existingSource.metadata.push(metadata);
} else { } else {
acc.push( { id: id, source: citation?.source, document: [document], metadata: metadata ? [metadata] : [] } ); acc.push( { id: id, source: source, document: [document], metadata: metadata ? [metadata] : [] } );
} }
}); });
return acc; return acc;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment