Skip to main content
⚠️ 本文档由 AI 自动翻译。如有任何不准确之处,请参考英文原版
使用命令行界面(CLI)设置和打包你的 Dify 插件。CLI 提供了一种简化的方式来管理你的插件开发工作流,从初始化到打包。 本指南将指导你如何使用 CLI 进行 Dify 插件开发。

前提条件

在开始之前,请确保已安装以下内容:
  • Python 版本 ≥ 3.12
  • Dify CLI
  • Homebrew(适用于 Mac 用户)

创建 Dify 插件项目

  • Mac
  • Linux
brew tap langgenius/dify
brew install dify
现在你已成功安装 Dify CLI。你可以通过运行以下命令来验证安装:
dify version
你可以使用以下命令创建一个新的 Dify 插件项目:
dify plugin init
根据提示填写必填字段:
Edit profile of the plugin
Plugin name (press Enter to next step): hello-world
Author (press Enter to next step): langgenius
Description (press Enter to next step): hello world example
Repository URL (Optional) (press Enter to next step): Repository URL (Optional)
  Enable multilingual README: [✔] English is required by default

Languages to generate:
    English: [✔] (required)
 简体中文 (Simplified Chinese): [✔]
    日本語 (Japanese): [✘]
    Português (Portuguese - Brazil): [✘]

Controls:
  ↑/↓ Navigate Space/Tab Toggle selection Enter Next step
选择 python 并按 Enter 继续使用 Python 插件模板。
Select the type of plugin you want to create, and press `Enter` to continue
Before starting, here's some basic knowledge about Plugin types in Dify:

- Tool: Tool Providers like Google Search, Stable Diffusion, etc. Used to perform specific tasks.
- Model: Model Providers like OpenAI, Anthropic, etc. Use their models to enhance AI capabilities.
- Endpoint: Similar to Service API in Dify and Ingress in Kubernetes. Extend HTTP services as endpoints with custom logi
- Agent Strategy: Implement your own agent strategies like Function Calling, ReAct, ToT, CoT, etc.

Based on the ability you want to extend, Plugins are divided into four types: Tool, Model, Extension, and Agent Strategy

- Tool: A tool provider that can also implement endpoints. For example, building a Discord Bot requires both Sending and
- Model: Strictly for model providers, no other extensions allowed.
- Extension: For simple HTTP services that extend functionality.
- Agent Strategy: Implement custom agent logic with a focused approach.

We've provided templates to help you get started. Choose one of the options below:
-> tool
  agent-strategy
  llm
  text-embedding
  rerank
  tts
  speech2text
  moderation
  extension
输入默认的 dify 版本,留空则使用最新版本:
Edit minimal Dify version requirement, leave it blank by default
Minimal Dify version (press Enter to next step): 
现在你已准备就绪!CLI 将创建一个以你提供的插件名称命名的新目录,并为你的插件设置基本结构。
cd hello-world

运行插件

确保你在 hello-world 目录中
cp .env.example .env
编辑 .env 文件以设置插件的环境变量,例如 API 密钥或其他配置。你可以在 Dify 仪表板中找到这些变量。登录到你的 Dify 环境,点击右上角的”插件”图标,然后点击调试图标(或类似虫子的图标)。在弹出窗口中,复制”API Key”和”Host Address”。(请参考你本地对应的截图,其中显示了获取密钥和主机地址的界面)
INSTALL_METHOD=remote
REMOTE_INSTALL_HOST=debug-plugin.dify.dev
REMOTE_INSTALL_PORT=5003
REMOTE_INSTALL_KEY=********-****-****-****-************
现在你可以使用以下命令在本地运行你的插件:
pip install -r requirements.txt
python -m main

编辑此页面 | 报告问题