fix: customGpt persistence blindspot, also remove free gpt

This commit is contained in:
Danny Avila 2023-03-07 14:22:33 -05:00
parent da55ac3774
commit da61a2841f
5 changed files with 46 additions and 21 deletions

View file

@ -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',