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
50.14k stars 7.18k forks source link

The variable "sys.files" cannot be obtained in other nodes of the workflow. #4363

Closed BellMeng closed 5 months ago

BellMeng commented 5 months ago

Self Checks

Dify version

0.6.8

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a LLM workflow.
  2. Try to use the variable "sys.files" in second workflow node. image image

✔️ Expected Behavior

The variable "sys.files" can be used in overall workflow node.

❌ Actual Behavior

The variable "sys.files" only can be used in start and end node.

dosubot[bot] commented 5 months ago

To address the issue with the "sys.files" variable not being accessible in intermediate nodes of your Dify workflow, it's important to understand that this behavior might be due to the sandboxed execution environment of Dify, which restricts certain functionalities for security reasons. However, there's a workaround that involves using the getNodeOutputVars function to access "sys.files" in intermediate nodes.

You can adapt your workflow to ensure that "sys.files" is included in the output variables of intermediate nodes by implementing custom logic within your workflow processing or node handling. This might involve modifying node output structures or ensuring that variables are passed along between nodes as needed.

Here's a code snippet that demonstrates how "sys.files" is added to the output variables for a start node, which can be adapted for your needs:

case BlockEnum.Start: {
  const {
    variables,
  } = data as StartNodeType
  res = variables.map((v) => {
    return [id, v.variable]
  })

  if (isChatMode) {
    res.push([id, 'sys', 'query'])
    res.push([id, 'sys', 'files'])
  }
  break
}

For further guidance on implementing this workaround, you might want to review the documentation and code examples provided in Dify's official resources. This approach will help you ensure that "sys.files" or any other necessary system variables are accessible throughout your workflow as needed.

#### Details **Sources** - [How to pass sys.files uploaded by the user in the starting node to the LLM in the workflow?](https://github.com/langgenius/dify/discussions/3370) - [en/features/workflow/nodes/code.md](https://github.com/langgenius/dify-docs/blob/main/en/features/workflow/nodes/code.md) - [web/app/components/workflow/nodes/_base/components/variable/utils.ts](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/_base/components/variable/utils.ts) - [api/core/workflow/entities/node_entities.py](https://github.com/langgenius/dify/blob/main/api/core/workflow/entities/node_entities.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

iamjoel commented 5 months ago

Now sys.files can be only used in LLM node for vision model.

mmmmmmmgo commented 5 months ago

I want to read or modify files passed to llm during workflow process. Is there planned support?

DavinciEvans commented 5 months ago

Now sys.files can be only used in LLM node for vision model.

I have used the LLM vision model, but it seems no sys.files appear in options.

20240516103158

wentaotang0 commented 2 months ago

企业微信截图_52eb6f25-b7ed-484f-9ad7-0196eca165ce 企业微信截图_508d6298-cd48-4639-9be0-84c7db6913c6 企业微信截图_c23392be-0ca3-49aa-b4d9-e82f3ccb522b

Hello, I also encountered the same problem, I want to reference the sys.files variable in other nodes, but I can't get it, including llm (gpt4o with Visual recognition), is there another way to help me?

My scenario is that I need to feed the text input to the llm output text as the input to the knowledge base