AI Personal Learning
and practical guidance
CyberKnife Drawing Mirror

Dify plugin with database query support

General Introduction

The dify-plugin-tools-dbquery is a customized tool designed for the Dify An open source plugin designed for the 1.0 platform, released by developer junjiem on GitHub. It provides database query functionality to help users in building applications based on the Large Language Model (LLM) to extract data from the database and generate dynamic content in conjunction with the LLM. The plugin contains two main tools: Database Query Utils (Database Query Utils) and Database Query Utils (Pre-authorization) (Pre-authorization Database Query Utils), which are suitable for scenarios such as smart quizzes and data analysis assistants. The plugin supports installation via GitHub and provides an offline packaging option, which is convenient for developers to deploy in a network-less environment.

Dify plugin with database query support-1


 

Function List

  • Database query tool: Retrieve data from the database via SQL query as input to the LLM.
  • Pre-Authorized Query Support: Provides query functionality for pre-configured authorizations to simplify the database access process.
  • Integrating the Dify Platform: Seamlessly embed Dify's workflows and intelligences to enhance the application's data processing capabilities.
  • Open source and offline package support: Source code and offline installation packages are provided to suit a wide range of deployment needs.
  • Dynamic Data Generation: Enter query results into LLM to generate context-sensitive answers or analysis.

 

Using Help

Installation process

The installation of dify-plugin-tools-dbquery needs to be done via GitHub repositories or offline packages, here are the detailed steps:

Method 1: Installation via GitHub

  1. Accessing GitHub Repositories
    Open your browser and type https://github.com/junjiem/dify-plugin-tools-dbquery, go to the project page.
  2. Go to Dify Plugin Management
    Login to Dify platform, click "Plugins" in the upper right corner to enter the plugin management page, select "Install via GitHub".
  3. Enter warehouse information
    Enter the repository address on the installation page:https://github.com/junjiem/dify-plugin-tools-dbqueryThe version number is selected along with the .difypkg file (if you don't have this file you need to package it yourself, see below).
  4. Solving signature verification problems
    If you encounter the error "plugin verification has been enabled, and the plugin you want to install has a bad signature", you need to modify Dify's .env Documentation:

    • locate .env file (usually in the Dify deployment directory).
    • Add or modify:FORCE_VERIFYING_SIGNATURE=falseThe
    • Restart the Dify service:
      docker-compose restart
      
    • Try the installation again.
  5. Completion of the installation
    Click "Install" and wait for Dify to download and deploy the plugin.

Method 2: Type the offline package and install it

If you need to use it without network environment, you can pack the offline package according to the official instructions:

  1. Preparing the environment
    • Make sure Docker, Python and pip are installed.
    • downloading Dify Plugin CLIChoose the version that is appropriate for your system (e.g. dify-plugin-linux-amd64).
  2. clone warehouse
git clone https://github.com/junjiem/dify-plugin-tools-dbquery.git
cd dify-plugin-tools-dbquery/db_query
  1. Download Dependencies
    Execute the following command to save the dependency locally:
pip download -r requirements.txt -d . /wheels --index-url https://mirrors.aliyun.com/pypi/simple
sed -i '1i\--no-index --find-links=. /wheels/' requirements.txt
  1. Packaging Offline Package
    Return to the parent catalog and pack:
cd ...
dify-plugin-linux-amd64 plugin package . /db_query
mv db_query.difypkg db_query-linux-amd64.difypkg

generated db_query-linux-amd64.difypkg That is, it is an offline package.
5. Adjusting Dify Configuration
If the plugin size exceeds 50MB (the default limit), you need to modify the .env::

  • PLUGIN_MAX_PACKAGE_SIZE=524288000(500MB)
  • NGINX_CLIENT_MAX_BODY_SIZE=500M
  • Restart the service:
    docker-compose restart
    
  1. Upload Installation
    On the Dify plugin management page, select "Upload Offline Packages", select the db_query-linux-amd64.difypkg file to complete the installation.

Operation of the main functions

After the installation is complete, you can use the plug-in by following the steps below:

1. Configuring database queries

  • Go to Dify Studio
    In the Dify platform workspace, open Studio and select an application (such as Chatflow or Workflow).
  • Add Query Tool
    In the Workflow Editor, click "Add Tool" and select the Database Query Utils maybe Database Query Utils (Pre-authorization)The
  • Setting Query Parameters
  • For the normal query tool, enter a SQL statement such as:
SELECT name, age FROM users WHERE age > 18
  • For pre-authorized tools, enter a pre-configured query ID or simply use the default query.
  • Configure the database connection (host, port, username, password, etc.), for example:
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=yourpassword
  • Click "Test" to confirm that the returned data is correct.

2. Integrated LLM output

  • Connecting Workflows
    Connect the output of the query tool to the LLM node. The query results will be used as context input, for example:
  • Enter the question, "Which users are over the age of 18?"
  • Query Results:[{"name": "ZhangSan", "age": 25}, {"name": "LiSi", "age": 30}]
  • LLM OUTPUT: "Zhang San (25 years old) and Li Si (30 years old) are over 18 years old."
  • Customized Cues
    Set the prompt word in the LLM node:
Answer the question based on the following data: {{query_result}}

3. Example applications

  • take: Build a "performance ranking assistant".
  • move::
  1. Create a Chatflow application.
  2. increase Database Query Utils, check the war table:
    SELECT player, score FROM leaderboard ORDER BY score DESC LIMIT 5
    
  3. Connect LLM, cue word:
    List the names and scores of the top five players: {{query_result}}
    
  4. User question, "Who are the top five?"
    OUTPUT: "The top five players are: Zhang San (100 points), Li Si (90 points), etc."

caveat

  • safety: Pre-authorization tools need to ensure that the scope of authorization is clear to avoid data leakage.
  • performance optimization: When querying big data, add LIMIT or indexing to improve efficiency.
  • documentation support: If in doubt, refer to the GitHub example files (e.g. .yml) or submit an Issue.

With the above steps, users can quickly get started with dify-plugin-tools-dbquery to realize the efficient combination of database query and LLM.

CDN1
May not be reproduced without permission:Chief AI Sharing Circle " Dify plugin with database query support

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish