persist bing ai conversation

This commit is contained in:
Daniel Avila 2023-02-20 21:52:08 -05:00
parent 81e52fed73
commit 7b7548c905
4 changed files with 28 additions and 8 deletions

View file

@ -18,7 +18,7 @@ const messageSchema = mongoose.Schema({
type: String,
},
invocationId: {
type: Number,
type: String,
},
parentMessageId: {
type: String,

View file

@ -49,8 +49,8 @@ router.post('/bing', async (req, res) => {
convo
});
console.log('CLIENT RESPONSE');
console.dir(response, { depth: null });
// console.log('CLIENT RESPONSE');
// console.dir(response, { depth: null });
userMessage.conversationSignature =
convo.conversationSignature || response.conversationSignature;
@ -72,7 +72,7 @@ router.post('/bing', async (req, res) => {
response.text = response.response;
response.id = response.details.messageId;
response.suggestions = response.details.suggestedResponses.map((s) => s.text);
response.suggestions = response.details.suggestedResponses && response.details.suggestedResponses.map((s) => s.text);
response.sender = model;
response.final = true;
await saveMessage(response);

View file

@ -42,8 +42,17 @@ export default function TextChat({ messages }) {
const { title, conversationId, id } = data;
console.log('parentMessageId is null');
console.log('title, convoId, id', title, conversationId, id);
dispatch(setConversation({ title, conversationId, parentMessageId: id }));
} else if (convo.conversationSignature === null) {
dispatch(
setConversation({
title,
conversationId,
parentMessageId: id,
conversationSignature: null,
clientId: null,
invocationId: null
})
);
} else if (convo.invocationId === null) {
const { title, conversationSignature, clientId, conversationId, invocationId } = data;
console.log('convoSig is null');
console.log(
@ -60,7 +69,8 @@ export default function TextChat({ messages }) {
conversationSignature,
clientId,
conversationId,
invocationId
invocationId,
parentMessageId: null
})
);
}
@ -160,4 +170,4 @@ export default function TextChat({ messages }) {
<Footer />
</div>
);
}
}

View file

@ -18,6 +18,16 @@ export default function handleSubmit({
};
}
if (model === 'bingai' && convo.conversationId) {
payload = {
...payload,
conversationId: convo.conversationId,
conversationSignature: convo.conversationSignature,
clientId: convo.clientId,
invocationId: convo.invocationId,
};
}
const server = model === 'bingai' ? endpoint + '/bing' : endpoint;
const events = new SSE(server, {
payload: JSON.stringify(payload),