匯入 Dify 應用程式——Dify 安裝中的聊天助理
一個以 Dify 的 DSL 匯出的 Dify 聊天應用程式,由 aggrega import 匯入為 Aggregate、Release 與 Manifest,建置出標準程式庫的 Dify 安裝,並依原樣為 Kubernetes 承載它。
匯入 Dify 應用程式 逐步說明:命令、它寫出的檔案、建置,以及所建置內容的一次執行。這個資料夾存放該逐步說明的每個階段:
| 資料夾 | 它保存的內容 |
|---|---|
source/ | 應用程式 support-assistant.yml;讓資料夾成為工作區的 .aggrega-config.yaml;以及 import-answers.yaml,即應用程式無法承載之內容的答案:存放安裝的應用程式機密與擁有者密碼的 Kubernetes Secrets 名稱,以及擁有者帳號的電子郵件 |
draft/ | aggrega import support-assistant.yml --target helm 寫出的檔案(原樣未改),以及它印出的內容:標準輸出上的 stdout.txt,標準錯誤上的 import.txt |
source/support-assistant.yml 是為這個範例撰寫的,形式與 Dify 匯出應用程式時的 DSL 版本 0.7.0 相同。
在文件存放庫的簽出內容中,check.sh 會再次執行匯入,將它寫出與印出的內容與 draft/ 比較,將逐步說明所引用的區塊與這些檔案比較,並驗證與建置匯入所寫出的內容。它需要與這個存放庫並列簽出的標準程式庫目錄(取得方式),或在 AGGREGA_CATALOG_DIRS 中指名它的目錄。
草擬範例
你可以用下方的命令執行這個範例的匯入,或讓你的 AI 助理替你執行。
把範例寫入一個以它命名的新資料夾:
aggrega draft --example import-dify它接著會印出要接著執行的命令。第一個會切換到新資料夾:
cd import-dify建置
匯入會在專案旁的 source/ 中草擬 Aggrega 檔案,從 import-answers.yaml 取得應用程式無法承載的內容,並 pull 建置所需的內容。它會將專案與標準程式庫目錄比對,工作區的預設登錄庫將該目錄發布為簽署快照:第一次匯入會擷取它、驗證它、保存在工作區的內容快取中,並在寫於草稿旁的記錄中以其摘要來指名。指名自己目錄資料夾的工作區——在 AGGREGA_CATALOG_DIRS 中,或在 workspace.catalog_dirs 之下——則改為對那些資料夾進行匯入:
cd sourceaggrega import support-assistant.yml --target helmaggrega validate --release release.yamlaggrega build --release release.yaml建立建置的資訊清單所讀取的 Secrets,以及執行它們,都在上方連結的逐步說明中。
搭配 AI 助理
以 Aggrega 的工具設定好的 AI 助理可以做同樣的事:把這個提示貼給它。
只使用 Aggrega 工具,且不要自行建立任何資料夾。如果工作區資料夾中還沒有 `import-dify` 資料夾,請呼叫一次 `draft` 工具,將 `example` 設為 `import-dify`,且不指定 `dir`:它會把範例寫入新的 `import-dify` 資料夾,其 `source` 資料夾存放這個範例所匯入的內容。接著呼叫 `import` 工具,將 `workspace_root` 設為 `import-dify/source`、`source` 設為 `support-assistant.yml`、`target` 設為 `helm`:它會從 `support-assistant.yml` 旁的 `import-answers.yaml` 讀取所需的答案,把草稿寫入 `import-dify/source`,並 pull 它們所需的內容。接著呼叫 `validate` 工具,將 `workspace_root` 設為 `import-dify/source`、`release` 設為 `release.yaml`,再呼叫 `build` 工具,將 `workspace_root` 設為 `import-dify/source`、`release` 設為 `release.yaml`、`write` 設為 true。告訴我建置寫出了哪些檔案;它們位於 `import-dify/source/dist/` 之下。測試
以 --target compose 匯入,並依逐步說明的 在 Docker Compose 上 所示啟動後,安裝會在這台機器上回應:API 位於 http://127.0.0.1:5001,主控台位於 http://127.0.0.1:3001/signin。應用程式會回應以它自己的金鑰所送出的訊息,該金鑰由 逐步說明 在登入後建立:從 Dify 的外掛程式市集安裝 OpenAI 提供者(草擬的 Release 的 marketplace_enabled 讓安裝得以連上該市集),並設定提供者的金鑰:
curl -sS http://127.0.0.1:5001/v1/chat-messages \ -H 'Authorization: Bearer <app key>' -H 'Content-Type: application/json' \ -d '{"inputs": {}, "query": "In one short sentence: what does a support plan cover?", "response_mode": "blocking", "user": "test-it"}'這次執行的提供者金鑰是預留位置,Dify 在設定時以 OpenAI 的 Incorrect API key provided 拒絕了它,所以訊息得到的是:
{"code":"provider_not_initialize","message":"Model gpt-4o-mini credentials is not initialized.","status":400}如上建置,為 Kubernetes 並依逐步說明的 執行它 套用後,一旦本機連接埠轉送到其 Service,API 就會在相同位址回應相同的請求;這次執行在那裡得到相同的回覆:
kubectl port-forward -n <namespace> svc/dify-zdapi-default 5001:5001