mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
properly records bing conversations
This commit is contained in:
parent
b4e22936ba
commit
81e52fed73
6 changed files with 91 additions and 32 deletions
|
|
@ -17,7 +17,7 @@ const sendMessage = (res, message) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
router.post('/bing', async (req, res) => {
|
router.post('/bing', async (req, res) => {
|
||||||
const { model, text, conversationSignature, conversationId } = req.body;
|
const { model, text, ...convo } = req.body;
|
||||||
if (!text.trim().includes(' ') && text.length < 5) {
|
if (!text.trim().includes(' ') && text.length < 5) {
|
||||||
return handleError(res, 'Prompt empty or too short');
|
return handleError(res, 'Prompt empty or too short');
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ router.post('/bing', async (req, res) => {
|
||||||
const userMessageId = crypto.randomUUID();
|
const userMessageId = crypto.randomUUID();
|
||||||
let userMessage = { id: userMessageId, sender: 'User', text };
|
let userMessage = { id: userMessageId, sender: 'User', text };
|
||||||
|
|
||||||
console.log('ask log', { model, ...userMessage, conversationSignature, conversationId });
|
console.log('ask log', { model, ...userMessage, ...convo });
|
||||||
|
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
Connection: 'keep-alive',
|
Connection: 'keep-alive',
|
||||||
|
|
@ -45,19 +45,16 @@ router.post('/bing', async (req, res) => {
|
||||||
|
|
||||||
let response = await askBing({
|
let response = await askBing({
|
||||||
text,
|
text,
|
||||||
progressCallback
|
progressCallback,
|
||||||
// convo: {
|
convo
|
||||||
// parentMessageId,
|
|
||||||
// conversationId
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('CLIENT RESPONSE');
|
console.log('CLIENT RESPONSE');
|
||||||
console.dir(response, { depth: null });
|
console.dir(response, { depth: null });
|
||||||
|
|
||||||
userMessage.conversationSignature =
|
userMessage.conversationSignature =
|
||||||
conversationSignature || response.conversationSignature;
|
convo.conversationSignature || response.conversationSignature;
|
||||||
userMessage.conversationId = conversationId || response.conversationId;
|
userMessage.conversationId = convo.conversationId || response.conversationId;
|
||||||
userMessage.invocationId = response.invocationId;
|
userMessage.invocationId = response.invocationId;
|
||||||
await saveMessage(userMessage);
|
await saveMessage(userMessage);
|
||||||
|
|
||||||
|
|
@ -69,7 +66,7 @@ router.post('/bing', async (req, res) => {
|
||||||
// return handleError(res, 'Prompt empty or too short');
|
// return handleError(res, 'Prompt empty or too short');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (!conversationSignature) {
|
if (!convo.conversationSignature) {
|
||||||
response.title = await titleConvo(text, response.response);
|
response.title = await titleConvo(text, response.response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,4 +173,4 @@ router.post('/', async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
@ -8,7 +8,13 @@ import { setText } from '~/store/textSlice';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import ConvoIcon from '../svg/ConvoIcon';
|
import ConvoIcon from '../svg/ConvoIcon';
|
||||||
|
|
||||||
export default function Conversation({ id, parentMessageId, conversationId, title = 'New conversation' }) {
|
export default function Conversation({
|
||||||
|
id,
|
||||||
|
parentMessageId,
|
||||||
|
conversationId,
|
||||||
|
title = 'New conversation',
|
||||||
|
bingData
|
||||||
|
}) {
|
||||||
const [renaming, setRenaming] = useState(false);
|
const [renaming, setRenaming] = useState(false);
|
||||||
const [titleInput, setTitleInput] = useState(title);
|
const [titleInput, setTitleInput] = useState(title);
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
|
|
@ -21,7 +27,34 @@ export default function Conversation({ id, parentMessageId, conversationId, titl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(setConversation({ title, error: false, conversationId: id, parentMessageId }));
|
if (bingData) {
|
||||||
|
const { title, conversationSignature, clientId, conversationId, invocationId } =
|
||||||
|
bingData;
|
||||||
|
dispatch(
|
||||||
|
setConversation({
|
||||||
|
title,
|
||||||
|
conversationSignature,
|
||||||
|
clientId,
|
||||||
|
conversationId,
|
||||||
|
invocationId,
|
||||||
|
error: false,
|
||||||
|
conversationId: id,
|
||||||
|
parentMessageId: null
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
dispatch(
|
||||||
|
setConversation({
|
||||||
|
title,
|
||||||
|
error: false,
|
||||||
|
conversationId: id,
|
||||||
|
parentMessageId,
|
||||||
|
conversationSignature: null,
|
||||||
|
clientId: null,
|
||||||
|
invocationId: null
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
const data = await trigger();
|
const data = await trigger();
|
||||||
dispatch(setMessages(data));
|
dispatch(setMessages(data));
|
||||||
dispatch(setText(''));
|
dispatch(setText(''));
|
||||||
|
|
@ -71,12 +104,12 @@ export default function Conversation({ id, parentMessageId, conversationId, titl
|
||||||
{...aProps}
|
{...aProps}
|
||||||
>
|
>
|
||||||
<ConvoIcon />
|
<ConvoIcon />
|
||||||
<div className="relative max-h-5 flex-1 overflow-hidden text-ellipsis break-all" >
|
<div className="relative max-h-5 flex-1 overflow-hidden text-ellipsis break-all">
|
||||||
{renaming === true ? (
|
{renaming === true ? (
|
||||||
<input
|
<input
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
type="text"
|
type="text"
|
||||||
className="m-0 mr-0 w-full leading-tight border border-blue-500 bg-transparent p-0 text-sm outline-none"
|
className="m-0 mr-0 w-full border border-blue-500 bg-transparent p-0 text-sm leading-tight outline-none"
|
||||||
value={titleInput}
|
value={titleInput}
|
||||||
onChange={(e) => setTitleInput(e.target.value)}
|
onChange={(e) => setTitleInput(e.target.value)}
|
||||||
onBlur={onRename}
|
onBlur={onRename}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import React, { useState } from 'react';
|
||||||
import Conversation from './Conversation';
|
import Conversation from './Conversation';
|
||||||
|
|
||||||
export default function Conversations({ conversations, conversationId }) {
|
export default function Conversations({ conversations, conversationId }) {
|
||||||
|
|
||||||
// const currentRef = useRef(null);
|
// const currentRef = useRef(null);
|
||||||
|
|
||||||
// const scrollToTop = () => {
|
// const scrollToTop = () => {
|
||||||
|
|
@ -20,15 +19,26 @@ export default function Conversations({ conversations, conversationId }) {
|
||||||
{/* <div ref={currentRef} /> */}
|
{/* <div ref={currentRef} /> */}
|
||||||
{conversations &&
|
{conversations &&
|
||||||
conversations.length > 0 &&
|
conversations.length > 0 &&
|
||||||
conversations.map((convo, i) => (
|
conversations.map((convo, i) => {
|
||||||
<Conversation
|
const bingData = convo.conversationSignature
|
||||||
key={convo.conversationId}
|
? {
|
||||||
id={convo.conversationId}
|
conversationSignature: convo.conversationSignature,
|
||||||
parentMessageId={convo.parentMessageId}
|
clientId: convo.clientId,
|
||||||
title={convo.title}
|
invocationId: convo.invocationId
|
||||||
conversationId={conversationId}
|
}
|
||||||
/>
|
: null;
|
||||||
))}
|
|
||||||
|
return (
|
||||||
|
<Conversation
|
||||||
|
key={convo.conversationId}
|
||||||
|
id={convo.conversationId}
|
||||||
|
parentMessageId={convo.parentMessageId}
|
||||||
|
title={convo.title}
|
||||||
|
conversationId={conversationId}
|
||||||
|
bingData={bingData}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
{conversations && conversations.length >= 12 && (
|
{conversations && conversations.length >= 12 && (
|
||||||
<button className="btn btn-dark btn-small m-auto mb-2 flex justify-center gap-2">
|
<button className="btn btn-dark btn-small m-auto mb-2 flex justify-center gap-2">
|
||||||
Show more
|
Show more
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export default function Message({
|
||||||
}
|
}
|
||||||
|
|
||||||
let icon = `${sender}:`;
|
let icon = `${sender}:`;
|
||||||
const isGPT = sender === 'chatgpt' || sender === 'davinci';
|
const isGPT = sender === 'chatgpt' || sender === 'davinci' || sender === 'GPT';
|
||||||
|
|
||||||
if (sender.toLowerCase() !== 'user') {
|
if (sender.toLowerCase() !== 'user') {
|
||||||
icon = (
|
icon = (
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,31 @@ export default function TextChat({ messages }) {
|
||||||
};
|
};
|
||||||
const convoHandler = (data) => {
|
const convoHandler = (data) => {
|
||||||
console.log('in convo handler');
|
console.log('in convo handler');
|
||||||
if (convo.conversationId === null && convo.parentMessageId === null) {
|
if (model !== 'bingai' && convo.parentMessageId === null) {
|
||||||
const { title, conversationId, id } = data;
|
const { title, conversationId, id } = data;
|
||||||
console.log('convo 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(setConversation({ title, conversationId, parentMessageId: id }));
|
||||||
console.log('convo after dispatch', convo);
|
} else if (convo.conversationSignature === null) {
|
||||||
|
const { title, conversationSignature, clientId, conversationId, invocationId } = data;
|
||||||
|
console.log('convoSig is null');
|
||||||
|
console.log(
|
||||||
|
'bing res data',
|
||||||
|
title,
|
||||||
|
conversationSignature,
|
||||||
|
clientId,
|
||||||
|
conversationId,
|
||||||
|
invocationId
|
||||||
|
);
|
||||||
|
dispatch(
|
||||||
|
setConversation({
|
||||||
|
title,
|
||||||
|
conversationSignature,
|
||||||
|
clientId,
|
||||||
|
conversationId,
|
||||||
|
invocationId
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(setSubmitState(false));
|
dispatch(setSubmitState(false));
|
||||||
|
|
@ -141,4 +160,4 @@ export default function TextChat({ messages }) {
|
||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ const initialState = {
|
||||||
conversationSignature: null,
|
conversationSignature: null,
|
||||||
clientId: null,
|
clientId: null,
|
||||||
invocationId: null,
|
invocationId: null,
|
||||||
convosLoading: false,
|
convosLoading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentSlice = createSlice({
|
const currentSlice = createSlice({
|
||||||
|
|
@ -20,7 +20,7 @@ const currentSlice = createSlice({
|
||||||
},
|
},
|
||||||
setError: (state, action) => {
|
setError: (state, action) => {
|
||||||
state.error = action.payload;
|
state.error = action.payload;
|
||||||
},
|
}
|
||||||
// setConvos: (state, action) => state.convos = action.payload,
|
// setConvos: (state, action) => state.convos = action.payload,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue