LibreChat/api/lib/parse/getCitations.js

15 lines
472 B
JavaScript
Raw Permalink Normal View History

2023-03-09 16:09:53 -05:00
// const regex = / \[\d+\..*?\]\(.*?\)/g;
const regex = / \[.*?]\(.*?\)/g;
const getCitations = (res) => {
const adaptiveCards = res.details.adaptiveCards;
const textBlocks = adaptiveCards && adaptiveCards[0].body;
2023-03-09 16:09:53 -05:00
if (!textBlocks) return '';
let links = textBlocks[textBlocks.length - 1]?.text.match(regex);
2023-03-09 18:07:36 -05:00
if (links?.length === 0 || !links) return '';
links = links.map((link) => link.trim());
2023-03-09 18:42:36 -05:00
return links.join('\n');
2023-03-09 16:09:53 -05:00
};
module.exports = getCitations;