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

Use workspace LLM to create thread name #2701

Closed
Closed
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
36 changes: 31 additions & 5 deletions server/models/workspaceThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,39 @@ const WorkspaceThread = {
user_id: user?.id || null,
thread_id: thread.id,
});

if (chatCount !== 1) return { renamed: false, thread };
const { thread: updatedThread } = await this.update(thread, {
name: newName,
});

onRename?.(updatedThread);
return true;
try {
const { ApiChatHandler } = require("../utils/chats/apiChatHandler");
const trimmedUserInput = newName.slice(0, 300); // don't send the entire message to LLM to save on tokens
const systemPrompt =
"You are a helpful AI that generates short, descriptive titles for conversations. Keep titles under 23 characters.";
const result = await ApiChatHandler.chatSync({
workspace,
message: `Based on the user's initial input, concisely create a title for this conversation in the format of: {action} {thing}. For example 'Building' (action) 'a brick wall' (thing). Return text only [a-zA-Z0-9 ]. Sentence case. This is the user's initial input: ${trimmedUserInput}`,
mode: "chat",
systemPrompt,
});

const suggestedName =
result.textResponse?.trim() || truncate(newName, 22);
const { thread: updatedThread } = await this.update(thread, {
name: suggestedName,
});

onRename?.(updatedThread);
return true;
} catch (error) {
console.error("Failed to generate thread name with LLM:", error);
// Fallback to original truncation method
const { thread: updatedThread } = await this.update(thread, {
name: truncate(newName, 22),
});

onRename?.(updatedThread);
return true;
}
},
};

Expand Down