Skip to main content

Flow觸發端點

使用 /run/webhook 端點來執行 Flow。

要建立、讀取、更新和刪除 Flow,請參閱 Flow管理端點

執行 Flow

tip

AgentBuilder 會自動為所有 Flow生成 /v1/run/$FLOW_ID 端點的 Python、JavaScript 和 curl 程式碼片段。 有關更多資訊,請參閱 生成 API 程式碼片段

按 ID 或名稱執行指定的 Flow。 Flow ID 可以在 API access 窗格上的程式碼片段或 Flow的 URL 中找到。

以下範例使用請求主體中傳遞的FLOW參數執行 Basic Prompting 範本FLOW。 此FLOW需要聊天輸入字串 (input_value),並對所有其他參數使用預設值。


_12
curl -X POST \
_12
"$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID" \
_12
-H "Content-Type: application/json" \
_12
-H "x-api-key: $LANGFLOW_API_KEY" \
_12
-d '{
_12
"input_value": "Tell me about something interesting!",
_12
"session_id": "chat-123",
_12
"input_type": "chat",
_12
"output_type": "chat",
_12
"output_component": "",
_12
"tweaks": null
_12
}'

來自 /v1/run/$FLOW_ID 的回應包括執行的元資料、輸入和輸出。

Result

以下範例說明來自 Basic Prompting FLOW的回應:


_29
{
_29
"session_id": "chat-123",
_29
"outputs": [{
_29
"inputs": {
_29
"input_value": "Tell me about something interesting!"
_29
},
_29
"outputs": [{
_29
"results": {
_29
"message": {
_29
"text": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"? It's a fascinating natural occurrence where living organisms produce and emit light. This ability is found in various species, including certain types of jellyfish, fireflies, and deep-sea creatures like anglerfish.\n\nBioluminescence occurs through a chemical reaction in which a light-emitting molecule called luciferin reacts with oxygen, catalyzed by an enzyme called luciferase. The result is a beautiful glow that can serve various purposes, such as attracting mates, deterring predators, or luring prey.\n\nOne of the most stunning displays of bioluminescence can be seen in the ocean, where certain plankton emit light when disturbed, creating a mesmerizing blue glow in the water. This phenomenon is often referred to as \"sea sparkle\" and can be seen in coastal areas around the world.\n\nBioluminescence not only captivates our imagination but also has practical applications in science and medicine, including the development of biosensors and imaging techniques. It's a remarkable example of nature's creativity and complexity!",
_29
"sender": "Machine",
_29
"sender_name": "AI",
_29
"session_id": "chat-123",
_29
"timestamp": "2025-03-03T17:17:37+00:00",
_29
"flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201",
_29
"properties": {
_29
"source": {
_29
"id": "OpenAIModel-d1wOZ",
_29
"display_name": "OpenAI",
_29
"source": "gpt-4o-mini"
_29
},
_29
"icon": "OpenAI"
_29
},
_29
"component_id": "ChatOutput-ylMzN"
_29
}
_29
}
_29
}]
_29
}]
_29
}

如果您在應用程式中解析回應,您很可能需要從回應中提取相關內容,而不是將整個回應傳回給使用者。 有關從 AgentBuilder API 回應中提取資料的腳本範例,請參閱 快速入門

串流 LLM 權杖回應

使用 /v1/run/$FLOW_ID,FLOW作為批次執行,具有可選的 LLM 權杖回應串流。

要串流 LLM 權杖回應,請將 ?stream=true 查詢參數附加到請求:


_10
curl -X POST \
_10
"$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID?stream=true" \
_10
-H "accept: application/json" \
_10
-H "Content-Type: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
-d '{
_10
"message": "Tell me something interesting!",
_10
"session_id": "chat-123"
_10
}'

LLM 聊天回應作為 token 事件串流回來,最終以關閉連接的 end 事件結束。

Result

以下範例被截斷以說明一系列 token 事件以及關閉 LLM 權杖串流回應的最終 end 事件:


_19
{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "User", "sender_name": "User", "session_id": "chat-123", "text": "Tell me about something interesting!", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": null, "display_name": null, "source": null}, "icon": "", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "0103a21b-ebf7-4c02-9d72-017fb297f812", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}
_19
_19
{"event": "add_message", "data": {"timestamp": "2025-03-03T17:20:18", "sender": "Machine", "sender_name": "AI", "session_id": "chat-123", "text": "", "files": [], "error": false, "edit": false, "properties": {"text_color": "", "background_color": "", "edited": false, "source": {"id": "OpenAIModel-d1wOZ", "display_name": "OpenAI", "source": "gpt-4o-mini"}, "icon": "OpenAI", "allow_markdown": false, "positive_feedback": null, "state": "complete", "targets": []}, "category": "message", "content_blocks": [], "id": "27b66789-e673-4c65-9e81-021752925161", "flow_id": "d2bbd92b-187e-4c84-b2d4-5df365704201"}}
_19
_19
{"event": "token", "data": {"chunk": " Have", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " you", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " ever", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " heard", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " of", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " the", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "token", "data": {"chunk": " phenomenon", "id": "27b66789-e673-4c65-9e81-021752925161", "timestamp": "2025-03-03 17:20:18 UTC"}}
_19
_19
{"event": "end", "data": {"result": {"session_id": "chat-123", "message": "Sure! Have you ever heard of the phenomenon known as \"bioluminescence\"?..."}}}

執行端點標頭

標頭資訊範例
Content-Type必要。指定 JSON 格式。"application/json"
accept可選。指定回應格式。"application/json"
x-api-key可選。僅在啟用驗證時需要。"sk-..."

執行端點參數

參數類型資訊
flow_idUUID/string必要。URL 的一部分:/run/$FLOW_ID
streamBoolean可選。查詢參數:/run/$FLOW_ID?stream=true
input_valuestring可選。JSON 主體欄位。主要輸入文字/提示。預設:null
input_typestring可選。JSON 主體欄位。輸入類型 ("chat" 或 "text")。預設:"chat"
output_typestring可選。JSON 主體欄位。輸出類型 ("chat", "any", "debug")。預設:"chat"
output_componentstring可選。JSON 主體欄位。輸出的目標Components。預設:""
tweaksobject可選。JSON 主體欄位。Components調整。預設:null
session_idstring可選。JSON 主體欄位。對話上下文 ID。請參閱 工作階段 ID。預設:null

包含所有標頭和參數的請求範例


_17
curl -X POST \
_17
"$LANGFLOW_SERVER_URL/api/v1/run/$FLOW_ID?stream=true" \
_17
-H "Content-Type: application/json" \
_17
-H "accept: application/json" \
_17
-H "x-api-key: $LANGFLOW_API_KEY" \
_17
-d '{
_17
"input_value": "Tell me a story",
_17
"input_type": "chat",
_17
"output_type": "chat",
_17
"output_component": "chat_output",
_17
"session_id": "chat-123",
_17
"tweaks": {
_17
"component_id": {
_17
"parameter_name": "value"
_17
}
_17
}
_17
}'

Webhook 執行FLOW

使用 /webhook 端點通過發送 HTTP POST 請求來啟動FLOW。

tip

在您將 Webhook Components 新增到FLOW後,打開 API access 窗格,然後點擊 Webhook curl 標籤以獲取為您的FLOW自動生成的 POST /webhook 請求。 有關更多資訊,請參閱 使用 webhooks 觸發FLOW


_10
curl -X POST \
_10
"$LANGFLOW_SERVER_URL/api/v1/webhook/$FLOW_ID" \
_10
-H "Content-Type: application/json" \
_10
-H "x-api-key: $LANGFLOW_API_KEY" \
_10
-d '{"data": "example-data"}'

Result

_10
{
_10
"message": "Task started in the background",
_10
"status": "in progress"
_10
}

已棄用的FLOW觸發端點

以下端點已棄用並由 /run 端點替換:

  • /process
  • /predict
Search