1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Difyをローカル環境に導入してみる

Posted at

導入環境

  • Ubuntu on Windows(バージョン:2004.2022.1.0)

導入

手順1:適当なディレクトリに移動してclone実行

User@MyComputer:~/development/dify$ git clone https://github.com/langgenius/dify.git
Cloning into 'dify'...
remote: Enumerating objects: 114781, done.
remote: Counting objects: 100% (43201/43201), done.
remote: Compressing objects: 100% (4376/4376), done.
remote: Total 114781 (delta 40135), reused 39275 (delta 38808), pack-reused 71580 (from 1)
Receiving objects: 100% (114781/114781), 63.58 MiB | 1.65 MiB/s, done.
Resolving deltas: 100% (85691/85691), done.

手順2:下記コマンド実行

User@MyComputer:~/development/dify$ cd dify/docker
User@MyComputer:~/development/dify/dify/docker$ cp .env.example .env

追加手順:dockerインストール

docker composeを実行するとあるが、そもそもdockerがUbuntu環境に入っているのか確認すると、(案の定)入ってない。

User@MyComputer:~/development/dify/dify/docker$ docker compose version

Command 'docker' not found, but can be installed with:

sudo apt install docker.io

ので、入れましょう。

User@MyComputer:~/development/dify/dify/docker$ sudo apt-get update
[sudo] password for User:
Hit:1 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal InRelease
Get:2 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-updates InRelease [128 kB]
...
Get:34 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Fetched 19.0 MB in 56s (337 kB/s)
Reading package lists... Done

User@MyComputer:~/development/dify/dify/docker$ sudo apt-get install
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 322 not upgraded.

User@MyComputer:~/development/dify/dify/docker$ sudo mkdir -p /etc/apt/keyrings

User@MyComputer:~/development/dify/dify/docker$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

User@MyComputer:~/development/dify/dify/docker$ echo \
> "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_> $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

User@MyComputer:~/development/dify/dify/docker$ sudo apt-get update
Hit:1 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal InRelease
Hit:2 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-updates InRelease
Hit:3 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-backports InRelease
Get:4 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Hit:5 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-security InRelease
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [51.8 kB]
Fetched 109 kB in 2s (45.4 kB/s)
Reading package lists... Done

User@MyComputer:~/development/dify/dify/docker$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree
Reading state information... Done
...

User@MyComputer:~/development/dify/dify/docker$ docker -v
Docker version 27.3.1, build ce12230

User@MyComputer:~/development/dify/dify/docker$ docker compose version
Docker Compose version v2.29.7

手順3:Dockerコンテナを起動

docker compose up -d

実行すると以下のようなエラーメッセージが表示された。

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker Daemonが起動していない。
下記記事が参考になった。幸い自分はsudo service docker startコマンド実行で何とかなった。

再度docker compose up -dコマンドを実行すると、Permission云々のエラーメッセージが出た。sudoを付けると先に進めた。

しばらく待つと以下のような表示が出る。

...
 ✔ Container docker-db-1              Started                                                                     17.4s
 ✔ Container docker-redis-1           Started                                                                     17.3s
 ✔ Container docker-ssrf_proxy-1      Started                                                                     16.6s[+] Running 11/11
 ✔ Network docker_ssrf_proxy_network  Created                                                                      2.1s
 ✔ Network docker_default             Created                                                                      4.1s
 ✔ Container docker-db-1              Started                                                                     17.4s
 ✔ Container docker-redis-1           Started                                                                     17.3s
 ✔ Container docker-ssrf_proxy-1      Started                                                                     16.6s
 ✔ Container docker-sandbox-1         Started                                                                     16.4s
 ✔ Container docker-web-1             Started                                                                     17.5s
 ✔ Container docker-weaviate-1        Started                                                                     17.4s
 ✔ Container docker-api-1             Started                                                                     19.2s
 ✔ Container docker-worker-1          Started                                                                     19.3s
 ✔ Container docker-nginx-1           Started                                                                     31.3s
User@MyComputer:~/development/dify/dify/docker$

起動状態の確認。

User@MyComputer:~/development/dify/dify/docker$ sudo docker compose ps
[sudo] password for User:
NAME                  IMAGE                              COMMAND                  SERVICE      CREATED         STATUS                   PORTS
docker-api-1          langgenius/dify-api:0.11.2         "/bin/bash /entrypoi…"   api          4 minutes ago   Up 4 minutes             5001/tcp
docker-db-1           postgres:15-alpine                 "docker-entrypoint.s…"   db           4 minutes ago   Up 4 minutes (healthy)   5432/tcp
docker-nginx-1        nginx:latest                       "sh -c 'cp /docker-e…"   nginx        4 minutes ago   Up 4 minutes             0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
docker-redis-1        redis:6-alpine                     "docker-entrypoint.s…"   redis        4 minutes ago   Up 4 minutes (healthy)   6379/tcp
docker-sandbox-1      langgenius/dify-sandbox:0.2.10     "/main"                  sandbox      4 minutes ago   Up 4 minutes (healthy)
docker-ssrf_proxy-1   ubuntu/squid:latest                "sh -c 'cp /docker-e…"   ssrf_proxy   4 minutes ago   Up 4 minutes             3128/tcp
docker-weaviate-1     semitechnologies/weaviate:1.19.0   "/bin/weaviate --hos…"   weaviate     4 minutes ago   Up 4 minutes
docker-web-1          langgenius/dify-web:0.11.2         "/bin/sh ./entrypoin…"   web          4 minutes ago   Up 4 minutes             3000/tcp
docker-worker-1       langgenius/dify-api:0.11.2         "/bin/bash /entrypoi…"   worker       4 minutes ago   Up 4 minutes             5001/tcp

手順4:Difyへのアクセス

http://localhost/install をブラウザのアドレスバーに入力する。
入力すると、↓のような画面が表示される。
image.png

ちなみに、http://localhostをアドレスバーに入力しても、http://localhost/installにリダイレクトされた。

必要事項を入力してセットアップボタンを押すと、サインインの画面になる。ここで入力した情報を使ってサインインすると、以下のような画面が表示される。
image.png

Difyを触ってみる

アプリ新規作成

「最初から作成」でChatbotを選択してみる。アプリ名は適当。
image.png

LLMプロバイダの選択

「設定に移動」を押すといろんなLLMプロバイダ一覧が出る。
image.png

とりあえず今回はOpenAIを選択し、APIキー(利用者各自に割り当てられた機密情報)を入力。
すると、OpenAIのLLMが選択された状態になる。
image.png

gpt3.5-turboとかgpt4-turboとかも選択できる。
なんとなく4o-miniを選んでみる。
image.png

設定して試してみる。
変数と、要件を指定すると、それっぽい文言のメール文章を書いてくれるアプリを作ることができた。
image.png

番外編:LLMプロバイダ追加

ここまでではとりあえずOpenAIを指定していたが、他のLLMプロバイダも使いたい・追加したい場合は、「設定⇒モデルプロバイダー」から任意のプロバイダを選択する。

image.png
今回はGeminiを追加した。(APIキーの発行が必要)

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?