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 =
|
||||
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 = {
|
||||
saveConvo: async ({ conversationId, title, ...convo }) => {
|
||||
try {
|
||||
|
|
@ -95,12 +104,14 @@ module.exports = {
|
|||
return { message: 'Error getting conversations' };
|
||||
}
|
||||
},
|
||||
getConvo: async (conversationId) => {
|
||||
getConvo,
|
||||
getConvoTitle: async (conversationId) => {
|
||||
try {
|
||||
return await Conversation.findOne({ conversationId }).exec();
|
||||
const convo = await getConvo(conversationId);
|
||||
return convo.title;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { message: 'Error getting single conversation' };
|
||||
return { message: 'Error getting conversation title' };
|
||||
}
|
||||
},
|
||||
deleteConvos: async (filter) => {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
const { saveMessage, deleteMessages } = require('./Message');
|
||||
const { getCustomGpts, updateCustomGpt, updateByLabel, deleteCustomGpts } = require('./CustomGpt');
|
||||
const { getConvo, saveConvo } = require('./Conversation');
|
||||
const { getConvoTitle, getConvo, saveConvo } = require('./Conversation');
|
||||
|
||||
module.exports = {
|
||||
saveMessage,
|
||||
deleteMessages,
|
||||
getConvoTitle,
|
||||
getConvo,
|
||||
saveConvo,
|
||||
getCustomGpts,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const crypto = require('crypto');
|
||||
const router = express.Router();
|
||||
const { titleConvo, askSydney } = require('../../app/');
|
||||
const { saveMessage, deleteMessages, saveConvo } = require('../../models');
|
||||
const { saveMessage, deleteMessages, saveConvo, getConvoTitle } = require('../../models');
|
||||
const { handleError, sendMessage } = require('./handlers');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
|
|
@ -39,31 +39,48 @@ router.post('/', async (req, res) => {
|
|||
});
|
||||
|
||||
console.log('SYDNEY RESPONSE');
|
||||
// console.dir(response, { depth: null });
|
||||
|
||||
userMessage.conversationSignature =
|
||||
convo.conversationSignature || response.conversationSignature;
|
||||
userMessage.conversationId = convo.conversationId || response.conversationId;
|
||||
userMessage.invocationId = response.invocationId;
|
||||
userMessage.jailbreakConversationId = convo.jailbreakConversationId || response.jailbreakConversationId;
|
||||
await saveMessage(userMessage);
|
||||
|
||||
if (!convo.conversationSignature) {
|
||||
response.title = await titleConvo({
|
||||
model,
|
||||
message: text,
|
||||
response: JSON.stringify(response.response)
|
||||
});
|
||||
}
|
||||
// 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)
|
||||
// });
|
||||
// }
|
||||
|
||||
// Save sydney response
|
||||
response.id = response.messageId;
|
||||
// response.parentMessageId = convo.parentMessageId ? convo.parentMessageId : response.messageId;
|
||||
response.parentMessageId = response.messageId;
|
||||
response.invocationId = convo.invocationId ? convo.invocationId + 1 : 1;
|
||||
response.title = convo.jailbreakConversationId
|
||||
? await getConvoTitle(convo.conversationId)
|
||||
: await titleConvo({
|
||||
model,
|
||||
message: text,
|
||||
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.parentMessageId = convo.parentMessageId || response.messageId;
|
||||
response.id = response.details.messageId;
|
||||
response.suggestions =
|
||||
response.details.suggestedResponses &&
|
||||
response.details.suggestedResponses.map((s) => s.text);
|
||||
response.sender = model;
|
||||
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 saveConvo(response);
|
||||
sendMessage(res, response);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export default function Conversation({
|
|||
dispatch(
|
||||
setConversation({
|
||||
...convo,
|
||||
parentMessageId: parentMessageId || null,
|
||||
parentMessageId,
|
||||
jailbreakConversationId,
|
||||
conversationSignature,
|
||||
clientId,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export default function Conversations({ conversations, conversationId, showMore
|
|||
? {
|
||||
jailbreakConversationId: convo.jailbreakConversationId,
|
||||
conversationSignature: convo.conversationSignature,
|
||||
parentMessageId: convo.parentMessageId || null,
|
||||
clientId: convo.clientId,
|
||||
invocationId: convo.invocationId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,11 +68,30 @@ export default function TextChat({ messages }) {
|
|||
})
|
||||
);
|
||||
} else if (
|
||||
isBing &&
|
||||
model === 'bingai' &&
|
||||
convo.conversationId === null &&
|
||||
convo.invocationId === null
|
||||
) {
|
||||
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 {
|
||||
title,
|
||||
jailbreakConversationId,
|
||||
|
|
@ -86,7 +105,7 @@ export default function TextChat({ messages }) {
|
|||
setConversation({
|
||||
title,
|
||||
jailbreakConversationId,
|
||||
parentMessageId: parentMessageId || null,
|
||||
parentMessageId,
|
||||
conversationSignature,
|
||||
clientId,
|
||||
conversationId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue