langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.23k stars 7.38k forks source link

Enhance `if_else_node` to Support Jinja for the `Add Condition` Operation #7386

Closed hu9029 closed 2 weeks ago

hu9029 commented 2 months ago

Self Checks

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Currently, conditional expressions do not support extracting and evaluating specific fields from a JSON object, especially when the value is in Chinese. If you need to evaluate a particular field within a JSON object returned from a previous step, this cannot be done with the existing functionality. It would be helpful if Jinja syntax could be supported when adding conditions, allowing for direct extraction and evaluation of fields within a JSON object using Jinja expressions.

2. Additional context or comments

No response

3. Can you help us with this feature?

alterxyz commented 2 months ago

Please refer to:

  1. https://docs.dify.ai/guides/workflow/node/template
  2. https://jinja.palletsprojects.com/en/3.1.x/

These resources should help you with the current capabilities and how to use them.

alterxyz commented 2 months ago

Also can you provide more info regarding your title "Enhance if_else_node to Support Jinja for the Add Condition Operation"?

hu9029 commented 2 months ago

The conditional branch node currently supports selecting variables for conditional evaluation, but only allows simple comparisons for dict structures. By enabling Jinja syntax in the conditional branch node, users can easily access and compare fields within dict structures. This functionality is similar to the Jinja toggle in LLM nodes, allowing both plain input and Jinja syntax for more flexible conditional logic.