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, type: String,
}, },
invocationId: { invocationId: {
type: Number, type: String,
}, },
parentMessageId: { parentMessageId: {
type: String, type: String,

View file

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

View file

@ -42,8 +42,17 @@ export default function TextChat({ messages }) {
const { title, conversationId, id } = data; const { title, conversationId, id } = data;
console.log('parentMessageId is null'); console.log('parentMessageId is null');
console.log('title, convoId, id', title, conversationId, id); console.log('title, convoId, id', title, conversationId, id);
dispatch(setConversation({ title, conversationId, parentMessageId: id })); dispatch(
} else if (convo.conversationSignature === null) { setConversation({
title,
conversationId,
parentMessageId: id,
conversationSignature: null,
clientId: null,
invocationId: null
})
);
} else if (convo.invocationId === null) {
const { title, conversationSignature, clientId, conversationId, invocationId } = data; const { title, conversationSignature, clientId, conversationId, invocationId } = data;
console.log('convoSig is null'); console.log('convoSig is null');
console.log( console.log(
@ -60,7 +69,8 @@ export default function TextChat({ messages }) {
conversationSignature, conversationSignature,
clientId, clientId,
conversationId, conversationId,
invocationId invocationId,
parentMessageId: null
}) })
); );
} }
@ -160,4 +170,4 @@ export default function TextChat({ messages }) {
<Footer /> <Footer />
</div> </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 server = model === 'bingai' ? endpoint + '/bing' : endpoint;
const events = new SSE(server, { const events = new SSE(server, {
payload: JSON.stringify(payload), payload: JSON.stringify(payload),