Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

feat: new endpoint-style structure in server side

Wentao Lyudd825dc6d445
diff --git a/api/lib/db/migrateDb.js b/api/lib/db/migrateDb.js
index 315f7094bf..24808acb4d 100644
--- a/api/lib/db/migrateDb.js
+++ b/api/lib/db/migrateDb.js
@@ -1,13 +1,14 @@
const mongoose = require('mongoose');
-const { Conversation, } = require('../../models/Conversation');
-const { getMessages, } = require('../../models/');
+const { Conversation } = require('../../models/Conversation');
+const { getMessages } = require('../../models/');
-async function migrateDb() {
+const migrateToStrictFollowParentMessageIdChain = async () => {
try {
- const conversations = await Conversation.find({ model: null }).exec();
+ const conversations = await Conversation.find({ endpoint: null, model: null }).exec();
+
+ if (!conversations || conversations.length === 0) return { noNeed: true };
- if (!conversations || conversations.length === 0)
- return { message: '[Migrate] No conversations to migrate' };
+ console.log('Migration: To strict follow the parentMessageId chain.');
for (let convo of conversations) {
const messages = await getMessages({
@@ -36,7 +37,7 @@ async function migrateDb() {
if (message.sender.toLowerCase() === 'user') {
message.isCreatedByUser = true;
}
-
+
promises.push(message.save());
});
await Promise.all(promises);
@@ -57,7 +58,58 @@ async function migrateDb() {
console.log(error);
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;
\ No newline at end of file
+module.exports = migrateDb;
diff --git a/api/models/schema/convoSchema.js b/api/models/schema/convoSchema.js
index 79e621ef8e..47f0d6df90 100644
--- a/api/models/schema/convoSchema.js
+++ b/api/models/schema/convoSchema.js
@@ -18,41 +18,75 @@ const convoSchema = mongoose.Schema(
default: 'New Chat',
meiliIndex: true
},
- jailbreakConversationId: {
+ user: {
type: String,
default: null
},
- conversationSignature: {
+ messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }],
+ // endpoint: [azureOpenAI, openAI, bingAI, chatGPTBrowser]
+ endpoint: {
type: String,
- default: null
+ default: null,
+ required: true
},
- clientId: {
- type: String
+ // for azureOpenAI, openAI, chatGPTBrowser only
+ model: {
+ type: String,
+ default: null,
+ required: false
},
- invocationId: {
- type: String
+ // for azureOpenAI, openAI only
+ chatGptLabel: {
+ type: String,
+ default: null,
+ required: false
},
- toneStyle: {
+ 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: {
type: String,
default: null
},
- chatGptLabel: {
+ conversationSignature: {
type: String,
default: null
},
- promptPrefix: {
+ clientId: {
type: String,
default: null
},
- model: {
+ invocationId: {
type: String,
- required: true
+ default: null
},
- user: {
- type: String
+ toneStyle: {
+ type: String,
+ default: null
},
- suggestions: [{ type: String }],
- messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }]
+ suggestions: [{ type: String }]
},
{ timestamps: true }
);