LibreChat/api/app/clients/chatgpt-client.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

require('dotenv').config();
const { KeyvFile } = require('keyv-file');
2023-03-31 03:22:57 +08:00
// const set = new Set(['gpt-4', 'text-davinci-003', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301']);
2023-03-31 03:22:57 +08:00
const askClient = async ({
text,
parentMessageId,
conversationId,
model,
chatGptLabel,
promptPrefix,
temperature,
top_p,
presence_penalty,
frequency_penalty,
2023-03-31 03:22:57 +08:00
onProgress,
abortController
}) => {
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
const store = {
2023-03-07 13:53:23 -05:00
store: new KeyvFile({ filename: './data/cache.json' })
};
2023-03-31 03:22:57 +08:00
const clientOptions = {
modelOptions: {
model: model,
temperature,
top_p,
presence_penalty,
frequency_penalty
2023-03-31 03:22:57 +08:00
},
chatGptLabel,
promptPrefix,
proxy: process.env.PROXY || null,
debug: false
};
const client = new ChatGPTClient(process.env.OPENAI_KEY, clientOptions, store);
2023-03-17 03:13:42 +08:00
let options = { onProgress, abortController };
2023-03-31 03:22:57 +08:00
if (!!parentMessageId && !!conversationId) {
options = { ...options, parentMessageId, conversationId };
}
const res = await client.sendMessage(text, options);
return res;
};
module.exports = { askClient };