fix: abort chat response

This commit is contained in:
archer
2023-08-05 14:14:51 +08:00
parent 236e7d3c3f
commit 09879004be
5 changed files with 41 additions and 35 deletions

View File

@@ -79,8 +79,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
const newTitle = prompts[0].content?.slice(0, 20) || '新对话';
// update history
if (completionChatId !== chatId && !controller.signal.aborted) {
forbidRefresh.current = true;
if (completionChatId !== chatId) {
const newHistory: ChatHistoryItemType = {
chatId: completionChatId,
updateTime: new Date(),
@@ -89,12 +88,15 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
top: false
};
updateHistory(newHistory);
router.replace({
query: {
chatId: completionChatId,
appId
}
});
if (controller.signal.reason !== 'leave') {
forbidRefresh.current = true;
router.replace({
query: {
chatId: completionChatId,
appId
}
});
}
} else {
const currentChat = history.find((item) => item.chatId === chatId);
currentChat &&
@@ -116,7 +118,7 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
[appId, chatId, history, router, setChatData, updateHistory]
);
// 删除一句话
// del one chat content
const delOneHistoryItem = useCallback(
async ({ contentId, index }: { contentId?: string; index: number }) => {
if (!chatId || !contentId) return;

View File

@@ -73,7 +73,7 @@ const OutLink = ({ shareId, chatId }: { shareId: string; chatId: string }) => {
shareId
});
if (completionChatId !== chatId && !controller.signal.aborted) {
if (completionChatId !== chatId && controller.signal.reason !== 'leave') {
router.replace({
query: {
shareId,