mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
clear all convos in progress, async code refactored in debugging warning
This commit is contained in:
parent
053368646d
commit
511ac948b4
10 changed files with 84 additions and 65 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -23,6 +23,7 @@ build/
|
|||
dist/
|
||||
public/main.js
|
||||
public/main.js.map
|
||||
public/main.js.LICENSE.txt
|
||||
|
||||
# Dependency directorys
|
||||
# Deployed apps should consider commenting these lines out:
|
||||
|
|
|
|||
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -11,7 +11,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@reduxjs/toolkit": "^1.9.2",
|
||||
"chatgpt": "^4.1.1",
|
||||
"chatgpt": "^4.2.0",
|
||||
"cors": "^2.8.5",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"dotenv": "^16.0.3",
|
||||
|
|
@ -5233,9 +5233,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/chatgpt": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/chatgpt/-/chatgpt-4.1.1.tgz",
|
||||
"integrity": "sha512-2Hn9kjSSndvmLiRLYK1xHXxf436xwby3vmLBlLayxFFErQHW2+47zjGlaanhrFzb89MfWsf+1GPwl/qKklDUeA==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/chatgpt/-/chatgpt-4.2.0.tgz",
|
||||
"integrity": "sha512-HYQ65GCa8PGtmmUB+XSAa17/IKTy/EEj8QU9HGU8UAsGBtKZushiozC0JpNcTyG+ivpuwzdduXJyL6ELnqkY4A==",
|
||||
"dependencies": {
|
||||
"eventsource-parser": "^0.0.5",
|
||||
"gpt-3-encoder": "^1.1.4",
|
||||
|
|
@ -16406,9 +16406,9 @@
|
|||
}
|
||||
},
|
||||
"chatgpt": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/chatgpt/-/chatgpt-4.1.1.tgz",
|
||||
"integrity": "sha512-2Hn9kjSSndvmLiRLYK1xHXxf436xwby3vmLBlLayxFFErQHW2+47zjGlaanhrFzb89MfWsf+1GPwl/qKklDUeA==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/chatgpt/-/chatgpt-4.2.0.tgz",
|
||||
"integrity": "sha512-HYQ65GCa8PGtmmUB+XSAa17/IKTy/EEj8QU9HGU8UAsGBtKZushiozC0JpNcTyG+ivpuwzdduXJyL6ELnqkY4A==",
|
||||
"requires": {
|
||||
"eventsource-parser": "^0.0.5",
|
||||
"gpt-3-encoder": "^1.1.4",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
"dependencies": {
|
||||
"@keyv/mongo": "^2.1.8",
|
||||
"@reduxjs/toolkit": "^1.9.2",
|
||||
"chatgpt": "^4.1.1",
|
||||
"chatgpt": "^4.2.0",
|
||||
"cors": "^2.8.5",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"dotenv": "^16.0.3",
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ app.get('/messages/:conversationId', async (req, res) => {
|
|||
app.post('/clear_convos', async (req, res) => {
|
||||
let filter = {};
|
||||
const { conversationId } = req.body.arg;
|
||||
console.log('conversationId', conversationId);
|
||||
if (!!conversationId) {
|
||||
filter = { conversationId };
|
||||
}
|
||||
|
|
@ -77,6 +76,7 @@ app.post('/ask', async (req, res) => {
|
|||
res.write(`event: message\ndata: ${data}\n\n`);
|
||||
};
|
||||
|
||||
try {
|
||||
let gptResponse = await ask(text, progressCallback, { parentMessageId, conversationId });
|
||||
if (!!parentMessageId) {
|
||||
gptResponse = { ...gptResponse, parentMessageId };
|
||||
|
|
@ -90,6 +90,10 @@ app.post('/ask', async (req, res) => {
|
|||
|
||||
res.write(`event: message\ndata: ${JSON.stringify(gptResponse)}\n\n`);
|
||||
res.end();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).send(error);
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
|
|
|
|||
|
|
@ -11,17 +11,14 @@ export default function Conversation({ id, parentMessageId, title = 'New convers
|
|||
const conversationId = useSelector((state) => state.convo.conversationId);
|
||||
const { trigger, isMutating } = manualSWR(
|
||||
`http://localhost:3050/messages/${id}`,
|
||||
'get',
|
||||
(res) => dispatch(setMessages(res))
|
||||
'get'
|
||||
);
|
||||
|
||||
const clickHandler = () => {
|
||||
if (conversationId === id) {
|
||||
return;
|
||||
}
|
||||
const clickHandler = async () => {
|
||||
|
||||
dispatch(setConversation({ conversationId: id, parentMessageId }));
|
||||
trigger();
|
||||
const data = await trigger();
|
||||
dispatch(setMessages(data));
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
30
src/components/Nav/ClearConvos.jsx
Normal file
30
src/components/Nav/ClearConvos.jsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import React from 'react';
|
||||
import NavLink from './NavLink';
|
||||
import TrashIcon from '../svg/TrashIcon';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setConversation } from '~/store/convoSlice';
|
||||
import { setMessages } from '~/store/messageSlice';
|
||||
|
||||
export default function ClearConvos() {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { trigger, isMutating } = manualSWR(
|
||||
'http://localhost:3050/clear_convos',
|
||||
'post',
|
||||
() => {
|
||||
dispatch(setMessages([]));
|
||||
dispatch(setConversation({ conversationId: null, parentMessageId: null }));
|
||||
}
|
||||
);
|
||||
|
||||
const clickHandler = () => trigger({});
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
svg={TrashIcon}
|
||||
text="Clear conversations"
|
||||
onClick={clickHandler}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
import React from 'react';
|
||||
|
||||
export default function NavLink({ svg, text, clickHandler}) {
|
||||
// const props
|
||||
// if (clickHandler) {
|
||||
export default function NavLink({ svg, text, clickHandler }) {
|
||||
const props = {
|
||||
className:
|
||||
'flex cursor-pointer items-center gap-3 rounded-md py-3 px-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10'
|
||||
};
|
||||
|
||||
// }
|
||||
// return (
|
||||
// <a {clickHandler && onClick={clickHandler}} className="flex cursor-pointer items-center gap-3 rounded-md py-3 px-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10">
|
||||
// {svg()}
|
||||
// {text}
|
||||
// </a>
|
||||
// );
|
||||
if (clickHandler) {
|
||||
props.onClick = clickHandler;
|
||||
}
|
||||
|
||||
return (
|
||||
<a {...props}>
|
||||
{svg()}
|
||||
{text}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,13 @@
|
|||
import React from 'react';
|
||||
import ClearConvos from './ClearConvos';
|
||||
import NavLink from './NavLink';
|
||||
import TrashIcon from '../svg/TrashIcon';
|
||||
import DarkModeIcon from '../svg/DarkModeIcon';
|
||||
import LogOutIcon from '../svg/LogOutIcon';
|
||||
import manualSWR from '~/utils/fetchers';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setConversation } from '~/store/convoSlice';
|
||||
import { setMessages } from '~/store/messageSlice';
|
||||
|
||||
export default function NavLinks() {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { trigger, isMutating } = manualSWR(
|
||||
'http://localhost:3050/clear_convos',
|
||||
'post',
|
||||
() => {
|
||||
dispatch(setMessages([]));
|
||||
dispatch(setConversation({ conversationId: null, parentMessageId: null }));
|
||||
}
|
||||
);
|
||||
|
||||
const clickHandler = () => trigger({});
|
||||
|
||||
return (
|
||||
<>
|
||||
<NavLink
|
||||
svg={TrashIcon}
|
||||
text="Clear conversations"
|
||||
onClick={clickHandler}
|
||||
/>
|
||||
<ClearConvos />
|
||||
<NavLink
|
||||
svg={DarkModeIcon}
|
||||
text="Dark mode"
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const currentSlice = createSlice({
|
|||
initialState,
|
||||
reducers: {
|
||||
setMessages: (state, action) => {
|
||||
state.messages = [...action.payload];
|
||||
state.messages = action.payload;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,8 +11,11 @@ const postRequest = async (url, { arg }) => {
|
|||
export const swr = (path) => useSWR(path, fetcher);
|
||||
|
||||
export default function manualSWR(path, type, successCallback) {
|
||||
const options = {};
|
||||
|
||||
if (successCallback) {
|
||||
options.onSuccess = successCallback;
|
||||
}
|
||||
const fetchFunction = type === 'get' ? fetcher : postRequest;
|
||||
return useSWRMutation(path, fetchFunction, {
|
||||
onSuccess: successCallback
|
||||
});
|
||||
return useSWRMutation(path, fetchFunction, options);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue