mirror of
https://github.com/langgenius/dify-docs.git
synced 2026-03-27 13:28:32 +07:00
161 lines
4.2 KiB
Plaintext
161 lines
4.2 KiB
Plaintext
---
|
||
dimensions:
|
||
type:
|
||
primary: conceptual
|
||
detail: architecture
|
||
level: beginner
|
||
standard_title: Cheatsheet
|
||
language: zh
|
||
title: Dify Plugin 开发速查表
|
||
description: 全面的Dify插件开发参考指南,包括环境要求、安装方法、开发流程、插件分类及类型、常用代码片段和常见问题解决方案。适合开发者快速查阅和参考。
|
||
---
|
||
|
||
### 环境要求
|
||
|
||
- Python 版本 ≥ 3.12
|
||
- Dify 插件脚手架工具 (dify-plugin-daemon)
|
||
|
||
> 了解更多:[初始化开发工具](/plugin-dev-zh/0221-initialize-development-tools)
|
||
|
||
### 获取 Dify Plugin 开发包
|
||
|
||
[Dify Plugin CLI](https://github.com/langgenius/dify-plugin-daemon/releases)
|
||
|
||
#### 不同平台安装方法
|
||
|
||
**macOS [Brew](https://github.com/langgenius/homebrew-dify)(全局安装):**
|
||
|
||
```bash
|
||
brew tap langgenius/dify
|
||
brew install dify
|
||
```
|
||
|
||
安装完成后,新建任意终端窗口,输出 `dify version` 命令,若输出版本号信息,则说明安装成功。
|
||
|
||
**macOS ARM (M 系列芯片):**
|
||
|
||
```bash
|
||
# 下载 dify-plugin-darwin-arm64
|
||
chmod +x dify-plugin-darwin-arm64
|
||
./dify-plugin-darwin-arm64 version
|
||
```
|
||
|
||
**macOS Intel:**
|
||
|
||
```bash
|
||
# 下载 dify-plugin-darwin-amd64
|
||
chmod +x dify-plugin-darwin-amd64
|
||
./dify-plugin-darwin-amd64 version
|
||
```
|
||
|
||
**Linux:**
|
||
|
||
```bash
|
||
# 下载 dify-plugin-linux-amd64
|
||
chmod +x dify-plugin-linux-amd64
|
||
./dify-plugin-linux-amd64 version
|
||
```
|
||
|
||
**全局安装 (推荐):**
|
||
|
||
```bash
|
||
# 重命名并移动到系统路径
|
||
# 示例 (macOS ARM)
|
||
mv dify-plugin-darwin-arm64 dify
|
||
sudo mv dify /usr/local/bin/
|
||
dify version
|
||
```
|
||
|
||
### 运行开发包
|
||
|
||
这里以 `dify` 为例。如果你使用的是局部的安装方式,请根据情况替换指令例如 `./dify-plugin-darwin-arm64 plugin init`。
|
||
|
||
|
||
|
||
### 插件开发流程
|
||
|
||
#### 1. 新建插件
|
||
|
||
```bash
|
||
./dify plugin init
|
||
```
|
||
|
||
按提示完成插件基本信息配置
|
||
|
||
> 了解更多:[Dify 插件开发:Hello World 指南](/plugin-dev-zh/0211-getting-started-dify-tool)
|
||
|
||
#### 2. 开发模式运行
|
||
|
||
配置 `.env` 文件,然后在插件目录下运行以下命令:
|
||
|
||
```bash
|
||
python -m main
|
||
```
|
||
|
||
> 了解更多:[远程调试插件](/plugin-dev-zh/0411-remote-debug-a-plugin)
|
||
|
||
#### 4. 打包与部署
|
||
|
||
打包插件:
|
||
|
||
```bash
|
||
cd ..
|
||
dify plugin package ./yourapp
|
||
```
|
||
|
||
> 了解更多:[发布概览](/plugin-dev-zh/0321-release-overview)
|
||
|
||
### 插件分类
|
||
|
||
#### 工具标签
|
||
|
||
分类 `tag` [class ToolLabelEnum(Enum)](https://github.com/langgenius/dify-plugin-sdks/blob/main/python/dify_plugin/entities/tool.py)
|
||
|
||
```python
|
||
class ToolLabelEnum(Enum):
|
||
SEARCH = "search"
|
||
IMAGE = "image"
|
||
VIDEOS = "videos"
|
||
WEATHER = "weather"
|
||
FINANCE = "finance"
|
||
DESIGN = "design"
|
||
TRAVEL = "travel"
|
||
SOCIAL = "social"
|
||
NEWS = "news"
|
||
MEDICAL = "medical"
|
||
PRODUCTIVITY = "productivity"
|
||
EDUCATION = "education"
|
||
BUSINESS = "business"
|
||
ENTERTAINMENT = "entertainment"
|
||
UTILITIES = "utilities"
|
||
OTHER = "other"
|
||
```
|
||
|
||
### 插件类型参考
|
||
|
||
Dify 支持多种类型的插件开发:
|
||
|
||
- **工具插件**:集成第三方 API 和服务
|
||
> 了解更多:[工具插件开发](/plugin-dev-zh/0211-getting-started-dify-tool)
|
||
- **模型插件**:集成 AI 模型
|
||
> 了解更多:[模型插件介绍](/plugin-dev-zh/0131-model-plugin-introduction)、[快速接入一个新模型](/plugin-dev-zh/0211-getting-started-new-model)
|
||
- **Agent 策略插件**:自定义 Agent 思考和决策策略
|
||
> 了解更多:[Agent 策略插件](/plugin-dev-zh/9433-agent-strategy-plugin)
|
||
- **扩展插件**:扩展 Dify 平台功能,例如 Endpoint 和 WebAPP
|
||
> 了解更多:[扩展插件](/plugin-dev-zh/9231-extension-plugin)
|
||
- **数据源插件**:在知识流水线中,作为文档数据的来源并充当整个流水线的起始点
|
||
> 了解更多:[数据源插件](/plugin-dev-zh/0222-datasource-plugin)
|
||
- **触发器插件**:外部事件发生时,自动触发 Workflow 运行
|
||
> 了解更多:[触发器插件](/plugin-dev-zh/0222-trigger-plugin)
|
||
|
||
{/*
|
||
Contributing Section
|
||
DO NOT edit this section!
|
||
It will be automatically generated by the script.
|
||
*/}
|
||
|
||
---
|
||
|
||
[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/plugin-dev-zh/0131-cheatsheet.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)
|
||
|