LibreChat/api/app/getCitations.js
2023-03-09 16:09:53 -05:00

13 lines
No EOL
430 B
JavaScript

// const regex = / \[\d+\..*?\]\(.*?\)/g;
const regex = / \[.*?]\(.*?\)/g;
const getCitations = (res) => {
const textBlocks = res.details.adaptiveCards[0].body;
if (!textBlocks) return '';
let links = textBlocks[textBlocks.length - 1]?.text.match(regex);
if (links?.length === 0) return '';
links = links.map((link) => '- ' + link.trim());
return 'Learn more:\n' + links.join('\n');
};
module.exports = getCitations;