2023-02-12 22:24:36 -05:00
|
|
|
require('dotenv').config();
|
|
|
|
|
const Keyv = require('keyv');
|
|
|
|
|
const { KeyvFile } = require('keyv-file');
|
|
|
|
|
|
2023-02-13 21:15:28 -05:00
|
|
|
const proxyOptions = {
|
2023-02-12 22:24:36 -05:00
|
|
|
reverseProxyUrl: 'https://chatgpt.pawan.krd/api/completions',
|
|
|
|
|
modelOptions: {
|
|
|
|
|
model: 'text-davinci-002-render'
|
|
|
|
|
},
|
|
|
|
|
debug: false
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-13 21:15:28 -05:00
|
|
|
const davinciOptions = {
|
|
|
|
|
modelOptions: {
|
|
|
|
|
model: 'text-davinci-003'
|
|
|
|
|
},
|
|
|
|
|
debug: false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const askClient = async ({ model, text, progressCallback, convo }) => {
|
2023-02-14 18:34:46 -05:00
|
|
|
// const clientOptions = model === 'chatgpt' ? proxyOptions : davinciOptions;
|
2023-02-12 22:24:36 -05:00
|
|
|
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
2023-02-19 21:06:21 -05:00
|
|
|
const client = new ChatGPTClient(process.env.OPENAI_KEY, davinciOptions, {
|
2023-02-12 22:24:36 -05:00
|
|
|
store: new KeyvFile({ filename: 'cache.json' })
|
|
|
|
|
});
|
|
|
|
|
let options = {
|
|
|
|
|
onProgress: async (partialRes) => await progressCallback(partialRes)
|
|
|
|
|
// onProgress: progressCallback
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!!convo.parentMessageId && !!convo.conversationId) {
|
|
|
|
|
options = { ...options, ...convo };
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 21:15:28 -05:00
|
|
|
const res = await client.sendMessage(text, options);
|
2023-02-12 22:24:36 -05:00
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = { askClient };
|