DeepSeek + Dify Build AI Applications
Build AI applications with low-code, without writing a single line of code. Visual orchestration interface, drag-and-drop workflow design, build knowledge base Q&A, Agent intelligent agents, and enterprise-level AI applications from scratch.
Start LearningData Source: github.com/langgenius/dify Official Repository
Why Choose Dify to Build AI Applications?
Dify is an open-source LLM application development platform that quickly turns DeepSeek models into AI applications. Visual orchestration, drag-and-drop workflows, support for knowledge bases, agents, and chatbots, perfectly suited for DeepSeek models.
| Official Repository | github.com/langgenius/dify |
| Open Source License | Apache 2.0 (Commercial Use Allowed) |
| Deployment | Docker Compose / Official Cloud Service |
| Core Features | Visual Prompt Orchestration, RAG Knowledge Base, Agent Workflows, API Publishing |
| DeepSeek Support | Native integration via OpenAI-API-compatible, supports all V3 and R1 series |
Core Advantages of Dify
- Visual prompt orchestration, drag-and-drop workflow design, no coding required
- Built-in RAG engine, supports PDF / Word / TXT / Markdown / Web pages and more
- Agent: tool calling, code execution, conditional branching
- Conversation logs and analytics to continuously optimize application performance
- One-click API publishing, supports iframe embedding and shareable links
- Seamless integration with DeepSeek via OpenAI-API-compatible
Dify Introduction and Installation
Dify is an open-source LLM application development platform that helps you quickly build large language models (such as DeepSeek) into usable AI applications. With one-click deployment via Docker Compose, installation can be completed in 5 minutes.
What is Dify?
Dify, developed by the LangGenius team, is a full-lifecycle development platform for LLM applications. It provides a one-stop solution from Prompt orchestration, knowledge base management, Agent workflows to application deployment. You can think of Dify as the "WordPress for AI applications" - through a visual interface, you can quickly build various AI applications without writing code.
Environment Requirements
- Docker and Docker Compose (required)
- At least 4GB of available memory (8GB or more recommended)
- At least 20GB of available disk space
- Supports Windows / macOS / Linux
One-Click Deployment with Docker Compose
The following commands will clone the Dify repository and start all services via Docker Compose:
# Clone the Dify repository git clone https://github.com/langgenius/dify.git # Enter the Docker directory cd dify/docker # Copy the environment variable configuration file cp .env.example .env # Start all services (PostgreSQL, Redis, Weaviate, Nginx, Dify API, Dify Web) docker compose up -d # View service status docker compose ps
After deployment, open your browser and visit http://localhost:3000 to enter the Dify management interface. On first visit, you will need to set up the administrator email and password.
Tip
If you don't want to deploy locally, Dify also offers an official cloud service (cloud.dify.ai). You can register and use it without the deployment steps. However, self-deployment gives you full control over your data, which is suitable for scenarios with privacy requirements.
Connect DeepSeek Model
Dify supports connecting DeepSeek models via OpenAI-API-compatible method. Whether it's the DeepSeek official API or DeepSeek deployed locally with Ollama, you can configure and use it in Dify.
Configuration Steps
- After logging into the Dify management interface, click the avatar in the top right corner and select "Settings"
- In the left menu, click "Model Providers"
- In the model provider list, find "OpenAI-API-compatible"
- Click the "Add to Providers" button
- Fill in the following configuration information
Method 1: Connect DeepSeek Official API
If you use the DeepSeek official API, configure as follows:
| Provider Type | OpenAI-API-compatible |
| Provider Name | DeepSeek (Custom) |
| API Base URL | https://api.deepseek.com/v1 |
| API Key | sk-your-deepseek-api-key |
API Key acquisition address: platform.deepseek.com/api_keys. You can create one after registration; new users have free credits.
Method 2: Connect DeepSeek Deployed Locally with Ollama
If you run DeepSeek models locally using Ollama, configure as follows:
| API Base URL | http://localhost:11434/v1 |
| API Key | Any value (Ollama local does not require verification) |
If Dify and Ollama run on the same machine, use localhost. If Ollama is on another machine, replace with the corresponding IP address. Ensure Ollama has set the OLLAMA_HOST=0.0.0.0:11434 environment variable.
Add Model
After configuration, on the "Model Providers" page, click on the DeepSeek provider you just added, then click the "Add Model" button:
deepseek-chat (V3) or deepseek-reasoner (R1)deepseek-r1:8bAfter saving, the DeepSeek model will appear in the available model list and can be selected when creating applications.
Create Your First Chat Application
After integrating the DeepSeek model, let's create your first AI chat application. Dify offers three application types: Chat Assistant, Text Generation, and Agent. We'll start with the simplest: Chat Assistant.
Step 1: Create an Application
- On the Dify homepage, click the "Create Application" button
- Select the "Chat Assistant" application type
- Enter an application name (e.g., "DeepSeek Smart Assistant")
- Choose an application icon (optional)
- Click "Create"
Step 2: Configure the Model
After entering the application editing page, in the "Model Settings" area on the right:
- In the "Model" dropdown, select the DeepSeek model you just added (deepseek-chat or deepseek-reasoner)
- Set model parameters:
- Temperature: 0.7 (conversation) / 0.1 (code) / 0.9 (creative writing)
- Max Tokens: Set according to needs; 2048 is usually sufficient
- Context Window: It is recommended to keep the default value
Step 3: Set the System Prompt
The system prompt defines the AI's role and behavior. In the "Orchestrate" page, in the "Prompt" area, enter the following:
You are a professional AI assistant powered by the DeepSeek model. Your response style: - Be concise and to the point, without unnecessary verbosity - If the question involves code, provide complete runnable examples - If the question involves math or logic, show the reasoning process - If the user's description is unclear, proactively ask for details - Respond in Chinese; technical terms may include the English original Your limitations: - If you don't know, say you don't know; do not fabricate information - For professional advice involving medical, legal, etc., remind users to consult professionals
Step 4: Test the Chat
In the "Preview" area on the right side of the page, you can directly test the chat. Enter a question and observe whether DeepSeek's response meets expectations. If the effect is not ideal, you can adjust the Temperature parameter or optimize the system prompt.
Debugging Tips
- If responses are too brief, try lowering Temperature and increasing max_tokens
- If responses deviate from the topic, optimize the system prompt to describe the role more clearly
- If using the R1 model, note that it outputs a chain of thought (thinking), which is a normal reasoning process
- Click "Logs & Annotations" to view historical conversations and analyze performance
For more tips on designing system prompts, please refer to the prompt engineering section in DeepSeek Usage Tutorial.
Knowledge Base Setup
The knowledge base is the core of RAG (Retrieval-Augmented Generation). Upload your documents to the Dify knowledge base, and DeepSeek can answer questions based on the document content, greatly improving the accuracy and professionalism of responses.
Upload Documents
In the Dify top navigation bar, click "Knowledge Base" to enter the knowledge base management page:
- Click the "Create Knowledge Base" button
- Fill in the knowledge base name (e.g., "Company Product Manual")
- Click "Upload Documents" and select the files to upload
Supported Document Formats
PDF / Word / PPT
Supports .pdf, .docx, .pptx formats, automatically extracts text content.
TXT / Markdown / CSV
Supports .txt, .md, .csv formats, suitable for structured data.
Web Scraping
Enter a URL, Dify automatically scrapes the web content and imports it into the knowledge base.
Code Files
Supports .py, .js, .java and other code files, suitable for technical documentation.
Chunk Settings
After uploading documents, Dify automatically splits the document into multiple "chunks", each chunk is independently vectorized and stored for retrieval. Chunk settings directly affect retrieval performance:
| Chunk Size | Recommended 500-1000 characters. Too small may lose information, too large may reduce retrieval precision. |
| Overlap | Recommended 50-100 characters. Overlap between chunks prevents key information from being cut off. |
Retrieval Settings
In the "Retrieval Settings" of the knowledge base, you can configure the following parameters:
| Retrieval Method | Vector Retrieval (semantic matching) / Full-Text Retrieval (keyword matching) / Hybrid Retrieval (recommended) |
| Top K | Returns the top K relevant document chunks, recommended 3-5. Larger values provide richer context but may introduce noise. |
| Similarity Threshold | Only returns results with similarity above this threshold, recommended 0.5-0.7. Higher thresholds yield more precise results but may miss relevant content. |
Best Practices
- The higher the document quality, the better the retrieval results. It is recommended to clean up irrelevant content in documents first.
- If the document contains many tables, it is recommended to convert them to Markdown table format before uploading.
- When the knowledge base has a large amount of documents (100,000+ characters), it is recommended to use hybrid retrieval mode.
- After uploading, it is recommended to test a few questions to confirm retrieval performance, then adjust parameters.
For more on RAG architecture, please refer to the Dify integration section in the DeepSeek Deployment Tutorial.
Knowledge Base Q&A Application
Combine the knowledge base with DeepSeek to build a professional document Q&A bot. When a user asks a question, Dify first retrieves relevant document chunks from the knowledge base, then hands them to DeepSeek to generate accurate answers based on these chunks.
Create a Knowledge Base Q&A Application
- On the Dify homepage, click "Create Application" and select "Chat Assistant"
- Fill in the application name (e.g., "Product Documentation Q&A")
- Go to the application orchestration page, and in the "Context" area, click "Add"
- Select the knowledge base you just created
- In the model settings on the right, select the DeepSeek model
Configure System Prompt
A knowledge base Q&A application requires a special system prompt to let the AI know how to use the retrieved documents:
You are a professional knowledge base Q&A assistant. Your answers must be based on the provided document content. Answering rules: 1. Prioritize using information from the documents to answer questions 2. If the documents contain relevant information, directly cite and answer 3. If the documents do not contain relevant information, clearly tell the user "This content is not included in the documents" 4. When answering, indicate the source of information (e.g., "According to Chapter 3 of the product manual...") 5. Do not fabricate information not present in the documents Document content: {{#context#}} User question: {{#query#}} Please answer the user's question based on the above document content.
RAG Workflow
The complete workflow of knowledge base Q&A is as follows:
- User Question: The user inputs a question
- Vector Retrieval: Dify converts the question into a vector and retrieves the most relevant document chunks from the knowledge base
- Context Assembly: The retrieved document chunks are used as context and assembled with the user question into a Prompt
- LLM Inference: DeepSeek generates an answer based on the context and question
- Return Result: The answer is returned to the user, with cited sources
Testing and Optimization
Test a few questions in the preview area to check the answer quality:
- If the answers are not accurate enough, check the document chunking and retrieval settings of the knowledge base
- If the answers are irrelevant to the documents, the variable references in the system prompt may be incorrect
- If relevant content cannot be retrieved, try lowering the similarity threshold or increasing the Top K value
- Check the "Logs & Annotations" page to see the specific document chunks retrieved each time
Agent Workflow
Agent is the most powerful feature of Dify. Through visual workflow orchestration, you can build AI agents that can make autonomous decisions, call tools, and execute code. DeepSeek acts as the reasoning engine, driving the entire decision logic of the Agent.
Create an Agent Application
- On the Dify homepage, click "Create Application"
- Select the "Agent" application type
- Fill in the application name (e.g., "Data Analysis Assistant")
- Go to the workflow orchestration page
Workflow Node Introduction
| Node Type | Function Description | Use Case |
|---|---|---|
| Start Node | The entry point of the workflow, defines input variables | Each workflow must have exactly one |
| LLM Node | Calls the DeepSeek model for reasoning and generation | Text generation, analysis, summarization, translation |
| Tool Node | Calls external APIs or built-in tools | Search, calculation, sending emails, database queries |
| Code Node | Executes Python or JavaScript code | Data processing, format conversion, custom logic |
| Conditional Branch | Branches based on conditions | Classification, routing, multi-scenario handling |
| Knowledge Retrieval | Retrieves relevant documents from the knowledge base | Knowledge base Q&A, document analysis |
| End Node | The exit of the workflow, defines output variables | Each workflow must have at least one output |
Hands-on: Build a Data Analysis Agent
Below is a complete data analysis Agent workflow example:
Workflow Structure:
- Start Node: Receives the user's data analysis request
- LLM Node (Intent Analysis): DeepSeek analyzes the user's intent and determines the analysis type (descriptive analysis / trend analysis / comparative analysis)
- Conditional Branch: Routes to different processing flows based on the analysis type
- Code Node (Data Processing): Executes Python code for data cleaning, aggregation, and calculation
- LLM Node (Generate Report): DeepSeek generates an analysis report based on the processing results
- End Node: Outputs the final analysis report
LLM Node Configuration Example
In the LLM node, select the DeepSeek model and configure the following prompt:
You are a data analysis expert. Please analyze the user's data analysis needs and determine which of the following types it belongs to: 1. Descriptive analysis: The user wants to understand the basic situation of the data (e.g., "What is the sales amount?") 2. Trend analysis: The user wants to understand the trend of the data (e.g., "Changes in the last three months") 3. Comparative analysis: The user wants to compare different dimensions (e.g., "Comparison between Product A and Product B") User requirement: {{#query#}} Please output only the analysis type number (1, 2, or 3), and do not output any other content.
Code Node Example
In the code node, you can write Python code for data processing:
def main(data: str) -> dict: """Process input data and return analysis results""" import json # Parse input data records = json.loads(data) # Calculate basic statistical indicators values = [r["value"] for r in records] total = sum(values) avg = total / len(values) if values else 0 max_val = max(values) if values else 0 min_val = min(values) if values else 0 return { "total": total, "average": round(avg, 2), "max": max_val, "min": min_val, "count": len(values), "summary": f"Total {len(values)} records, sum {total}, average {avg:.2f}" }
Conditional Branch Configuration
The conditional branch node routes based on the output of the LLM node:
- Condition 1: LLM output == "1" -> Enter descriptive analysis flow
- Condition 2: LLM output == "2" -> Enter trend analysis flow
- Condition 3: LLM output == "3" -> Enter comparative analysis flow
- Default branch: Other cases -> Enter general analysis flow
Agent Debugging Tips
- Use the "Run" function to debug the workflow step by step, viewing the input and output of each node
- Setting Temperature=0.1 in the LLM node can make classification more stable
- Logs printed in the code node can be viewed in the run logs for easy debugging
- For complex workflows, it is recommended to draw a flowchart first, then implement it in Dify
Publish and Embed
After the application development is complete, Dify provides multiple publishing methods: API publishing (for program calls), iframe embedding (for embedding in web pages), and share links (for direct sharing). No additional development is required; it can go live with one click.
Method 1: API Publishing
Publish the application as a REST API, which can be called from any backend program:
- In the application editing page, click the "Publish" button in the top right corner
- Select "Access API"
- Obtain the API key and interface documentation
# Call the Dify application API curl -X POST https://your-dify-host/v1/chat-messages \ -H "Authorization: Bearer app-xxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "inputs": {}, "query": "Hello, please help me analyze the recent sales data", "response_mode": "streaming", "user": "user-001" }'
Method 2: iframe Embedding
Embed the application into your website so users can use it directly on the web page:
- In the application editing page, click "Publish" in the top right corner
- Select "Embed in Website"
- Copy the generated iframe code
<!-- Paste the following code into your web page --> <iframe src="https://your-dify-host/chatbot/xxxxxxxxxxxxx" style="width: 100%; height: 600px; border: none; border-radius: 12px;" allow="microphone"> </iframe>
Method 3: Share Link
Generate a public share link that anyone can use to access your application:
- In the application editing page, click "Publish" in the top right corner
- Select "Run"
- Copy the generated share link
Access Control Settings
| API Key | Used as authentication credential when calling the API; can be managed on the "API Access" page |
| IP Whitelist | Restrict API calls to specific IP addresses only |
| Rate Limit | Set the maximum number of requests per minute/hour to prevent abuse |
| Conversation Logs | View all user conversations in "Logs & Annotations" to analyze usage |
Real-World Cases
Below are three real-world DeepSeek + Dify application cases, from simple to complex, covering the most common application scenarios. Each case includes complete configuration ideas and parameter references.
Case 1: Intelligent Customer Service Bot
Scenario Description: Build an intelligent customer service for a corporate website to automatically answer user inquiries about product usage, after-sales policies, and frequently asked questions.
Configuration Points:
- Knowledge Base: Upload product manuals, FAQ documents, and after-sales policy files
- Model Selection: DeepSeek V3 (deepseek-chat), Temperature=0.3
- System Prompt: Set as "professional customer service", requiring politeness, patience, and accuracy
- Deployment: Embed via iframe into the official website's customer service page
- Performance Optimization: Regularly review logs and supplement knowledge base documents for high-frequency questions
Case 2: Document Q&A Assistant
Scenario Description: Build an internal document Q&A system for the team, allowing colleagues to directly ask about company policies, project documents, technical specifications, etc.
Configuration Points:
- Knowledge Base: Upload all internal documents, chunk size 800, overlap 100
- Retrieval Settings: Hybrid retrieval, Top K=5, similarity threshold 0.6
- Model Selection: DeepSeek V3 (deepseek-chat), Temperature=0.1
- System Prompt: Emphasize "answer based on documents, do not fabricate information"
- Variable Settings: Use {{#context#}} and {{#query#}} variables
Case 3: Data Analysis Assistant
Scenario Description: Build a data analysis Agent where users can upload data files, and the Agent automatically completes data cleaning, analysis, and report generation.
Workflow Configuration:
- Start Node -> Receive user input and data files
- LLM Node -> Analyze user intent, determine analysis type
- Conditional Branch -> Select different processing flows based on analysis type
- Code Node -> Execute Python data processing (pandas, numpy)
- LLM Node -> Generate analysis report based on processed results
- End Node -> Output formatted report
Key Parameters:
- Model Selection: DeepSeek R1 (deepseek-reasoner) for complex reasoning, V3 for report generation
- Code Node Timeout: Set to 60 seconds to avoid timeout on large data processing
- Tool Configuration: Add web search tool to support querying external data
More Application Scenarios
AI Tutor
Upload textbooks and exercise books, DeepSeek answers students' questions based on the knowledge base and explains problem-solving approaches.
Product Recommendation Assistant
Combined with the product database, DeepSeek recommends suitable products based on user needs, improving conversion rates.
Health Consultation Assistant
Upload medical knowledge base to provide popular science consultation on common illnesses (note: not a substitute for professional doctor diagnosis).
Regulation Query Assistant
Upload legal and regulatory documents to help users quickly query relevant provisions and explanations.
DeepSeek + Dify FAQ
Related Tutorials
Dive deeper into DeepSeek model usage, deployment, and development tips.
DeepSeek Ecosystem Tools
Complete guides for Ollama, Open WebUI, Dify, Continue.dev, and more.
DeepSeek Deployment Tutorials
Deployment solutions for all scenarios: Ollama, Docker, vLLM, K8s.
DeepSeek Usage Tutorials
Four ways to use, from beginner to expert.
DeepSeek Model Download
Download guides for Ollama, Hugging Face, GitHub.
DeepSeek Model Complete Guide
Technical architecture, Benchmark performance comparison, model selection.
DeepSeek Open Source Models
Complete catalog of 6 series, 20+ models.