Dify 是一個開源的 LLM 應用開發平臺。其直觀的界面結合了 AI 工作流、RAG 管道、Agent、模型管理、可觀測性功能等,讓您可以快速從原型到生產。以下是其核心功能列表:
?
1. 工作流: 在畫布上構建和測試功能強大的 AI 工作流程,利用以下所有功能以及更多功能。
2. 全面的模型支持: 與數百種專有/開源 LLMs 以及數十種推理提供商和自托管解決方案無縫集成,涵蓋 GPT、Mistral、Llama3 以及任何與 OpenAI API 兼容的模型。
?首先學習dify
dify 官網:https://github.com/langgenius/dify
入門指南:Dify:企業級 Agentic AI 解決方案開發平臺
手冊:產品簡介 - Dify Docs
本想嘗試手工部署dify,但是看到這段一定要裝docker才能部署嗎 · Issue #2826 · langgenius/dify:
是的,您可以不使用Docker從源代碼啟動應用程序。主要的應用服務(服務器和前端服務)的部署并不固定需要Docker,因為我們提供的指南包括了在主機上設置環境和直接運行服務的步驟。然而,中間件服務(如PostgresSQL,Redis,Weaviate)建議使用Docker Compose啟動,但如果Docker不是選項,這些中間件服務也可以直接在主機或其他合適的環境上安裝和運行。
所以最終決定還是用Docker部署吧,這樣就不用再去配置PostgresSQL、Redis等中間件了。
快速啟動:
啟動 Dify 服務器的最簡單方法是運行我們的?docker-compose.yml?文件。在運行安裝命令之前,請確保您的機器上安裝了?Docker?和?Docker Compose:
cd docker cp .env.example .env docker compose up -d
運行后,可以在瀏覽器上訪問?http://localhost/install?進入 Dify 控制臺并開始初始化安裝操作。
Ollama部署DeepSeek具體參考:
使用Ollama 在Ubuntu運行deepseek大模型:以deepseek-r1為例_ubuntu deepseek-CSDN博客
在Windows下安裝Ollama并體驗DeepSeek r1大模型
實踐
Dify 社區版即開源版本。
下載源代碼
首先下載dify的源代碼
git clone https://githubfast.com/langgenius/dify
安裝docker
sudo apt install docker-compose-v2
運行docker
cd dify/docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d
啟動API
進入目錄
cd api
準備環境變量
cp .env.example .env
?生成隨機密鑰并替換 .env 文件中的 SECRET_KEY 值
這句還沒執行:
awk -v key="$(openssl rand -base64 42)" '/^SECRET_KEY=/ {sub(/=.*/, "=" key)} 1' .env > temp_env && mv temp_env .env
分步執行,以免出錯:
openssl rand -base64 42
V8Ye+wDwIWMLLeMghrPv6NZ019GtsltpuycNT3vlRyNc3T3SVvkST62U
?將秘鑰放入.env文件:
SECRET_KEY=V8Ye+wDwIWMLLeMghrPv6NZ019GtsltpuycNT3vlRyNc3T3SVvkST62U
安裝依賴
uv sync
如果慢,就加上鏡像
uv sync -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
?執行數據庫遷移
uv run flask db upgrade
遷移升級完成
INFO [alembic.runtime.migration] Running upgrade 4474872b0ee6 -> 0ab65e1cc7fa, remove sequence_number from workflow_runs
INFO [alembic.runtime.migration] Running upgrade 0ab65e1cc7fa -> 58eb7bdb93fe, add mcp server tool and app server
INFO [alembic.runtime.migration] Running upgrade 58eb7bdb93fe -> 1c9ba48be8e4, add uuidv7 function in SQL
INFO [alembic.runtime.migration] Running upgrade 1c9ba48be8e4 -> 71f5020c6470, tool oauth
INFO [alembic.runtime.migration] Running upgrade 71f5020c6470 -> 1a83934ad6d1, update models
INFO [alembic.runtime.migration] Running upgrade 1a83934ad6d1 -> 375fe79ead14, oauth_refresh_token
INFO [alembic.runtime.migration] Running upgrade 375fe79ead14 -> 8bcc02c9bd07, add_tenant_plugin_autoupgrade_table
啟動API服務
uv run flask run --host 0.0.0.0 --port=5001 --debug
安裝web
安裝pnpm
npm i -g pnpm
進入 web 目錄
cd web
安裝依賴
pnpm install --frozen-lockfile
Done in 4m 23.1s using pnpm v10.13.1?
?修改.env.local文件
# For production release, change this to PRODUCTION
NEXT_PUBLIC_DEPLOY_ENV=DEVELOPMENT
# The deployment edition, SELF_HOSTED or CLOUD
NEXT_PUBLIC_EDITION=SELF_HOSTED
# The base URL of console application, refers to the Console base URL of WEB service if console domain is
# different from api or web app domain.
# example: http://cloud.dify.ai/console/api
NEXT_PUBLIC_API_PREFIX=http://localhost:5001/console/api
# The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
# console or api domain.
# example: http://udify.app/api
NEXT_PUBLIC_PUBLIC_API_PREFIX=http://localhost:5001/api# SENTRY
NEXT_PUBLIC_SENTRY_DSN=
NEXT_PUBLIC_SENTRY_ORG=
NEXT_PUBLIC_SENTRY_PROJECT=
構建web服務
pnpm build
啟動web服務
pnpm start
待續?
先進行到這里,以后再繼續
未知,也許是最后一步吧
?然后用瀏覽器配置:
http://127.0.0.1/install
創建一個用戶,登錄
創建空白應用
?集成ollama模型
調試
啟動docker compose -f docker-compose.middleware.yaml up -d報錯
docker compose -f docker-compose.middleware.yaml up -d unknown shorthand flag: 'f' in -f
后來發現,原來以前這樣安裝的:
sudo apt install docker.io
需要這樣安裝
sudo apt install docker-compose
最后知道需要安裝版本2
?啟動docker compose報錯ERROR: Invalid interpolation format for "db" option in service "services":
docker-compose -f docker-compose.middleware.yaml up
ERROR: Invalid interpolation format for "db" option in service "services": "${POSTGRES_PASSWORD:-difyai123456}"
插值語法沖突?
${VAR:-default}
是標準的shell變量替換語法,但Docker Compose對某些版本(特別是v2.3以下)要求嚴格遵循${VAR}
或$VAR
格式?12
- 檢查當前版本:
docker-compose --version
- 升級到最新版可解決大多數語法兼容性問題?
看下版本
docker-compose -version
docker-compose version 1.25.0, build unknown
升級
sudo apt update
sudo apt upgrade docker-compose
升級docker-compose的時候報錯
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/i/intel-microcode/intel-microcode_3.20250211.0ubuntu0.20.04.1_amd64.deb ?404 ?Not Found [IP: 120.52.95.245 80]
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/l/linux-meta/linux-generic_5.4.0.211.206_amd64.deb ?404 ?Not Found [IP: 120.52.95.245 80]
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/l/linux-meta/linux-image-generic_5.4.0.211.206_amd64.deb ?404 ?Not Found [IP: 120.52.95.245 80]
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/l/linux-meta/linux-headers-generic_5.4.0.211.206_amd64.deb ?404 ?Not Found [IP: 120.52.95.245 80]
E: Failed to fetch http://repo.huaweicloud.com/ubuntu/pool/main/s/sosreport/sosreport_4.7.2-0ubuntu1~20.04.2_amd64.deb ?404 ?Not Found [IP: 120.52.95.245 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
嘗試
sudo apt update --fix-missing
不行
嘗試
該錯誤表明華為云鏡像源中部分軟件包已失效或路徑變更,需按以下步驟處理:
一、立即修復方案
-
?清理緩存并重試?
sudo apt cleansudo apt update --fix-missing
哦了,果然清理緩存之后就好了!
怎么更新之后還是老版本??
?docker-compose -v
docker-compose version 1.25.0, build unknown
原來如此啊,需要安裝版本2
apt search docker-compose
Sorting... Done
Full Text Search... Done
docker-compose/focal,focal,now 1.25.0-1 all [installed]Punctual, lightweight development environments using Dockerdocker-compose-v2/focal-updates 2.27.1+ds1-0ubuntu1~20.04.1 amd64tool for running multi-container applications on Docker
安裝docker-compose-v2:?
sudo apt install docker-compose-v2
刪除老版本
sudo apt remove docker-compose
啟動用這句話
?
sudo docker compose -f docker-compose.middleware.yaml up
docker啟動報錯Error response from daemon: Get "https://registry-1.docker.io/v2/":
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
上網問題,配置加速鏡像即可。參考:Python、Ubuntu、FreeBSD、docker、Huggingface、github、npm等常用加速鏡像_清華大學github鏡像-CSDN博客
pnpm build報錯
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----1: 0xe16044 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]2: 0x11e0dd0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]3: 0x11e10a7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]4: 0x140e985 [node]5: 0x140e9b3 [node]6: 0x1427a8a [node]7: 0x142ac58 [node]8: 0x1c90921 [node]
Aborted (core dumped)ELIFECYCLE? Command failed with exit code 134.