mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
titles conversations based on first two messages
This commit is contained in:
parent
511c8c9599
commit
4e6b6be15c
6 changed files with 132 additions and 13 deletions
|
|
@ -11,6 +11,10 @@ const convoSchema = mongoose.Schema({
|
|||
type: String,
|
||||
required: true
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: 'New conversation',
|
||||
},
|
||||
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
|
||||
created: {
|
||||
type: Date,
|
||||
|
|
@ -22,12 +26,16 @@ const Conversation =
|
|||
mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
||||
|
||||
module.exports = {
|
||||
saveConversation: async ({ conversationId, parentMessageId }) => {
|
||||
saveConversation: async ({ conversationId, parentMessageId, title }) => {
|
||||
const messages = await Message.find({ conversationId });
|
||||
const update = { parentMessageId, messages };
|
||||
if (title) {
|
||||
update.title = title;
|
||||
}
|
||||
|
||||
await Conversation.findOneAndUpdate(
|
||||
{ conversationId },
|
||||
{ $set: { parentMessageId, messages } },
|
||||
{ $set: update },
|
||||
{ new: true, upsert: true }
|
||||
).exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue