mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-27 04:44:10 +01:00
⏭️ fix: Skip Title Generation for Temporary Chats (#11282)
* Not generating titles for temporary chats * Minor linter fix to prettify debug line * Adding a test for skipping title generation for temporary chats
This commit is contained in:
parent
7d38047bc2
commit
083251508e
4 changed files with 37 additions and 0 deletions
|
|
@ -1120,6 +1120,14 @@ class AgentClient extends BaseClient {
|
||||||
}
|
}
|
||||||
const { handleLLMEnd, collected: collectedMetadata } = createMetadataAggregator();
|
const { handleLLMEnd, collected: collectedMetadata } = createMetadataAggregator();
|
||||||
const { req, agent } = this.options;
|
const { req, agent } = this.options;
|
||||||
|
|
||||||
|
if (req?.body?.isTemporary) {
|
||||||
|
logger.debug(
|
||||||
|
`[api/server/controllers/agents/client.js #titleConvo] Skipping title generation for temporary conversation`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const appConfig = req.config;
|
const appConfig = req.config;
|
||||||
let endpoint = agent.endpoint;
|
let endpoint = agent.endpoint;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,25 @@ describe('AgentClient - titleConvo', () => {
|
||||||
expect(client.recordCollectedUsage).not.toHaveBeenCalled();
|
expect(client.recordCollectedUsage).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should skip title generation for temporary chats', async () => {
|
||||||
|
// Set isTemporary to true
|
||||||
|
mockReq.body.isTemporary = true;
|
||||||
|
|
||||||
|
const text = 'Test temporary chat';
|
||||||
|
const abortController = new AbortController();
|
||||||
|
|
||||||
|
const result = await client.titleConvo({ text, abortController });
|
||||||
|
|
||||||
|
// Should return undefined without generating title
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
|
||||||
|
// generateTitle should NOT have been called
|
||||||
|
expect(mockRun.generateTitle).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
// recordCollectedUsage should NOT have been called
|
||||||
|
expect(client.recordCollectedUsage).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should skip title generation when titleConvo is false in all config', async () => {
|
it('should skip title generation when titleConvo is false in all config', async () => {
|
||||||
// Set titleConvo to false in "all" config
|
// Set titleConvo to false in "all" config
|
||||||
mockReq.config = {
|
mockReq.config = {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ const addTitle = async (req, { text, response, client }) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip title generation for temporary conversations
|
||||||
|
if (req?.body?.isTemporary) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
||||||
const key = `${req.user.id}-${response.conversationId}`;
|
const key = `${req.user.id}-${response.conversationId}`;
|
||||||
/** @type {NodeJS.Timeout} */
|
/** @type {NodeJS.Timeout} */
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@ const addTitle = async (req, { text, responseText, conversationId }) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip title generation for temporary conversations
|
||||||
|
if (req?.body?.isTemporary) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
const titleCache = getLogStores(CacheKeys.GEN_TITLE);
|
||||||
const key = `${req.user.id}-${conversationId}`;
|
const key = `${req.user.id}-${conversationId}`;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue