Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
feat: cites text with links
Daniel Avilaa451574760c2
diff --git a/api/app/citeText.js b/api/app/citeText.jsindex fc85c3285f..8998535fea 100644--- a/api/app/citeText.js+++ b/api/app/citeText.js@@ -1,27 +1,29 @@-/*-// 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 citationRegex = /\[\^\d+?\^]/g;-const regex = /\[\^\d+?\^]/g;+const citeText = (res, noLinks = false) => {+ let result = res.text || res;+ const citations = Array.from(new Set(result.match(citationRegex)));+ if (citations?.length === 0) return result;-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;+ if (noLinks) {+ citations.forEach((citation) => {+ const digit = citation.match(/\d+?/g)[0];+ result = result.replaceAll(citation, `<sup>[${digit}](#)</sup>`);+ });++ return result;+ }-const citeText = (res) => {let sources = res.details.sourceAttributions;- if (!sources) return res.response;+ if (sources?.length === 0) return result;sources = sources.map((source) => source.seeMoreUrl);++ citations.forEach((citation) => {+ const digit = citation.match(/\d+?/g)[0];+ result = result.replaceAll(citation, `<sup>[${digit}](${sources[digit - 1]})</sup>`);+ });++ return result;};-module.exports = citeText;\ No newline at end of file+module.exports = citeText;diff --git a/api/app/getCitations.js b/api/app/getCitations.jsindex 46d4e72c07..0061daff0d 100644--- a/api/app/getCitations.js+++ b/api/app/getCitations.js@@ -5,7 +5,7 @@ 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 '';+ if (links?.length === 0 || !links) return '';links = links.map((link) => '- ' + link.trim());return 'Learn more:\n' + links.join('\n');};diff --git a/api/app/index.js b/api/app/index.jsindex 0a829609fd..7b61f8de95 100644--- a/api/app/index.js+++ b/api/app/index.js@@ -5,6 +5,7 @@ const { askBing } = require('./bingai');const { askSydney } = require('./sydney');const titleConvo = require('./titleConvo');const getCitations = require('./getCitations');+const citeText = require('./citeText');const detectCode = require('./detectCode');module.exports = {@@ -15,5 +16,6 @@ module.exports = {askSydney,titleConvo,getCitations,+ citeText,detectCode};\ No newline at end of filediff --git a/api/server/routes/askSydney.js b/api/server/routes/askSydney.jsindex 1755a40d16..fc6fe9f5ce 100644--- a/api/server/routes/askSydney.js+++ b/api/server/routes/askSydney.js@@ -1,7 +1,7 @@const express = require('express');const crypto = require('crypto');const router = express.Router();-const { titleConvo, getCitations, askSydney } = require('../../app/');+const { titleConvo, getCitations, citeText, askSydney } = require('../../app/');const { saveMessage, deleteMessages, saveConvo, getConvoTitle } = require('../../models');const { handleError, sendMessage } = require('./handlers');@@ -29,6 +29,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 });};@@ -60,6 +61,7 @@ router.post('/', async (req, res) => {? convo.conversationSignature: crypto.randomUUID();response.text = response.response;+ delete response.response;response.suggestions =response.details.suggestedResponses &&response.details.suggestedResponses.map((s) => s.text);@@ -67,7 +69,7 @@ router.post('/', async (req, res) => {response.final = true;const links = getCitations(response);- console.log('sydney links', links);+ response.text = citeText(response);// Save user messageuserMessage.conversationId = response.conversationId;diff --git a/client/src/utils/handleSubmit.js b/client/src/utils/handleSubmit.jsindex 02f89f21d6..09e1aa52b6 100644--- a/client/src/utils/handleSubmit.js+++ b/client/src/utils/handleSubmit.js@@ -24,7 +24,6 @@ export default function handleSubmit({const isBing = model === 'bingai' || model === 'sydney';if (isBing && convo.conversationId) {- console.log('bing convo', convo);payload = {...payload,jailbreakConversationId: convo.jailbreakConversationId,diff --git a/client/webpack.config.js b/client/webpack.config.jsindex 2461658544..3c44be5385 100644--- a/client/webpack.config.js+++ b/client/webpack.config.js@@ -10,6 +10,7 @@ module.exports = {* to use its built-in optimizations accordingly. default is production*/mode: 'development',+ cache: false,/** "entry"* the entry point*/