2023-03-21 20:06:27 -04:00
|
|
|
const mongoose = require('mongoose');
|
2023-03-22 01:31:01 -04:00
|
|
|
const mongoMeili = require('../plugins/mongoMeili');
|
|
|
|
|
const convoSchema = mongoose.Schema(
|
2023-03-21 20:06:27 -04:00
|
|
|
{
|
|
|
|
|
conversationId: {
|
|
|
|
|
type: String,
|
|
|
|
|
unique: true,
|
|
|
|
|
required: true,
|
|
|
|
|
index: true,
|
|
|
|
|
meiliIndex: true
|
|
|
|
|
},
|
|
|
|
|
parentMessageId: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: 'New Chat',
|
|
|
|
|
meiliIndex: true
|
|
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
user: {
|
2023-03-21 20:06:27 -04:00
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
|
|
|
|
|
// endpoint: [azureOpenAI, openAI, bingAI, chatGPTBrowser]
|
|
|
|
|
endpoint: {
|
2023-03-21 20:06:27 -04:00
|
|
|
type: String,
|
2023-03-31 00:20:18 +08:00
|
|
|
default: null,
|
|
|
|
|
required: true
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
// for azureOpenAI, openAI, chatGPTBrowser only
|
|
|
|
|
model: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null,
|
|
|
|
|
required: false
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
// for azureOpenAI, openAI only
|
|
|
|
|
chatGptLabel: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null,
|
|
|
|
|
required: false
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
promptPrefix: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null,
|
|
|
|
|
required: false
|
|
|
|
|
},
|
|
|
|
|
temperature: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 0.8,
|
|
|
|
|
required: false
|
|
|
|
|
},
|
|
|
|
|
top_p: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
required: false
|
|
|
|
|
},
|
|
|
|
|
presence_penalty: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
required: false
|
|
|
|
|
},
|
|
|
|
|
// for bingai only
|
|
|
|
|
jailbreak: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
jailbreakConversationId: {
|
2023-03-24 16:21:10 -04:00
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
conversationSignature: {
|
2023-03-21 20:06:27 -04:00
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
clientId: {
|
2023-03-21 20:06:27 -04:00
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
invocationId: {
|
2023-03-21 20:06:27 -04:00
|
|
|
type: String,
|
2023-03-31 00:20:18 +08:00
|
|
|
default: null
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
toneStyle: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
2023-03-31 00:20:18 +08:00
|
|
|
suggestions: [{ type: String }]
|
2023-03-21 20:06:27 -04:00
|
|
|
},
|
|
|
|
|
{ timestamps: true }
|
2023-03-22 01:31:01 -04:00
|
|
|
);
|
|
|
|
|
|
2023-03-22 10:23:55 -04:00
|
|
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
2023-03-22 09:38:38 -04:00
|
|
|
convoSchema.plugin(mongoMeili, {
|
|
|
|
|
host: process.env.MEILI_HOST,
|
2023-03-22 10:23:55 -04:00
|
|
|
apiKey: process.env.MEILI_MASTER_KEY,
|
2023-03-22 09:38:38 -04:00
|
|
|
indexName: 'convos', // Will get created automatically if it doesn't exist already
|
|
|
|
|
primaryKey: 'conversationId'
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-22 01:31:01 -04:00
|
|
|
|
|
|
|
|
const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
|
|
|
|
|
|
|
|
|
module.exports = Conversation;
|