やりたいこと
Dify なるものが最近ホットだということで、少し触ってみました。
どう使うのか、どんなことができるのかなど参考になればと記事にしてみます。
Dify とは
GitHub のリポジトリによると以下とのこと。
DifyはオープンソースのLLMアプリケーション開発プラットフォームです。直感的なインターフェースには、AIワークフロー、RAGパイプライン、エージェント機能、モデル管理、観測機能などが組み合わさっており、プロトタイプから本番までの移行を迅速に行うことができます。以下は、主要機能のリストです:
- ワークフロー
- 包括的なモデルサポート
- プロンプトIDE
- RAGパイプライン
- エージェント機能
- LLMOps
- Backend-as-a-Service
Apache License 2.0 に基づいているため、商業利用可能。 (ただし、追加の条件ありなので要確認)。
また、有償版もあり SaaS として利用することも可能。
とりあえず動かしてみる
説明を読んでもよく分からないので、とりあえず動かしてみる。
リポジトリをクローンして https://github.com/langgenius/dify?tab=readme-ov-file#quick-start の内容に従ってみる (Docker
と Docker-compose
がインストールされている必要あり)。いくつかコンテナが起動される。
cd docker
docker compose up -d # 環境によっては docker-compose かも
http://localhost/install にアクセスするとログイン画面が表示される。初回は管理者アカウントの設定を求められるので、指示に従って設定する。
設定が完了するとログインできるようになるので、管理者アカウントでログインすると以下のような画面が表示される。
今回はテンプレートからワークフローを作成してみる。「テンプレートから作成」をクリックして、「Workflow」のタブをクリックすると、もともと用意されているワークフロー用のテンプレートが表示されるので、「Workflow Planning Assistant」にマウスオーバーして「このテンプレートを使用する」をクリックする。その後「作成」をクリック。以下のようなエディタが表示される。
このエディタ上で各ブロックを構成して、ワークフローを構築する。
右上に「デバッグとプレビュー」のボタンがあるので実行してしまいたくなるが、ワークフロー内で利用する LLM の設定を行っていないので、エラーになる。サイドメニューの「概要」をクリックして、それらの設定を行う。
「モデルプロバイダの設定へ」をクリックすると、利用できるプロバイダの一覧が表示されるので使いたいモデルに合わせて設定していくが、ワークフロー内で利用しているのは gpt-4 と gpt-3.5 系なので、それに合うモデルを設定する必要がある。ここでは、Azure OpenAI Service の gpt-35-turbo、gpt-4-preview を使う (事前にモデルをデプロイしておくこと)。
ワークフローのエディタに戻り、「Workflow Planning」のブロックをクリックする。右側に設定ペインが表示されるので、モデルの箇所でさっき設定したモデルを指定する。このブロックでは、gpt-4 系が必要。システムプロンプトなどもここで修正できる。
同様に、「Generate App Name」をクリックして gpt-3.5 系のモデル設定を行う。
ここまで行うとワークフローの実行が可能になる!
右上に「デバッグとプレビュー」のボタンをクリックすると、チャットエリアが表示されるので下部のテキストボックスにどんなワークフローを作成したいかを入力する。今回は以下のような内容にしてみた。
エンジニアを採用する際、応募者が募集要項を満たしているかを判定するワークフローを作りたい。
応募書類と募集要項から、応募者のスキルやこれまでの経験を考慮して書類選考を通過させるか判定する。
出力は以下のような感じ。いい感じのワークフローを提案してくれている。
App Name: エンジニア採用書類選考ワークフロー
Plan:
To create a workflow to determine whether a job applicant meets the job requirements for an engineering position based on their application and the job description, you might use a combination of nodes to process and evaluate the information provided. Here is a suggested workflow:
Start - Define the initial parameters for launching a workflow
Node Description: Input the job description and the applicant's resume as variables.
Knowledge Retrieval - Retrieve necessary skills and experience from the job description
Node Description: Query the text content of the job description to extract the list of required skills and experiences.
LLM - Process applicant's resume
Node Description: Parse the applicant's resume and extract the list of skills and experiences they have.
Code - Compare the extracted skills and experiences
Node Description: Write custom logic to compare the required skills and experiences from the job description with those extracted from the applicant's resume.
IF/ELSE - Decision on eligibility based on comparison
Node Description: If the applicant's skills and experiences match the requirements, proceed to the 'pass' branch; otherwise, proceed to the 'fail' branch.
Template (Pass Branch) - Generate pass message
Node Description: Craft a message using Jinja template syntax indicating that the applicant has passed the document screening.
Template (Fail Branch) - Generate fail message
Node Description: Craft a message using Jinja template syntax indicating that the applicant has not passed the document screening.
Variable Assigner - Assign the result message to a variable
Node Description: Ensure that the output from both the 'pass' and 'fail' branches is assigned to the same variable for a unified message.
End - Output the result
Node Description: Output the result message from the Variable Assigner, indicating whether the applicant has passed or failed the document screening.
Here is how the nodes would be interconnected:
Start (1) -> Knowledge Retrieval (2) -> LLM (3) -> Code (4) -> IF/ELSE (5) -> Template (Pass Branch, 6) -> Variable Assigner (8) -> End (9)
|-> Template (Fail Branch, 7) -> Variable Assigner (8) -> End (9)
The workflow begins with the Start node and ends with the End node. The output would contain the result of whether the applicant meets the job requirements based on the comparison of their skills and experience with the job description.
いろいろとカスタマイズすれば、自社の採用活動に使えるワークフローを構築できそう!
この出力に基づいて実際にワークフローを作成してくれるワークフローを構築できたら面白そうだなとも思う!
ということで
Dify を使って、ワークフローを構築してみました (テンプレートからですが)。個人的に、LLM とのやりとりがめんどくさいと感じることが多かったので、それらのやりとりを一気にやってくれてカスタマイズも簡単にできるのですごく良いなと思います!ワークフロー以外にも通常のチャットボットやエージェントも構築できるので、使い方次第でいろんなことが実現できそうです。
また、いろんなモデルも使えるので、異なるモデルでそれぞれの回答を比較したり、今後特定の分野に特化したモデルをフローに合わせて使い分けたりというのにも役立ちそうだなと感じます。
まだ触り始めたばかりなので、今後もいろいろやってみておもしろい使い方を記事にしてみようと思います!
以上です。