From e31358219cd409a3c821a2078387da50828c234d Mon Sep 17 00:00:00 2001 From: -LAN- Date: Fri, 15 Nov 2024 01:06:10 +0800 Subject: [PATCH] feat(llm-panel): refine variable filtering logic Introduce `filterJinjia2InputVar` to enhance variable filtering, specifically excluding `arrayFile` types from Jinja2 input variables. This adjustment improves the management of variable types, aligning with expected input capacities and ensuring more reliable configurations. Additionally, support for file variables is enabled in relevant components, broadening functionality and user options. --- web/app/components/workflow/nodes/llm/panel.tsx | 4 +++- web/app/components/workflow/nodes/llm/use-config.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 76607b29b1..1def75cdf7 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -67,6 +67,7 @@ const Panel: FC> = ({ handleStop, varInputs, runResult, + filterJinjia2InputVar, } = useConfig(id, data) const model = inputs.model @@ -194,7 +195,7 @@ const Panel: FC> = ({ list={inputs.prompt_config?.jinja2_variables || []} onChange={handleVarListChange} onVarNameChange={handleVarNameChange} - filterVar={filterVar} + filterVar={filterJinjia2InputVar} /> )} @@ -233,6 +234,7 @@ const Panel: FC> = ({ hasSetBlockStatus={hasSetBlockStatus} nodesOutputVars={availableVars} availableNodes={availableNodesWithParent} + isSupportFileVar /> {inputs.memory.query_prompt_template && !inputs.memory.query_prompt_template.includes('{{#sys.query#}}') && ( diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts index 1b84f81110..dd550d7ba8 100644 --- a/web/app/components/workflow/nodes/llm/use-config.ts +++ b/web/app/components/workflow/nodes/llm/use-config.ts @@ -281,6 +281,10 @@ const useConfig = (id: string, payload: LLMNodeType) => { return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.arrayFile].includes(varPayload.type) }, []) + const filterJinjia2InputVar = useCallback((varPayload: Var) => { + return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber].includes(varPayload.type) + }, []) + const filterMemoryPromptVar = useCallback((varPayload: Var) => { return [VarType.arrayObject, VarType.array, VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.arrayFile].includes(varPayload.type) }, []) @@ -406,6 +410,7 @@ const useConfig = (id: string, payload: LLMNodeType) => { handleRun, handleStop, runResult, + filterJinjia2InputVar, } }