匯入 Flowise chatflow
本逐步說明會將從 Flowise 匯出的 chatflow——一條帶有聊天模型與記憶體的對話鏈——匯入為 Aggregate、Release 與 Manifest,它們會建置帶著該 chatflow 的 Flowise,依原樣用於 Docker Compose,接著建置並執行結果。下方的每個檔案與每段輸出都來自真實執行;該 chatflow 與逐步說明的每個階段都在 import-flowise 範例中,其中的檢查指令碼會再次執行匯入,將其寫出的內容、印出的內容,以及本頁引用的區塊與該處保存的檔案比對,並驗證與建置匯入所寫出的內容。
草擬範例
你可以用本頁的命令執行這個匯入,或是讓你的 AI 助理替你執行。
把範例寫入一個以它命名的新資料夾:
aggrega draft --example import-flowise接著它會印出接下來要執行的命令。第一個切換到新資料夾;其後的下一個,在下方,切換到其 source 資料夾,匯入就在那裡執行。該資料夾帶有 chatflow 檔案 support-chat.json,本頁只描述而不引用它:
cd import-flowise
chatflow
support-chat.json 是為本逐步說明撰寫的,採用 Flowise 編輯器匯出 chatflow 的格式,包含三個節點與它們之間的兩條邊:一個選用 gpt-4o-mini 的 ChatOpenAI 節點、一個 Buffer Memory 節點,以及一個接收兩者並以簡短系統訊息回答的 Conversation Chain 節點。ChatOpenAI 節點沒有選取任何已儲存的認證,並讓其 Base Path 留空,所以 Flowise 用來執行它的 OpenAI 用戶端會從 Flowise 的環境讀取其位址與金鑰。
chatflow 旁的 .aggrega-config.yaml 讓該資料夾成為工作區:
# The workspace key marks this directory as the workspace root, so an import run# here writes its drafts beside support-chat.json.workspace: {}# The registry the importer is fetched from the first time an import needs it.default_registry: hub.aggrega.ai而 import-answers.yaml 保存的是任何 chatflow 都無法保存之內容的答案。Flowise 在啟動時不會從檔案載入任何 chatflow,所以建置會透過 Flowise 自己的 API,以擁有者帳號為它植入內容,而沒有任何匯出內容指名該帳號:其電子郵件是 Docker Compose 匯入所需的唯一答案。Kubernetes 的匯入還需要保存各機密的 Kubernetes Secret 名稱——擁有者的密碼與 OpenAI 金鑰——所以該檔案也會指名這兩個 Secret(見 On Kubernetes):
# Values the import could not draft from the source, keyed by the drafted file and the key path inside# it. Write each one beside its key; an import of the same source, and a sync, read them from here and# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable# name, ${NAME}, or the name of a Kubernetes Secret.release.yaml: # Email address of the platform's owner account, read only when values.flow_definition is set. The # step that seeds the chatflow registers this account when the instance has no owner yet, which makes # it the owner, and signs in as it; on an instance that already has one, it names an account allowed # to import chatflows, and the password attached to the owner_password slot is that account's. # Required when values.flow_definition is set: the build halts when it is empty. It has no default. spec.components.flowise.infra.owner_email: "owner@example.com" # The origin of the secret value, written by the operator in the Release. Read exactly as # values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes # from, never the value. spec.components.flowise.features.owner_password.infra.origin: "flowise-owner" # The origin of the secret value, written by the operator in the Release. Read exactly as # values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes # from, never the value. spec.components.flowise.uses.model.chatopenai-0.features.credential.infra.origin: "openai-api-key"owner@example.com 代表你自己的電子郵件。沒有該檔案時,在終端機進行的匯入會逐一詢問每個值,一次一個問題,措辭取自其鍵上方的說明,並將你的答案寫入新的答案檔;在無法詢問的情況下,它會寫出帶有這些鍵與空白答案的該檔案,列出這些鍵,並以狀態 1 結束。匯入答案檔完整說明了該檔案。
匯入會將每個節點與工作區目錄的 Components 比對,而 --target 會從其 Recipes 草擬 Manifest。工作區沒有指定目錄資料夾,所以匯入會從它取得匯入器的登錄庫讀取標準程式庫目錄:那是已發布目錄的簽署快照,由第一次匯入取得、驗證並保存在工作區的內容快取中,並以其摘要記載於匯入寫在草稿旁的記錄中。若工作區在 AGGREGA_CATALOG_DIRS 或 workspace.catalog_dirs 之下指定了自己的目錄資料夾,則改為針對那些目錄匯入。切換到 source:
cd source執行匯入
aggrega import support-chat.json --target compose在標準輸出上,它會列出所寫出的內容:
wrote aggregate.yamlwrote release.yamlwrote manifest.yamlwrote .aggrega-import.json在標準錯誤上,其中 <workspace> 代表你執行它所在的資料夾:
[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]read as the flowise format, with drafted paths relative to <workspace>warn: node chatOpenAI_0 reaches chatopenai-0 through the model connection chatopenai-0 of core/ai-agent/flowise: its Base Path is empty, so the OpenAI client Flowise runs it on reads the address the platform delivers for this connection, OPENAI_BASE_URL, and, since it selects no credential, the key delivered as OPENAI_API_KEYinfo: the answers file <workspace>/import-answers.yaml also answers spec.components.flowise.features.owner_password.infra.origin in release.yaml, spec.components.flowise.uses.model.chatopenai-0.features.credential.infra.origin in release.yaml, which these drafts do not leave empty; those answers are kept there and not appliedmapped chatOpenAI_0 (chatOpenAI) to core/ai-model/openai as a reference, HIGH at 0.9made no choice for bufferMemory_0 (bufferMemory)made no choice for conversationChain_0 (conversationChain) warning: node "flowise" (provider "compose"): artifact "flowise-flow/flowise-flow.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set.Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)
mapped行說明 ChatOpenAI 節點成為標準程式庫的 OpenAI 模型core/ai-model/openai,是被參照而非草擬,因為它在高階層以 0.9 相符:它是自己的元件,連接到平台的model插槽。warn行說明 chatflow 如何連到該模型:該節點讀取平台為模型連線提供的位址與金鑰,所以 Release 附加在連線上的金鑰就是 chatflow 所使用的金鑰。info行與答案檔有關。它回答了草稿留空的擁有者電子郵件;其兩個 Secret 名稱所回答的,是只有 Kubernetes 匯入才會留空的內容,所以它們留在檔案中,在此未被使用。made no choice行說明記憶體與鏈仍留在 chatflow 內:平台沒有任何插槽接受它們。- 最後兩行是拉取。在每個值都已回答之後,匯入像
aggrega pull一樣拉取了草稿 Release 的相依項目,並寫出release.lock;下方的建置不需要更多內容。warning行是建置也會印出的一行,Validate and build 會加以說明。
它寫出什麼
Aggregate、Release 與 Manifest 都命名為 imported/support-chat,取自檔案 support-chat.json,因為 Flowise 的匯出內容本身不帶名稱,位於匯入器的 target_namespace 設定所指定的命名空間之下,除非你另行設定,否則為 imported(Settings)。
aggregate.yaml——標準程式庫之 Flowise 平台 core/ai-agent/flowise 的一個實例,帶著依匯出原樣的 chatflow(此處省略大部分內容),以及連接到其 model 插槽的模型:
apiVersion: aggrega.ai/v1beta1kind: Aggregatemetadata: name: imported/support-chat version: 0.1.0 description: Draft Aggregate imported from a source in the flowise format.spec: components: flowise: type: core/ai-agent/flowise features: # For the compose target, the lines below declare owner_password on flowise: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. owner_password: type: core/secret-value values: key: OWNER_PASSWORD values: # chatflow_id is derived from the exported flow, which gives no identifier of its own. chatflow_id: '40d9f5c5-5187-54c1-a9f5-a8dac92f88bb' flow_definition: | { "nodes": [ [… omitted: the chatflow's nodes, as exported, up to the Conversation Chain's inputs] "inputs": { "model": "{{"{{"}}chatOpenAI_0.data.instance}}", "memory": "{{"{{"}}bufferMemory_0.data.instance}}", [… omitted: the rest of the chatflow, as exported] } uses: model: chatopenai-0: target: chatopenai-0 # For the compose target, the lines below declare credential on chatopenai-0: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none. features: credential: type: core/secret-value values: key: OPENAI_API_KEY # swap to core/ai-model/azure-openai (score 0.4000) by setting type: core/ai-model/azure-openai chatopenai-0: type: core/ai-model/openai values: model: |- gpt-4o-mini- 模型是
core/ai-model/openai,使用該節點所選的模型gpt-4o-mini。其上方的註解指出目錄中該節點所相似的另一個 Component,並附上其分數。 - 兩個機密——chatflow 植入時所用之擁有者帳號的密碼,以及平台出示給模型的 OpenAI 金鑰——在此宣告,並附上各自在 Flowise 環境中送達時所用的變數
OWNER_PASSWORD與OPENAI_API_KEY。在 Docker Compose 上,僅由 Release 附加的機密會以鍵value送達,而兩者會衝突;在此宣告後,各自有自己的鍵。Release 說明各自的來源。 chatflow_id是由 chatflow 推導而來,因為 Flowise 編輯器的匯出內容不帶自己的識別碼,所以同一個 chatflow 永遠產生同一個識別碼。Flowise chatflow 為兩個節點之間的每個連線寫下{{<node id>.data.instance}},而 Aggregate 的文字會被當作範本讀取,所以草稿將每個{{寫成{{"{{"}},建置會將它轉回兩個大括號。
release.yaml——Release,它以 Manifest 部署該 Aggregate:
apiVersion: aggrega.ai/v1beta1kind: Releasemetadata: name: imported/support-chat # environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to. environment: development version: 0.1.0 description: Draft Release imported from a source in the flowise format.spec: aggregate: imported/support-chat manifest: imported/support-chat components: flowise: infra: # The image running core/ai-agent/flowise, at the version this importer drafts, which the catalog's Recipes for it are known to run; the import does not raise or lower it to follow the source. image: "flowiseai/flowise:3.1.3" # Left for the Release, since the source cannot supply it: infra.owner_email, the email address of the platform's owner account, required while values.flow_definition is set owner_email: "owner@example.com" # Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal. published_port: 3000 features: owner_password: type: core/secret-value infra: # Attached by reference, never as a value: the owner account's password, required while values.flow_definition is set, read from the variable FLOWISE_OWNER_PASSWORD, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${FLOWISE_OWNER_PASSWORD}" uses: model: chatopenai-0: features: credential: type: core/secret-value infra: # Attached by reference, never as a value: the credential flowise presents to chatopenai-0 on its model connection, read from the variable OPENAI_API_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value. origin: "${OPENAI_API_KEY}" chatopenai-0: {}environment是development,這是預設值,其上方的註解說明要將它改為該 Release 部署的環境。- 映像檔是 Flowise 3.1.3,也就是目錄中 Flowise 的 Recipes 所執行的版本。
published_port是 3000,也就是 Flowise 提供服務的連接埠,所以它在你機器上的http://127.0.0.1:3000回應。如其註解所說,這部機器上的任何處理程序都能在那裡連到它,其他則都不能;刪除該行可讓 Flowise 只留在堆疊的網路上。owner_email是來自答案檔的答案。其上方的註解說明了匯入為何無法草擬它。- 兩個機密是變數參照
${FLOWISE_OWNER_PASSWORD}與${OPENAI_API_KEY},由 Docker Compose 在堆疊啟動時從你的 shell 填入,所以沒有任何檔案帶有任一值。
manifest.yaml——平台與模型的 Compose Recipes,以及將機密的變數參照依原樣寫入 Compose 檔案的實現:
apiVersion: aggrega.ai/v1beta1kind: Manifestmetadata: name: imported/support-chat version: 0.1.0spec: mappings: components: type: core/ai-agent/flowise: compose/flowise core/ai-model/openai: compose/openai features: type: core/secret-value: compose/dotenv-secret.aggrega-import.json 是匯入所寫內容的記錄,之後的 aggrega import --sync 會讀取它,而 release.lock 以版本與摘要鎖定該 Release 所解析到的每個目錄實體。
驗證並建置
aggrega validate --release release.yamlaggrega build --release release.yaml

驗證會印出:
notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)release dependency validation passed: release.yaml (schema-pillar + dependency pillars)以及建置,其中 <workspace> 代表保存草稿的資料夾:
warning: node "flowise" (provider "compose"): artifact "flowise-flow/flowise-flow.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set. notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)[… omitted: a total build time, which differs per run]Build completed: 1 file written to <workspace>/distwarning 行與 Compose 檔案中帶有 chatflow 的部分有關,也就是最上層的 configs 項目,它沒有可讓建置放置標籤的服務。notice 行僅供參考:機密 Feature 接受來自 Aggregate 的 values 或 Release 的 infra 的 origin,而該通知回報有一個葉節點在兩處都被宣告。兩者都不改變判定結果。
dist/compose/docker-compose.yaml 保存兩個服務。Flowise 本身:
flowise: image: flowiseai/flowise:3.1.3 environment: DATABASE_PATH: /home/node/.flowise SECRETKEY_PATH: /home/node/.flowise OPENAI_BASE_URL: https://api.openai.com/v1 OPENAI_API_KEY: ${OPENAI_API_KEY} ports: - 127.0.0.1:3000:3000 [… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version] volumes: - type: volume source: flowise--data target: /home/node networks: - compose [… omitted: the service's health check]以及在 Flowise 回報健康後植入 chatflow,然後結束的服務:
flowise-flow-seed: image: flowiseai/flowise:3.1.3 entrypoint: - node - /seed/seed.js environment: FLOWISE_URL: http://127.0.0.1:3000 OWNER_EMAIL: owner@example.com OWNER_PASSWORD: ${FLOWISE_OWNER_PASSWORD} CHATFLOW_ID: 40d9f5c5-5187-54c1-a9f5-a8dac92f88bb CHATFLOW_NAME: 40d9f5c5-5187-54c1-a9f5-a8dac92f88bb [… omitted: the labels the build writes on every service] network_mode: service:flowise depends_on: flowise: condition: service_healthy restart: "no" configs: - source: flowise-flow target: /seed/flow.json - source: flowise-flow-seed target: /seed/seed.js它會在全新的 Flowise 上註冊擁有者帳號,或以該帳號登入,並將 chatflow 寫在 chatflow_id。金鑰與密碼是變數參照,在堆疊啟動時從你的 shell 填入。只有在 Release 於 Flowise 的 infra 中設定 published_port 時,Flowise 的 Compose Recipe 才會在你的機器上發布連接埠,而且僅限回送位址 127.0.0.1;沒有它時,該服務只能在堆疊的網路上連到。
搭配 AI 助理
設定了 Aggrega 工具的 AI 助理也能做同樣的事:把這段提示貼給它。
只使用 Aggrega 工具,且不要自行建立任何資料夾。如果 Workspace 資料夾中還沒有 `import-flowise` 資料夾,請呼叫一次 `draft` 工具,將 `example` 設為 `import-flowise`,且不帶 `dir`:它會將範例寫入新的 `import-flowise` 資料夾,其 `source` 資料夾保存本頁所匯入的內容。接著呼叫 `import` 工具,將 `workspace_root` 設為 `import-flowise/source`、`source` 設為 `support-chat.json`、`target` 設為 `compose`:它會從 `support-chat.json` 旁的 `import-answers.yaml` 讀取所需的答案,將草稿寫入 `import-flowise/source`,並拉取它們所需的內容。接著呼叫 `validate` 工具,將 `workspace_root` 設為 `import-flowise/source`、`release` 設為 `release.yaml`,並呼叫 `build` 工具,將 `workspace_root` 設為 `import-flowise/source`、`release` 設為 `release.yaml`、`write` 設為 true。告訴我建置寫出了哪些檔案;它們位於 `import-flowise/source/dist/` 之下。在 VS Code 中開啟
安裝 Aggrega extension for Visual Studio Code 後,在 VS Code 中開啟資料夾 import-flowise/source,匯入就是把草稿寫在那裡。該資料夾保存一個 Release,即草稿的 release.yaml,所以編輯器會替你選取它,並在你編輯草稿時依該 Release 檢查它們,在檔案與 Problems 面板中標示所發現的問題。命令選擇區中的 Aggrega: Show topology graph 會繪出該 Release 的元件以及它們之間的連線。Aggrega: Build、Aggrega: Preview build 與 Aggrega: Pull 都作用於同一個 Release,而且每一個也是活動列中 Aggrega 檢視的 Commands 面板上的按鈕;Build 會將其檔案寫入該資料夾的 dist/。其餘內容請見 Use Aggrega in Visual Studio Code。
執行
在你的 shell 中設定金鑰與擁有者的密碼,啟動 Flowise,然後執行植入:
export OPENAI_API_KEY='your OpenAI key'export FLOWISE_OWNER_PASSWORD='a password of your own'docker compose -p support-chat -f dist/compose/docker-compose.yaml up -d --wait flowisedocker compose -p support-chat -f dist/compose/docker-compose.yaml up flowise-flow-seed-p 為專案命名,如 How an import runs 的執行步驟所說明。--wait 在 Flowise 回報健康後返回;它只指名 flowise,因為它會將任何已結束的容器視為失敗,而植入依設計就會結束。第二個命令執行植入、印出其記錄,並在它結束時返回:
flowise-flow-seed-1 | registered the owner account owner@example.comflowise-flow-seed-1 | imported chatflow 40d9f5c5-5187-54c1-a9f5-a8dac92f88bb as "40d9f5c5-5187-54c1-a9f5-a8dac92f88bb"flowise-flow-seed-1 exited with code 0當你機器上已有另一個程式在監聽 127.0.0.1:3000 時,第一個命令會停止並顯示 failed to bind host port 127.0.0.1:3000/tcp: address already in use:將 published_port 設為可用的連接埠,然後再次建置。下方的執行就是這樣做的,使用了 3002,並以該連接埠取代 3000。
測試
開啟 http://127.0.0.1:3000,也就是 published_port 所發布的位址,並以擁有者的電子郵件與密碼登入:植入的 chatflow 就在 Flowise 中。
沒有設定自己 API 金鑰的 chatflow,無需金鑰就會回應其預測端點。問它一個問題:
curl -sS -X POST http://127.0.0.1:3000/api/v1/prediction/40d9f5c5-5187-54c1-a9f5-a8dac92f88bb \ -H 'Content-Type: application/json' -d '{"question": "In one short sentence: what is Docker Compose?"}'該次執行對 OpenAI 金鑰使用了預留位置,所以答案是 OpenAI 對它的拒絕,這顯示 chatflow 已執行到其對模型的呼叫為止:
{"statusCode":500,"success":false,"message":"401 Unauthorized – check your API key and ensure it has access to the requested model.","stack":{}}使用你的金鑰時,回覆會在 text 帶有答案。
在 Kubernetes 上,套用 On Kubernetes 所說明的建置並讓其植入 Job 完成後,將本機連接埠轉送到 Flowise 的 Service flowise-default,位於你套用到的命名空間中,並讓該命令持續執行:
kubectl port-forward -n <namespace> svc/flowise-default 3000:3000在另一個終端機中,上面的問題會在同一位址原封不動地連到 chatflow;該次執行得到對預留位置金鑰的同樣拒絕。
以下方命令停止堆疊。-v 也會移除 Flowise 的資料磁碟區,連同擁有者帳號與植入所寫入的 chatflow:
docker compose -p support-chat -f dist/compose/docker-compose.yaml down -v在 Kubernetes 上
同一個 chatflow 可用 helm 目標匯入到 Kubernetes。供 Docker Compose 使用的草稿已經在 source 中,而匯入從不覆寫那裡的 Aggregate,所以請用 --output-dir 將這些草稿草擬到它們自己的資料夾,然後從那裡驗證並建置:
aggrega import support-chat.json --target helm --output-dir helmcd helmaggrega validate --release release.yamlaggrega build --release release.yaml草稿在目標不同之處會有差異。Manifest 將平台對應到 helm/flowise,將模型對應到 helm/openai,並將每個機密對應到 helm/k8s-existing-secret,後者從命名空間中已存在的 Secret 讀取它。Release 將擁有者的密碼與 OpenAI 金鑰附加為 core/referenced-secret,各自指名其 Secret,並從答案檔取得全部三個答案:擁有者的電子郵件、flowise-owner 與 openai-api-key。
建置會將一般的 Kubernetes 資訊清單寫在工作區根目錄 source 的 dist/helm/ 之下,從 helm 看來是 ../dist/helm/,chatflow 的植入就在其中,作為一個 Job。在你套用到的命名空間中建立這兩個 Secret,各自在資料鍵 value 之下保存其值,然後套用該資料夾,如 How an import runs 的執行步驟所說明。