feat: stop response call api (#340)
This commit is contained in:
parent
e083a7067b
commit
b16a7b0b3b
6 changed files with 28 additions and 8 deletions
|
|
@ -53,6 +53,7 @@ export type IChatProps = {
|
|||
displayScene?: DisplayScene
|
||||
useCurrentUserAvatar?: boolean
|
||||
isResponsing?: boolean
|
||||
canStopResponsing?: boolean
|
||||
abortResponsing?: () => void
|
||||
controlClearQuery?: number
|
||||
controlFocus?: number
|
||||
|
|
@ -412,6 +413,7 @@ const Chat: FC<IChatProps> = ({
|
|||
displayScene,
|
||||
useCurrentUserAvatar,
|
||||
isResponsing,
|
||||
canStopResponsing,
|
||||
abortResponsing,
|
||||
controlClearQuery,
|
||||
controlFocus,
|
||||
|
|
@ -508,7 +510,7 @@ const Chat: FC<IChatProps> = ({
|
|||
{
|
||||
!isHideSendInput && (
|
||||
<div className={cn(!feedbackDisabled && '!left-3.5 !right-3.5', 'absolute z-10 bottom-0 left-0 right-0')}>
|
||||
{isResponsing && (
|
||||
{(isResponsing && canStopResponsing) && (
|
||||
<div className='flex justify-center mb-4'>
|
||||
<Button className='flex items-center space-x-1 bg-white' onClick={() => abortResponsing?.()}>
|
||||
{stopIcon}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import type { IChatItem } from '@/app/components/app/chat'
|
|||
import Chat from '@/app/components/app/chat'
|
||||
import ConfigContext from '@/context/debug-configuration'
|
||||
import { ToastContext } from '@/app/components/base/toast'
|
||||
import { fetchConvesationMessages, fetchSuggestedQuestions, sendChatMessage, sendCompletionMessage } from '@/service/debug'
|
||||
import { fetchConvesationMessages, fetchSuggestedQuestions, sendChatMessage, sendCompletionMessage, stopChatMessageResponding } from '@/service/debug'
|
||||
import Button from '@/app/components/base/button'
|
||||
import type { ModelConfig as BackendModelConfig } from '@/types/app'
|
||||
import { promptVariablesToUserInputsForm } from '@/utils/model-config'
|
||||
|
|
@ -136,6 +136,7 @@ const Debug: FC<IDebug> = ({
|
|||
|
||||
const doShowSuggestion = isShowSuggestion && !isResponsing
|
||||
const [suggestQuestions, setSuggestQuestions] = useState<string[]>([])
|
||||
const [messageTaskId, setMessageTaskId] = useState('')
|
||||
const onSend = async (message: string) => {
|
||||
if (isResponsing) {
|
||||
notify({ type: 'info', message: t('appDebug.errorMessage.waitForResponse') })
|
||||
|
|
@ -208,12 +209,13 @@ const Debug: FC<IDebug> = ({
|
|||
getAbortController: (abortController) => {
|
||||
setAbortController(abortController)
|
||||
},
|
||||
onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId }: any) => {
|
||||
onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
|
||||
responseItem.content = responseItem.content + message
|
||||
if (isFirstMessage && newConversationId) {
|
||||
setConversationId(newConversationId)
|
||||
_newConversationId = newConversationId
|
||||
}
|
||||
setMessageTaskId(taskId)
|
||||
if (messageId)
|
||||
responseItem.id = messageId
|
||||
|
||||
|
|
@ -375,8 +377,10 @@ const Debug: FC<IDebug> = ({
|
|||
feedbackDisabled
|
||||
useCurrentUserAvatar
|
||||
isResponsing={isResponsing}
|
||||
abortResponsing={() => {
|
||||
canStopResponsing={!!messageTaskId}
|
||||
abortResponsing={async () => {
|
||||
abortController?.abort()
|
||||
await stopChatMessageResponding(appId, messageTaskId)
|
||||
setResponsingFalse()
|
||||
}}
|
||||
isShowSuggestion={doShowSuggestion}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue