mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* Release 0.4.5 * Update @waylaidwanderer/node-chatgpt-api to latest version * Update dockerfiles to use workspaces and ensure packages are @ latest * Remove package-lock.json files from workspace directories as no longer needed * refactor(api): remove deprecated text-davinci-002-render-paid model from CHATGPT_MODELS refactor(api/client): change model comparison to use startsWith() instead of === for GPT-4 models
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
require('dotenv').config();
|
|
const { KeyvFile } = require('keyv-file');
|
|
|
|
const browserClient = async ({
|
|
text,
|
|
parentMessageId,
|
|
conversationId,
|
|
model,
|
|
token,
|
|
onProgress,
|
|
abortController,
|
|
userId
|
|
}) => {
|
|
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://ai.fakeopen.com/api/conversation',
|
|
// Access token from https://chat.openai.com/api/auth/session
|
|
accessToken: process.env.CHATGPT_TOKEN == 'user_provided' ? token : process.env.CHATGPT_TOKEN ?? null,
|
|
model: model,
|
|
debug: false,
|
|
proxy: process.env.PROXY || null,
|
|
user: userId
|
|
};
|
|
|
|
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 };
|