text generation run

This commit is contained in:
JzoNg 2024-09-25 20:33:09 +08:00
parent 0ab525a691
commit 719ef9cef9
11 changed files with 44 additions and 12 deletions

View File

@ -4,12 +4,11 @@ import {
} from 'react' } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
// import Loading from '@/app/components/base/loading'
import { Markdown } from '@/app/components/base/markdown' import { Markdown } from '@/app/components/base/markdown'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor' import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
import type { WorkflowProcess } from '@/app/components/base/chat/types' import type { WorkflowProcess } from '@/app/components/base/chat/types'
// import { WorkflowRunningStatus } from '@/app/components/workflow/types' import { FileList } from '@/app/components/base/file-uploader'
const ResultTab = ({ const ResultTab = ({
data, data,
@ -56,7 +55,16 @@ const ResultTab = ({
)} )}
<div className={cn('grow bg-white')}> <div className={cn('grow bg-white')}>
{currentTab === 'RESULT' && ( {currentTab === 'RESULT' && (
<Markdown content={data?.resultText || ''} /> <>
<Markdown content={data?.resultText || ''} />
{data?.files?.length && (
<FileList
files={data?.files}
showDeleteAction={false}
showDownloadAction
/>
)}
</>
)} )}
{currentTab === 'DETAIL' && content && ( {currentTab === 'DETAIL' && content && (
<CodeEditor <CodeEditor

View File

@ -55,6 +55,7 @@ export type WorkflowProcess = {
tracing: NodeTracing[] tracing: NodeTracing[]
expand?: boolean // for UI expand?: boolean // for UI
resultText?: string resultText?: string
files?: FileEntity[]
} }
export type ChatItem = IChatItem & { export type ChatItem = IChatItem & {

View File

@ -392,7 +392,6 @@ const TextGeneration: FC<IMainProps> = ({
image_file_size_limit: appParams?.system_parameters?.image_file_size_limit, image_file_size_limit: appParams?.system_parameters?.image_file_size_limit,
}) })
const prompt_variables = userInputsFormToPromptVariables(user_input_form) const prompt_variables = userInputsFormToPromptVariables(user_input_form)
console.log(prompt_variables)
setPromptConfig({ setPromptConfig({
prompt_template: '', // placeholder for future prompt_template: '', // placeholder for future
prompt_variables, prompt_variables,

View File

@ -20,6 +20,9 @@ import type { WorkflowProcess } from '@/app/components/base/chat/types'
import { sleep } from '@/utils' import { sleep } from '@/utils'
import type { SiteInfo } from '@/models/share' import type { SiteInfo } from '@/models/share'
import { TEXT_GENERATION_TIMEOUT_MS } from '@/config' import { TEXT_GENERATION_TIMEOUT_MS } from '@/config'
import {
getProcessedFilesFromResponse,
} from '@/app/components/base/file-uploader/utils'
export type IResultProps = { export type IResultProps = {
isWorkflow: boolean isWorkflow: boolean
@ -295,6 +298,7 @@ const Result: FC<IResultProps> = ({
if (isStringOutput) { if (isStringOutput) {
setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => {
draft.resultText = data.outputs[Object.keys(data.outputs)[0]] draft.resultText = data.outputs[Object.keys(data.outputs)[0]]
draft.files = getProcessedFilesFromResponse(data.files || [])
})) }))
} }
} }

View File

@ -14,7 +14,6 @@ import TextGenerationImageUploader from '@/app/components/base/image-uploader/te
import type { VisionFile, VisionSettings } from '@/types/app' import type { VisionFile, VisionSettings } from '@/types/app'
import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader' import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader'
import { getProcessedFiles } from '@/app/components/base/file-uploader/utils' import { getProcessedFiles } from '@/app/components/base/file-uploader/utils'
// import { InputVarType } from '@/app/components/workflow/types'
export type IRunOnceProps = { export type IRunOnceProps = {
siteInfo: SiteInfo siteInfo: SiteInfo

View File

@ -24,6 +24,9 @@ import {
} from '@/service/workflow' } from '@/service/workflow'
import { useFeaturesStore } from '@/app/components/base/features/hooks' import { useFeaturesStore } from '@/app/components/base/features/hooks'
import { AudioPlayerManager } from '@/app/components/base/audio-btn/audio.player.manager' import { AudioPlayerManager } from '@/app/components/base/audio-btn/audio.player.manager'
import {
getProcessedFilesFromResponse,
} from '@/app/components/base/file-uploader/utils'
export const useWorkflowRun = () => { export const useWorkflowRun = () => {
const store = useStoreApi() const store = useStoreApi()
@ -207,6 +210,7 @@ export const useWorkflowRun = () => {
draft.result = { draft.result = {
...draft.result, ...draft.result,
...data, ...data,
files: getProcessedFilesFromResponse(data.files || []),
} as any } as any
if (isStringOutput) { if (isStringOutput) {
draft.resultTabActive = true draft.resultTabActive = true

View File

@ -1,5 +1,6 @@
import { import {
memo, memo,
useCallback,
useMemo, useMemo,
} from 'react' } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
@ -14,7 +15,7 @@ import {
useStore, useStore,
useWorkflowStore, useWorkflowStore,
} from '../store' } from '../store'
import { useWorkflowRun } from '../hooks' import { useCheckStartNodeForm, useWorkflowRun } from '../hooks'
import type { StartNodeType } from '../nodes/start/types' import type { StartNodeType } from '../nodes/start/types'
import { TransferMethod } from '../../base/text-generation/types' import { TransferMethod } from '../../base/text-generation/types'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
@ -55,6 +56,8 @@ const InputsPanel = ({ onRun }: Props) => {
return data return data
}, [fileSettings?.image?.enabled, startVariables]) }, [fileSettings?.image?.enabled, startVariables])
const { getProcessedInputs } = useCheckStartNodeForm()
const handleValueChange = (variable: string, v: any) => { const handleValueChange = (variable: string, v: any) => {
const { const {
inputs, inputs,
@ -73,17 +76,17 @@ const InputsPanel = ({ onRun }: Props) => {
} }
} }
const doRun = () => { const doRun = useCallback(() => {
onRun() onRun()
handleRun({ inputs, files }) handleRun({ inputs: getProcessedInputs(inputs), files })
} }, [files, getProcessedInputs, handleRun, inputs, onRun])
const canRun = (() => { const canRun = useMemo(() => {
if (files?.some(item => (item.transfer_method as any) === TransferMethod.local_file && !item.upload_file_id)) if (files?.some(item => (item.transfer_method as any) === TransferMethod.local_file && !item.upload_file_id))
return false return false
return true return true
})() }, [files])
return ( return (
<> <>

View File

@ -157,6 +157,7 @@ const WorkflowPreview = () => {
<ResultText <ResultText
isRunning={workflowRunningData?.result?.status === WorkflowRunningStatus.Running || !workflowRunningData?.result} isRunning={workflowRunningData?.result?.status === WorkflowRunningStatus.Running || !workflowRunningData?.result}
outputs={workflowRunningData?.resultText} outputs={workflowRunningData?.resultText}
allFiles={workflowRunningData?.result?.files as any}
error={workflowRunningData?.result?.error} error={workflowRunningData?.result?.error}
onClick={() => switchTab('DETAIL')} onClick={() => switchTab('DETAIL')}
/> />

View File

@ -5,12 +5,15 @@ import { ImageIndentLeft } from '@/app/components/base/icons/src/vender/line/edi
import { Markdown } from '@/app/components/base/markdown' import { Markdown } from '@/app/components/base/markdown'
import LoadingAnim from '@/app/components/base/chat/chat/loading-anim' import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
import StatusContainer from '@/app/components/workflow/run/status-container' import StatusContainer from '@/app/components/workflow/run/status-container'
import { FileList } from '@/app/components/base/file-uploader'
import type { FileEntity } from '@/app/components/base/file-uploader/types'
type ResultTextProps = { type ResultTextProps = {
isRunning?: boolean isRunning?: boolean
outputs?: any outputs?: any
error?: string error?: string
onClick?: () => void onClick?: () => void
allFiles?: FileEntity[]
} }
const ResultText: FC<ResultTextProps> = ({ const ResultText: FC<ResultTextProps> = ({
@ -18,6 +21,7 @@ const ResultText: FC<ResultTextProps> = ({
outputs, outputs,
error, error,
onClick, onClick,
allFiles,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
@ -48,6 +52,13 @@ const ResultText: FC<ResultTextProps> = ({
{outputs && ( {outputs && (
<div className='px-4 py-2'> <div className='px-4 py-2'>
<Markdown content={outputs} /> <Markdown content={outputs} />
{allFiles?.length && (
<FileList
files={allFiles}
showDeleteAction={false}
showDownloadAction
/>
)}
</div> </div>
)} )}
</div> </div>

View File

@ -6,7 +6,7 @@ import type {
import type { Resolution, TransferMethod } from '@/types/app' import type { Resolution, TransferMethod } from '@/types/app'
import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types' import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types'
import type { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types' import type { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
import type { NodeTracing } from '@/types/workflow' import type { FileResponse, NodeTracing } from '@/types/workflow'
import type { Collection, Tool } from '@/app/components/tools/types' import type { Collection, Tool } from '@/app/components/tools/types'
import type { ChatVarType } from '@/app/components/workflow/panel/chat-variable-panel/type' import type { ChatVarType } from '@/app/components/workflow/panel/chat-variable-panel/type'
@ -326,6 +326,7 @@ export type WorkflowRunningData = {
steps?: number steps?: number
showSteps?: boolean showSteps?: boolean
total_steps?: number total_steps?: number
files?: FileResponse[]
} }
tracing?: NodeTracing[] tracing?: NodeTracing[]
} }

View File

@ -109,6 +109,7 @@ export type WorkflowFinishedResponse = {
email: string email: string
} }
finished_at: number finished_at: number
files?: FileResponse[]
} }
} }