Update index.ts

This commit is contained in:
bertybuttface 2023-02-09 17:50:16 +00:00
parent c9ddac5d5a
commit 81530d2462

View File

@ -19,13 +19,6 @@ LogService.setLevel(LogLevel.INFO);
LogService.trace = LogService.debug;
if (KEYV_URL && KEYV_BACKEND === 'file') LogService.warn('config', 'KEYV_URL is ignored when KEYV_BACKEND is set to `file`')
let chatgptStore:Keyv
if (KEYV_BACKEND === 'file'){
chatgptStore = new Keyv({store: new KeyvFile({ filename: path.join(DATA_PATH, `chatgpt-bot-api.json`),})})
} else {
chatgptStore = new Keyv(KEYV_URL, { namespace: 'chatgpt-bot-api' });
}
let storage: IStorageProvider
if (KEYV_BOT_STORAGE) {
storage = new KeyvStorageProvider('chatgpt-bot-storage');
@ -36,6 +29,11 @@ if (KEYV_BOT_STORAGE) {
let cryptoStore: ICryptoStorageProvider;
if (MATRIX_ENCRYPTION) cryptoStore = new RustSdkCryptoStorageProvider(path.join(DATA_PATH, "encrypted")); // /storage/encrypted
let cacheOptions // Options for the Keyv cache, see https://www.npmjs.com/package/keyv
if (KEYV_BACKEND === 'file'){
cacheOptions = { store: new KeyvFile({ filename: path.join(DATA_PATH, `chatgpt-bot-api.json`) }) };
} else { cacheOptions = { uri: KEYV_URL } }
async function main() {
if (!MATRIX_ACCESS_TOKEN){
const botUsernameWithoutDomain = parseMatrixUsernamePretty(MATRIX_BOT_USERNAME);
@ -54,9 +52,6 @@ async function main() {
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
debug: false,
};
const cacheOptions = { // Options for the Keyv cache, see https://www.npmjs.com/package/keyv
store: chatgptStore,
};
const chatgpt = new ChatGPTClient(OPENAI_API_KEY, clientOptions, cacheOptions);
// Automatically join rooms the bot is invited to