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
b4afefea
Commit
b4afefea
authored
Jun 30, 2023
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: multi run quene bug
parent
da54fd87
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
36 deletions
+72
-36
index.tsx
web/app/components/share/text-generation/index.tsx
+54
-19
index.tsx
web/app/components/share/text-generation/result/index.tsx
+13
-15
index.tsx
...ts/share/text-generation/run-batch/csv-download/index.tsx
+1
-1
app-debug.en.ts
web/i18n/lang/app-debug.en.ts
+2
-0
app-debug.zh.ts
web/i18n/lang/app-debug.zh.ts
+1
-0
base.ts
web/service/base.ts
+1
-1
No files found.
web/app/components/share/text-generation/index.tsx
View file @
b4afefea
...
@@ -61,7 +61,9 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -61,7 +61,9 @@ const TextGeneration: FC<IMainProps> = ({
const
isMobile
=
media
===
MediaType
.
mobile
const
isMobile
=
media
===
MediaType
.
mobile
const
[
currTab
,
setCurrTab
]
=
useState
<
string
>
(
'batch'
)
const
[
currTab
,
setCurrTab
]
=
useState
<
string
>
(
'batch'
)
const
[
isBatch
,
setIsBatch
]
=
useState
(
false
)
// Notice this situation isCallBatchAPI but not in batch tab
const
[
isCallBatchAPI
,
setIsCallBatchAPI
]
=
useState
(
false
)
const
isInBatchTab
=
currTab
===
'batch'
const
[
inputs
,
setInputs
]
=
useState
<
Record
<
string
,
any
>>
({})
const
[
inputs
,
setInputs
]
=
useState
<
Record
<
string
,
any
>>
({})
const
[
query
,
setQuery
]
=
useState
(
''
)
// run once query content
const
[
query
,
setQuery
]
=
useState
(
''
)
// run once query content
const
[
appId
,
setAppId
]
=
useState
<
string
>
(
''
)
const
[
appId
,
setAppId
]
=
useState
<
string
>
(
''
)
...
@@ -92,25 +94,31 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -92,25 +94,31 @@ const TextGeneration: FC<IMainProps> = ({
// send message task
// send message task
const
[
controlSend
,
setControlSend
]
=
useState
(
0
)
const
[
controlSend
,
setControlSend
]
=
useState
(
0
)
const
handleSend
=
()
=>
{
const
handleSend
=
()
=>
{
setIs
Batch
(
false
)
setIs
CallBatchAPI
(
false
)
setControlSend
(
Date
.
now
())
setControlSend
(
Date
.
now
())
}
}
const
[
allTaskList
,
setAllTaskList
]
=
useState
<
Task
[]
>
([])
const
[
allTaskList
,
setAllTaskList
]
=
useState
<
Task
[]
>
([])
// const pendingTaskList = allTaskList.filter(task => task.status === TaskStatus.pending)
const
pendingTaskList
=
allTaskList
.
filter
(
task
=>
task
.
status
===
TaskStatus
.
pending
)
const
runningTaskList
=
allTaskList
.
filter
(
task
=>
task
.
status
===
TaskStatus
.
running
)
const
noPendingTask
=
pendingTaskList
.
length
===
0
const
completedTaskList
=
allTaskList
.
filter
(
task
=>
task
.
status
===
TaskStatus
.
completed
)
const
showTaskList
=
allTaskList
.
filter
(
task
=>
task
.
status
!==
TaskStatus
.
pending
)
const
showTaskList
=
[...
runningTaskList
,
...
completedTaskList
]
// console.log(showTaskList.map(item => ({ id: item.id, status: item.status })))
const
allTaskFinished
=
allTaskList
.
every
(
task
=>
task
.
status
===
TaskStatus
.
completed
)
const
handleRunBatch
=
(
data
:
string
[][])
=>
{
const
handleRunBatch
=
(
data
:
string
[][])
=>
{
setIsBatch
(
true
)
if
(
!
allTaskFinished
)
{
notify
({
type
:
'info'
,
message
:
t
(
'appDebug.errorMessage.waitForBatchResponse'
)
})
return
}
setIsCallBatchAPI
(
true
)
const
allTaskList
:
Task
[]
=
data
.
map
((
item
,
i
)
=>
{
const
allTaskList
:
Task
[]
=
data
.
map
((
item
,
i
)
=>
{
const
inputs
:
Record
<
string
,
string
>
=
{}
const
inputs
:
Record
<
string
,
string
>
=
{}
item
.
slice
(
0
,
-
1
).
forEach
((
input
,
index
)
=>
{
item
.
slice
(
0
,
-
1
).
forEach
((
input
,
index
)
=>
{
inputs
[
promptConfig
?.
prompt_variables
[
index
].
key
as
string
]
=
input
inputs
[
promptConfig
?.
prompt_variables
[
index
].
key
as
string
]
=
input
})
})
return
{
return
{
id
:
1
,
id
:
i
+
1
,
status
:
i
+
1
<
PARALLEL_LIMIT
?
TaskStatus
.
running
:
TaskStatus
.
pending
,
status
:
i
<
PARALLEL_LIMIT
?
TaskStatus
.
running
:
TaskStatus
.
pending
,
params
:
{
params
:
{
inputs
,
inputs
,
query
:
item
[
item
.
length
-
1
],
query
:
item
[
item
.
length
-
1
],
...
@@ -118,9 +126,29 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -118,9 +126,29 @@ const TextGeneration: FC<IMainProps> = ({
}
}
})
})
setAllTaskList
(
allTaskList
)
setAllTaskList
(
allTaskList
)
setControlSend
(
Date
.
now
())
}
}
// TODO: finished add pending tasks.
const
handleCompleted
=
(
taskId
?:
number
,
isSuccess
?:
boolean
)
=>
{
console
.
log
(
taskId
,
isSuccess
)
const
nextPendingTaskId
=
pendingTaskList
[
0
]?.
id
const
newAllTaskList
=
allTaskList
.
map
((
item
)
=>
{
if
(
item
.
id
===
taskId
)
{
return
{
...
item
,
status
:
TaskStatus
.
completed
,
}
}
if
(
item
.
id
===
nextPendingTaskId
)
{
return
{
...
item
,
status
:
TaskStatus
.
running
,
}
}
return
item
})
setAllTaskList
(
newAllTaskList
)
}
const
fetchInitData
=
()
=>
{
const
fetchInitData
=
()
=>
{
return
Promise
.
all
([
isInstalledApp
return
Promise
.
all
([
isInstalledApp
...
@@ -168,18 +196,20 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -168,18 +196,20 @@ const TextGeneration: FC<IMainProps> = ({
const
renderRes
=
(
task
?:
Task
)
=>
(<
Res
const
renderRes
=
(
task
?:
Task
)
=>
(<
Res
key=
{
task
?.
id
}
key=
{
task
?.
id
}
is
Batch=
{
isBatch
}
is
CallBatchAPI=
{
isCallBatchAPI
}
isPC=
{
isPC
}
isPC=
{
isPC
}
isMobile=
{
isMobile
}
isMobile=
{
isMobile
}
isInstalledApp=
{
!!
isInstalledApp
}
isInstalledApp=
{
!!
isInstalledApp
}
installedAppInfo=
{
installedAppInfo
}
installedAppInfo=
{
installedAppInfo
}
promptConfig=
{
promptConfig
}
promptConfig=
{
promptConfig
}
moreLikeThisEnabled=
{
!!
moreLikeThisConfig
?.
enabled
}
moreLikeThisEnabled=
{
!!
moreLikeThisConfig
?.
enabled
}
inputs=
{
is
Batch
?
(
task
as
Task
).
params
.
inputs
:
inputs
}
inputs=
{
is
CallBatchAPI
?
(
task
as
Task
).
params
.
inputs
:
inputs
}
query=
{
is
Batch
?
(
task
as
Task
).
params
.
query
:
query
}
query=
{
is
CallBatchAPI
?
(
task
as
Task
).
params
.
query
:
query
}
controlSend=
{
isBatch
?
0
:
controlSend
}
controlSend=
{
controlSend
}
onShowRes=
{
showResSidebar
}
onShowRes=
{
showResSidebar
}
handleSaveMessage=
{
handleSaveMessage
}
handleSaveMessage=
{
handleSaveMessage
}
taskId=
{
task
?.
id
}
onCompleted=
{
handleCompleted
}
/>)
/>)
const
renderBatchRes
=
()
=>
{
const
renderBatchRes
=
()
=>
{
...
@@ -213,7 +243,12 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -213,7 +243,12 @@ const TextGeneration: FC<IMainProps> = ({
</
div
>
</
div
>
<
div
className=
'grow overflow-y-auto'
>
<
div
className=
'grow overflow-y-auto'
>
{
!
isBatch
?
renderRes
()
:
renderBatchRes
()
}
{
!
isCallBatchAPI
?
renderRes
()
:
renderBatchRes
()
}
{
!
noPendingTask
&&
(
<
div
className=
'mt-4'
>
<
Loading
type=
'area'
/>
</
div
>
)
}
</
div
>
</
div
>
</>
</>
</
div
>
</
div
>
...
@@ -278,7 +313,7 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -278,7 +313,7 @@ const TextGeneration: FC<IMainProps> = ({
onChange=
{
setCurrTab
}
onChange=
{
setCurrTab
}
/>
/>
<
div
className=
'grow h-20 overflow-y-auto'
>
<
div
className=
'grow h-20 overflow-y-auto'
>
{
currTab
===
'create'
&&
(
<
div
className=
{
cn
(
currTab
===
'create'
?
'block'
:
'hidden'
)
}
>
<
ConfigScence
<
ConfigScence
siteInfo=
{
siteInfo
}
siteInfo=
{
siteInfo
}
inputs=
{
inputs
}
inputs=
{
inputs
}
...
@@ -288,13 +323,13 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -288,13 +323,13 @@ const TextGeneration: FC<IMainProps> = ({
onQueryChange=
{
setQuery
}
onQueryChange=
{
setQuery
}
onSend=
{
handleSend
}
onSend=
{
handleSend
}
/>
/>
)
}
</
div
>
{
currTab
===
'batch'
&&
(
<
div
className=
{
cn
(
isInBatchTab
?
'block'
:
'hidden'
)
}
>
<
RunBatch
<
RunBatch
vars=
{
promptConfig
.
prompt_variables
}
vars=
{
promptConfig
.
prompt_variables
}
onSend=
{
handleRunBatch
}
onSend=
{
handleRunBatch
}
/>
/>
)
}
</
div
>
{
currTab
===
'saved'
&&
(
{
currTab
===
'saved'
&&
(
<
SavedItems
<
SavedItems
...
...
web/app/components/share/text-generation/result/index.tsx
View file @
b4afefea
...
@@ -12,9 +12,8 @@ import type { Feedbacktype } from '@/app/components/app/chat'
...
@@ -12,9 +12,8 @@ import type { Feedbacktype } from '@/app/components/app/chat'
import
Loading
from
'@/app/components/base/loading'
import
Loading
from
'@/app/components/base/loading'
import
type
{
PromptConfig
}
from
'@/models/debug'
import
type
{
PromptConfig
}
from
'@/models/debug'
import
type
{
InstalledApp
}
from
'@/models/explore'
import
type
{
InstalledApp
}
from
'@/models/explore'
export
type
IResultProps
=
{
export
type
IResultProps
=
{
is
Batch
:
boolean
is
CallBatchAPI
:
boolean
isPC
:
boolean
isPC
:
boolean
isMobile
:
boolean
isMobile
:
boolean
isInstalledApp
:
boolean
isInstalledApp
:
boolean
...
@@ -26,10 +25,12 @@ export type IResultProps = {
...
@@ -26,10 +25,12 @@ export type IResultProps = {
controlSend
?:
number
controlSend
?:
number
onShowRes
:
()
=>
void
onShowRes
:
()
=>
void
handleSaveMessage
:
(
messageId
:
string
)
=>
void
handleSaveMessage
:
(
messageId
:
string
)
=>
void
taskId
?:
number
onCompleted
:
(
taskId
?:
number
,
success
?:
boolean
)
=>
void
}
}
const
Result
:
FC
<
IResultProps
>
=
({
const
Result
:
FC
<
IResultProps
>
=
({
is
Batch
,
is
CallBatchAPI
,
isPC
,
isPC
,
isMobile
,
isMobile
,
isInstalledApp
,
isInstalledApp
,
...
@@ -41,6 +42,8 @@ const Result: FC<IResultProps> = ({
...
@@ -41,6 +42,8 @@ const Result: FC<IResultProps> = ({
controlSend
,
controlSend
,
onShowRes
,
onShowRes
,
handleSaveMessage
,
handleSaveMessage
,
taskId
,
onCompleted
,
})
=>
{
})
=>
{
const
[
isResponsing
,
{
setTrue
:
setResponsingTrue
,
setFalse
:
setResponsingFalse
}]
=
useBoolean
(
false
)
const
[
isResponsing
,
{
setTrue
:
setResponsingTrue
,
setFalse
:
setResponsingFalse
}]
=
useBoolean
(
false
)
const
[
completionRes
,
setCompletionRes
]
=
useState
(
''
)
const
[
completionRes
,
setCompletionRes
]
=
useState
(
''
)
...
@@ -63,7 +66,7 @@ const Result: FC<IResultProps> = ({
...
@@ -63,7 +66,7 @@ const Result: FC<IResultProps> = ({
const
checkCanSend
=
()
=>
{
const
checkCanSend
=
()
=>
{
// batch will check outer
// batch will check outer
if
(
is
Batch
)
if
(
is
CallBatchAPI
)
return
true
return
true
const
prompt_variables
=
promptConfig
?.
prompt_variables
const
prompt_variables
=
promptConfig
?.
prompt_variables
...
@@ -131,24 +134,19 @@ const Result: FC<IResultProps> = ({
...
@@ -131,24 +134,19 @@ const Result: FC<IResultProps> = ({
onCompleted
:
()
=>
{
onCompleted
:
()
=>
{
setResponsingFalse
()
setResponsingFalse
()
setMessageId
(
tempMessageId
)
setMessageId
(
tempMessageId
)
onCompleted
(
taskId
,
true
)
},
},
onError
()
{
onError
()
{
setResponsingFalse
()
setResponsingFalse
()
onCompleted
(
taskId
,
false
)
},
},
},
isInstalledApp
,
installedAppInfo
?.
id
)
},
isInstalledApp
,
installedAppInfo
?.
id
)
}
}
// run once
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
controlSend
)
if
(
controlSend
)
handleSend
()
handleSend
()
},
[
controlSend
])
},
[
controlSend
])
// run batch
useEffect
(()
=>
{
if
(
isBatch
)
handleSend
()
},
[
isBatch
])
const
renderTextGenerationRes
=
()
=>
(
const
renderTextGenerationRes
=
()
=>
(
<
TextGenerationRes
<
TextGenerationRes
className=
'mt-3'
className=
'mt-3'
...
@@ -162,13 +160,13 @@ const Result: FC<IResultProps> = ({
...
@@ -162,13 +160,13 @@ const Result: FC<IResultProps> = ({
isMobile=
{
isMobile
}
isMobile=
{
isMobile
}
isInstalledApp=
{
isInstalledApp
}
isInstalledApp=
{
isInstalledApp
}
installedAppId=
{
installedAppInfo
?.
id
}
installedAppId=
{
installedAppInfo
?.
id
}
isLoading=
{
is
Batch
?
(
!
completionRes
&&
isResponsing
)
:
false
}
isLoading=
{
is
CallBatchAPI
?
(
!
completionRes
&&
isResponsing
)
:
false
}
/>
/>
)
)
return
(
return
(
<
div
className=
{
cn
(
(
isBatch
&&
!
isNoData
)
?
''
:
'h-full'
)
}
>
<
div
className=
{
cn
(
isNoData
&&
!
isCallBatchAPI
&&
'h-full'
)
}
>
{
!
is
Batch
&&
(
{
!
is
CallBatchAPI
&&
(
(
isResponsing
&&
!
completionRes
)
(
isResponsing
&&
!
completionRes
)
?
(
?
(
<
div
className=
'flex h-full w-full justify-center items-center'
>
<
div
className=
'flex h-full w-full justify-center items-center'
>
...
@@ -183,7 +181,7 @@ const Result: FC<IResultProps> = ({
...
@@ -183,7 +181,7 @@ const Result: FC<IResultProps> = ({
</>
</>
)
)
)
}
)
}
{
is
Batch
&&
(
{
is
CallBatchAPI
&&
(
<
div
className=
'mt-2'
>
<
div
className=
'mt-2'
>
{
renderTextGenerationRes
()
}
{
renderTextGenerationRes
()
}
</
div
>
</
div
>
...
...
web/app/components/share/text-generation/run-batch/csv-download/index.tsx
View file @
b4afefea
...
@@ -29,7 +29,7 @@ const CSVDownload: FC<ICSVDownloadProps> = ({
...
@@ -29,7 +29,7 @@ const CSVDownload: FC<ICSVDownloadProps> = ({
<
div
className=
'mt-6'
>
<
div
className=
'mt-6'
>
<
div
className=
'text-sm text-gray-900 font-medium'
>
{
t
(
'share.generation.csvStructureTitle'
)
}
</
div
>
<
div
className=
'text-sm text-gray-900 font-medium'
>
{
t
(
'share.generation.csvStructureTitle'
)
}
</
div
>
<
div
className=
'mt-2 max-h-[500px] overflow-auto'
>
<
div
className=
'mt-2 max-h-[500px] overflow-auto'
>
<
table
className=
'w-full border-separate border-spacing-0 border border-gray-200 rounded-lg'
>
<
table
className=
'w-full border-separate border-spacing-0 border border-gray-200 rounded-lg
text-xs
'
>
<
thead
className=
'text-gray-500'
>
<
thead
className=
'text-gray-500'
>
<
tr
>
<
tr
>
{
addQueryContentVars
.
map
((
item
,
i
)
=>
(
{
addQueryContentVars
.
map
((
item
,
i
)
=>
(
...
...
web/i18n/lang/app-debug.en.ts
View file @
b4afefea
...
@@ -81,6 +81,8 @@ const translation = {
...
@@ -81,6 +81,8 @@ const translation = {
queryRequired
:
'Request text is required.'
,
queryRequired
:
'Request text is required.'
,
waitForResponse
:
waitForResponse
:
'Please wait for the response to the previous message to complete.'
,
'Please wait for the response to the previous message to complete.'
,
waitForBatchResponse
:
'Please wait for the response to the batch task to complete.'
,
},
},
chatSubTitle
:
'Pre Prompt'
,
chatSubTitle
:
'Pre Prompt'
,
completionSubTitle
:
'Prefix Prompt'
,
completionSubTitle
:
'Prefix Prompt'
,
...
...
web/i18n/lang/app-debug.zh.ts
View file @
b4afefea
...
@@ -79,6 +79,7 @@ const translation = {
...
@@ -79,6 +79,7 @@ const translation = {
valueOfVarRequired
:
'变量值必填'
,
valueOfVarRequired
:
'变量值必填'
,
queryRequired
:
'主要文本必填'
,
queryRequired
:
'主要文本必填'
,
waitForResponse
:
'请等待上条信息响应完成'
,
waitForResponse
:
'请等待上条信息响应完成'
,
waitForBatchResponse
:
'请等待批量任务完成'
,
},
},
chatSubTitle
:
'对话前提示词'
,
chatSubTitle
:
'对话前提示词'
,
completionSubTitle
:
'前缀提示词'
,
completionSubTitle
:
'前缀提示词'
,
...
...
web/service/base.ts
View file @
b4afefea
...
@@ -308,13 +308,13 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
...
@@ -308,13 +308,13 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
}
}
return
handleStream
(
res
,
(
str
:
string
,
isFirstMessage
:
boolean
,
moreInfo
:
IOnDataMoreInfo
)
=>
{
return
handleStream
(
res
,
(
str
:
string
,
isFirstMessage
:
boolean
,
moreInfo
:
IOnDataMoreInfo
)
=>
{
if
(
moreInfo
.
errorMessage
)
{
if
(
moreInfo
.
errorMessage
)
{
onError
?.(
moreInfo
.
errorMessage
)
Toast
.
notify
({
type
:
'error'
,
message
:
moreInfo
.
errorMessage
})
Toast
.
notify
({
type
:
'error'
,
message
:
moreInfo
.
errorMessage
})
return
return
}
}
onData
?.(
str
,
isFirstMessage
,
moreInfo
)
onData
?.(
str
,
isFirstMessage
,
moreInfo
)
},
onCompleted
)
},
onCompleted
)
}).
catch
((
e
)
=>
{
}).
catch
((
e
)
=>
{
// debugger
Toast
.
notify
({
type
:
'error'
,
message
:
e
})
Toast
.
notify
({
type
:
'error'
,
message
:
e
})
onError
?.(
e
)
onError
?.(
e
)
})
})
...
...
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