chatgpt is taking shape, convo persists, layout mimics original

This commit is contained in:
Daniel Avila 2023-02-05 19:41:24 -05:00
parent 3a199757ae
commit f889f23792
9 changed files with 161 additions and 35 deletions

View file

@ -1,11 +1,23 @@
require('dotenv').config();
const Keyv = require('keyv');
const messageStore = new Keyv(process.env.MONGODB_URI, { namespace: 'chatgpt' });
const ask = async (question) => {
const ask = async (question, progressCallback, convo) => {
const { ChatGPTAPI } = await import('chatgpt');
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_KEY });
const res = await api.sendMessage(question, {
onProgress: (partialRes) => console.log(partialRes.text)
});
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_KEY, messageStore });
let options = {
onProgress: (partialRes) => {
if (partialRes.text.length > 0) {
progressCallback(partialRes);
}
}
};
if (!!convo.parentMessageId && !!convo.conversationId) {
options = { ...options, ...convo };
}
const res = await api.sendMessage(question, options);
return res;
};