跳到內容
AggregaAggregaAggregaAggrega
選擇語言: 繁體中文
本頁為機器翻譯。閱讀英文原文。

匯入 Langflow 流程——Basic Prompting 入門專案

Langflow 的 Basic Prompting 入門專案,匯出為 JSON,由 aggrega import 匯入為 Aggregate、Release 與 Manifest,並依原樣為 Docker Compose 建置。

匯入 Langflow 流程 逐步說明:命令、它寫出的檔案、建置,以及所建置內容的一次執行。這個資料夾存放該逐步說明的每個階段:

資料夾它保存的內容
source/匯出的流程 basic-prompting.json;讓資料夾成為工作區的 .aggrega-config.yaml;以及 import-answers.yaml,即流程無法承載之內容的答案,為 Kubernetes 匯入時會要求這些答案
draft/aggrega import basic-prompting.json --target compose 寫出的檔案(原樣未改),以及它印出的內容:標準輸出上的 stdout.txt,標準錯誤上的 import.txt

source/basic-prompting.json 是 Langflow 1.6.0 隨附的入門專案,原樣取自 Langflow 存放庫(https://github.com/langflow-ai/langflow,位於提交 504c02fc47e76087b82b0e7cbe4186e9cdd916d4,檔案 src/lfx/tests/data/starter_projects_1_6_0/Basic Prompting.json),授權條款重製於其旁的 LICENSE.langflow。草稿帶有相同的流程,其邊的控制代碼依 Langflow 編輯器的寫法書寫。

在文件存放庫的簽出內容中,check.sh 會再次執行匯入,將它寫出與印出的內容與 draft/ 比較,將逐步說明所引用的區塊與這些檔案比較,並驗證與建置匯入所寫出的內容。它需要與這個存放庫並列簽出的標準程式庫目錄(取得方式),或在 AGGREGA_CATALOG_DIRS 中指名它的目錄。

草擬範例

你可以用下方的命令執行這個範例的匯入,或讓你的 AI 助理替你執行。

把範例寫入一個以它命名的新資料夾:

Terminal window
aggrega draft --example import-langflow

它接著會印出要接著執行的命令。第一個會切換到新資料夾:

Terminal window
cd import-langflow

建置

匯入會在專案旁的 source/ 中草擬 Aggrega 檔案,並 pull 建置所需的內容。它會將專案與標準程式庫目錄比對,工作區的預設登錄庫將該目錄發布為簽署快照:第一次匯入會擷取它、驗證它、保存在工作區的內容快取中,並在寫於草稿旁的記錄中以其摘要來指名。指名自己目錄資料夾的工作區——在 AGGREGA_CATALOG_DIRS 中,或在 workspace.catalog_dirs 之下——則改為對那些資料夾進行匯入:

Terminal window
cd source
aggrega import basic-prompting.json --target compose
aggrega validate --release release.yaml
aggrega build --release release.yaml

執行建置所寫出的內容,請見上方連結的逐步說明。

搭配 AI 助理

以 Aggrega 的工具設定好的 AI 助理可以做同樣的事:把這個提示貼給它。

只使用 Aggrega 工具,且不要自行建立任何資料夾。如果工作區資料夾中還沒有 `import-langflow` 資料夾,請呼叫一次 `draft` 工具,將 `example` 設為 `import-langflow`,且不指定 `dir`:它會把範例寫入新的 `import-langflow` 資料夾,其 `source` 資料夾存放這個範例所匯入的內容。接著呼叫 `import` 工具,將 `workspace_root` 設為 `import-langflow/source`、`source` 設為 `basic-prompting.json`、`target` 設為 `compose`:它會從 `basic-prompting.json` 旁的 `import-answers.yaml` 讀取所需的答案,把草稿寫入 `import-langflow/source`,並 pull 它們所需的內容。接著呼叫 `validate` 工具,將 `workspace_root` 設為 `import-langflow/source`、`release` 設為 `release.yaml`,再呼叫 `build` 工具,將 `workspace_root` 設為 `import-langflow/source`、`release` 設為 `release.yaml`、`write` 設為 true。告訴我建置寫出了哪些檔案;它們位於 `import-langflow/source/dist/` 之下。

測試

依逐步說明執行堆疊後,開啟 http://127.0.0.1:7860 並以 admin 登入:Basic Prompting 就在編輯器中。API 以 API 金鑰執行流程,該金鑰由 逐步說明 在登入後建立;使用它:

Terminal window
curl -sS -X POST 'http://127.0.0.1:7860/api/v1/run/0dbee653-41ae-4e51-af2e-55757fb24be3?stream=false' \
-H 'x-api-key: <api_key>' -H 'Content-Type: application/json' \
-d '{"input_value": "In one short sentence: what is Docker Compose?", "input_type": "chat", "output_type": "chat"}'
{"detail":"{\"message\":\"Error running graph: Error building Component Language Model: \\n\\nError code: 401 - {'error': {'message': 'Incorrect API key provided: sk-place*****************-key. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'code': 'invalid_api_key', 'param': None}, 'status': 401}\",[… omitted: three empty fields, and a suggestion to update three of the flow's components]}"}

這次執行的 OpenAI 金鑰是預留位置,所以回答是 OpenAI 對它的拒絕:流程執行到它呼叫模型為止。

以 --target helm 匯入並套用到 Kubernetes 後,一旦本機連接埠轉送到其 Service,Langflow 就會在相同位址回應相同的請求:

Terminal window
kubectl port-forward -n <namespace> svc/langflow-default 7860:7860