Add sanitizeGeneratedChatTitle function and update sendMessage logic
This commit is contained in:
11
src/App.jsx
11
src/App.jsx
@@ -12,6 +12,15 @@ import {
|
|||||||
loadStoredWebsearchEngines,
|
loadStoredWebsearchEngines,
|
||||||
normalizeWebsearchEngines,
|
normalizeWebsearchEngines,
|
||||||
} from './websearchEngines'
|
} from './websearchEngines'
|
||||||
|
|
||||||
|
function sanitizeGeneratedChatTitle(title) {
|
||||||
|
return (title || '')
|
||||||
|
.replace(/<think(?:ing)?>[\s\S]*?<\/think(?:ing)?>/gi, '')
|
||||||
|
.replace(/[*#]/g, '')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
|
||||||
// Extract <think> or <thinking> block (first occurrence) and return { think, answer }
|
// Extract <think> or <thinking> block (first occurrence) and return { think, answer }
|
||||||
function splitThinkBlocks(text) {
|
function splitThinkBlocks(text) {
|
||||||
if (!text) return { think: null, answer: '' };
|
if (!text) return { think: null, answer: '' };
|
||||||
@@ -1495,7 +1504,7 @@ async function sendMessage() {
|
|||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const sanitizedTitle = data.title.replace(/<think(?:ing)?>[\s\S]*?<\/think(?:ing)?>/i, '').trim()
|
const sanitizedTitle = sanitizeGeneratedChatTitle(data.title)
|
||||||
setChatSessions(prevSessions =>
|
setChatSessions(prevSessions =>
|
||||||
prevSessions.map(session =>
|
prevSessions.map(session =>
|
||||||
session.session_id === targetSessionId ? { ...session, name: sanitizedTitle } : session
|
session.session_id === targetSessionId ? { ...session, name: sanitizedTitle } : session
|
||||||
|
|||||||
Reference in New Issue
Block a user