mirror of
https://github.com/Mintplex-Labs/anything-llm
synced 2026-04-26 01:25:15 +02:00
[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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user