2023-03-01 21:39:57 -05:00
|
|
|
require('dotenv').config();
|
|
|
|
|
const { KeyvFile } = require('keyv-file');
|
|
|
|
|
|
|
|
|
|
const clientOptions = {
|
|
|
|
|
// Warning: This will expose your access token to a third party. Consider the risks before using this.
|
2023-03-11 23:08:04 -05:00
|
|
|
reverseProxyUrl: 'https://bypass.duti.tech/api/conversation',
|
2023-03-01 21:39:57 -05:00
|
|
|
// Access token from https://chat.openai.com/api/auth/session
|
2023-03-08 19:47:23 -05:00
|
|
|
accessToken: process.env.CHATGPT_TOKEN,
|
|
|
|
|
// debug: true
|
2023-03-11 14:12:51 +08:00
|
|
|
proxy: process.env.PROXY || null,
|
2023-03-01 21:39:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const browserClient = async ({ text, progressCallback, convo }) => {
|
|
|
|
|
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
|
|
|
|
|
|
|
|
|
|
const store = {
|
2023-03-07 13:53:23 -05:00
|
|
|
store: new KeyvFile({ filename: './data/cache.json' })
|
2023-03-01 21:39:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const client = new ChatGPTBrowserClient(clientOptions, store);
|
|
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
|
onProgress: async (partialRes) => await progressCallback(partialRes)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!!convo.parentMessageId && !!convo.conversationId) {
|
|
|
|
|
options = { ...options, ...convo };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await client.sendMessage(text, options);
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = { browserClient };
|