mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
chatgpt is taking shape, convo persists, layout mimics original
This commit is contained in:
parent
3a199757ae
commit
f889f23792
9 changed files with 161 additions and 35 deletions
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue