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 { InstalledApp } from '@/models/explore'
import type { ModerationService } from '@/models/common' import type { ModerationService } from '@/models/common'
import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app' import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app'
import { BlockEnum } from '@/app/components/workflow/types'
export type IResultProps = { export type IResultProps = {
isWorkflow: boolean isWorkflow: boolean
@@ -181,35 +182,44 @@ const Result: FC<IResultProps> = ({
if (isWorkflow) { if (isWorkflow) {
// ###TODO### // ###TODO###
let outputsExisted = false
sendWorkflowMessage( sendWorkflowMessage(
data, data,
{ {
onWorkflowStarted: ({ workflow_run_id }) => { onWorkflowStarted: ({ workflow_run_id }) => {
tempMessageId = workflow_run_id tempMessageId = workflow_run_id
// console.log('onWorkflowStarted runID: ', workflow_run_id)
}, },
onTextChunk: ({ data }) => { onNodeStarted: ({ data }) => {
res.push(data.text) // console.log('onNodeStarted: ', data.node_type)
setCompletionRes(res.join(''))
}, },
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) if (isTimeout)
return 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() setRespondingFalse()
setMessageId(tempMessageId) setMessageId(tempMessageId)
onCompleted(getCompletionRes(), taskId, true) onCompleted(getCompletionRes(), taskId, true)
clearInterval(runId) clearInterval(runId)
}, },
onTextReplace: ({ data }) => {
res = [data.text]
setCompletionRes(res.join(''))
},
onError() {
if (isTimeout)
return
setRespondingFalse()
onCompleted(getCompletionRes(), taskId, false)
clearInterval(runId)
},
}, },
isInstalledApp, isInstalledApp,
installedAppInfo?.id, 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 { import {
del as consoleDel, get as consoleGet, patch as consolePatch, post as consolePost, 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, 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 ( export const sendWorkflowMessage = async (
body: Record<string, any>, body: Record<string, any>,
{ {
onTextChunk,
onWorkflowStarted, onWorkflowStarted,
onTextReplace, onNodeStarted,
onNodeFinished,
onWorkflowFinished, onWorkflowFinished,
onError,
}: { }: {
onTextChunk: IOnTextChunk
onWorkflowStarted: IOnWorkflowStarted onWorkflowStarted: IOnWorkflowStarted
onNodeStarted: IOnNodeStarted
onNodeFinished: IOnNodeFinished
onWorkflowFinished: IOnWorkflowFinished onWorkflowFinished: IOnWorkflowFinished
onTextReplace: IOnTextReplace
onError: IOnError
}, },
isInstalledApp: boolean, isInstalledApp: boolean,
installedAppId = '', installedAppId = '',
@@ -88,7 +86,7 @@ export const sendWorkflowMessage = async (
...body, ...body,
response_mode: 'streaming', response_mode: 'streaming',
}, },
}, { onTextChunk, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onError, onTextReplace }) }, { onNodeStarted, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onNodeFinished })
} }
export const fetchAppInfo = async () => { export const fetchAppInfo = async () => {

View File

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