feat: includes sources

This commit is contained in:
Daniel Avila 2023-03-09 18:42:36 -05:00
parent a451574760
commit 30936573ac
6 changed files with 49 additions and 9 deletions

View file

@ -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;

View file

@ -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<small>${links}</small>` : '');
await saveMessage(response);
await saveConvo(response);
sendMessage(res, response);

View file

@ -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,7 +41,9 @@ 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;
@ -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<small>${links}</small>` : '');
// Save user message
userMessage.conversationId = response.conversationId;

View file

@ -91,7 +91,6 @@ export default function TextChat({ messages }) {
})
);
} else if (model === 'sydney') {
console.log('Sydney data:', data)
const {
title,
jailbreakConversationId,

View file

@ -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;
}