Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #106 from matrixgpt/keyv-fix
Browse files Browse the repository at this point in the history
Keyv fixes
  • Loading branch information
bertybuttface authored Feb 10, 2023
2 parents c9ddac5 + 81530d2 commit 8d2c0d4
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 8d2c0d4

Please sign in to comment.