| | |
| | | } from '../../hooks' |
| | | import useAvailableVarList from '../_base/hooks/use-available-var-list' |
| | | import useConfigVision from '../../hooks/use-config-vision' |
| | | import type { LLMNodeType, StructuredOutput } from './types' |
| | | import { useModelList, useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' |
| | | import type { LLMNodeType } from './types' |
| | | import { useModelListAndDefaultModelAndCurrentProviderAndModel } from '@/app/components/header/account-setting/model-provider-page/hooks' |
| | | import { |
| | | ModelFeatureEnum, |
| | | ModelTypeEnum, |
| | | } from '@/app/components/header/account-setting/model-provider-page/declarations' |
| | | import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' |
| | |
| | | setInputs(newInputs) |
| | | }, [inputs, setInputs]) |
| | | |
| | | // structure output |
| | | const { data: modelList } = useModelList(ModelTypeEnum.textGeneration) |
| | | const isModelSupportStructuredOutput = modelList |
| | | ?.find(provideItem => provideItem.provider === model?.provider) |
| | | ?.models.find(modelItem => modelItem.model === model?.name) |
| | | ?.features?.includes(ModelFeatureEnum.StructuredOutput) |
| | | |
| | | const [structuredOutputCollapsed, setStructuredOutputCollapsed] = useState(true) |
| | | const handleStructureOutputEnableChange = useCallback((enabled: boolean) => { |
| | | const newInputs = produce(inputs, (draft) => { |
| | | draft.structured_output_enabled = enabled |
| | | }) |
| | | setInputs(newInputs) |
| | | if (enabled) |
| | | setStructuredOutputCollapsed(false) |
| | | }, [inputs, setInputs]) |
| | | |
| | | const handleStructureOutputChange = useCallback((newOutput: StructuredOutput) => { |
| | | const newInputs = produce(inputs, (draft) => { |
| | | draft.structured_output = newOutput |
| | | }) |
| | | setInputs(newInputs) |
| | | }, [inputs, setInputs]) |
| | | |
| | | const filterInputVar = useCallback((varPayload: Var) => { |
| | | return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile].includes(varPayload.type) |
| | | }, []) |
| | |
| | | handleRun, |
| | | handleStop, |
| | | runInputData, |
| | | runInputDataRef, |
| | | setRunInputData, |
| | | runResult, |
| | | toVarInputs, |
| | |
| | | const setInputVarValues = useCallback((newPayload: Record<string, any>) => { |
| | | const newVars = { |
| | | ...newPayload, |
| | | '#context#': runInputDataRef.current['#context#'], |
| | | '#files#': runInputDataRef.current['#files#'], |
| | | '#context#': runInputData['#context#'], |
| | | '#files#': runInputData['#files#'], |
| | | } |
| | | setRunInputData(newVars) |
| | | }, [runInputDataRef, setRunInputData]) |
| | | }, [runInputData, setRunInputData]) |
| | | |
| | | const contexts = runInputData['#context#'] |
| | | const setContexts = useCallback((newContexts: string[]) => { |
| | | setRunInputData({ |
| | | ...runInputDataRef.current, |
| | | ...runInputData, |
| | | '#context#': newContexts, |
| | | }) |
| | | }, [runInputDataRef, setRunInputData]) |
| | | }, [runInputData, setRunInputData]) |
| | | |
| | | const visionFiles = runInputData['#files#'] |
| | | const setVisionFiles = useCallback((newFiles: any[]) => { |
| | | setRunInputData({ |
| | | ...runInputDataRef.current, |
| | | ...runInputData, |
| | | '#files#': newFiles, |
| | | }) |
| | | }, [runInputDataRef, setRunInputData]) |
| | | }, [runInputData, setRunInputData]) |
| | | |
| | | const allVarStrArr = (() => { |
| | | const arr = isChatModel ? (inputs.prompt_template as PromptItem[]).filter(item => item.edition_type !== EditionType.jinja2).map(item => item.text) : [(inputs.prompt_template as PromptItem).text] |
| | |
| | | setContexts, |
| | | varInputs, |
| | | runningStatus, |
| | | isModelSupportStructuredOutput, |
| | | handleStructureOutputChange, |
| | | structuredOutputCollapsed, |
| | | setStructuredOutputCollapsed, |
| | | handleStructureOutputEnableChange, |
| | | handleRun, |
| | | handleStop, |
| | | runResult, |