mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
31 lines
1,001 B
JavaScript
31 lines
1,001 B
JavaScript
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.
|
|
reverseProxyUrl: 'https://bypass.duti.tech/api/conversation',
|
|
// Access token from https://chat.openai.com/api/auth/session
|
|
accessToken: process.env.CHATGPT_TOKEN,
|
|
// debug: true
|
|
proxy: process.env.PROXY || null,
|
|
};
|
|
|
|
const browserClient = async ({ text, onProgress, convo, abortController }) => {
|
|
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
|
|
|
|
const store = {
|
|
store: new KeyvFile({ filename: './data/cache.json' })
|
|
};
|
|
|
|
const client = new ChatGPTBrowserClient(clientOptions, store);
|
|
let options = { onProgress, abortController };
|
|
|
|
if (!!convo.parentMessageId && !!convo.conversationId) {
|
|
options = { ...options, ...convo };
|
|
}
|
|
|
|
const res = await client.sendMessage(text, options);
|
|
return res;
|
|
};
|
|
|
|
module.exports = { browserClient };
|