You Will Learn
- File upload usage
- Basic usage of Chatflow
- Prompt writing skill
- Iteration node usage
- Doc extractor and list operator usage
Prerequisites
Create a Chatflow in Dify. Make sure you have added a model provider and have sufficient quota.Adding Nodes
In this experiment, at least four types of nodes are required: start node, document extractor node, LLM node, and answer node.Start Node
In the start node, you need to add a file variable. File upload is supported in v0.10.0 Dify, allowing you to add files as variable. In the start node, you need to add a file variable and check the document in the supported file types. Some readers might notice thesys.files in the system variables, which are files or file lists uploaded by users in the dialog box.
The difference between creating your own file variables is that this feature requires enabling file upload in the functions and setting the upload file types, and each time a new file is uploaded in the dialog, this variable will be overwritten.
Please choose the appropriate file upload method according to your business scenario.
Doc Extractor
LLM cannot read files directly. This is a common misconception among many users when they first use file upload, as they might think simply using the file as a variable in an LLM node would work. However, in reality, the LLM reads nothing from file variables. Thus, Dify introduced the doc extractor node, which can extract text from the file variable and output it as a text variable. The doc extractor node takes the file variable from the start node as input and converts document files into text output.LLM
In this experiment, two LLM nodes need to be designed: structure extraction and question generation.Structure Extraction
The structure extraction node can extract the structure of the original text, summarizing key content. The prompts are as follow:Question Generation
The question generation node can summarize the issues of the article from the content summarized by the structure extraction node, assisting the reader in thinking through the questions during the reading process. The prompts are as follow:Question 1: Handling Multiple Uploaded Files
To handle multiple uploaded files, an iterative node is needed. The iterative node is similar to the while loop in many programming languages, except that Dify has no conditional restrictions, and the input variable can only be of typearray (list). The reason is that Dify will execute all the content in the list until it is done.
Therefore, you need to adjust the file variable in the start node to an array type, i.e., a file list.