Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix jinja2 variable naming inconsistencies (#22578)

Kalo Chin7a69b578236a
diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py
index 9bfb402dc88..be0675a0f28 100644
--- a/api/core/workflow/nodes/llm/node.py
+++ b/api/core/workflow/nodes/llm/node.py
@@ -849,7 +849,7 @@ class LLMNode(BaseNode[LLMNodeData]):
if message.edition_type == "jinja2":
result_text = _render_jinja2_message(
template=message.jinja2_text or "",
- jinjia2_variables=jinja2_variables,
+ jinja2_variables=jinja2_variables,
variable_pool=variable_pool,
)
prompt_message = _combine_message_content_with_role(
@@ -1021,20 +1021,20 @@ def _combine_message_content_with_role(
def _render_jinja2_message(
*,
template: str,
- jinjia2_variables: Sequence[VariableSelector],
+ jinja2_variables: Sequence[VariableSelector],
variable_pool: VariablePool,
):
if not template:
return ""
- jinjia2_inputs = {}
- for jinja2_variable in jinjia2_variables:
+ jinja2_inputs = {}
+ for jinja2_variable in jinja2_variables:
variable = variable_pool.get(jinja2_variable.value_selector)
- jinjia2_inputs[jinja2_variable.variable] = variable.to_object() if variable else ""
+ jinja2_inputs[jinja2_variable.variable] = variable.to_object() if variable else ""
code_execute_resp = CodeExecutor.execute_workflow_code_template(
language=CodeLanguage.JINJA2,
code=template,
- inputs=jinjia2_inputs,
+ inputs=jinja2_inputs,
)
result_text = code_execute_resp["result"]
return result_text
@@ -1130,7 +1130,7 @@ def _handle_completion_template(
if template.edition_type == "jinja2":
result_text = _render_jinja2_message(
template=template.jinja2_text or "",
- jinjia2_variables=jinja2_variables,
+ jinja2_variables=jinja2_variables,
variable_pool=variable_pool,
)
else:
diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx
index 471d65ef203..b4754292653 100644
--- a/web/app/components/workflow/nodes/llm/panel.tsx
+++ b/web/app/components/workflow/nodes/llm/panel.tsx
@@ -60,7 +60,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
setStructuredOutputCollapsed,
handleStructureOutputEnableChange,
handleStructureOutputChange,
- filterJinjia2InputVar,
+ filterJinja2InputVar,
} = useConfig(id, data)
const model = inputs.model
@@ -166,7 +166,7 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
list={inputs.prompt_config?.jinja2_variables || []}
onChange={handleVarListChange}
onVarNameChange={handleVarNameChange}
- filterVar={filterJinjia2InputVar}
+ filterVar={filterJinja2InputVar}
isSupportFileVar={false}
/>
</Field>
diff --git a/web/app/components/workflow/nodes/llm/use-config.ts b/web/app/components/workflow/nodes/llm/use-config.ts
index e4da65bedc3..b8516caed8b 100644
--- a/web/app/components/workflow/nodes/llm/use-config.ts
+++ b/web/app/components/workflow/nodes/llm/use-config.ts
@@ -309,7 +309,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile].includes(varPayload.type)
}, [])
- const filterJinjia2InputVar = useCallback((varPayload: Var) => {
+ const filterJinja2InputVar = useCallback((varPayload: Var) => {
return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber].includes(varPayload.type)
}, [])
@@ -356,7 +356,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
structuredOutputCollapsed,
setStructuredOutputCollapsed,
handleStructureOutputEnableChange,
- filterJinjia2InputVar,
+ filterJinja2InputVar,
}
}