mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

feat: support OPENAI_REVERSE_PROXY feat: support set availModels in env file fix: chatgpt Browser send logic refactor. fix: title wrong usage of responseMessage BREAKING: some env paramaters has been changed!
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
require('dotenv').config();
|
|
const { KeyvFile } = require('keyv-file');
|
|
|
|
const browserClient = async ({
|
|
text,
|
|
parentMessageId,
|
|
conversationId,
|
|
model,
|
|
onProgress,
|
|
abortController
|
|
}) => {
|
|
const { ChatGPTBrowserClient } = await import('@waylaidwanderer/chatgpt-api');
|
|
const store = {
|
|
store: new KeyvFile({ filename: './data/cache.json' })
|
|
};
|
|
|
|
const clientOptions = {
|
|
// Warning: This will expose your access token to a third party. Consider the risks before using this.
|
|
reverseProxyUrl: process.env.CHATGPT_REVERSE_PROXY || 'https://bypass.churchless.tech/api/conversation',
|
|
// Access token from https://chat.openai.com/api/auth/session
|
|
accessToken: process.env.CHATGPT_TOKEN,
|
|
model: model,
|
|
// debug: true
|
|
proxy: process.env.PROXY || null
|
|
};
|
|
|
|
const client = new ChatGPTBrowserClient(clientOptions, store);
|
|
let options = { onProgress, abortController };
|
|
|
|
if (!!parentMessageId && !!conversationId) {
|
|
options = { ...options, parentMessageId, conversationId };
|
|
}
|
|
|
|
console.log('gptBrowser clientOptions', clientOptions);
|
|
|
|
if (parentMessageId === '00000000-0000-0000-0000-000000000000') {
|
|
delete options.conversationId;
|
|
}
|
|
|
|
const res = await client.sendMessage(text, options);
|
|
return res;
|
|
};
|
|
|
|
module.exports = { browserClient };
|