2024-03-23 20:21:40 -04:00
|
|
|
const { CacheKeys } = require('librechat-data-provider');
|
|
|
|
|
const getLogStores = require('~/cache/getLogStores');
|
|
|
|
|
const { isEnabled } = require('~/server/utils');
|
|
|
|
|
const { saveConvo } = require('~/models');
|
|
|
|
|
|
|
|
|
|
const addTitle = async (req, { text, response, client }) => {
|
|
|
|
|
const { TITLE_CONVO = 'true' } = process.env ?? {};
|
|
|
|
|
if (!isEnabled(TITLE_CONVO)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (client.options.titleConvo === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the request was aborted, don't generate the title.
|
|
|
|
|
if (client.abortController.signal.aborted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
|
|
|
|
const key = `${req.user.id}-${response.conversationId}`;
|
|
|
|
|
|
2024-08-18 06:00:03 -04:00
|
|
|
const title = await client.titleConvo({
|
|
|
|
|
text,
|
|
|
|
|
responseText: response?.text,
|
|
|
|
|
conversationId: response.conversationId,
|
|
|
|
|
});
|
2024-03-23 20:21:40 -04:00
|
|
|
await titleCache.set(key, title, 120000);
|
2024-07-20 01:51:59 -04:00
|
|
|
await saveConvo(
|
|
|
|
|
req,
|
|
|
|
|
{
|
|
|
|
|
conversationId: response.conversationId,
|
|
|
|
|
title,
|
|
|
|
|
},
|
|
|
|
|
{ context: 'api/server/services/Endpoints/anthropic/addTitle.js' },
|
|
|
|
|
);
|
2024-03-23 20:21:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = addTitle;
|