mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
* fix: handling of top_k and top_p parameters for Claude-3.7 models (allowed without reasoning) * feat: bump @librechat/agents for Anthropic Reasoning support * fix: update reasoning handling for OpenRouter integration * fix: enhance agent token spending logic to include cache creation and read details * fix: update logic for thinking status in ContentParts component * refactor: improve agent title handling * chore: bump @librechat/agents to version 2.1.7 for parallel tool calling for Google models
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
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}`;
|
|
const responseText =
|
|
response?.content && Array.isArray(response?.content)
|
|
? response.content.reduce((acc, block) => {
|
|
if (block?.type === 'text') {
|
|
return acc + block.text;
|
|
}
|
|
return acc;
|
|
}, '')
|
|
: (response?.content ?? response?.text ?? '');
|
|
|
|
const title = await client.titleConvo({
|
|
text,
|
|
responseText,
|
|
conversationId: response.conversationId,
|
|
});
|
|
await titleCache.set(key, title, 120000);
|
|
await saveConvo(
|
|
req,
|
|
{
|
|
conversationId: response.conversationId,
|
|
title,
|
|
},
|
|
{ context: 'api/server/services/Endpoints/agents/title.js' },
|
|
);
|
|
};
|
|
|
|
module.exports = addTitle;
|