diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index f952f81..51eff81 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -1,22 +1,22 @@ -import React, {FC, useEffect, useRef, useState} from 'react'; -import {useTranslation} from 'react-i18next'; -import {RunButton} from '../components/RunButton'; -import {Avatar, Divider, PresenceBadge, Text, Textarea} from '@fluentui/react-components'; -import commonStore, {ModelStatus} from '../stores/commonStore'; -import {observer} from 'mobx-react-lite'; -import {PresenceBadgeStatus} from '@fluentui/react-badge'; -import {ConfigSelector} from '../components/ConfigSelector'; -import {v4 as uuid} from 'uuid'; +import React, { FC, useEffect, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { RunButton } from '../components/RunButton'; +import { Avatar, Divider, PresenceBadge, Text, Textarea } from '@fluentui/react-components'; +import commonStore, { ModelStatus } from '../stores/commonStore'; +import { observer } from 'mobx-react-lite'; +import { PresenceBadgeStatus } from '@fluentui/react-badge'; +import { ConfigSelector } from '../components/ConfigSelector'; +import { v4 as uuid } from 'uuid'; import classnames from 'classnames'; -import {fetchEventSource} from '@microsoft/fetch-event-source'; -import {ConversationPair, getConversationPairs, Record} from '../utils/get-conversation-pairs'; +import { fetchEventSource } from '@microsoft/fetch-event-source'; +import { ConversationPair, getConversationPairs, Record } from '../utils/get-conversation-pairs'; import logo from '../../../build/appicon.png'; import MarkdownRender from '../components/MarkdownRender'; -import {ToolTipButton} from '../components/ToolTipButton'; -import {ArrowCircleUp28Regular, Delete28Regular, RecordStop28Regular} from '@fluentui/react-icons'; -import {CopyButton} from '../components/CopyButton'; -import {ReadButton} from '../components/ReadButton'; -import {toast} from 'react-toastify'; +import { ToolTipButton } from '../components/ToolTipButton'; +import { ArrowCircleUp28Regular, Delete28Regular, RecordStop28Regular } from '@fluentui/react-icons'; +import { CopyButton } from '../components/CopyButton'; +import { ReadButton } from '../components/ReadButton'; +import { toast } from 'react-toastify'; export const userName = 'M E'; export const botName = 'A I'; @@ -46,7 +46,7 @@ export type Conversations = { } const ChatPanel: FC = observer(() => { - const {t} = useTranslation(); + const { t } = useTranslation(); const [message, setMessage] = useState(''); const bodyRef = useRef(null); const inputRef = useRef(null); @@ -95,7 +95,7 @@ const ChatPanel: FC = observer(() => { if (e.type === 'click' || (e.keyCode === 13 && !e.shiftKey)) { e.preventDefault(); if (commonStore.modelStatus === ModelStatus.Offline) { - toast(t('Please click the button in the top right corner to start the model'), {type: 'warning'}); + toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' }); return; } if (!message) return; @@ -127,13 +127,13 @@ const ChatPanel: FC = observer(() => { const questionId = commonStore.conversationsOrder[index - 1]; const question = commonStore.conversations[questionId]; if (question.done && question.type === MessageType.Normal && question.sender === userName) { - records.push({question: question.content, answer: conversation.content}); + records.push({ question: question.content, answer: conversation.content }); } } } }); const messages = getConversationPairs(records, false); - (messages as ConversationPair[]).push({role: 'user', content: message}); + (messages as ConversationPair[]).push({ role: 'user', content: message }); const answerId = uuid(); commonStore.conversations[answerId] = { @@ -224,7 +224,7 @@ const ChatPanel: FC = observer(() => {
{ {conversation.content}
-
+
{(conversation.type === MessageType.Error || !conversation.done) && + } /> }
- - + +
; @@ -252,12 +252,14 @@ const ChatPanel: FC = observer(() => {
} - size="large" shape="circular" appearance="subtle" - onClick={(e) => { - commonStore.setConversations({}); - commonStore.setConversationsOrder([]); - }} + icon={} + size="large" shape="circular" appearance="subtle" + onClick={(e) => { + if (generating) + sseControllerRef.current?.abort(); + commonStore.setConversations({}); + commonStore.setConversationsOrder([]); + }} />