5.0 KiB
How to Integrate with Dify?
This guide explains how to integrate LangBot with Dify, a powerful LLMOps platform that allows you to create and deploy AI applications.
What is Dify?
Dify is an open-source LLMOps platform that helps you build, deploy, and monitor AI applications. It provides a user-friendly interface for creating AI applications without writing code, as well as APIs for integrating with other systems.
Integration Methods
There are two ways to integrate LangBot with Dify:
- Service API: Use Dify's Service API to access applications created in Dify
- Completion API: Use Dify's Completion API as a model provider in LangBot
This guide focuses on the Service API integration, which is the recommended approach for most use cases.
Prerequisites
Before you begin, you need:
- A Dify account and a deployed application
- The API key for your Dify application
- LangBot version 4.0 or higher
Step 1: Create a Dify Application
- Sign up or log in to Dify
- Create a new application or use an existing one
- Configure your application with the desired model, prompt, and other settings
- Deploy your application
- Go to the API Reference section and copy your API key
Step 2: Configure LangBot
Method 1: Configure via WebUI
- Access the LangBot WebUI at
http://your-server-ip:5300 - Navigate to the "Models" section
- Click "Add Provider"
- Select "Dify" as the provider type
- Enter your Dify API key and application ID
- Save the configuration
Method 2: Configure via Configuration File
Edit the data/config.yaml file and add the Dify provider:
providers:
- id: dify
type: dify
config:
api_key: "your-dify-api-key"
application_id: "your-dify-application-id"
base_url: "https://api.dify.ai/v1" # Optional, defaults to Dify's official API endpoint
Step 3: Test the Integration
Send a test message to your bot:
!model use dify
Hello, how are you?
The bot should respond using your Dify application.
Advanced Configuration
Using Multiple Dify Applications
You can configure multiple Dify applications in LangBot:
providers:
- id: dify-general
type: dify
config:
api_key: "your-dify-api-key-1"
application_id: "your-dify-application-id-1"
- id: dify-specialized
type: dify
config:
api_key: "your-dify-api-key-2"
application_id: "your-dify-application-id-2"
Configuring Input Variables
If your Dify application uses input variables, you can configure them in LangBot:
providers:
- id: dify
type: dify
config:
api_key: "your-dify-api-key"
application_id: "your-dify-application-id"
input_variables:
- name: "user_name"
value: "{sender.name}"
- name: "group_name"
value: "{group.name}"
Using Dify's File Capabilities
If your Dify application supports file inputs, you can configure LangBot to handle them:
providers:
- id: dify
type: dify
config:
api_key: "your-dify-api-key"
application_id: "your-dify-application-id"
file_enabled: true
When file support is enabled, users can send files to the bot, and they will be forwarded to Dify:
!model use dify
[Attach a file]
Can you analyze this document?
Troubleshooting
Connection Issues
If you're having trouble connecting to Dify, check:
- Your API key is correct
- Your application ID is correct
- Your Dify application is deployed and active
- Your server can access the Dify API endpoint
Response Format Issues
If the responses from Dify don't look right:
- Check your Dify application's prompt configuration
- Make sure your application is using the correct model
- Verify that your application is configured for chat completion (not text completion)
Rate Limiting
If you're hitting rate limits:
- Check your Dify plan's rate limits
- Consider implementing rate limiting in LangBot
- Upgrade your Dify plan if necessary
Example Use Cases
Customer Support Bot
Create a Dify application for customer support, with knowledge of your products and services, and integrate it with LangBot to provide automated customer support in your messaging channels.
Content Creation Assistant
Create a Dify application for content creation, with templates and guidelines for your brand, and integrate it with LangBot to help your team create content more efficiently.
Data Analysis Bot
Create a Dify application for data analysis, with the ability to interpret and visualize data, and integrate it with LangBot to provide data insights on demand.
Conclusion
Integrating LangBot with Dify allows you to leverage Dify's powerful LLMOps capabilities while using LangBot's messaging platform integrations. This combination provides a flexible and powerful solution for deploying AI applications across multiple messaging platforms.
For more information, check out the Dify documentation and the LangBot documentation.