From 66ad54168a948f291257972d47b15d45cde9bf4e Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Fri, 17 Mar 2023 02:08:03 +0800 Subject: [PATCH] feat: regenerate for bingai --- api/server/routes/askBing.js | 11 ++++++++--- api/server/routes/askSydney.js | 14 ++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/api/server/routes/askBing.js b/api/server/routes/askBing.js index 0614faf86a..007aba779b 100644 --- a/api/server/routes/askBing.js +++ b/api/server/routes/askBing.js @@ -9,6 +9,7 @@ router.post('/', async (req, res) => { const { model, text, + overrideParentMessageId=null, parentMessageId, conversationId: oldConversationId, ...convo @@ -37,8 +38,10 @@ router.post('/', async (req, res) => { ...convo }); - await saveMessage(userMessage); - await saveConvo(req?.session?.user?.username, { ...userMessage, model, ...convo }); + if (!overrideParentMessageId) { + await saveMessage(userMessage); + await saveConvo(req?.session?.user?.username, { ...userMessage, model, ...convo }); + } return await ask({ isNewConversation, @@ -46,6 +49,7 @@ router.post('/', async (req, res) => { model, convo, preSendRequest: true, + overrideParentMessageId, req, res }); @@ -101,7 +105,8 @@ const ask = async ({ convo.conversationSignature || response.conversationSignature; userMessage.conversationId = response.conversationId || conversationId; userMessage.invocationId = response.invocationId; - await saveMessage(userMessage); + if (!overrideParentMessageId) + await saveMessage(userMessage); // Bing API will not use our conversationId at the first time, // so change the placeholder conversationId to the real one. diff --git a/api/server/routes/askSydney.js b/api/server/routes/askSydney.js index a2017cf7d6..77f95371a0 100644 --- a/api/server/routes/askSydney.js +++ b/api/server/routes/askSydney.js @@ -9,6 +9,7 @@ router.post('/', async (req, res) => { const { model, text, + overrideParentMessageId=null, parentMessageId, conversationId: oldConversationId, ...convo @@ -37,8 +38,10 @@ router.post('/', async (req, res) => { ...convo }); - await saveMessage(userMessage); - await saveConvo(req?.session?.user?.username, { ...userMessage, model, ...convo }); + if (!overrideParentMessageId) { + await saveMessage(userMessage); + await saveConvo(req?.session?.user?.username, { ...userMessage, model, ...convo }); + } return await ask({ isNewConversation, @@ -46,6 +49,7 @@ router.post('/', async (req, res) => { model, convo, preSendRequest: true, + overrideParentMessageId, req, res }); @@ -102,7 +106,8 @@ const ask = async ({ userMessage.conversationId = response.conversationId || conversationId; userMessage.invocationId = response.invocationId; // Unlike gpt and bing, Sydney will never accept our given userMessage.messageId, it will generate its own one. - await saveMessage(userMessage); + if (!overrideParentMessageId) + await saveMessage(userMessage); // Save sydney response // response.id = response.messageId; @@ -125,7 +130,8 @@ const ask = async ({ // Save user message userMessage.conversationId = response.conversationId || conversationId; - await saveMessage(userMessage); + if (!overrideParentMessageId) + await saveMessage(userMessage); // Bing API will not use our conversationId at the first time, // so change the placeholder conversationId to the real one.