[FEAT] Rename new threads on thread creation (#1607)

* make thread name 'Thread' when new thread is created

* implement auto generated thread titles

* implement truncated prompt as thread name

* move rename of thread into workspaceThread function

---------

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
Sean Hatfield
2024-06-07 14:06:47 -07:00
committed by GitHub
parent 13da9cb396
commit 3c98d15c6a
7 changed files with 72 additions and 13 deletions

View File

@@ -8,7 +8,7 @@ const WorkspaceThread = {
try {
const thread = await prisma.workspace_threads.create({
data: {
name: "New thread",
name: "Thread",
slug: uuidv4(),
user_id: userId ? Number(userId) : null,
workspace_id: workspace.id,
@@ -84,6 +84,25 @@ const WorkspaceThread = {
return [];
}
},
// Will fire on first message (included or not) for a thread and rename the thread with the newName prop.
autoRenameThread: async function ({
workspace = null,
thread = null,
user = null,
newName = null,
}) {
if (!workspace || !thread || !newName) return false;
const { WorkspaceChats } = require("./workspaceChats");
const chatCount = await WorkspaceChats.count({
workspaceId: workspace.id,
user_id: user?.id || null,
thread_id: thread.id,
});
if (chatCount !== 1) return false;
await this.update(thread, { name: newName });
return true;
},
};
module.exports = { WorkspaceThread };