mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
32 lines
787 B
JavaScript
32 lines
787 B
JavaScript
![]() |
const Keyv = require('keyv');
|
||
|
const { KeyvFile } = require('keyv-file');
|
||
|
const crypto = require('crypto');
|
||
|
|
||
|
const addToCache = async ( { conversationId, parentMessageId }) => {
|
||
|
const conversationsCache = new Keyv({
|
||
|
store: new KeyvFile({ filename: './data/cache.json' })
|
||
|
});
|
||
|
|
||
|
let conversation = await conversationsCache.get(conversationId);
|
||
|
let isNewConversation = false;
|
||
|
if (!conversation) {
|
||
|
conversation = {
|
||
|
messages: [],
|
||
|
createdAt: Date.now()
|
||
|
};
|
||
|
isNewConversation = true;
|
||
|
}
|
||
|
|
||
|
// const shouldGenerateTitle = opts.shouldGenerateTitle && isNewConversation;
|
||
|
|
||
|
const userMessage = {
|
||
|
id: crypto.randomUUID(),
|
||
|
parentMessageId,
|
||
|
role: 'User',
|
||
|
message
|
||
|
};
|
||
|
conversation.messages.push(userMessage);
|
||
|
};
|
||
|
|
||
|
module.exports = { addToCache };
|