mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
38 lines
979 B
JavaScript
38 lines
979 B
JavaScript
require('dotenv').config();
|
|
const { KeyvFile } = require('keyv-file');
|
|
|
|
const clientOptions = {
|
|
modelOptions: {
|
|
model: 'gpt-3.5-turbo'
|
|
},
|
|
proxy: process.env.PROXY || null,
|
|
debug: false
|
|
};
|
|
|
|
const customClient = async ({ text, progressCallback, convo, promptPrefix, chatGptLabel }) => {
|
|
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
|
|
const store = {
|
|
store: new KeyvFile({ filename: './data/cache.json' })
|
|
};
|
|
|
|
clientOptions.chatGptLabel = chatGptLabel;
|
|
|
|
if (promptPrefix.length > 0) {
|
|
clientOptions.promptPrefix = promptPrefix;
|
|
}
|
|
|
|
const client = new ChatGPTClient(process.env.OPENAI_KEY, 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 = customClient;
|