Dify quick start examples (public preview)

Updated at:
Important

Scope of responsibility: Applications deployed from the App Center (unless otherwise specified) are consistent with their open-source community versions. You are responsible for any stability risks and security vulnerabilities associated with open-source software. SAE's service guarantee only covers the stability of the underlying runtime and does not cover the quality, security, or maintenance of the open-source software itself. We recommend thoroughly reviewing and auditing an application for technical and security issues before deploying it to a production environment.

Prerequisites

  1. Deploy Dify on SAE (public preview).

  2. Configure a model provider. Note that services from model providers may incur fees. Refer to the billing information for each model provider for details. This tutorial uses Qwen as an example.

    1. Log in to the Dify management page and click your profile picture in the upper-right corner > Settings > Model Provider. Select Qwen and click Install. Wait for the installation to complete.

    2. Refresh the page. In the To be configured section, click Settings. Enter the API key obtained from the Model Studio console. Click Save.

    3. Verify the model provider configuration:

      1. On the Dify management page, click Create Blank App.

      2. Select App Type: Expand the For Beginners section, select Text Generation App, specify a custom App Name, and click Create.

      3. In the upper-right corner, select an available model from the model provider. In the Query field, enter Who are you? and click Run. If the Result shows a self-introduction from the large language model, the configuration is successful.

Build an AI image generator

This application generates an image based on a prompt from an end user.

  1. Configure the Stability tool:

    1. On the Dify management page, go to the Tools tab, search for and select Stability, and then click Install. Wait for the installation to complete.

    2. Refresh the page. The Stability tool appears in the list of installed tools at the top. Click the Stability tool, click API Key Authorization, and enter the API key obtained from Stability.

  2. Build an Agent:

    1. On the Dify management page, click Create Blank App.

    2. Select App Type: Expand the For Beginners section, select Agent, specify a custom App Name, and click Create.

    3. Select a model: In the upper-right corner, click the model configuration button. For Model, we recommend selecting qwen-plus-latest(Qwen3).

    4. Add a tool: In the Tools section, click Add. Select Stability and click Add All.

    5. Write the system prompt: In the Prompts section, enter the following content. You can customize the image style by replacing descriptions such as anime style.

      ## Task
      Use the stability_text2image tool to draw the specified content based on the user's prompt. The image should be in an anime art style.
      
      ## Constraints
      If the user's request is not related to drawing, reply with: "I'm sorry, I don't understand what you're saying."
    6. Test the application:

      1. In the Debug and Preview section, enter a user prompt for testing, for example:

        Draw a programmer writing code on a computer.
      2. The Result returns the content and image generated by the large language model, confirming a successful Agent build. If the test fails, try modifying the system prompt or selecting a different model in the upper-right corner.

  3. Publish the application:

    1. In the upper-right corner, click Publish > Publish Update. Wait for the publication to complete.

    2. In the upper-right corner, click Publish > Run to open the application interface for end users.

    3. To provide the service, share the application's URL with your end users.

    4. End users can enter prompts in the dialog box to generate images as needed.

Build a document comprehension assistant

This assistant helps end users quickly understand a document's structure.

  1. Build a Chatflow:

    1. On the Dify management page, click Create Blank App.

    2. For Select App Type, choose Chatflow, specify a custom App Name, and click Create. This takes you to the Chatflow orchestration page. If the system has created any default nodes, keep only the Start node and delete the others.

    3. Add a file variable to the Start node:

      1. On the Chatflow orchestration page, click the Start node, and then click + in the Input Fields section.

      2. Set Field Type to Single File and specify a custom Variable Name. Set Supported File Types to Document and Upload File Type to Both. This allows end users to upload a local file or specify a file URL. Click Save.

    4. Add a Document Extractor node:

      1. Click the + icon after the Start node and select Document Extractor. This node extracts text from a file variable and outputs it as a text variable.

      2. In the Document Extractor node Settings, select the file variable from the Start node for the Input Variable. Keep the default Output Variable text (which corresponds to Extracted Text).

    5. Add an LLM node:

      1. Click the + next to the Document Extractor node and select LLM. This node calls a large language model to analyze the document content and generate the document structure.

      2. In the LLM node Settings, for Model, we recommend selecting qwen-plus-latest(Qwen3).

      3. In the SYSTEM field, enter the following system prompt. Be sure to replace the {{Document Extractor result variable}} placeholder with the actual variable. To do this, place your cursor before the placeholder {{Document Extractor result variable}}, type /, and select the output variable from the Document Extractor node in the menu. Finally, delete the placeholder text.

        Read the following article content and perform the task.
        {{Document Extractor result variable}}
        # Task
        
        - **Primary Goal**: Fully analyze the structure of the article.
        - **Objective**: Detail the content of each section of the article.
        - **Requirement**: Analyze in as much detail as possible.
        - **Constraint**: No specific format restrictions, but the analysis must be organized and logical.
        - **Expected Output**: A detailed analysis of the article's structure, including the main content and purpose of each section.
        
        # Reasoning Sequence
        
        - **Reasoning**: Identify and analyze the article's structure by reading it carefully.
        - **Conclusion**: Provide the specific content and purpose of each section.
        
        # Output Format
        
        - **Analysis Format**: Each section should be listed with a title, followed by a detailed description of its content.
        - **Structural Format**: Markdown, to enhance readability.
        - **Specifics**: Describe the content and purpose of each section, including but not limited to the introduction, body, conclusion, and references.
        
        # Example Output
        
        ## Example Article Analysis
        
        ### Introduction
        - **Content**: Introduces the background, purpose, and importance of the research.
        - **Purpose**: Grabs the reader's attention and provides context for the article.
        
        ### Methods
        - **Content**: Describes the specific methods and procedures of the research, including experimental design, data collection, and analysis techniques.
        - **Purpose**: Allows the reader to understand the scientific rigor and reproducibility of the study.
        
        ### Results
        - **Content**: Presents the main findings and data of the research.
        - **Purpose**: Provides an evidentiary basis for the study's conclusions.
        
        ### Discussion
        - **Content**: Explains the significance of the results, compares them with other studies, and suggests potential areas for improvement.
        - **Purpose**: Helps the reader understand the broader implications of the results and potential for future research.
        
        ### Conclusion
        - **Content**: Summarizes the main findings and contributions of the research.
        - **Purpose**: Reinforces the core message of the article and provides a clear conclusion.
        
        ### References
        - **Content**: Lists all the literature cited in the article.
        - **Purpose**: Provides resources for further reading and ensures academic integrity.
        
        # Notes
        
        - **Edge Cases**: If the article structure is atypical (for example, missing certain sections or having extra sections), these special cases should be clearly noted in the analysis.
        - **Important Considerations**: The analysis should focus on the article's logic and coherence, ensuring that the content of each section aligns with the overall objective of the article.
      4. Keep the default Output Variables: text (which corresponds to Generated Content) and usage (which corresponds to Model Usage Information).

    6. Add a Direct Reply node:

      1. Click the + icon after the LLM node and select Direct Reply.

      2. In the Direct Reply node Settings, type / in the Reply field and insert the text output variable from the LLM node from the menu that appears.

  2. Test the application: Click Preview. In the dialog box, upload a document and enter a prompt such as Generate the document structure. If the execution fails or the result is unsatisfactory, try adjusting the model or parameters in the LLM node configuration.

  3. Publish the application:

    1. In the upper-right corner, click Publish > Publish Update. Wait for the publication to complete.

    2. In the upper-right corner, click Publish > Run to open the application interface for end users.

    3. To provide the service, share the application's URL with your end users.

