From da61a2841fec33ba9bfdcc9c5602e70a1399ef6f Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 7 Mar 2023 14:22:33 -0500 Subject: [PATCH] fix: customGpt persistence blindspot, also remove free gpt --- README.md | 4 +++- api/models/Conversation.js | 31 ++++++++++++++++++++++--------- api/models/index.js | 3 ++- api/server/routes/ask.js | 14 +++++++++++--- client/src/store/modelSlice.js | 15 ++++++++------- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ea16ab6fc0..dc0f3ffcc2 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,10 @@ ## Updates
-2023-03-06 +2023-03-07 Due to increased interest in the repo, I've dockerized the app as of this update for quick setup! See setup instructions below. I realize this still takes some time with installing docker dependencies, so it's on the roadmap to have a deployed demo. Besides this, I've made major improvements for a lot of the existing features across the board, mainly UI/UX. + +Also worth noting, the method to access the Free Version is no longer working, so I've removed it from model selection until further notice.
diff --git a/api/models/Conversation.js b/api/models/Conversation.js index 32adac4654..dfe4761a32 100644 --- a/api/models/Conversation.js +++ b/api/models/Conversation.js @@ -75,17 +75,30 @@ module.exports = { }, // getConvos: async () => await Conversation.find({}).sort({ created: -1 }).exec(), getConvos: async (pageNumber = 1, pageSize = 12) => { - const skip = (pageNumber - 1) * pageSize; - // const limit = pageNumber * pageSize; + try { + const skip = (pageNumber - 1) * pageSize; + // const limit = pageNumber * pageSize; - const conversations = await Conversation.find({}) - .sort({ created: -1 }) - .skip(skip) - // .limit(limit) - .limit(pageSize) - .exec(); + const conversations = await Conversation.find({}) + .sort({ created: -1 }) + .skip(skip) + // .limit(limit) + .limit(pageSize) + .exec(); - return conversations; + return conversations; + } catch (error) { + console.log(error); + return { message: 'Error getting conversations' }; + } + }, + getConvo: async (conversationId) => { + try { + return await Conversation.findOne({ conversationId }).exec(); + } catch (error) { + console.log(error); + return { message: 'Error getting single conversation' }; + } }, deleteConvos: async (filter) => { let deleteCount = await Conversation.deleteMany(filter).exec(); diff --git a/api/models/index.js b/api/models/index.js index 569cc5cd29..0b195d7248 100644 --- a/api/models/index.js +++ b/api/models/index.js @@ -1,10 +1,11 @@ const { saveMessage, deleteMessages } = require('./Message'); const { getCustomGpts, updateCustomGpt, updateByLabel, deleteCustomGpts } = require('./CustomGpt'); -const { saveConvo } = require('./Conversation'); +const { getConvo, saveConvo } = require('./Conversation'); module.exports = { saveMessage, deleteMessages, + getConvo, saveConvo, getCustomGpts, updateCustomGpt, diff --git a/api/server/routes/ask.js b/api/server/routes/ask.js index b3422cd785..ea515c6c75 100644 --- a/api/server/routes/ask.js +++ b/api/server/routes/ask.js @@ -9,14 +9,13 @@ const { customClient, detectCode } = require('../../app/'); -const { saveMessage, deleteMessages, saveConvo } = require('../../models'); +const { getConvo, saveMessage, deleteMessages, saveConvo } = require('../../models'); const { handleError, sendMessage } = require('./handlers'); router.use('/bing', askBing); router.post('/', async (req, res) => { - const { model, text, parentMessageId, conversationId, chatGptLabel, promptPrefix } = - req.body; + let { model, text, parentMessageId, conversationId, chatGptLabel, promptPrefix } = req.body; if (!text.trim().includes(' ') && text.length < 5) { return handleError(res, 'Prompt empty or too short'); } @@ -43,6 +42,15 @@ router.post('/', async (req, res) => { client = browserClient; } + if (model === 'chatgptCustom' && !chatGptLabel && conversationId) { + const convo = await getConvo({ conversationId }); + if (convo) { + console.log('found convo for custom gpt', { convo }) + chatGptLabel = convo.chatGptLabel; + promptPrefix = convo.promptPrefix; + } + } + res.writeHead(200, { Connection: 'keep-alive', 'Content-Type': 'text/event-stream', diff --git a/client/src/store/modelSlice.js b/client/src/store/modelSlice.js index 473d0dc407..c18d857164 100644 --- a/client/src/store/modelSlice.js +++ b/client/src/store/modelSlice.js @@ -16,15 +16,16 @@ const initialState = { _id: '2', name: 'BingAI', value: 'bingai' - }, - { - _id: '3', - name: 'ChatGPT', - value: 'chatgptBrowser' } + // { + // _id: '3', + // name: 'ChatGPT', + // value: 'chatgptBrowser' + // } ], modelMap: {}, - initial: { chatgpt: true, chatgptCustom: true, bingai: true, chatgptBrowser: true } + // initial: { chatgpt: true, chatgptCustom: true, bingai: true, chatgptBrowser: true } + initial: { chatgpt: true, chatgptCustom: true, bingai: true, } }; const currentSlice = createSlice({ @@ -37,7 +38,7 @@ const currentSlice = createSlice({ state.models = models; const modelMap = {}; - models.slice(4).forEach((modelItem) => { + models.slice(initialState.models.length).forEach((modelItem) => { modelMap[modelItem.value] = { chatGptLabel: modelItem.chatGptLabel, promptPrefix: modelItem.promptPrefix