diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 74c9963..8f9cdbc 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -227,6 +227,8 @@ export const Chat = memo(({stopConversationRef}: Props) => { } if (isStream) { queryDoneRef.current = false; + const abortController = new AbortController(); + homeDispatch({field: 'controller', value: abortController}); let response: ReadableStream | null = await ChatStream( node, promptToSend, @@ -234,6 +236,7 @@ export const Chat = memo(({stopConversationRef}: Props) => { api, key, messagesToSend, + abortController ); if (response) { let notFinishData = ''; diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index 4e1e9fd..4272ca3 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -1,5 +1,5 @@ /* eslint-disable @next/next/no-img-element */ -import {IconArrowDown, IconBolt,} from '@tabler/icons-react'; +import {IconArrowDown, IconBolt, IconSend} from '@tabler/icons-react'; import React, {KeyboardEvent, MutableRefObject, useCallback, useContext, useEffect, useRef, useState,} from 'react'; import {useTranslation} from 'next-i18next'; @@ -35,7 +35,7 @@ export const ChatInput = ({ const {t} = useTranslation('chat'); const { - state: {selectedConversation, messageIsStreaming, prompts}, + state: {selectedConversation, controller, messageIsStreaming, prompts}, dispatch: homeDispatch, } = useContext(HomeContext); @@ -64,6 +64,13 @@ export const ChatInput = ({ updatePromptListVisibility(value); }; + const stopSend = () => { + if (messageIsStreaming && controller) { + controller.abort(); + homeDispatch({field: 'messageIsStreaming', value: false}); + } + } + const handleSend = () => { let thisList: string[] = imageSrcList; if (urlInputShow) { @@ -431,33 +438,28 @@ export const ChatInput = ({ />