fix workflow outputs

This commit is contained in:
JzoNg
2024-03-19 12:33:42 +08:00
parent 978ee93df7
commit cf0c96e0d1
3 changed files with 33 additions and 23 deletions

View File

@@ -14,6 +14,7 @@ import type { PromptConfig } from '@/models/debug'
import type { InstalledApp } from '@/models/explore'
import type { ModerationService } from '@/models/common'
import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app'
import { BlockEnum } from '@/app/components/workflow/types'
export type IResultProps = {
isWorkflow: boolean
@@ -181,35 +182,44 @@ const Result: FC<IResultProps> = ({
if (isWorkflow) {
// ###TODO###
let outputsExisted = false
sendWorkflowMessage(
data,
{
onWorkflowStarted: ({ workflow_run_id }) => {
tempMessageId = workflow_run_id
// console.log('onWorkflowStarted runID: ', workflow_run_id)
},
onTextChunk: ({ data }) => {
res.push(data.text)
setCompletionRes(res.join(''))
onNodeStarted: ({ data }) => {
// console.log('onNodeStarted: ', data.node_type)
},
onWorkflowFinished: () => {
onNodeFinished: ({ data }) => {
// console.log('onNodeFinished: ', data.node_type, data)
if (data.node_type === BlockEnum.LLM && data.outputs.text)
setCompletionRes(data.outputs.text)
if (data.node_type === BlockEnum.End && data.outputs)
outputsExisted = true
},
onWorkflowFinished: ({ data }) => {
// console.log('onWorkflowFinished: ', data)
if (isTimeout)
return
if (data.error) {
notify({ type: 'error', message: data.error })
setRespondingFalse()
onCompleted(getCompletionRes(), taskId, false)
clearInterval(runId)
return
}
if (!outputsExisted) {
notify({ type: 'info', message: 'Outputs not existed.' })
setCompletionRes('')
}
setRespondingFalse()
setMessageId(tempMessageId)
onCompleted(getCompletionRes(), taskId, true)
clearInterval(runId)
},
onTextReplace: ({ data }) => {
res = [data.text]
setCompletionRes(res.join(''))
},
onError() {
if (isTimeout)
return
setRespondingFalse()
onCompleted(getCompletionRes(), taskId, false)
clearInterval(runId)
},
},
isInstalledApp,
installedAppInfo?.id,

View File

@@ -1,4 +1,4 @@
import type { IOnCompleted, IOnData, IOnError, IOnFile, IOnMessageEnd, IOnMessageReplace, IOnTextChunk, IOnTextReplace, IOnThought, IOnWorkflowFinished, IOnWorkflowStarted } from './base'
import type { IOnCompleted, IOnData, IOnError, IOnFile, IOnMessageEnd, IOnMessageReplace, IOnNodeFinished, IOnNodeStarted, IOnThought, IOnWorkflowFinished, IOnWorkflowStarted } from './base'
import {
del as consoleDel, get as consoleGet, patch as consolePatch, post as consolePost,
delPublic as del, getPublic as get, patchPublic as patch, postPublic as post, ssePost,
@@ -68,17 +68,15 @@ export const sendCompletionMessage = async (body: Record<string, any>, { onData,
export const sendWorkflowMessage = async (
body: Record<string, any>,
{
onTextChunk,
onWorkflowStarted,
onTextReplace,
onNodeStarted,
onNodeFinished,
onWorkflowFinished,
onError,
}: {
onTextChunk: IOnTextChunk
onWorkflowStarted: IOnWorkflowStarted
onNodeStarted: IOnNodeStarted
onNodeFinished: IOnNodeFinished
onWorkflowFinished: IOnWorkflowFinished
onTextReplace: IOnTextReplace
onError: IOnError
},
isInstalledApp: boolean,
installedAppId = '',
@@ -88,7 +86,7 @@ export const sendWorkflowMessage = async (
...body,
response_mode: 'streaming',
},
}, { onTextChunk, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onError, onTextReplace })
}, { onNodeStarted, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onNodeFinished })
}
export const fetchAppInfo = async () => {

View File

@@ -90,6 +90,7 @@ export type NodeStartedResponse = {
data: {
id: string
node_id: string
node_type: string
index: number
predecessor_node_id?: string
inputs: any
@@ -104,6 +105,7 @@ export type NodeFinishedResponse = {
data: {
id: string
node_id: string
node_type: string
index: number
predecessor_node_id?: string
inputs: any