mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
* feat(mongoDb): utitlize lean queries and index createdAt timestamps for cosmosDB support * fix: remove unnecessary lean() method from deleteMany calls * fix: remove unnecessary lean() method from deleteMany calls * fix: remove lean() from queries that need hydration * chore(migrateDb.js): remove unused migration script fix(Preset.js): return lean documents when retrieving presets refactor(index.js): remove migration script from server initialization refactor(convos.js): remove toObject() when sending conversation object refactor(presets.js): remove toObject() when sending presets object
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const mongoMeili = require('../plugins/mongoMeili');
|
|
const { conversationPreset } = require('./defaults');
|
|
const convoSchema = mongoose.Schema(
|
|
{
|
|
conversationId: {
|
|
type: String,
|
|
unique: true,
|
|
required: true,
|
|
index: true,
|
|
meiliIndex: true,
|
|
},
|
|
title: {
|
|
type: String,
|
|
default: 'New Chat',
|
|
meiliIndex: true,
|
|
},
|
|
user: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
|
|
// google only
|
|
examples: [{ type: mongoose.Schema.Types.Mixed }],
|
|
agentOptions: {
|
|
type: mongoose.Schema.Types.Mixed,
|
|
default: null,
|
|
},
|
|
...conversationPreset,
|
|
// for bingAI only
|
|
bingConversationId: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
jailbreakConversationId: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
conversationSignature: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
clientId: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
invocationId: {
|
|
type: Number,
|
|
default: 1,
|
|
},
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
|
convoSchema.plugin(mongoMeili, {
|
|
host: process.env.MEILI_HOST,
|
|
apiKey: process.env.MEILI_MASTER_KEY,
|
|
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
|
primaryKey: 'conversationId',
|
|
});
|
|
}
|
|
|
|
convoSchema.index({ createdAt: 1 });
|
|
|
|
const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
|
|
|
module.exports = Conversation;
|