Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: thread title summarization doesn't work well on reasoning models #4504

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions web/containers/Providers/ModelHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function ModelHandler() {
return
}

const messageContent = message.content[0]?.text?.value
let messageContent = message.content[0]?.text?.value
if (!messageContent) {
console.warn(
`Failed to update title for thread ${message.thread_id}: Responded content is null!`
Expand All @@ -144,27 +144,17 @@ export default function ModelHandler() {
// And no new line character is present
// And non-alphanumeric characters should be removed
if (messageContent.includes('\n')) {
console.warn(
`Failed to update title for thread ${message.thread_id}: Title can't contain new line character!`
)
return
messageContent = messageContent.replace(/\n/g, ' ')
}
const match = messageContent.match(/<\/think>(.*)$/)
if (match) {
messageContent = match[1]
}

// Remove non-alphanumeric characters
const cleanedMessageContent = messageContent
.replace(/[^\p{L}\s]+/gu, '')
.trim()

// Split the message into words
const words = cleanedMessageContent.split(' ')

if (words.length >= maxWordForThreadTitle) {
console.warn(
`Failed to update title for thread ${message.thread_id}: Title can't be greater than ${maxWordForThreadTitle} words!`
)
return
}

// Do not persist empty message
if (!cleanedMessageContent.trim().length) return

Expand Down Expand Up @@ -361,7 +351,7 @@ export default function ModelHandler() {

if (!threadMessages || threadMessages.length === 0) return

const summarizeFirstPrompt = `Summarize in a ${maxWordForThreadTitle}-word Title. Give the title only. "${threadMessages[0]?.content[0]?.text?.value}"`
const summarizeFirstPrompt = `Summarize in a ${maxWordForThreadTitle}-word Title. Give the title only. Here is the message: "${threadMessages[0]?.content[0]?.text?.value}"`

// Prompt: Given this query from user {query}, return to me the summary in 10 words as the title
const msgId = ulid()
Expand Down
Loading