mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
wip: refactor: new abort message handling
This commit is contained in:
parent
b59588c6ee
commit
6246ffff1e
2 changed files with 45 additions and 14 deletions
31
api/server/routes/ask/addToCache.js
Normal file
31
api/server/routes/ask/addToCache.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue