mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
bing styling in progress
This commit is contained in:
parent
eae82edb83
commit
5e57deab5f
7 changed files with 58 additions and 22 deletions
27
api/app/citeText.js
Normal file
27
api/app/citeText.js
Normal 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
13
api/app/getCitations.js
Normal 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;
|
||||
|
|
@ -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
|
||||
};
|
||||
14
api/package-lock.json
generated
14
api/package-lock.json
generated
|
|
@ -11,7 +11,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@vscode/vscode-languagedetection": "^1.0.22",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.0",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
|
|
@ -1492,9 +1492,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@waylaidwanderer/chatgpt-api": {
|
||||
"version": "1.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.0.tgz",
|
||||
"integrity": "sha512-753dc/Eaf+1XmSXrLu+99LR4N+ACL7fQyA7GlsUXjRVXcH+m/iDqqXrU+o1JKGy84VlNKokAvq3oy9LVunKCIw==",
|
||||
"version": "1.28.2",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.2.tgz",
|
||||
"integrity": "sha512-efNvZr8uosiYD69zFq50OPM36s+tyRMixlHpwDzn2q9UuZrdHC++kmm23OAnDxv3/+vA4UwCsZXn+92c35NHBQ==",
|
||||
"dependencies": {
|
||||
"@dqbd/tiktoken": "^0.4.0",
|
||||
"@fastify/cors": "^8.2.0",
|
||||
|
|
@ -5781,9 +5781,9 @@
|
|||
"integrity": "sha512-rQ/BgMyLuIXSmbA0MSkIPHtcOw14QkeDbAq19sjvaS9LTRr905yij0S8lsyqN5JgOsbtIx7pAcyOxFMzPmqhZQ=="
|
||||
},
|
||||
"@waylaidwanderer/chatgpt-api": {
|
||||
"version": "1.28.0",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.0.tgz",
|
||||
"integrity": "sha512-753dc/Eaf+1XmSXrLu+99LR4N+ACL7fQyA7GlsUXjRVXcH+m/iDqqXrU+o1JKGy84VlNKokAvq3oy9LVunKCIw==",
|
||||
"version": "1.28.2",
|
||||
"resolved": "https://registry.npmjs.org/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.28.2.tgz",
|
||||
"integrity": "sha512-efNvZr8uosiYD69zFq50OPM36s+tyRMixlHpwDzn2q9UuZrdHC++kmm23OAnDxv3/+vA4UwCsZXn+92c35NHBQ==",
|
||||
"requires": {
|
||||
"@dqbd/tiktoken": "^0.4.0",
|
||||
"@fastify/cors": "^8.2.0",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@vscode/vscode-languagedetection": "^1.0.22",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.0",
|
||||
"@waylaidwanderer/chatgpt-api": "^1.28.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const express = require('express');
|
||||
const crypto = require('crypto');
|
||||
const router = express.Router();
|
||||
const { titleConvo, askSydney } = require('../../app/');
|
||||
const { titleConvo, getCitations, askSydney } = require('../../app/');
|
||||
const { saveMessage, deleteMessages, saveConvo, getConvoTitle } = require('../../models');
|
||||
const { handleError, sendMessage } = require('./handlers');
|
||||
|
||||
|
|
@ -39,16 +39,7 @@ router.post('/', async (req, res) => {
|
|||
});
|
||||
|
||||
console.log('SYDNEY RESPONSE');
|
||||
// the usual values expected by the client are generated since only
|
||||
// jailbreakConversationId and initial messageId is needed by sydney
|
||||
// to continue the conversation
|
||||
// if (!convo.jailbreakConversationId) {
|
||||
// response.title = await titleConvo({
|
||||
// model,
|
||||
// message: text,
|
||||
// response: JSON.stringify(response.response)
|
||||
// });
|
||||
// }
|
||||
// console.dir(response, { depth: null });
|
||||
|
||||
// Save sydney response
|
||||
response.id = response.messageId;
|
||||
|
|
@ -75,6 +66,9 @@ router.post('/', async (req, res) => {
|
|||
response.sender = model;
|
||||
response.final = true;
|
||||
|
||||
const links = getCitations(response);
|
||||
console.log('sydney links', links);
|
||||
|
||||
// Save user message
|
||||
userMessage.conversationId = response.conversationId;
|
||||
userMessage.parentMessageId = response.parentMessageId;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export default function Message({
|
|||
chatgpt: 'rgb(16, 163, 127)',
|
||||
chatgptBrowser: 'rgb(25, 207, 207)',
|
||||
bingai: '',
|
||||
sydney: 'rgb(214, 255, 255)',
|
||||
sydney: '',
|
||||
};
|
||||
|
||||
const isBing = sender === 'bingai' || sender === 'sydney';
|
||||
|
|
@ -65,7 +65,7 @@ export default function Message({
|
|||
if ((notUser && backgroundColor) || isBing) {
|
||||
icon = (
|
||||
<div
|
||||
style={{ backgroundColor }}
|
||||
style={isBing ? { background: 'radial-gradient(circle at 90% 110%, #F0F0FA, #D0E0F9)' } : { backgroundColor }}
|
||||
className="relative flex h-[30px] w-[30px] items-center justify-center rounded-sm p-1 text-white"
|
||||
>
|
||||
{isBing ? <BingIcon /> : <GPTIcon />}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue