feat: Parallel Execution of Nodes in Workflows (#8192)

Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
Co-authored-by: Yi <yxiaoisme@gmail.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
takatost
2024-09-10 15:23:16 +08:00
committed by GitHub
parent 5da0182800
commit dabfd74622
156 changed files with 11158 additions and 5605 deletions

View File

@@ -11,10 +11,10 @@ import {
} from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import type { ChatItem, WorkflowProcess } from '../../types'
import TracingPanel from '@/app/components/workflow/run/tracing-panel'
import cn from '@/utils/classnames'
import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
import { WorkflowRunningStatus } from '@/app/components/workflow/types'
import NodePanel from '@/app/components/workflow/run/node'
import { useStore as useAppStore } from '@/app/components/app/store'
type WorkflowProcessProps = {
@@ -107,16 +107,12 @@ const WorkflowProcessItem = ({
!collapse && (
<div className='mt-1.5'>
{
data.tracing.map(node => (
<div key={node.id} className='mb-1 last-of-type:mb-0'>
<NodePanel
nodeInfo={node}
hideInfo={hideInfo}
hideProcessDetail={hideProcessDetail}
onShowIterationDetail={showIterationDetail}
/>
</div>
))
<TracingPanel
list={data.tracing}
onShowIterationDetail={showIterationDetail}
hideNodeInfo={hideInfo}
hideNodeProcessDetail={hideProcessDetail}
/>
}
</div>
)

View File

@@ -241,8 +241,6 @@ export const useChat = (
isAnswer: true,
}
let isInIteration = false
handleResponding(true)
hasStopResponded.current = false
@@ -503,12 +501,13 @@ export const useChat = (
...responseItem,
}
}))
isInIteration = true
},
onIterationFinish: ({ data }) => {
const tracing = responseItem.workflowProcess!.tracing!
tracing[tracing.length - 1] = {
...tracing[tracing.length - 1],
const iterationIndex = tracing.findIndex(item => item.node_id === data.node_id
&& (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))!
tracing[iterationIndex] = {
...tracing[iterationIndex],
...data,
status: WorkflowRunningStatus.Succeeded,
} as any
@@ -520,10 +519,9 @@ export const useChat = (
...responseItem,
}
}))
isInIteration = false
},
onNodeStarted: ({ data }) => {
if (isInIteration)
if (data.iteration_id)
return
responseItem.workflowProcess!.tracing!.push({
@@ -539,10 +537,15 @@ export const useChat = (
}))
},
onNodeFinished: ({ data }) => {
if (isInIteration)
if (data.iteration_id)
return
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.node_id === data.node_id)
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => {
if (!item.execution_metadata?.parallel_id)
return item.node_id === data.node_id
return item.node_id === data.node_id && (item.execution_metadata?.parallel_id === data.execution_metadata.parallel_id)
})
responseItem.workflowProcess!.tracing[currentIndex] = data as any
handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.findIndex(item => item.id === responseItem.id)