mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
feat: new endpoint-style structure in server side
This commit is contained in:
parent
36c126e7a5
commit
dd825dc6d4
2 changed files with 114 additions and 28 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const { Conversation, } = require('../../models/Conversation');
|
const { Conversation } = require('../../models/Conversation');
|
||||||
const { getMessages, } = require('../../models/');
|
const { getMessages } = require('../../models/');
|
||||||
|
|
||||||
async function migrateDb() {
|
const migrateToStrictFollowParentMessageIdChain = async () => {
|
||||||
try {
|
try {
|
||||||
const conversations = await Conversation.find({ model: null }).exec();
|
const conversations = await Conversation.find({ endpoint: null, model: null }).exec();
|
||||||
|
|
||||||
if (!conversations || conversations.length === 0)
|
if (!conversations || conversations.length === 0) return { noNeed: true };
|
||||||
return { message: '[Migrate] No conversations to migrate' };
|
|
||||||
|
console.log('Migration: To strict follow the parentMessageId chain.');
|
||||||
|
|
||||||
for (let convo of conversations) {
|
for (let convo of conversations) {
|
||||||
const messages = await getMessages({
|
const messages = await getMessages({
|
||||||
|
|
@ -36,7 +37,7 @@ async function migrateDb() {
|
||||||
if (message.sender.toLowerCase() === 'user') {
|
if (message.sender.toLowerCase() === 'user') {
|
||||||
message.isCreatedByUser = true;
|
message.isCreatedByUser = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(message.save());
|
promises.push(message.save());
|
||||||
});
|
});
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
@ -57,7 +58,58 @@ async function migrateDb() {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return { message: '[Migrate] Error migrating conversations' };
|
return { message: '[Migrate] Error migrating conversations' };
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const migrateToSupportBetterCustomization = async () => {
|
||||||
|
try {
|
||||||
|
const conversations = await Conversation.find({ endpoint: null }).exec();
|
||||||
|
|
||||||
|
if (!conversations || conversations.length === 0) return { noNeed: true };
|
||||||
|
|
||||||
|
console.log('Migration: To support better customization.');
|
||||||
|
|
||||||
|
const promises = [];
|
||||||
|
for (let convo of conversations) {
|
||||||
|
const originalModel = convo?.model;
|
||||||
|
|
||||||
|
if (originalModel === 'chatgpt') {
|
||||||
|
convo.endpoint = 'openAI';
|
||||||
|
convo.model = 'gpt-3.5-turbo';
|
||||||
|
} else if (originalModel === 'chatgptCustom') {
|
||||||
|
convo.endpoint = 'openAI';
|
||||||
|
convo.model = 'gpt-3.5-turbo';
|
||||||
|
} else if (originalModel === 'bingai') {
|
||||||
|
convo.endpoint = 'bingAI';
|
||||||
|
convo.model = null;
|
||||||
|
convo.jailbreak = false;
|
||||||
|
} else if (originalModel === 'sydney') {
|
||||||
|
convo.endpoint = 'bingAI';
|
||||||
|
convo.model = null;
|
||||||
|
convo.jailbreak = true;
|
||||||
|
} else if (originalModel === 'chatgptBrowser') {
|
||||||
|
convo.endpoint = 'chatGPTBrowser';
|
||||||
|
convo.model = 'text-davinci-002-render-sha';
|
||||||
|
convo.jailbreak = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
promises.push(convo.save());
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return { message: '[Migrate] Error migrating conversations' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function migrateDb() {
|
||||||
|
let ret = [];
|
||||||
|
ret[0] = await migrateToStrictFollowParentMessageIdChain();
|
||||||
|
ret[1] = await migrateToSupportBetterCustomization();
|
||||||
|
|
||||||
|
const isMigrated = !!ret.find(element => !element?.noNeed);
|
||||||
|
|
||||||
|
if (!isMigrated) console.log('[Migrate] Nothing to migrate');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = migrateDb;
|
||||||
module.exports = migrateDb;
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,54 @@ const convoSchema = mongoose.Schema(
|
||||||
default: 'New Chat',
|
default: 'New Chat',
|
||||||
meiliIndex: true
|
meiliIndex: true
|
||||||
},
|
},
|
||||||
|
user: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
|
||||||
|
// endpoint: [azureOpenAI, openAI, bingAI, chatGPTBrowser]
|
||||||
|
endpoint: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
// for azureOpenAI, openAI, chatGPTBrowser only
|
||||||
|
model: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
// for azureOpenAI, openAI only
|
||||||
|
chatGptLabel: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
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: {
|
jailbreakConversationId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null
|
default: null
|
||||||
|
|
@ -27,32 +75,18 @@ const convoSchema = mongoose.Schema(
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
clientId: {
|
clientId: {
|
||||||
type: String
|
type: String,
|
||||||
|
default: null
|
||||||
},
|
},
|
||||||
invocationId: {
|
invocationId: {
|
||||||
type: String
|
type: String,
|
||||||
|
default: null
|
||||||
},
|
},
|
||||||
toneStyle: {
|
toneStyle: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
chatGptLabel: {
|
suggestions: [{ type: String }]
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
promptPrefix: {
|
|
||||||
type: String,
|
|
||||||
default: null
|
|
||||||
},
|
|
||||||
model: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
type: String
|
|
||||||
},
|
|
||||||
suggestions: [{ type: String }],
|
|
||||||
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }]
|
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue