mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
✂️ fix: Trim Reasoning Tags from Titles and Delete Button Visibility (#10285)
* fix: Sanitize LLM titles by stripping <think> tags and fix modal overflow * chore: linting * chore: Simplify title sanitization by removing unnecessary variable assignment and import order --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
9fbc2afe40
commit
05c706137e
6 changed files with 288 additions and 3 deletions
|
|
@ -10,6 +10,10 @@ jest.mock('@librechat/agents', () => ({
|
|||
}),
|
||||
}));
|
||||
|
||||
jest.mock('@librechat/api', () => ({
|
||||
...jest.requireActual('@librechat/api'),
|
||||
}));
|
||||
|
||||
describe('AgentClient - titleConvo', () => {
|
||||
let client;
|
||||
let mockRun;
|
||||
|
|
@ -252,6 +256,38 @@ describe('AgentClient - titleConvo', () => {
|
|||
expect(result).toBe('Generated Title');
|
||||
});
|
||||
|
||||
it('should sanitize the generated title by removing think blocks', async () => {
|
||||
const titleWithThinkBlock = '<think>reasoning about the title</think> User Hi Greeting';
|
||||
mockRun.generateTitle.mockResolvedValue({
|
||||
title: titleWithThinkBlock,
|
||||
});
|
||||
|
||||
const text = 'Test conversation text';
|
||||
const abortController = new AbortController();
|
||||
|
||||
const result = await client.titleConvo({ text, abortController });
|
||||
|
||||
// Should remove the <think> block and return only the clean title
|
||||
expect(result).toBe('User Hi Greeting');
|
||||
expect(result).not.toContain('<think>');
|
||||
expect(result).not.toContain('</think>');
|
||||
});
|
||||
|
||||
it('should return fallback title when sanitization results in empty string', async () => {
|
||||
const titleOnlyThinkBlock = '<think>only reasoning no actual title</think>';
|
||||
mockRun.generateTitle.mockResolvedValue({
|
||||
title: titleOnlyThinkBlock,
|
||||
});
|
||||
|
||||
const text = 'Test conversation text';
|
||||
const abortController = new AbortController();
|
||||
|
||||
const result = await client.titleConvo({ text, abortController });
|
||||
|
||||
// Should return the fallback title since sanitization would result in empty string
|
||||
expect(result).toBe('Untitled Conversation');
|
||||
});
|
||||
|
||||
it('should handle errors gracefully and return undefined', async () => {
|
||||
mockRun.generateTitle.mockRejectedValue(new Error('Title generation failed'));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue