diff --git a/api/app/citeText.js b/api/app/citeText.js index 8998535fea..536c981d4e 100644 --- a/api/app/citeText.js +++ b/api/app/citeText.js @@ -8,7 +8,7 @@ const citeText = (res, noLinks = false) => { if (noLinks) { citations.forEach((citation) => { const digit = citation.match(/\d+?/g)[0]; - result = result.replaceAll(citation, `[${digit}](#)`); + result = result.replaceAll(citation, `[${digit}](#) `); }); return result; @@ -20,7 +20,7 @@ const citeText = (res, noLinks = false) => { citations.forEach((citation) => { const digit = citation.match(/\d+?/g)[0]; - result = result.replaceAll(citation, `[${digit}](${sources[digit - 1]})`); + result = result.replaceAll(citation, `[${digit}](${sources[digit - 1]}) `); }); return result; diff --git a/api/app/getCitations.js b/api/app/getCitations.js index 0061daff0d..f4086a4e9e 100644 --- a/api/app/getCitations.js +++ b/api/app/getCitations.js @@ -6,8 +6,8 @@ const getCitations = (res) => { if (!textBlocks) return ''; let links = textBlocks[textBlocks.length - 1]?.text.match(regex); if (links?.length === 0 || !links) return ''; - links = links.map((link) => '- ' + link.trim()); - return 'Learn more:\n' + links.join('\n'); + links = links.map((link) => link.trim()); + return links.join('\n'); }; module.exports = getCitations; \ No newline at end of file diff --git a/api/server/routes/askBing.js b/api/server/routes/askBing.js index d77282f888..36218320b6 100644 --- a/api/server/routes/askBing.js +++ b/api/server/routes/askBing.js @@ -1,9 +1,10 @@ const express = require('express'); const crypto = require('crypto'); const router = express.Router(); -const { titleConvo, askBing } = require('../../app/'); +const { titleConvo, getCitations, citeText, askBing } = require('../../app/'); const { saveMessage, deleteMessages, saveConvo } = require('../../models'); const { handleError, sendMessage } = require('./handlers'); +const citationRegex = /\[\^\d+?\^]/g; router.post('/', async (req, res) => { const { model, text, ...convo } = req.body; @@ -29,6 +30,7 @@ router.post('/', async (req, res) => { const progressCallback = async (partial) => { tokens += partial === text ? '' : partial; // tokens = appendCode(tokens); + tokens = citeText(tokens, true); sendMessage(res, { text: tokens, message: true }); }; @@ -39,7 +41,8 @@ router.post('/', async (req, res) => { }); console.log('BING RESPONSE'); - console.dir(response, { depth: null }); + // console.dir(response, { depth: null }); + const hasCitations = citationRegex.test(response.response); userMessage.conversationSignature = convo.conversationSignature || response.conversationSignature; @@ -56,12 +59,19 @@ router.post('/', async (req, res) => { } response.text = response.response; + delete response.response; response.id = response.details.messageId; response.suggestions = response.details.suggestedResponses && response.details.suggestedResponses.map((s) => s.text); response.sender = model; response.final = true; + + const links = getCitations(response); + response.text = + citeText(response) + + (links?.length > 0 && hasCitations ? `\n${links}` : ''); + await saveMessage(response); await saveConvo(response); sendMessage(res, response); diff --git a/api/server/routes/askSydney.js b/api/server/routes/askSydney.js index fc6fe9f5ce..b328f879fa 100644 --- a/api/server/routes/askSydney.js +++ b/api/server/routes/askSydney.js @@ -4,6 +4,7 @@ const router = express.Router(); const { titleConvo, getCitations, citeText, askSydney } = require('../../app/'); const { saveMessage, deleteMessages, saveConvo, getConvoTitle } = require('../../models'); const { handleError, sendMessage } = require('./handlers'); +const citationRegex = /\[\^\d+?\^]/g; router.post('/', async (req, res) => { const { model, text, ...convo } = req.body; @@ -40,8 +41,10 @@ router.post('/', async (req, res) => { }); console.log('SYDNEY RESPONSE'); + console.log(response.response); // console.dir(response, { depth: null }); - + const hasCitations = citationRegex.test(response.response); + // Save sydney response response.id = response.messageId; // response.parentMessageId = convo.parentMessageId ? convo.parentMessageId : response.messageId; @@ -69,7 +72,9 @@ router.post('/', async (req, res) => { response.final = true; const links = getCitations(response); - response.text = citeText(response); + response.text = + citeText(response) + + (links?.length > 0 && hasCitations ? `\n${links}` : ''); // Save user message userMessage.conversationId = response.conversationId; diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 2350c68e5d..9cf474357b 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -91,7 +91,6 @@ export default function TextChat({ messages }) { }) ); } else if (model === 'sydney') { - console.log('Sydney data:', data) const { title, jailbreakConversationId, diff --git a/client/src/style.css b/client/src/style.css index 7fd5ad79b6..961c67b597 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -7,6 +7,32 @@ outline: 1px solid limegreen !important; } */ +/* p small { + opacity: 0; + animation: fadeIn 3s ease forwards; +} + +@keyframes fadeIn { + from { + opacity: 0; + transform: translateY(-10px); + } + to { + opacity: 1; + transform: translateY(0); + } +} */ + +p > small { + opacity: 0; + animation: fadein 2s forwards; +} + +@keyframes fadein { + from { opacity: 0; transform: translateY(-20px); } + to { opacity: 1; transform: translateY(0); } +} + blockquote, dd, dl, fieldset, figure, h1, h2, h3, h4, h5, h6, hr, p, pre { margin: 0; }