mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
add new reducer to ensure conversations are renewed on model change
This commit is contained in:
parent
30936573ac
commit
0ba92c4c03
7 changed files with 53 additions and 24 deletions
|
|
@ -3,7 +3,7 @@ import TrashIcon from '../svg/TrashIcon';
|
||||||
import CrossIcon from '../svg/CrossIcon';
|
import CrossIcon from '../svg/CrossIcon';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { setConversation, removeConvo } from '~/store/convoSlice';
|
import { setNewConvo, removeConvo } from '~/store/convoSlice';
|
||||||
import { setMessages } from '~/store/messageSlice';
|
import { setMessages } from '~/store/messageSlice';
|
||||||
|
|
||||||
export default function DeleteButton({ conversationId, renaming, cancelHandler }) {
|
export default function DeleteButton({ conversationId, renaming, cancelHandler }) {
|
||||||
|
|
@ -14,7 +14,8 @@ export default function DeleteButton({ conversationId, renaming, cancelHandler }
|
||||||
() => {
|
() => {
|
||||||
dispatch(setMessages([]));
|
dispatch(setMessages([]));
|
||||||
dispatch(removeConvo(conversationId));
|
dispatch(removeConvo(conversationId));
|
||||||
dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
// dispatch(setConversation({ title: 'New chat', conversationId: null, parentMessageId: null }));
|
||||||
|
dispatch(setNewConvo());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react';
|
||||||
import TextareaAutosize from 'react-textarea-autosize';
|
import TextareaAutosize from 'react-textarea-autosize';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { setModel, setCustomGpt } from '~/store/submitSlice';
|
import { setModel, setCustomGpt } from '~/store/submitSlice';
|
||||||
|
import { setNewConvo } from '~/store/convoSlice';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import { Button } from '../ui/Button.tsx';
|
import { Button } from '../ui/Button.tsx';
|
||||||
import { Input } from '../ui/Input.tsx';
|
import { Input } from '../ui/Input.tsx';
|
||||||
|
|
@ -36,6 +37,16 @@ export default function ModelDialog({ mutate, setModelSave, handleSaveState }) {
|
||||||
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
dispatch(setCustomGpt({ chatGptLabel, promptPrefix }));
|
||||||
dispatch(setModel('chatgptCustom'));
|
dispatch(setModel('chatgptCustom'));
|
||||||
handleSaveState(chatGptLabel.toLowerCase());
|
handleSaveState(chatGptLabel.toLowerCase());
|
||||||
|
// Set new conversation
|
||||||
|
dispatch(setNewConvo());
|
||||||
|
// dispatch(
|
||||||
|
// setConversation({
|
||||||
|
// title: 'New Chat',
|
||||||
|
// error: false,
|
||||||
|
// conversationId: null,
|
||||||
|
// parentMessageId: null
|
||||||
|
// })
|
||||||
|
// );
|
||||||
// dispatch(setDisabled(false));
|
// dispatch(setDisabled(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { setModel, setDisabled, setCustomGpt, setCustomModel } from '~/store/submitSlice';
|
import { setModel, setDisabled, setCustomGpt, setCustomModel } from '~/store/submitSlice';
|
||||||
import { setConversation } from '~/store/convoSlice';
|
import { setNewConvo } from '~/store/convoSlice';
|
||||||
import ModelDialog from './ModelDialog';
|
import ModelDialog from './ModelDialog';
|
||||||
import MenuItems from './MenuItems';
|
import MenuItems from './MenuItems';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
|
|
@ -76,14 +76,15 @@ export default function ModelMenu() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set new conversation
|
// Set new conversation
|
||||||
dispatch(
|
dispatch(setNewConvo());
|
||||||
setConversation({
|
// dispatch(
|
||||||
title: 'New Chat',
|
// setConversation({
|
||||||
error: false,
|
// title: 'New Chat',
|
||||||
conversationId: null,
|
// error: false,
|
||||||
parentMessageId: null
|
// conversationId: null,
|
||||||
})
|
// parentMessageId: null
|
||||||
);
|
// })
|
||||||
|
// );
|
||||||
};
|
};
|
||||||
|
|
||||||
const onOpenChange = (open) => {
|
const onOpenChange = (open) => {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import TrashIcon from '../svg/TrashIcon';
|
||||||
import { useSWRConfig } from 'swr';
|
import { useSWRConfig } from 'swr';
|
||||||
import manualSWR from '~/utils/fetchers';
|
import manualSWR from '~/utils/fetchers';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { setConversation, removeAll } from '~/store/convoSlice';
|
import { setNewConvo, removeAll } from '~/store/convoSlice';
|
||||||
import { setMessages } from '~/store/messageSlice';
|
import { setMessages } from '~/store/messageSlice';
|
||||||
|
|
||||||
export default function ClearConvos() {
|
export default function ClearConvos() {
|
||||||
|
|
@ -12,14 +12,15 @@ export default function ClearConvos() {
|
||||||
|
|
||||||
const { trigger } = manualSWR(`http://localhost:3080/api/convos/clear`, 'post', () => {
|
const { trigger } = manualSWR(`http://localhost:3080/api/convos/clear`, 'post', () => {
|
||||||
dispatch(setMessages([]));
|
dispatch(setMessages([]));
|
||||||
dispatch(
|
dispatch(setNewConvo());
|
||||||
setConversation({
|
// dispatch(
|
||||||
error: false,
|
// setConversation({
|
||||||
title: 'New chat',
|
// error: false,
|
||||||
conversationId: null,
|
// title: 'New chat',
|
||||||
parentMessageId: null
|
// conversationId: null,
|
||||||
})
|
// parentMessageId: null
|
||||||
);
|
// })
|
||||||
|
// );
|
||||||
mutate(`http://localhost:3080/api/convos`);
|
mutate(`http://localhost:3080/api/convos`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { setConversation } from '~/store/convoSlice';
|
import { setNewConvo } from '~/store/convoSlice';
|
||||||
import { setMessages } from '~/store/messageSlice';
|
import { setMessages } from '~/store/messageSlice';
|
||||||
import { setText } from '~/store/textSlice';
|
import { setText } from '~/store/textSlice';
|
||||||
|
|
||||||
|
|
@ -10,7 +10,8 @@ export default function NewChat() {
|
||||||
const clickHandler = () => {
|
const clickHandler = () => {
|
||||||
dispatch(setText(''));
|
dispatch(setText(''));
|
||||||
dispatch(setMessages([]));
|
dispatch(setMessages([]));
|
||||||
dispatch(setConversation({ title: 'New Chat', error: false, conversationId: null, parentMessageId: null }));
|
dispatch(setNewConvo());
|
||||||
|
// dispatch(setConversation({ title: 'New Chat', error: false, conversationId: null, parentMessageId: null }));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,20 @@ const currentSlice = createSlice({
|
||||||
incrementPage: (state) => {
|
incrementPage: (state) => {
|
||||||
state.pageNumber = state.pageNumber + 1;
|
state.pageNumber = state.pageNumber + 1;
|
||||||
},
|
},
|
||||||
|
setNewConvo: (state) => {
|
||||||
|
state.error = false;
|
||||||
|
state.title = 'New Chat';
|
||||||
|
state.conversationId = null;
|
||||||
|
state.parentMessageId = null;
|
||||||
|
state.jailbreakConversationId = null;
|
||||||
|
state.conversationSignature = null;
|
||||||
|
state.clientId = null;
|
||||||
|
state.invocationId = null;
|
||||||
|
state.chatGptLabel = null;
|
||||||
|
state.promptPrefix = null;
|
||||||
|
state.convosLoading = false;
|
||||||
|
state.pageNumber = 1;
|
||||||
|
},
|
||||||
setConvos: (state, action) => {
|
setConvos: (state, action) => {
|
||||||
const newConvos = action.payload.filter((convo) => {
|
const newConvos = action.payload.filter((convo) => {
|
||||||
return !state.convos.some((c) => c.conversationId === convo.conversationId);
|
return !state.convos.some((c) => c.conversationId === convo.conversationId);
|
||||||
|
|
@ -46,7 +60,7 @@ const currentSlice = createSlice({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { setConversation, setConvos, setError, incrementPage, removeConvo, removeAll } =
|
export const { setConversation, setConvos, setNewConvo, setError, incrementPage, removeConvo, removeAll } =
|
||||||
currentSlice.actions;
|
currentSlice.actions;
|
||||||
|
|
||||||
export default currentSlice.reducer;
|
export default currentSlice.reducer;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
p > small {
|
p > small {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
animation: fadein 2s forwards;
|
animation: fadein 3s forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadein {
|
@keyframes fadein {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue