ข้ามไปยังเนื้อหา
AggregaAggregaAggregaAggrega
เลือกภาษา: ไทย
หน้านี้ถูกแปลด้วยเครื่อง อ่านต้นฉบับภาษาอังกฤษ

นำเข้า flow ของ Langflow

บทแนะนำทีละขั้นตอนนี้นำเข้า flow ที่ส่งออกจาก Langflow ซึ่งเป็น Basic Prompting โปรเจกต์เริ่มต้นที่ Langflow 1.6.0 มาให้ ไปเป็น Aggregate, Release และ Manifest ที่บิลด์ Langflow พร้อม flow สำหรับ Docker Compose ตามที่เขียนไว้ จากนั้นบิลด์และรันผลที่ได้ ทุกไฟล์และทุกบล็อกเอาต์พุตด้านล่างมาจากการรันจริง flow และแต่ละขั้นตอนของบทแนะนำอยู่ในตัวอย่าง import-langflow ซึ่งสคริปต์ตรวจสอบรันการนำเข้าอีกครั้ง เปรียบเทียบสิ่งที่การนำเข้าเขียน สิ่งที่พิมพ์ และบล็อกที่หน้านี้อ้างถึงกับไฟล์ที่เก็บไว้ที่นั่น แล้วตรวจสอบความถูกต้องและบิลด์สิ่งที่การนำเข้าเขียน

ร่างตัวอย่าง

คุณรันการนำเข้านี้ด้วยคำสั่งในหน้านี้ได้ หรือ ให้ผู้ช่วย AI ของคุณรันให้

เขียนตัวอย่างลงในโฟลเดอร์ใหม่ที่ตั้งชื่อตามตัวอย่าง:

Terminal window
aggrega draft --example import-langflow

จากนั้นจะพิมพ์คำสั่งที่ต้องรันต่อไป คำสั่งแรกเปลี่ยนเข้าไปในโฟลเดอร์ใหม่ คำสั่งถัดจากนั้นด้านล่างเปลี่ยนเข้าไปในโฟลเดอร์ source ของโฟลเดอร์ใหม่ ซึ่งเป็นที่ที่การนำเข้ารัน โฟลเดอร์นั้นมีไฟล์ flow คือ basic-prompting.json ซึ่งหน้านี้อธิบายแทนที่จะอ้างถึงทั้งไฟล์:

Terminal window
cd import-langflow

โฟลเดอร์ source ของตัวอย่างที่ร่างไว้เปิดอยู่ใน Visual Studio Code แสดงการส่งออก flow ของ Langflow ที่เป็น flow ของ basic prompting

flow

Basic Prompting เชื่อมโหนดสี่โหนดเป็นลูกโซ่: Chat Input, Prompt, Language Model ที่เรียก gpt-4.1 ของ OpenAI และ Chat Output ตามที่ Langflow มาให้ เป็นไฟล์ JSON ไฟล์เดียวคือ basic-prompting.json ขนาดประมาณ 54 KB ซึ่งมีซอร์สโค้ดของแต่ละส่วนประกอบรวมถึง flow โหนด Language Model ของ flow อ่านคีย์จากตัวแปรส่วนกลาง OPENAI_API_KEY ซึ่ง Langflow อ่านจากสภาพแวดล้อมของตน เมื่อไม่มีตัวแปรชื่อนั้นเก็บไว้

ข้าง flow .aggrega-config.yaml ทำให้โฟลเดอร์เป็นพื้นที่ทำงาน:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside basic-prompting.json.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

และ import-answers.yaml เก็บคำตอบสำหรับสิ่งที่ flow เก็บไม่ได้ การนำเข้าสำหรับ Docker Compose ไม่ต้องใช้คำตอบเหล่านี้เลย: แนบข้อมูลลับแต่ละรายการด้วยการอ้างอิงตัวแปรที่ Docker Compose เติมจาก shell ของคุณ การนำเข้าสำหรับ Kubernetes แนบข้อมูลลับแต่ละรายการด้วยชื่อของ Secret ใน Kubernetes ซึ่งมีเพียงคุณที่ตั้งชื่อได้ ไฟล์จึงระบุชื่อ Secrets สองรายการที่การนำเข้านั้นถามหา (ดู บน 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:
# 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.langflow.features.admin_password.infra.origin: "langflow-admin"
# 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.langflow.uses.model.languagemodelcomponent-kboja.features.credential.infra.origin: "openai-api-key"

คำตอบแต่ละรายการคือชื่อของ Secret ไม่ใช่ข้อมูลลับเอง จึงเก็บไฟล์ไว้กับ flow ได้ ไฟล์คำตอบของการนำเข้า อธิบายไฟล์โดยละเอียด

การนำเข้าเทียบโหนดแต่ละโหนดกับ Components ของแค็ตตาล็อกของพื้นที่ทำงาน และ --target ร่าง Manifest จาก Recipes ของแค็ตตาล็อกนั้น พื้นที่ทำงานไม่ระบุโฟลเดอร์แค็ตตาล็อกใดเลย การนำเข้าจึงอ่านแค็ตตาล็อกของไลบรารีมาตรฐานจากรีจิสทรีที่ใช้ดึงตัวนำเข้า คือสแนปช็อตที่ลงนามของแค็ตตาล็อกที่เผยแพร่ ซึ่งการนำเข้าครั้งแรกดึงมา ตรวจสอบ และเก็บไว้ในแคชเนื้อหาของพื้นที่ทำงาน และระบุด้วยไดเจสต์ในบันทึกที่การนำเข้าเขียนไว้ข้างฉบับร่าง พื้นที่ทำงานที่ระบุโฟลเดอร์แค็ตตาล็อกของตนเอง — ใน AGGREGA_CATALOG_DIRS หรือใต้ workspace.catalog_dirs — จะนำเข้าเทียบกับโฟลเดอร์เหล่านั้นแทน เปลี่ยนไดเรกทอรีไปที่ source:

Terminal window
cd source

รันการนำเข้า

Terminal window
aggrega import basic-prompting.json --target compose

ที่เอาต์พุตมาตรฐาน การนำเข้าแสดงสิ่งที่เขียน:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote .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 langflow format, with drafted paths relative to <workspace>
warn: the flow is carried in values.flow_definition with the handles of all 3 of its edges written as Langflow's editor writes them — the same handles, their keys in order with no space between them — since the editor compares an edge's handles with the ones it writes for the nodes the edge joins, character for character, when it opens the flow, and drops every edge whose handles differ
warn: node LanguageModelComponent-kBOja reaches languagemodelcomponent-kboja through the model connection languagemodelcomponent-kboja of core/ai-agent/langflow: its field api_key names the variable OPENAI_API_KEY, which the platform delivers for this connection and Langflow reads as a global variable; no field of it gives its API's address, so the OpenAI client it runs takes OPENAI_BASE_URL, the address the platform delivers for this connection, from the environment
made no choice for ChatInput-SzjnT (ChatInput)
made no choice for Prompt-tOH5D (Prompt)
made no choice for ChatOutput-8ZWWB (ChatOutput)
mapped LanguageModelComponent-kBOja (LanguageModelComponent) to core/ai-model/openai as a reference, HIGH at 0.9
warning: node "langflow" (provider "compose"): artifact "langflow-flow/langflow-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)

การนำเข้าที่รันจากตัวแก้ไข: Aggregate, Release และ Manifest ที่ร่างไว้ปรากฏข้างไฟล์ที่ส่งออกของ flow Aggrega output แสดงรายการวิธีที่ส่วนประกอบแต่ละรายการของ flow ถูกแมปและไฟล์ที่เขียน และการแจ้งเตือนระบุว่าการนำเข้าร่างไฟล์ 3 ไฟล์ โดยรู้จักเป็น langflow

  • บรรทัด mapped ระบุว่าโหนด Language Model กลายเป็นอะไร คือโมเดล OpenAI ในไลบรารีมาตรฐาน core/ai-model/openai ซึ่งอ้างอิงแทนที่จะร่างขึ้นใหม่ เพราะจับคู่ได้ในระดับสูงที่ 0.9 เป็นส่วนประกอบเดี่ยวของตัวเอง ที่เชื่อมโยงกับซ็อกเก็ต model ของแพลตฟอร์ม โดยค่าเริ่มต้น ร่างรัน flow ทั้งหมดบนแพลตฟอร์มที่รัน Langflow และให้ส่วนประกอบของตัวเองเฉพาะโหนดที่ซ็อกเก็ตของแพลตฟอร์มนั้นรับ ได้แก่ โมเดล เครื่องมือ หรือที่จัดเก็บเวกเตอร์ เมื่อรู้จักโหนดนั้นว่าเป็นอย่างใดอย่างหนึ่งเหล่านี้
  • บรรทัด warn แรก ระบุว่า flow มาพร้อมแฮนเดิลของเส้นเชื่อมแต่ละเส้นที่เขียนตามที่ตัวแก้ไขของ Langflow เขียน Langflow เก็บโปรเจกต์เริ่มต้นไว้โดยมีช่องว่างหลังทุกเครื่องหมายทวิภาคและจุลภาคในแฮนเดิลของเส้นเชื่อม ตัวแก้ไขของ Langflow เมื่อเปิด flow จะทิ้งเส้นเชื่อมทุกเส้นที่แฮนเดิลไม่ตรงกับที่ตัวแก้ไขเขียน แล้วบันทึก flow โดยไม่มีเส้นเชื่อมนั้น เมื่อเขียนเช่นนี้ flow จะเปิดพร้อมการเชื่อมต่อสามรายการ และรันพร้อมการเชื่อมต่อเหล่านั้น
  • บรรทัด warn ที่ระบุโหนด บอกว่า flow เข้าถึงโมเดลนั้นอย่างไร โหนดอ่านคีย์จากตัวแปร OPENAI_API_KEY และอ่านที่อยู่จาก OPENAI_BASE_URL และแพลตฟอร์มส่งมอบทั้งสองค่าสำหรับการเชื่อมต่อของโมเดล flow จึงไม่ต้องแก้ไข
  • บรรทัด made no choice ระบุโหนดที่ไม่มีซ็อกเก็ตใดของแพลตฟอร์มรับ: โหนดเหล่านั้นอยู่ภายใน flow ซึ่ง Langflow รันตามที่ส่งออก
  • สองบรรทัดสุดท้าย คือขั้นตอน pull ไม่มีคำถามเหลือให้ตอบ การนำเข้าจึง pull การพึ่งพาของ Release ที่ร่างไว้ เหมือนที่ aggrega pull ทำ และเขียน release.lock บิลด์ด้านล่างไม่ต้องใช้อะไรเพิ่ม บรรทัด warning เป็นบรรทัดที่บิลด์พิมพ์เช่นกัน และ ตรวจสอบความถูกต้องและบิลด์ อธิบายบรรทัดนั้น

ไฟล์คำตอบระบุ Secrets สองรายการที่การนำเข้านี้ไม่ได้ถามหา: การนำเข้าไม่ปล่อยค่าว่างไว้สำหรับรายการเหล่านั้น จึงไม่นำคำตอบใดไปใช้และปล่อยไฟล์ไว้ตามเดิม

สิ่งที่การนำเข้าเขียน

Aggregate, Release และ Manifest ตั้งชื่อว่า imported/basic-prompting ตามชื่อของ flow เอง คือ Basic Prompting ที่ย่อเป็น basic-prompting (flow ที่ไม่มีชื่อจะตั้งชื่อตามไฟล์ของ flow) ภายใต้เนมสเปซที่การตั้งค่า target_namespace ของตัวนำเข้ากำหนด คือ imported เว้นแต่คุณตั้งค่าอื่น (การตั้งค่า)

aggregate.yaml ประกอบด้วยอินสแตนซ์หนึ่งของแพลตฟอร์ม Langflow ในไลบรารีมาตรฐาน คือ core/ai-agent/langflow ซึ่งพา flow ตามที่ส่งออก ยกเว้นแฮนเดิลของเส้นเชื่อมที่เขียนตามที่ตัวแก้ไขของ Langflow เขียน โดยตัดออกจากที่นี่กว่าหนึ่งพันบรรทัด และโมเดลที่แพลตฟอร์มเข้าถึง:

apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/basic-prompting
version: 0.1.0
description: Draft Aggregate imported from a source in the langflow format.
spec:
components:
langflow:
type: core/ai-agent/langflow
features:
# For the compose target, the lines below declare admin_password on langflow: 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.
admin_password:
type: core/secret-value
values:
key: LANGFLOW_SUPERUSER_PASSWORD
values:
flow_id: '0dbee653-41ae-4e51-af2e-55757fb24be3'
flow_definition: |-
{
"data": {
"edges": [
[… omitted: the rest of the flow]
}
uses:
model:
languagemodelcomponent-kboja:
target: languagemodelcomponent-kboja
# For the compose target, the lines below declare credential on languagemodelcomponent-kboja: 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
languagemodelcomponent-kboja:
type: core/ai-model/openai
values:
model: |-
gpt-4.1
  • โมเดล คือ core/ai-model/openai โดยใช้โมเดลที่โหนดของ flow เลือก คือ gpt-4.1 ความคิดเห็นเหนือโมเดลระบุ Component อีกรายการของแค็ตตาล็อกที่โหนดคล้าย พร้อมคะแนน สำหรับผู้อ่านที่ต้องการรายการนั้น
  • ข้อมูลลับสองรายการ คือรหัสผ่านของผู้ดูแลระบบที่ตัวแก้ไขของ Langflow ถามหา และคีย์ OpenAI ที่แพลตฟอร์มยื่นให้โมเดล ประกาศไว้ที่นี่พร้อมตัวแปรที่แต่ละรายการมาถึงในสภาพแวดล้อมของ Langflow คือ LANGFLOW_SUPERUSER_PASSWORD และ OPENAI_API_KEY บน Docker Compose ข้อมูลลับที่มีเพียง Release แนบไว้จะมาถึงใต้คีย์ value และทั้งสองรายการจะชนกัน เมื่อประกาศที่นี่ แต่ละรายการมีคีย์ของตนเอง Release ระบุว่าแต่ละรายการมาจากที่ใด
  • flow_id คือตัวระบุที่การส่งออกกำหนดให้ flow

release.yaml — Release ซึ่งปรับใช้ Aggregate ด้วย Manifest:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/basic-prompting
# 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 langflow format.
spec:
aggregate: imported/basic-prompting
manifest: imported/basic-prompting
components:
langflow:
infra:
# The image running core/ai-agent/langflow, 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. The source states version "1.5.0" of the platform.
image: "langflowai/langflow:1.6.0"
# 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: 7860
features:
admin_password:
type: core/secret-value
infra:
# Attached by reference, never as a value: the administrator's password, read while values.require_authentication stays true, read from the variable LANGFLOW_ADMIN_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: "${LANGFLOW_ADMIN_PASSWORD}"
uses:
model:
languagemodelcomponent-kboja:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential langflow presents to languagemodelcomponent-kboja 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}"
languagemodelcomponent-kboja: {}
  • environment คือ development ซึ่งเป็นค่าเริ่มต้นที่ความคิดเห็นด้านบนบอกให้เปลี่ยนเป็นสภาพแวดล้อมที่ Release ปรับใช้
  • อิมเมจ คือ Langflow 1.6.0 ซึ่งเป็นเวอร์ชันที่ Recipes ของแค็ตตาล็อกสำหรับ Langflow รัน flow ทดสอบครั้งล่าสุดบน Langflow 1.5.0 ตามที่ความคิดเห็นระบุ การนำเข้าคงเวอร์ชันที่ Recipes รันไว้แทนที่จะทำตามเวอร์ชันของ flow
  • published_port คือ 7860 ซึ่งเป็นพอร์ตที่ Langflow ให้บริการ ตัวแก้ไขจึงตอบที่ http://127.0.0.1:7860 บนเครื่องของคุณ ตามที่ความคิดเห็นของบรรทัดนั้นระบุ กระบวนการใดก็ตามบนเครื่องนี้เข้าถึงได้ที่นั่นและไม่มีสิ่งอื่นเข้าถึงได้ ลบบรรทัดนั้นเพื่อให้ Langflow อยู่บนเครือข่ายของสแตกเท่านั้น
  • ข้อมูลลับสองรายการ เป็นการอ้างอิงตัวแปร คือ ${LANGFLOW_ADMIN_PASSWORD} และ ${OPENAI_API_KEY} ซึ่ง Docker Compose เติมจาก shell ของคุณเมื่อสแตกเริ่มทำงาน จึงไม่มีไฟล์ใดมีค่าทั้งสองนี้

manifest.yaml — Recipes ของ Compose สำหรับแพลตฟอร์มและโมเดล และการทำให้เป็นรูปธรรมที่เขียนการอ้างอิงตัวแปรของข้อมูลลับลงในไฟล์ Compose ตามที่เขียนไว้:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/basic-prompting
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/langflow: compose/langflow
core/ai-model/openai: compose/openai
features:
type:
core/secret-value: compose/dotenv-secret

.aggrega-import.json คือบันทึกของสิ่งที่การนำเข้าเขียน ซึ่ง aggrega import --sync ครั้งต่อมาอ่าน และ release.lock ปักหมุดเอนทิตีแค็ตตาล็อกทุกรายการที่ Release หาค่าไปถึง ด้วยเวอร์ชันและไดเจสต์

ตรวจสอบความถูกต้องและบิลด์

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml

Release ที่ร่างไว้เปิดอยู่ในตัวแก้ไขหลังตรวจสอบความถูกต้อง โดย Aggrega output และการแจ้งเตือนต่างรายงานว่าไม่พบปัญหา

บิลด์ของ Release ที่ร่างไว้: โฟลเดอร์ dist ปรากฏใน Explorer โดยเอาต์พุตของ Aggrega แสดงรายการไฟล์ Docker Compose ที่เขียน และการแจ้งเตือนระบุว่าเขียนไฟล์แล้ว

การตรวจสอบความถูกต้องพิมพ์:

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 "langflow" (provider "compose"): artifact "langflow-flow/langflow-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>/dist

บรรทัด warning เกี่ยวกับส่วนของไฟล์ Compose ที่พา flow คือรายการ configs ระดับบนสุด ซึ่งไม่มีบริการให้ประทับป้ายกำกับของบิลด์ บรรทัด notice เป็นเชิงแนะนำ: Feature ข้อมูลลับรับ origin จาก values ของ Aggregate หรือ infra ของ Release และข้อแนะนำนี้รายงานว่ามีลีฟหนึ่งรายการประกาศไว้ทั้งสองแห่ง ทั้งสองบรรทัดไม่เปลี่ยนคำตัดสิน

dist/compose/docker-compose.yaml มี Langflow และบริการหนึ่งที่รันครั้งเดียวก่อน Langflow:

services:
langflow:
image: langflowai/langflow:1.6.0
environment:
LANGFLOW_CONFIG_DIR: /app/langflow
LANGFLOW_SAVE_DB_IN_CONFIG_DIR: "true"
LANGFLOW_AUTO_LOGIN: "false"
LANGFLOW_SUPERUSER: admin
LANGFLOW_SUPERUSER_PASSWORD: ${LANGFLOW_ADMIN_PASSWORD}
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_API_KEY: ${OPENAI_API_KEY}
LANGFLOW_LOAD_FLOWS_PATH: /app/flows
ports:
- 127.0.0.1:7860:7860
[… 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: langflow--data
target: /app/langflow
networks:
- compose
depends_on:
langflow--data-owner:
condition: service_completed_successfully
[… omitted: the service's health check]
configs:
- source: langflow-flow
target: /app/flows/flow.json
langflow--data-owner:
image: langflowai/langflow:1.6.0
entrypoint:
- chown
- "1000:0"
- /app/langflow
[… omitted: the labels the build writes on every service]
volumes:
- type: volume
source: langflow--data
target: /app/langflow
networks:
- compose
restart: "no"
user: "0"

flow ไปถึง Langflow เป็น /app/flows/flow.json จากรายการ configs ที่มี flow ซึ่ง Aggregate พามา และ Langflow โหลด flow จาก LANGFLOW_LOAD_FLOWS_PATH ทุกครั้งที่เริ่มทำงาน คีย์และรหัสผ่านเป็นการอ้างอิงตัวแปรที่เติมจาก shell ของคุณเมื่อสแตกเริ่มทำงาน Recipe สำหรับ Compose ของ Langflow เผยแพร่พอร์ตบนเครื่องของคุณเฉพาะเมื่อ Release ตั้ง published_port ใน infra ของ Langflow และเผยแพร่บนที่อยู่ลูปแบ็ก 127.0.0.1 เท่านั้น หากไม่ตั้งค่านั้น จะเข้าถึงบริการได้บนเครือข่ายของสแตกเท่านั้น

langflow--data-owner รันอิมเมจของ Langflow เป็น root มอบวอลุ่มข้อมูลให้ผู้ใช้ 1000 กลุ่ม 0 ซึ่งเป็นตัวตนที่อิมเมจของ Langflow รันเป็น แล้วออกจากการทำงาน Langflow เริ่มทำงานเมื่อบริการนั้นเสร็จสมบูรณ์: Docker สร้างวอลุ่มที่ root เป็นเจ้าของ และถ้าไม่ทำเช่นนั้น Langflow จะเขียนข้อมูลลงที่นั่นไม่ได้

กับผู้ช่วย AI

ผู้ช่วย AI ที่ ตั้งค่าด้วยเครื่องมือของ Aggrega ทำสิ่งเดียวกันได้: วางพรอมต์นี้ลงไป

ใช้เฉพาะเครื่องมือของ Aggrega และอย่าสร้างโฟลเดอร์เอง ถ้าโฟลเดอร์ Workspace ยังไม่มีโฟลเดอร์ `import-langflow` เรียกเครื่องมือ `draft` หนึ่งครั้ง โดยตั้ง `example` เป็น `import-langflow` และไม่ระบุ `dir`: เครื่องมือจะเขียนตัวอย่างลงในโฟลเดอร์ `import-langflow` ใหม่ ซึ่งโฟลเดอร์ `source` ของโฟลเดอร์นั้นเก็บสิ่งที่หน้านี้นำเข้า จากนั้นเรียกเครื่องมือ `import` โดยตั้ง `workspace_root` เป็น `import-langflow/source` ตั้ง `source` เป็น `basic-prompting.json` และตั้ง `target` เป็น `compose`: เครื่องมืออ่านคำตอบที่ต้องใช้จาก `import-answers.yaml` ข้าง `basic-prompting.json` เขียนร่างลงใน `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/`

เปิดใน VS Code

เมื่อติดตั้ง ส่วนขยาย Aggrega สำหรับ Visual Studio Code แล้ว เปิดโฟลเดอร์ import-langflow/source ใน VS Code ซึ่งเป็นที่ที่การนำเข้าเขียนร่างไว้ โฟลเดอร์มี Release หนึ่งรายการคือ release.yaml ที่ร่างไว้ ตัวแก้ไขจึงเลือก Release นั้นให้คุณ และตรวจสอบร่างเทียบกับ Release นั้นขณะที่คุณแก้ไข โดยทำเครื่องหมายสิ่งที่พบในไฟล์และในแผง Problems Aggrega: Show topology graph ใน Command Palette วาดส่วนประกอบของ Release และการเชื่อมต่อระหว่างส่วนประกอบเหล่านั้น Aggrega: Build, Aggrega: Preview build และ Aggrega: Pull ทำงานกับ Release เดียวกัน และแต่ละคำสั่งยังเป็นปุ่มบนแผง Commands ของมุมมอง Aggrega ในแถบกิจกรรม Build เขียนไฟล์ลงใน dist/ ของโฟลเดอร์ ใช้ Aggrega ใน Visual Studio Code ครอบคลุมส่วนที่เหลือ

วิธีรัน

ตั้งค่าคีย์และรหัสผ่านของผู้ดูแลระบบใน shell ของคุณ แล้วเริ่มสแตก:

Terminal window
export OPENAI_API_KEY='your OpenAI key'
export LANGFLOW_ADMIN_PASSWORD='a password of your own'
docker compose -p basic-prompting -f dist/compose/docker-compose.yaml up -d --wait

-p ระบุชื่อโปรเจกต์ ตามที่ขั้นตอนรันใน วิธีที่การนำเข้าทำงาน อธิบายไว้ --wait คืนการทำงานเมื่อ langflow--data-owner เสร็จสมบูรณ์และ Langflow รายงานว่าทำงานปกติ

ทดสอบ

เปิด http://127.0.0.1:7860 ซึ่งเป็นที่อยู่ที่ published_port เผยแพร่ แล้วลงชื่อเข้าใช้เป็น admin ด้วยรหัสผ่านที่คุณตั้ง: Basic Prompting อยู่ในตัวแก้ไขพร้อมการเชื่อมต่อสามรายการ

Langflow รัน flow ผ่าน API ให้เฉพาะผู้ที่มีคีย์ API ซึ่งผู้ดูแลระบบสร้างได้เมื่อลงชื่อเข้าใช้แล้ว ลงชื่อเข้าใช้:

Terminal window
curl -sS -X POST http://127.0.0.1:7860/api/v1/login \
-d username=admin --data-urlencode "password=$LANGFLOW_ADMIN_PASSWORD"
{"access_token":"[… omitted: the access token]","refresh_token":"[… omitted: the refresh token]","token_type":"bearer"}

สร้างคีย์ด้วยโทเค็นการเข้าถึง:

Terminal window
curl -sS -X POST http://127.0.0.1:7860/api/v1/api_key/ \
-H 'Authorization: Bearer <access_token>' -H 'Content-Type: application/json' -d '{"name": "test-it"}'
{"name":"test-it","last_used_at":null,"total_uses":0,"is_active":true,"id":"[… omitted: the key's identifier]","api_key":"[… omitted: the key]","user_id":"[… omitted: the owner's identifier]"}

และรัน flow ด้วยคีย์:

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"}'

การรันใช้ค่าตัวแทนแทนคีย์ OpenAI คำตอบจึงเป็นการที่ OpenAI ปฏิเสธคีย์ ซึ่งแสดงว่า flow รันไปได้ถึงการเรียกโมเดล:

{"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]}"}

เมื่อใช้คีย์ของคุณ การตอบกลับจะมีคำตอบของโมเดลอยู่ที่ outputs[0].outputs[0].results.message.text

บน Kubernetes เมื่อนำบิลด์ที่ บน Kubernetes อธิบายไปใช้แล้ว ส่งต่อพอร์ตภายในเครื่องไปยัง Service ของ Langflow คือ langflow-default ในเนมสเปซที่คุณนำไปใช้ และปล่อยให้คำสั่งรันต่อไป:

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

จากเทอร์มินัลอื่น คำขอสามรายการข้างต้นไปถึง Langflow ที่ที่อยู่เดิมโดยไม่ต้องแก้ไข การรันได้รับการปฏิเสธคีย์ตัวแทนเช่นเดียวกัน

หยุดสแตกด้วยคำสั่งด้านล่าง -v ยังลบวอลุ่มข้อมูลของ Langflow ไปด้วย รวมถึงบัญชีของผู้ดูแลระบบ คีย์ API และประวัติการรันของ flow:

Terminal window
docker compose -p basic-prompting -f dist/compose/docker-compose.yaml down -v

บน Kubernetes

flow เดียวกันนำเข้าสำหรับ Kubernetes ได้ด้วยเป้าหมาย helm ร่างสำหรับ Docker Compose อยู่ใน source แล้ว และการนำเข้าไม่เขียนทับ Aggregate ที่นั่นเลย จึงร่างชุดนี้ลงในโฟลเดอร์ของตัวเองด้วย --output-dir แล้วตรวจสอบความถูกต้องและบิลด์จากโฟลเดอร์นั้น:

Terminal window
aggrega import basic-prompting.json --target helm --output-dir helm
cd helm
aggrega validate --release release.yaml
aggrega build --release release.yaml

ร่างต่างกันตรงที่เป้าหมายต่างกัน Manifest แมปแพลตฟอร์มไปยัง helm/langflow แมปโมเดลไปยัง helm/openai และแมปข้อมูลลับแต่ละรายการไปยัง helm/k8s-existing-secret ซึ่งอ่านข้อมูลลับนั้นจาก Secret ที่มีอยู่แล้วในเนมสเปซ Release แนบข้อมูลลับสองรายการเป็น core/referenced-secret โดยแต่ละรายการระบุชื่อ Secret นั้น และชื่อเหล่านั้นคือสิ่งที่ไฟล์คำตอบเก็บไว้:

features:
admin_password:
type: core/referenced-secret
infra:
# Left for the Release, since the source cannot supply it: the name of a Kubernetes Secret already in the namespace holding, under the data key value, the administrator's password, read while values.require_authentication stays true.
origin: "langflow-admin"

หากไม่มีไฟล์คำตอบ การนำเข้าจะถามชื่อทั้งสองที่เทอร์มินัลและเขียนคำตอบของคุณลงในไฟล์คำตอบใหม่ ในกรณีที่ถามอะไรไม่ได้ การนำเข้าจะเขียนไฟล์นั้นโดยมีคีย์ทั้งสองและคำตอบว่างเปล่า แล้วจบด้วยสถานะ 1 และบรรทัดนี้ โดย <workspace> แทนโฟลเดอร์ที่คุณรัน:

2 values the drafts leave empty are still owed, listed in the answers file <workspace>/import-answers.yaml: write each beside its key there, then run the import again

บิลด์เขียนแมนิเฟสต์ Kubernetes แบบธรรมดาไว้ใต้ dist/helm/ ที่รูทของพื้นที่ทำงาน คือ source ซึ่งจาก helm คือ ../dist/helm/ สร้าง Secrets สองรายการในเนมสเปซที่คุณนำไปใช้ โดยแต่ละรายการเก็บค่าไว้ใต้คีย์ข้อมูล value แล้วนำโฟลเดอร์ไปใช้ตามที่ขั้นตอนรันใน วิธีที่การนำเข้าทำงาน อธิบายไว้