mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
working sydney, need to test the other models
This commit is contained in:
parent
2c1ae68dc4
commit
67054e7504
6 changed files with 75 additions and 26 deletions
|
|
@ -47,6 +47,15 @@ const convoSchema = mongoose.Schema({
|
||||||
const Conversation =
|
const Conversation =
|
||||||
mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
|
||||||
|
|
||||||
|
const getConvo = async (conversationId) => {
|
||||||
|
try {
|
||||||
|
return await Conversation.findOne({ conversationId }).exec();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return { message: 'Error getting single conversation' };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
saveConvo: async ({ conversationId, title, ...convo }) => {
|
saveConvo: async ({ conversationId, title, ...convo }) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -95,12 +104,14 @@ module.exports = {
|
||||||
return { message: 'Error getting conversations' };
|
return { message: 'Error getting conversations' };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getConvo: async (conversationId) => {
|
getConvo,
|
||||||
|
getConvoTitle: async (conversationId) => {
|
||||||
try {
|
try {
|
||||||
return await Conversation.findOne({ conversationId }).exec();
|
const convo = await getConvo(conversationId);
|
||||||
|
return convo.title;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return { message: 'Error getting single conversation' };
|
return { message: 'Error getting conversation title' };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteConvos: async (filter) => {
|
deleteConvos: async (filter) => {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
const { saveMessage, deleteMessages } = require('./Message');
|
const { saveMessage, deleteMessages } = require('./Message');
|
||||||
const { getCustomGpts, updateCustomGpt, updateByLabel, deleteCustomGpts } = require('./CustomGpt');
|
const { getCustomGpts, updateCustomGpt, updateByLabel, deleteCustomGpts } = require('./CustomGpt');
|
||||||
const { getConvo, saveConvo } = require('./Conversation');
|
const { getConvoTitle, getConvo, saveConvo } = require('./Conversation');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
saveMessage,
|
saveMessage,
|
||||||
deleteMessages,
|
deleteMessages,
|
||||||
|
getConvoTitle,
|
||||||
getConvo,
|
getConvo,
|
||||||
saveConvo,
|
saveConvo,
|
||||||
getCustomGpts,
|
getCustomGpts,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const { titleConvo, askSydney } = require('../../app/');
|
const { titleConvo, askSydney } = require('../../app/');
|
||||||
const { saveMessage, deleteMessages, saveConvo } = require('../../models');
|
const { saveMessage, deleteMessages, saveConvo, getConvoTitle } = require('../../models');
|
||||||
const { handleError, sendMessage } = require('./handlers');
|
const { handleError, sendMessage } = require('./handlers');
|
||||||
|
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
|
|
@ -39,31 +39,48 @@ router.post('/', async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('SYDNEY RESPONSE');
|
console.log('SYDNEY RESPONSE');
|
||||||
// console.dir(response, { depth: null });
|
// the usual values expected by the client are generated since only
|
||||||
|
// jailbreakConversationId and initial messageId is needed by sydney
|
||||||
|
// to continue the conversation
|
||||||
|
// if (!convo.jailbreakConversationId) {
|
||||||
|
// response.title = await titleConvo({
|
||||||
|
// model,
|
||||||
|
// message: text,
|
||||||
|
// response: JSON.stringify(response.response)
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
userMessage.conversationSignature =
|
// Save sydney response
|
||||||
convo.conversationSignature || response.conversationSignature;
|
response.id = response.messageId;
|
||||||
userMessage.conversationId = convo.conversationId || response.conversationId;
|
// response.parentMessageId = convo.parentMessageId ? convo.parentMessageId : response.messageId;
|
||||||
userMessage.invocationId = response.invocationId;
|
response.parentMessageId = response.messageId;
|
||||||
userMessage.jailbreakConversationId = convo.jailbreakConversationId || response.jailbreakConversationId;
|
response.invocationId = convo.invocationId ? convo.invocationId + 1 : 1;
|
||||||
await saveMessage(userMessage);
|
response.title = convo.jailbreakConversationId
|
||||||
|
? await getConvoTitle(convo.conversationId)
|
||||||
if (!convo.conversationSignature) {
|
: await titleConvo({
|
||||||
response.title = await titleConvo({
|
model,
|
||||||
model,
|
message: text,
|
||||||
message: text,
|
response: JSON.stringify(response.response)
|
||||||
response: JSON.stringify(response.response)
|
});
|
||||||
});
|
response.conversationId = convo.conversationId
|
||||||
}
|
? convo.conversationId
|
||||||
|
: crypto.randomUUID();
|
||||||
|
response.conversationSignature = convo.conversationSignature
|
||||||
|
? convo.conversationSignature
|
||||||
|
: crypto.randomUUID();
|
||||||
response.text = response.response;
|
response.text = response.response;
|
||||||
response.parentMessageId = convo.parentMessageId || response.messageId;
|
|
||||||
response.id = response.details.messageId;
|
|
||||||
response.suggestions =
|
response.suggestions =
|
||||||
response.details.suggestedResponses &&
|
response.details.suggestedResponses &&
|
||||||
response.details.suggestedResponses.map((s) => s.text);
|
response.details.suggestedResponses.map((s) => s.text);
|
||||||
response.sender = model;
|
response.sender = model;
|
||||||
response.final = true;
|
response.final = true;
|
||||||
|
|
||||||
|
// Save user message
|
||||||
|
userMessage.conversationId = response.conversationId;
|
||||||
|
userMessage.parentMessageId = response.parentMessageId;
|
||||||
|
await saveMessage(userMessage);
|
||||||
|
|
||||||
|
// Save sydney response & convo, then send
|
||||||
await saveMessage(response);
|
await saveMessage(response);
|
||||||
await saveConvo(response);
|
await saveConvo(response);
|
||||||
sendMessage(res, response);
|
sendMessage(res, response);
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ export default function Conversation({
|
||||||
dispatch(
|
dispatch(
|
||||||
setConversation({
|
setConversation({
|
||||||
...convo,
|
...convo,
|
||||||
parentMessageId: parentMessageId || null,
|
parentMessageId,
|
||||||
jailbreakConversationId,
|
jailbreakConversationId,
|
||||||
conversationSignature,
|
conversationSignature,
|
||||||
clientId,
|
clientId,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export default function Conversations({ conversations, conversationId, showMore
|
||||||
? {
|
? {
|
||||||
jailbreakConversationId: convo.jailbreakConversationId,
|
jailbreakConversationId: convo.jailbreakConversationId,
|
||||||
conversationSignature: convo.conversationSignature,
|
conversationSignature: convo.conversationSignature,
|
||||||
|
parentMessageId: convo.parentMessageId || null,
|
||||||
clientId: convo.clientId,
|
clientId: convo.clientId,
|
||||||
invocationId: convo.invocationId
|
invocationId: convo.invocationId
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,30 @@ export default function TextChat({ messages }) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
isBing &&
|
model === 'bingai' &&
|
||||||
convo.conversationId === null &&
|
convo.conversationId === null &&
|
||||||
convo.invocationId === null
|
convo.invocationId === null
|
||||||
) {
|
) {
|
||||||
console.log('Bing data:', data)
|
console.log('Bing data:', data)
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
conversationSignature,
|
||||||
|
clientId,
|
||||||
|
conversationId,
|
||||||
|
invocationId
|
||||||
|
} = data;
|
||||||
|
dispatch(
|
||||||
|
setConversation({
|
||||||
|
title,
|
||||||
|
parentMessageId: null,
|
||||||
|
conversationSignature,
|
||||||
|
clientId,
|
||||||
|
conversationId,
|
||||||
|
invocationId,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else if (model === 'sydney') {
|
||||||
|
console.log('Sydney data:', data)
|
||||||
const {
|
const {
|
||||||
title,
|
title,
|
||||||
jailbreakConversationId,
|
jailbreakConversationId,
|
||||||
|
|
@ -86,7 +105,7 @@ export default function TextChat({ messages }) {
|
||||||
setConversation({
|
setConversation({
|
||||||
title,
|
title,
|
||||||
jailbreakConversationId,
|
jailbreakConversationId,
|
||||||
parentMessageId: parentMessageId || null,
|
parentMessageId,
|
||||||
conversationSignature,
|
conversationSignature,
|
||||||
clientId,
|
clientId,
|
||||||
conversationId,
|
conversationId,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue