mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* fix(Message): avoid overwriting unprovided properties * fix(OpenAIClient): return intermediateReply on user abort * fix(AskController): do not send/save final message if abort was triggered * fix(countTokens): avoid fetching remote registry and exclusively use cl100k_base or p50k_base weights for token counting * refactor(Message/messageSchema): rely on messageSchema for default values when saving messages * fix(EditController): do not send/save final message if abort was triggered * fix(config/helpers): fix module resolution error
118 lines
2.3 KiB
JavaScript
118 lines
2.3 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const mongoMeili = require('~/models/plugins/mongoMeili');
|
|
const messageSchema = mongoose.Schema(
|
|
{
|
|
messageId: {
|
|
type: String,
|
|
unique: true,
|
|
required: true,
|
|
index: true,
|
|
meiliIndex: true,
|
|
},
|
|
conversationId: {
|
|
type: String,
|
|
required: true,
|
|
meiliIndex: true,
|
|
},
|
|
user: {
|
|
type: String,
|
|
index: true,
|
|
default: null,
|
|
},
|
|
model: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
conversationSignature: {
|
|
type: String,
|
|
// required: true
|
|
},
|
|
clientId: {
|
|
type: String,
|
|
},
|
|
invocationId: {
|
|
type: Number,
|
|
},
|
|
parentMessageId: {
|
|
type: String,
|
|
// required: true
|
|
},
|
|
tokenCount: {
|
|
type: Number,
|
|
},
|
|
summaryTokenCount: {
|
|
type: Number,
|
|
},
|
|
sender: {
|
|
type: String,
|
|
required: true,
|
|
meiliIndex: true,
|
|
},
|
|
text: {
|
|
type: String,
|
|
required: true,
|
|
meiliIndex: true,
|
|
},
|
|
summary: {
|
|
type: String,
|
|
},
|
|
isCreatedByUser: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false,
|
|
},
|
|
isEdited: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
unfinished: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
error: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
finish_reason: {
|
|
type: String,
|
|
},
|
|
_meiliIndex: {
|
|
type: Boolean,
|
|
required: false,
|
|
select: false,
|
|
default: false,
|
|
},
|
|
files: [{ type: mongoose.Schema.Types.Mixed }],
|
|
plugin: {
|
|
latest: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
inputs: {
|
|
type: [mongoose.Schema.Types.Mixed],
|
|
required: false,
|
|
},
|
|
outputs: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
},
|
|
plugins: [{ type: mongoose.Schema.Types.Mixed }],
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
|
messageSchema.plugin(mongoMeili, {
|
|
host: process.env.MEILI_HOST,
|
|
apiKey: process.env.MEILI_MASTER_KEY,
|
|
indexName: 'messages',
|
|
primaryKey: 'messageId',
|
|
});
|
|
}
|
|
|
|
messageSchema.index({ createdAt: 1 });
|
|
|
|
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);
|
|
|
|
module.exports = Message;
|