Build a knowledge-based customer service bot

The intelligent customer service bot can query a knowledge base to answer customer questions.

  1. Create a knowledge base:

    1. On the Dify management page, go to the Knowledge tab and click Create Knowledge.

    2. For Select data source, choose Import from text. Upload a local file as your knowledge base content. This tutorial uses the Model Studio Series Phone Introduction.docx file as an example. Click Next.

    3. In the Segmentation Settings section, set the Segment identifier to \n and keep the other settings at their defaults. Click Save and Process. After processing is complete, click Go to Documents.

    4. In the Documents list, click the document's name to open its details page and view the segmentation results. In the left navigation pane, click Retrieval Testing. Enter test text in the Source Text field and click Test to check the retrieval performance. If you are not satisfied with the segmentation or retrieval results, click Settings in the left navigation pane to adjust the configuration.

  2. Build a Chatflow:

    1. On the Dify management page, click Create Blank App.

    2. For Select App Type, choose Chatflow, specify a custom App Name, and click Create. This takes you to the Chatflow orchestration page. If the system has created any default nodes, keep only the Start node and delete the others.

    3. Add a Question Classifier node:

      1. Click the + icon after the Start node and select Question Classifier. This node determines the next step in the workflow based on the user's input.

      2. In the Question Classifier node Settings, for Model, we recommend selecting qwen-plus-latest(Qwen3). For Input Variable, select the user input sys.query from the Start node.

      3. Set Category 1 to: User asks a question unrelated to Model Studio phones. Click the + icon after Category 1 in the flowchart, select Direct Reply, and set the Reply to I'm sorry, I cannot answer your question.

      4. Set Category 2 to User asks questions related to Model Studio phones. Afterward, you also need to add Knowledge Retrieval, LLM, and Direct Reply nodes to the Category 2 flow.

    4. Add a Knowledge Retrieval node:

      1. Click the + icon after Category 2 and select Knowledge Retrieval. For the Query Variable, select the user input sys.query from the Start node.

      2. In the Knowledge section, add the knowledge base you created earlier.

    5. Add an LLM node:

      1. Click the + icon after the Knowledge Retrieval node and select LLM. This node calls a large language model to generate an answer based on the retrieved knowledge base results.

      2. In the LLM node Settings, for Model, we recommend selecting qwen-plus-latest(Qwen3).

      3. For the Context, select the result from the Knowledge Retrieval node.

      4. In SYSTEM, enter the following system prompt, and replace the {{context}} and {{user input}} placeholders with actual variables. To do this, place the cursor before the {{context}} placeholder string, type /, and follow the on-screen instructions to insert the Context variable. Then, place the cursor before the {{user input}} placeholder string, type /, and follow the on-screen instructions to insert the user input sys.query from the Start node. Finally, delete the placeholder strings.

        Answer {{user_input}} based on {{context}}.
      5. Keep the default Output Variables: text (which corresponds to Generated Content) and usage (which corresponds to Model Usage Information).

    6. Add a Direct Reply node:

      1. Click the + icon after the LLM node and select Direct Reply.

      2. In the Direct Reply node Settings, type / in the Reply field and insert the text output variable from the LLM node from the menu that appears.

  3. Test the application: Click Preview. In the dialog box, enter a question such as What is the screen resolution of the Model Studio X1?. If the execution fails or the result is unsatisfactory, try adjusting the model or parameters in the relevant nodes.

  4. Publish the application:

    1. In the upper-right corner, click Publish > Publish Update. Wait for the publication to complete.

    2. In the upper-right corner, click Publish > Run to open the application interface for end users.

    3. To provide the service, share the application's URL with your end users.