bing styling in progress

This commit is contained in:
Danny Avila 2023-03-09 16:09:53 -05:00
parent eae82edb83
commit 5e57deab5f
7 changed files with 58 additions and 22 deletions

27
api/app/citeText.js Normal file
View file

@ -0,0 +1,27 @@
/*
// example
const ex = "Fetch API[^1^], Axios[^3^], or XMLHttpRequest[^2^]. Each of these...";
const links = [
'https://www.freecodecamp.org/news/here-is-the-most-popular-ways-to-make-an-http-request-in-javascript-954ce8c95aaa/',
'https://stackoverflow.com/questions/247483/http-get-request-in-javascript',
'https://livecodestream.dev/post/5-ways-to-make-http-requests-in-javascript/'
];
const regex = /\[\^\d+?\^]/g;
const citations = Array.from(new Set(ex.match(regex)));
const linkMap = {};
citations.forEach(citation => {
const digit = citation.match(/\d+?/g)[0];
linkMap[citation] = links[digit - 1];
});
*/
const citationRegex = /\[\^\d+?\^]/g;
const citeText = (res) => {
let sources = res.details.sourceAttributions;
if (!sources) return res.response;
sources = sources.map((source) => source.seeMoreUrl);
};
module.exports = citeText;

13
api/app/getCitations.js Normal file
View file

@ -0,0 +1,13 @@
// 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;

View file

@ -4,6 +4,7 @@ const customClient = require('./chatgpt-custom');
const { askBing } = require('./bingai');
const { askSydney } = require('./sydney');
const titleConvo = require('./titleConvo');
const getCitations = require('./getCitations');
const detectCode = require('./detectCode');
module.exports = {
@ -13,5 +14,6 @@ module.exports = {
askBing,
askSydney,
titleConvo,
getCitations,
detectCode
};