Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
87af414a
Unverified
Commit
87af414a
authored
Jun 13, 2023
by
Joel
Committed by
GitHub
Jun 13, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: stop response enchancement (#352)
parent
72555d5d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
index.tsx
web/app/components/app/configuration/debug/index.tsx
+7
-4
index.tsx
web/app/components/share/chat/index.tsx
+6
-3
No files found.
web/app/components/app/configuration/debug/index.tsx
View file @
87af414a
...
@@ -75,6 +75,8 @@ const Debug: FC<IDebug> = ({
...
@@ -75,6 +75,8 @@ const Debug: FC<IDebug> = ({
const
[
abortController
,
setAbortController
]
=
useState
<
AbortController
|
null
>
(
null
)
const
[
abortController
,
setAbortController
]
=
useState
<
AbortController
|
null
>
(
null
)
const
[
isShowFormattingChangeConfirm
,
setIsShowFormattingChangeConfirm
]
=
useState
(
false
)
const
[
isShowFormattingChangeConfirm
,
setIsShowFormattingChangeConfirm
]
=
useState
(
false
)
const
[
isShowSuggestion
,
setIsShowSuggestion
]
=
useState
(
false
)
const
[
isShowSuggestion
,
setIsShowSuggestion
]
=
useState
(
false
)
const
[
messageTaskId
,
setMessageTaskId
]
=
useState
(
''
)
const
[
hasStopResponded
,
setHasStopResponded
,
getHasStopResponded
]
=
useGetState
(
false
)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
formattingChanged
&&
chatList
.
some
(
item
=>
!
item
.
isAnswer
))
if
(
formattingChanged
&&
chatList
.
some
(
item
=>
!
item
.
isAnswer
))
...
@@ -83,7 +85,7 @@ const Debug: FC<IDebug> = ({
...
@@ -83,7 +85,7 @@ const Debug: FC<IDebug> = ({
setFormattingChanged
(
false
)
setFormattingChanged
(
false
)
},
[
formattingChanged
])
},
[
formattingChanged
])
const
clearConversation
=
()
=>
{
const
clearConversation
=
async
()
=>
{
setConversationId
(
null
)
setConversationId
(
null
)
abortController
?.
abort
()
abortController
?.
abort
()
setResponsingFalse
()
setResponsingFalse
()
...
@@ -136,7 +138,6 @@ const Debug: FC<IDebug> = ({
...
@@ -136,7 +138,6 @@ const Debug: FC<IDebug> = ({
const
doShowSuggestion
=
isShowSuggestion
&&
!
isResponsing
const
doShowSuggestion
=
isShowSuggestion
&&
!
isResponsing
const
[
suggestQuestions
,
setSuggestQuestions
]
=
useState
<
string
[]
>
([])
const
[
suggestQuestions
,
setSuggestQuestions
]
=
useState
<
string
[]
>
([])
const
[
messageTaskId
,
setMessageTaskId
]
=
useState
(
''
)
const
onSend
=
async
(
message
:
string
)
=>
{
const
onSend
=
async
(
message
:
string
)
=>
{
if
(
isResponsing
)
{
if
(
isResponsing
)
{
notify
({
type
:
'info'
,
message
:
t
(
'appDebug.errorMessage.waitForResponse'
)
})
notify
({
type
:
'info'
,
message
:
t
(
'appDebug.errorMessage.waitForResponse'
)
})
...
@@ -203,6 +204,7 @@ const Debug: FC<IDebug> = ({
...
@@ -203,6 +204,7 @@ const Debug: FC<IDebug> = ({
let
_newConversationId
:
null
|
string
=
null
let
_newConversationId
:
null
|
string
=
null
setHasStopResponded
(
false
)
setResponsingTrue
()
setResponsingTrue
()
setIsShowSuggestion
(
false
)
setIsShowSuggestion
(
false
)
sendChatMessage
(
appId
,
data
,
{
sendChatMessage
(
appId
,
data
,
{
...
@@ -255,7 +257,7 @@ const Debug: FC<IDebug> = ({
...
@@ -255,7 +257,7 @@ const Debug: FC<IDebug> = ({
}
}
}))
}))
}
}
if
(
suggestedQuestionsAfterAnswerConfig
.
enabled
)
{
if
(
suggestedQuestionsAfterAnswerConfig
.
enabled
&&
!
getHasStopResponded
()
)
{
const
{
data
}:
any
=
await
fetchSuggestedQuestions
(
appId
,
responseItem
.
id
)
const
{
data
}:
any
=
await
fetchSuggestedQuestions
(
appId
,
responseItem
.
id
)
setSuggestQuestions
(
data
)
setSuggestQuestions
(
data
)
setIsShowSuggestion
(
true
)
setIsShowSuggestion
(
true
)
...
@@ -379,8 +381,8 @@ const Debug: FC<IDebug> = ({
...
@@ -379,8 +381,8 @@ const Debug: FC<IDebug> = ({
isResponsing=
{
isResponsing
}
isResponsing=
{
isResponsing
}
canStopResponsing=
{
!!
messageTaskId
}
canStopResponsing=
{
!!
messageTaskId
}
abortResponsing=
{
async
()
=>
{
abortResponsing=
{
async
()
=>
{
abortController
?.
abort
()
await
stopChatMessageResponding
(
appId
,
messageTaskId
)
await
stopChatMessageResponding
(
appId
,
messageTaskId
)
setHasStopResponded
(
true
)
setResponsingFalse
()
setResponsingFalse
()
}
}
}
}
isShowSuggestion=
{
doShowSuggestion
}
isShowSuggestion=
{
doShowSuggestion
}
...
@@ -399,6 +401,7 @@ const Debug: FC<IDebug> = ({
...
@@ -399,6 +401,7 @@ const Debug: FC<IDebug> = ({
className=
"mt-2"
className=
"mt-2"
content=
{
completionRes
}
content=
{
completionRes
}
isLoading=
{
!
completionRes
&&
isResponsing
}
isLoading=
{
!
completionRes
&&
isResponsing
}
isInstalledApp=
{
false
}
/>
/>
)
}
)
}
</
div
>
</
div
>
...
...
web/app/components/share/chat/index.tsx
View file @
87af414a
...
@@ -191,7 +191,7 @@ const Main: FC<IMainProps> = ({
...
@@ -191,7 +191,7 @@ const Main: FC<IMainProps> = ({
},
[
chatList
,
currConversationId
])
},
[
chatList
,
currConversationId
])
// user can not edit inputs if user had send message
// user can not edit inputs if user had send message
const
canEditInpus
=
!
chatList
.
some
(
item
=>
item
.
isAnswer
===
false
)
&&
isNewConversation
const
canEditInpus
=
!
chatList
.
some
(
item
=>
item
.
isAnswer
===
false
)
&&
isNewConversation
const
createNewChat
=
()
=>
{
const
createNewChat
=
async
()
=>
{
// if new chat is already exist, do not create new chat
// if new chat is already exist, do not create new chat
abortController
?.
abort
()
abortController
?.
abort
()
setResponsingFalse
()
setResponsingFalse
()
...
@@ -333,6 +333,8 @@ const Main: FC<IMainProps> = ({
...
@@ -333,6 +333,8 @@ const Main: FC<IMainProps> = ({
const
doShowSuggestion
=
isShowSuggestion
&&
!
isResponsing
const
doShowSuggestion
=
isShowSuggestion
&&
!
isResponsing
const
[
suggestQuestions
,
setSuggestQuestions
]
=
useState
<
string
[]
>
([])
const
[
suggestQuestions
,
setSuggestQuestions
]
=
useState
<
string
[]
>
([])
const
[
messageTaskId
,
setMessageTaskId
]
=
useState
(
''
)
const
[
messageTaskId
,
setMessageTaskId
]
=
useState
(
''
)
const
[
hasStopResponded
,
setHasStopResponded
,
getHasStopResponded
]
=
useGetState
(
false
)
const
handleSend
=
async
(
message
:
string
)
=>
{
const
handleSend
=
async
(
message
:
string
)
=>
{
if
(
isResponsing
)
{
if
(
isResponsing
)
{
notify
({
type
:
'info'
,
message
:
t
(
'appDebug.errorMessage.waitForResponse'
)
})
notify
({
type
:
'info'
,
message
:
t
(
'appDebug.errorMessage.waitForResponse'
)
})
...
@@ -371,6 +373,7 @@ const Main: FC<IMainProps> = ({
...
@@ -371,6 +373,7 @@ const Main: FC<IMainProps> = ({
let
tempNewConversationId
=
''
let
tempNewConversationId
=
''
setHasStopResponded
(
false
)
setResponsingTrue
()
setResponsingTrue
()
setIsShowSuggestion
(
false
)
setIsShowSuggestion
(
false
)
sendChatMessage
(
data
,
{
sendChatMessage
(
data
,
{
...
@@ -411,7 +414,7 @@ const Main: FC<IMainProps> = ({
...
@@ -411,7 +414,7 @@ const Main: FC<IMainProps> = ({
resetNewConversationInputs
()
resetNewConversationInputs
()
setChatNotStarted
()
setChatNotStarted
()
setCurrConversationId
(
tempNewConversationId
,
appId
,
true
)
setCurrConversationId
(
tempNewConversationId
,
appId
,
true
)
if
(
suggestedQuestionsAfterAnswerConfig
?.
enabled
)
{
if
(
suggestedQuestionsAfterAnswerConfig
?.
enabled
&&
!
getHasStopResponded
()
)
{
const
{
data
}:
any
=
await
fetchSuggestedQuestions
(
responseItem
.
id
,
isInstalledApp
,
installedAppInfo
?.
id
)
const
{
data
}:
any
=
await
fetchSuggestedQuestions
(
responseItem
.
id
,
isInstalledApp
,
installedAppInfo
?.
id
)
setSuggestQuestions
(
data
)
setSuggestQuestions
(
data
)
setIsShowSuggestion
(
true
)
setIsShowSuggestion
(
true
)
...
@@ -536,8 +539,8 @@ const Main: FC<IMainProps> = ({
...
@@ -536,8 +539,8 @@ const Main: FC<IMainProps> = ({
isResponsing=
{
isResponsing
}
isResponsing=
{
isResponsing
}
canStopResponsing=
{
!!
messageTaskId
}
canStopResponsing=
{
!!
messageTaskId
}
abortResponsing=
{
async
()
=>
{
abortResponsing=
{
async
()
=>
{
abortController
?.
abort
()
await
stopChatMessageResponding
(
appId
,
messageTaskId
,
isInstalledApp
,
installedAppInfo
?.
id
)
await
stopChatMessageResponding
(
appId
,
messageTaskId
,
isInstalledApp
,
installedAppInfo
?.
id
)
setHasStopResponded
(
true
)
setResponsingFalse
()
setResponsingFalse
()
}
}
}
}
checkCanSend=
{
checkCanSend
}
checkCanSend=
{
checkCanSend
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment