Files
dify-docs/plugin-dev-ja/0131-cheatsheet.mdx
2025-07-16 16:42:34 +08:00

155 lines
4.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
dimensions:
type:
primary: conceptual
detail: architecture
level: beginner
standard_title: Cheatsheet
language: ja
title: Difyプラグイン開発チートシート
description: 環境要件、インストール方法、開発フロー、プラグインの分類と種類、よく使われるコードスニペット、よくある問題の解決策など、Difyプラグイン開発に関する包括的なリファレンスガイドです。開発者が素早く参照するのに適しています。
---
### 環境要件
- Python バージョン ≥ 3.12
- Dify プラグインスケルトンツール (dify-plugin-daemon)
> 詳細はこちら:[開発ツールの初期化](/plugin-dev-ja/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-ja/0211-getting-started-dify-tool)
#### 2. 開発モードでの実行
`.env` ファイルを設定し、プラグインディレクトリで以下のコマンドを実行します:
```bash
python -m main
```
> 詳細はこちら:[プラグインのリモートデバッグ](/plugin-dev-ja/0411-remote-debug-a-plugin)
#### 4. パッケージ化とデプロイ
プラグインのパッケージ化:
```bash
cd ..
dify plugin package ./yourapp
```
> 詳細はこちら:[リリース概要](/plugin-dev-ja/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-ja/0211-getting-started-dify-tool)
- **モデルプラグイン**: AI モデルを統合
> 詳細はこちら:[モデルプラグイン紹介](/plugin-dev-ja/0131-model-plugin-introduction.ja)、[新しいモデルの迅速な統合](/plugin-dev-ja/0211-getting-started-new-model)
- **Agent 戦略プラグイン**: Agent の思考および意思決定戦略をカスタマイズ
> 詳細はこちら:[Agent 戦略プラグイン](/plugin-dev-ja/9433-agent-strategy-plugin)
- **拡張プラグイン**: Dify プラットフォーム機能を拡張Endpoint および WebAPP
> 詳細はこちら:[拡張プラグイン](/plugin-dev-ja/9231-extension-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-ja/0131-cheatsheet.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)