mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 10:00:11 -04:00
Co-authored-by: Blackoutta <hyytez@gmail.com> Co-authored-by: QuantumGhost <QuantumGhost@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
1626 lines
82 KiB
Plaintext
1626 lines
82 KiB
Plaintext
import { CodeGroup } from '../code.tsx'
|
||
import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
|
||
|
||
# ワークフローアプリ API
|
||
|
||
ワークフローアプリケーションは、セッションをサポートせず、翻訳、記事作成、要約 AI などに最適です。
|
||
|
||
<div>
|
||
### ベース URL
|
||
<CodeGroup title="コード" targetCode={props.appDetail.api_base_url} />
|
||
|
||
### 認証
|
||
|
||
サービス API は `API-Key` 認証を使用します。
|
||
<i>**API キーの漏洩を防ぐため、API キーはクライアント側で共有または保存せず、サーバー側で保存することを強くお勧めします。**</i>
|
||
|
||
すべての API リクエストにおいて、以下のように `Authorization`HTTP ヘッダーに API キーを含めてください:
|
||
|
||
<CodeGroup title="コード" targetCode='Authorization: Bearer {API_KEY}' />
|
||
</div>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/workflows/run'
|
||
method='POST'
|
||
title='ワークフローを実行'
|
||
name='#Execute-Workflow'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
ワークフローを実行します。公開されたワークフローがないと実行できません。
|
||
|
||
### リクエストボディ
|
||
- `inputs` (object) 必須
|
||
アプリで定義されたさまざまな変数値の入力を許可します。
|
||
`inputs`パラメータには複数のキー/値ペアが含まれ、各キーは特定の変数に対応し、各値はその変数の特定の値です。
|
||
ワークフローアプリケーションは少なくとも1つのキー/値ペアの入力を必要とします。値はファイルリストである場合もあります。
|
||
ファイルリストは、テキスト理解と質問への回答を組み合わせたファイルの入力に適しています。モデルがファイルの解析と理解機能をサポートしている場合にのみ使用できます。
|
||
|
||
変数がファイルリストの場合、リストの各要素は以下の属性を持つ必要があります。
|
||
- `type` (string) サポートされるタイプ:
|
||
- `document` サポートされるタイプには以下が含まれます:'TXT', 'MD', 'MARKDOWN', 'MDX', 'PDF', 'HTML', 'XLSX', 'XLS', 'VTT', 'PROPERTIES', 'DOC', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
|
||
- `image` サポートされるタイプには以下が含まれます:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
|
||
- `audio` サポートされるタイプには以下が含まれます:'MP3', 'M4A', 'WAV', 'WEBM', 'MPGA'
|
||
- `video` サポートされるタイプには以下が含まれます:'MP4', 'MOV', 'MPEG', 'WEBM'
|
||
- `custom` サポートされるタイプには以下が含まれます:その他のファイルタイプ
|
||
- `transfer_method` (string) 転送方法:
|
||
- `remote_url`: ファイルのURL。
|
||
- `local_file`: ファイルをアップロード。
|
||
- `url` ファイルのURL。(転送方法が `remote_url` の場合のみ)。
|
||
- `upload_file_id` アップロードされたファイルID。(転送方法が `local_file` の場合のみ)。
|
||
|
||
- `response_mode` (string) 必須
|
||
応答の返却モードを指定します。サポートされているモード:
|
||
- `streaming` ストリーミングモード(推奨)、SSE([Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events))を通じてタイプライターのような出力を実装します。
|
||
- `blocking` ブロッキングモード、実行完了後に結果を返します。(プロセスが長い場合、リクエストが中断される可能性があります)
|
||
<i>Cloudflare の制限により、100 秒後に応答がない場合、リクエストは中断されます。</i>
|
||
- `user` (string) 必須
|
||
ユーザー識別子、エンドユーザーのアイデンティティを定義するために使用されます。
|
||
アプリケーション内で開発者によって一意に定義される必要があります。
|
||
- `files` (array[object]) オプション
|
||
- `trace_id` (string) オプション
|
||
トレースID。既存の業務システムのトレースコンポーネントと連携し、エンドツーエンドの分散トレーシングを実現するために使用します。指定がない場合、システムが自動的に trace_id を生成します。以下の3つの方法で渡すことができ、優先順位は次のとおりです:
|
||
1. Header:HTTPヘッダー `X-Trace-Id` で渡す(最優先)。
|
||
2. クエリパラメータ:URLクエリパラメータ `trace_id` で渡す。
|
||
3. リクエストボディ:リクエストボディの `trace_id` フィールドで渡す(本フィールド)。
|
||
|
||
|
||
### 応答
|
||
`response_mode`が`blocking`の場合、CompletionResponse オブジェクトを返します。
|
||
`response_mode`が`streaming`の場合、ChunkCompletionResponse ストリームを返します。
|
||
|
||
### CompletionResponse
|
||
アプリの結果を返します。`Content-Type`は`application/json`です。
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `data` (object) 結果の詳細
|
||
- `id` (string) ワークフロー実行の ID
|
||
- `workflow_id` (string) 関連するワークフローの ID
|
||
- `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `outputs` (json) オプションの出力内容
|
||
- `error` (string) オプションのエラー理由
|
||
- `elapsed_time` (float) オプションの使用時間(秒)
|
||
- `total_tokens` (int) オプションの使用トークン数
|
||
- `total_steps` (int) デフォルト 0
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
|
||
### ChunkCompletionResponse
|
||
アプリによって出力されたストリームチャンクを返します。`Content-Type`は`text/event-stream`です。
|
||
各ストリーミングチャンクは`data:`で始まり、2 つの改行文字`\n\n`で区切られます。以下のように表示されます:
|
||
<CodeGroup>
|
||
```streaming {{ title: '応答' }}
|
||
data: {"event": "text_chunk", "workflow_run_id": "b85e5fc5-751b-454d-b14e-dc5f240b0a31", "task_id": "bd029338-b068-4d34-a331-fc85478922c2", "data": {"text": "\u4e3a\u4e86", "from_variable_selector": ["1745912968134", "text"]}}\n\n
|
||
```
|
||
</CodeGroup>
|
||
ストリーミングチャンクの構造は`event`に応じて異なります:
|
||
- `event: workflow_started` ワークフローが実行を開始
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `workflow_started`に固定
|
||
- `data` (object) 詳細
|
||
- `id` (string) ワークフロー実行の一意の ID
|
||
- `workflow_id` (string) 関連するワークフローの ID
|
||
- `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
|
||
- `event: node_started` ノード実行開始
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `node_started`に固定
|
||
- `data` (object) 詳細
|
||
- `id` (string) ワークフロー実行の一意の ID
|
||
- `node_id` (string) ノードの ID
|
||
- `node_type` (string) ノードのタイプ
|
||
- `title` (string) ノードの名前
|
||
- `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
|
||
- `predecessor_node_id` (string) オプションのプレフィックスノード ID、キャンバス表示実行パスに使用
|
||
- `inputs` (object) ノードで使用されるすべての前のノード変数の内容
|
||
- `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
|
||
- `event: text_chunk` テキストフラグメント
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `text_chunk`に固定
|
||
- `data` (object) 詳細
|
||
- `text` (string) テキスト内容
|
||
- `from_variable_selector` (array) テキスト生成元パス(開発者がどのノードのどの変数から生成されたかを理解するための情報)
|
||
- `event: node_finished` ノード実行終了、同じイベントで異なる状態で成功または失敗
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `node_finished`に固定
|
||
- `data` (object) 詳細
|
||
- `id` (string) ワークフロー実行の一意の ID
|
||
- `node_id` (string) ノードの ID
|
||
- `node_type` (string) ノードのタイプ
|
||
- `title` (string) ノードの名前
|
||
- `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
|
||
- `predecessor_node_id` (string) オプションのプレフィックスノード ID、キャンバス表示実行パスに使用
|
||
- `inputs` (object) ノードで使用されるすべての前のノード変数の内容
|
||
- `process_data` (json) オプションのノードプロセスデータ
|
||
- `outputs` (json) オプションの出力内容
|
||
- `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `error` (string) オプションのエラー理由
|
||
- `elapsed_time` (float) オプションの使用時間(秒)
|
||
- `execution_metadata` (json) メタデータ
|
||
- `total_tokens` (int) オプションの使用トークン数
|
||
- `total_price` (decimal) オプションの総コスト
|
||
- `currency` (string) オプション 例:`USD` / `RMB`
|
||
- `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
|
||
- `event: human_input_required` ワークフローが一時停止し、Human-in-the-Loop 入力が必要
|
||
- `task_id` (string) タスク ID、リクエスト追跡に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `human_input_required`に固定
|
||
- `data` (object) 詳細
|
||
- `form_id` (string) ヒューマン入力フォーム ID
|
||
- `node_id` (string) Human Input ノード ID
|
||
- `node_title` (string) Human Input ノードタイトル
|
||
- `form_content` (string) レンダリング済みフォーム内容
|
||
- `inputs` (array[object]) フォーム入力項目の定義
|
||
- `actions` (array[object]) ユーザーが選択できるアクションボタン
|
||
- `id` (string) アクション ID
|
||
- `title` (string) ボタンラベル
|
||
- `button_style` (string) ボタンスタイル
|
||
- `display_in_ui` (bool) UI にこのフォームを表示するかどうか
|
||
- `form_token` (string) `/form/human_input/:form_token` API で使用するトークン
|
||
- `resolved_default_values` (object) 実行時に解決されたデフォルト値
|
||
- `expiration_time` (timestamp) フォームの有効期限(Unix 秒)
|
||
- `event: workflow_finished` ワークフロー実行終了、同じイベントで異なる状態で成功または失敗
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
|
||
- `workflow_run_id` (string) ワークフロー実行の一意の ID
|
||
- `event` (string) `workflow_finished`に固定
|
||
- `data` (object) 詳細
|
||
- `id` (string) ワークフロー実行の ID
|
||
- `workflow_id` (string) 関連するワークフローの ID
|
||
- `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `outputs` (json) オプションの出力内容
|
||
- `error` (string) オプションのエラー理由
|
||
- `elapsed_time` (float) オプションの使用時間(秒)
|
||
- `total_tokens` (int) オプションの使用トークン数
|
||
- `total_steps` (int) デフォルト 0
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
- `event: tts_message` TTS オーディオストリームイベント、つまり音声合成出力。内容は Mp3 形式のオーディオブロックで、base64 文字列としてエンコードされています。再生時には、base64 をデコードしてプレーヤーに入力するだけです。(このメッセージは自動再生が有効な場合にのみ利用可能)
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `message_id` (string) 一意のメッセージ ID
|
||
- `audio` (string) 音声合成後のオーディオ、base64 テキストコンテンツとしてエンコードされており、再生時には base64 をデコードしてプレーヤーに入力するだけです
|
||
- `created_at` (int) 作成タイムスタンプ、例:1705395332
|
||
- `event: tts_message_end` TTS オーディオストリーム終了イベント。このイベントを受信すると、オーディオストリームの終了を示します。
|
||
- `task_id` (string) タスク ID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `message_id` (string) 一意のメッセージ ID
|
||
- `audio` (string) 終了イベントにはオーディオがないため、これは空の文字列です
|
||
- `created_at` (int) 作成タイムスタンプ、例:1705395332
|
||
- `event: ping` 接続を維持するために 10 秒ごとに送信される Ping イベント。
|
||
|
||
### エラー
|
||
- 400, `invalid_param`, 異常なパラメータ入力
|
||
- 400, `app_unavailable`, アプリの設定が利用できません
|
||
- 400, `provider_not_initialize`, 利用可能なモデル資格情報の設定がありません
|
||
- 400, `provider_quota_exceeded`, モデル呼び出しのクォータが不足しています
|
||
- 400, `model_currently_not_support`, 現在のモデルは利用できません
|
||
- 400, `workflow_request_error`, ワークフロー実行に失敗しました
|
||
- 500, 内部サーバーエラー
|
||
|
||
</Col>
|
||
<Col sticky>
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="POST"
|
||
label="/workflows/run"
|
||
targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/run' \\
|
||
--header 'Authorization: Bearer {api_key}' \\
|
||
--header 'Content-Type: application/json' \\
|
||
--data-raw '{
|
||
"inputs": ${JSON.stringify(props.inputs)},
|
||
"response_mode": "streaming",
|
||
"user": "abc-123"
|
||
}'`}
|
||
/>
|
||
<CodeGroup title="ファイル変数の例">
|
||
```json {{ title: 'ファイル変数の例' }}
|
||
{
|
||
"inputs": {
|
||
"{variable_name}":
|
||
[
|
||
{
|
||
"transfer_method": "local_file",
|
||
"upload_file_id": "{upload_file_id}",
|
||
"type": "{document_type}"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
### ブロッキングモード
|
||
ブロッキングモードでは、完了済みのワークフロー結果、または一時停止中のワークフロー結果のいずれかが返されます。
|
||
|
||
Human-in-the-Loop で実行が一時停止した場合も、レスポンスには `workflow_run_id` と `task_id` が含まれますが、`data.status` は `paused` になります。
|
||
一時停止レスポンスには `paused_nodes` と `reasons` も含まれます。`human_input_required` の各 reason には `form_id` と `expiration_time` が含まれます。
|
||
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"workflow_run_id": "djflajgkldjgd",
|
||
"task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
|
||
"data": {
|
||
"id": "fdlsjfjejkghjda",
|
||
"workflow_id": "fldjaslkfjlsda",
|
||
"status": "succeeded",
|
||
"outputs": {
|
||
"text": "Nice to meet you."
|
||
},
|
||
"error": null,
|
||
"elapsed_time": 0.875,
|
||
"total_tokens": 3562,
|
||
"total_steps": 8,
|
||
"created_at": 1705407629,
|
||
"finished_at": 1727807631
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
<CodeGroup title="一時停止レスポンス例">
|
||
```json {{ title: '一時停止レスポンス例' }}
|
||
{
|
||
"task_id": "3938b985-f4c6-4806-87b6-215e0aca9d81",
|
||
"workflow_run_id": "4a80f375-682b-49c5-b199-e950aac4968f",
|
||
"data": {
|
||
"id": "4a80f375-682b-49c5-b199-e950aac4968f",
|
||
"workflow_id": "e46514f1-c008-41ff-94b0-4f33d4b97d36",
|
||
"status": "paused",
|
||
"outputs": {},
|
||
"error": null,
|
||
"elapsed_time": 0.035667,
|
||
"total_tokens": 0,
|
||
"total_steps": 2,
|
||
"created_at": 1776074783,
|
||
"finished_at": null,
|
||
"paused_nodes": [
|
||
"1775717346519"
|
||
],
|
||
"reasons": [
|
||
{
|
||
"form_id": "019d864e-7a36-74a2-b94e-e5660c47f5a7",
|
||
"form_content": "this is form 1:\n{{#$output.some_field#}}\n",
|
||
"inputs": [
|
||
{
|
||
"type": "paragraph",
|
||
"output_variable_name": "some_field",
|
||
"default": {
|
||
"type": "variable",
|
||
"selector": [
|
||
"sys",
|
||
"workflow_run_id"
|
||
],
|
||
"value": ""
|
||
}
|
||
}
|
||
],
|
||
"actions": [
|
||
{
|
||
"id": "approve",
|
||
"title": "YES",
|
||
"button_style": "default"
|
||
},
|
||
{
|
||
"id": "reject",
|
||
"title": "NO",
|
||
"button_style": "default"
|
||
}
|
||
],
|
||
"display_in_ui": true,
|
||
"node_id": "1775717346519",
|
||
"node_title": "Human Input",
|
||
"resolved_default_values": {
|
||
"some_field": "4a80f375-682b-49c5-b199-e950aac4968f"
|
||
},
|
||
"form_token": "SZwvfmL47fTIsZynP2Jr9i",
|
||
"type": "human_input_required",
|
||
"expiration_time": 1776333983
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
### ストリーミングモード
|
||
<CodeGroup title="応答">
|
||
```streaming {{ title: '応答' }}
|
||
data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
|
||
data: {"event": "node_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "created_at": 1679586595}}
|
||
data: {"event": "node_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "execution_metadata": {"total_tokens": 63127864, "total_price": 2.378, "currency": "USD"}, "created_at": 1679586595}}
|
||
data: {"event": "workflow_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "total_tokens": 63127864, "total_steps": "1", "created_at": 1679586595, "finished_at": 1679976595}}
|
||
data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
|
||
data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
|
||
```
|
||
</CodeGroup>
|
||
ストリーミングモードでも Human-in-the-Loop により一時停止する場合があります。その場合、SSE ストリームではまず `human_input_required` が送られ、その後に `workflow_paused` が送られます。
|
||
|
||
<CodeGroup title="一時停止ストリーミングレスポンス例">
|
||
```streaming {{ title: '一時停止ストリーミングレスポンス例' }}
|
||
event: ping
|
||
|
||
data: {
|
||
"event": "workflow_started",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"workflow_id": "e46514f1-c008-41ff-94b0-4f33d4b97d36",
|
||
"inputs": {
|
||
"sys.files": [],
|
||
"sys.user_id": "abc-123",
|
||
"sys.app_id": "d1074979-f67e-4114-8691-e35878df9a89",
|
||
"sys.workflow_id": "e46514f1-c008-41ff-94b0-4f33d4b97d36",
|
||
"sys.workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345"
|
||
},
|
||
"created_at": 1776129228,
|
||
"reason": "initial"
|
||
}
|
||
}
|
||
|
||
data: {
|
||
"event": "node_started",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"id": "7d9bb041-5ecb-497f-a674-d8706eed0ab1",
|
||
"node_id": "1775717266623",
|
||
"node_type": "start",
|
||
"title": "User Input",
|
||
"index": 1,
|
||
"predecessor_node_id": null,
|
||
"inputs": null,
|
||
"inputs_truncated": false,
|
||
"created_at": 1776129228,
|
||
"extras": {},
|
||
"iteration_id": null,
|
||
"loop_id": null,
|
||
"agent_strategy": null
|
||
}
|
||
}
|
||
|
||
data: {
|
||
"event": "node_finished",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"id": "7d9bb041-5ecb-497f-a674-d8706eed0ab1",
|
||
"node_id": "1775717266623",
|
||
"node_type": "start",
|
||
"title": "User Input",
|
||
"index": 1,
|
||
"predecessor_node_id": null,
|
||
"inputs": {
|
||
"sys.files": [],
|
||
"sys.user_id": "abc-123",
|
||
"sys.app_id": "d1074979-f67e-4114-8691-e35878df9a89",
|
||
"sys.workflow_id": "e46514f1-c008-41ff-94b0-4f33d4b97d36",
|
||
"sys.workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"sys.timestamp": 1776129228
|
||
},
|
||
"inputs_truncated": false,
|
||
"process_data": {},
|
||
"process_data_truncated": false,
|
||
"outputs": {
|
||
"sys.files": [],
|
||
"sys.user_id": "abc-123",
|
||
"sys.app_id": "d1074979-f67e-4114-8691-e35878df9a89",
|
||
"sys.workflow_id": "e46514f1-c008-41ff-94b0-4f33d4b97d36",
|
||
"sys.workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"sys.timestamp": 1776129228
|
||
},
|
||
"outputs_truncated": false,
|
||
"status": "succeeded",
|
||
"error": null,
|
||
"elapsed_time": 0.000097,
|
||
"execution_metadata": null,
|
||
"created_at": 1776129228,
|
||
"finished_at": 1776129228,
|
||
"files": [],
|
||
"iteration_id": null,
|
||
"loop_id": null
|
||
}
|
||
}
|
||
|
||
data: {
|
||
"event": "node_started",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"id": "c09ff568-1d55-4f0d-9a07-512bcbfeb289",
|
||
"node_id": "1775717346519",
|
||
"node_type": "human-input",
|
||
"title": "Human Input",
|
||
"index": 1,
|
||
"predecessor_node_id": null,
|
||
"inputs": null,
|
||
"inputs_truncated": false,
|
||
"created_at": 1776129228,
|
||
"extras": {},
|
||
"iteration_id": null,
|
||
"loop_id": null,
|
||
"agent_strategy": null
|
||
}
|
||
}
|
||
|
||
data: {
|
||
"event": "human_input_required",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"form_id": "019d898d-3d80-7105-b920-9899ead4ff3e",
|
||
"node_id": "1775717346519",
|
||
"node_title": "Human Input",
|
||
"form_content": "this is form 1:\n{{#$output.some_field#}}\n",
|
||
"inputs": [
|
||
{
|
||
"type": "paragraph",
|
||
"output_variable_name": "some_field",
|
||
"default": {
|
||
"type": "variable",
|
||
"selector": [
|
||
"sys",
|
||
"workflow_run_id"
|
||
],
|
||
"value": ""
|
||
}
|
||
}
|
||
],
|
||
"actions": [
|
||
{
|
||
"id": "approve",
|
||
"title": "YES",
|
||
"button_style": "default"
|
||
},
|
||
{
|
||
"id": "reject",
|
||
"title": "NO",
|
||
"button_style": "default"
|
||
}
|
||
],
|
||
"display_in_ui": true,
|
||
"form_token": "0Tb1nXYe4hzQUD706nHB4y",
|
||
"resolved_default_values": {
|
||
"some_field": "a4959eb4-c852-4e0c-ac7a-348233f7f345"
|
||
},
|
||
"expiration_time": 1776388428
|
||
}
|
||
}
|
||
|
||
data: {
|
||
"event": "workflow_paused",
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"task_id": "0399c5c2-181b-4493-a78e-1421914e8a25",
|
||
"data": {
|
||
"workflow_run_id": "a4959eb4-c852-4e0c-ac7a-348233f7f345",
|
||
"paused_nodes": [
|
||
"1775717346519"
|
||
],
|
||
"outputs": {},
|
||
"reasons": [
|
||
{
|
||
"form_id": "019d898d-3d80-7105-b920-9899ead4ff3e",
|
||
"form_content": "this is form 1:\n{{#$output.some_field#}}\n",
|
||
"inputs": [
|
||
{
|
||
"type": "paragraph",
|
||
"output_variable_name": "some_field",
|
||
"default": {
|
||
"type": "variable",
|
||
"selector": [
|
||
"sys",
|
||
"workflow_run_id"
|
||
],
|
||
"value": ""
|
||
}
|
||
}
|
||
],
|
||
"actions": [
|
||
{
|
||
"id": "approve",
|
||
"title": "YES",
|
||
"button_style": "default"
|
||
},
|
||
{
|
||
"id": "reject",
|
||
"title": "NO",
|
||
"button_style": "default"
|
||
}
|
||
],
|
||
"display_in_ui": true,
|
||
"node_id": "1775717346519",
|
||
"node_title": "Human Input",
|
||
"resolved_default_values": {
|
||
"some_field": "a4959eb4-c852-4e0c-ac7a-348233f7f345"
|
||
},
|
||
"form_token": "0Tb1nXYe4hzQUD706nHB4y",
|
||
"type": "human_input_required",
|
||
"expiration_time": 1776388428
|
||
}
|
||
],
|
||
"status": "paused",
|
||
"created_at": 1776129228,
|
||
"elapsed_time": 0.070478,
|
||
"total_tokens": 0,
|
||
"total_steps": 2
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
<CodeGroup title="ファイルアップロードのサンプルコード">
|
||
```json {{ title: 'ファイルアップロードのサンプルコード' }}
|
||
import requests
|
||
import json
|
||
|
||
def upload_file(file_path, user):
|
||
upload_url = "https://api.dify.ai/v1/files/upload"
|
||
headers = {
|
||
"Authorization": "Bearer app-xxxxxxxx",
|
||
}
|
||
|
||
try:
|
||
print("ファイルをアップロードしています...")
|
||
with open(file_path, 'rb') as file:
|
||
files = {
|
||
'file': (file_path, file, 'text/plain') # ファイルが適切な MIME タイプでアップロードされていることを確認してください
|
||
}
|
||
data = {
|
||
"user": user,
|
||
"type": "TXT" # ファイルタイプをTXTに設定します
|
||
}
|
||
|
||
response = requests.post(upload_url, headers=headers, files=files, data=data)
|
||
if response.status_code == 201: # 201 は作成が成功したことを意味します
|
||
print("ファイルが正常にアップロードされました")
|
||
return response.json().get("id") # アップロードされたファイルIDを取得する
|
||
else:
|
||
print(f"ファイルのアップロードに失敗しました。ステータス コード: {response.status_code}")
|
||
return None
|
||
except Exception as e:
|
||
print(f"エラーが発生しました: {str(e)}")
|
||
return None
|
||
|
||
def run_workflow(file_id, user, response_mode="blocking"):
|
||
workflow_url = "https://api.dify.ai/v1/workflows/run"
|
||
headers = {
|
||
"Authorization": "Bearer app-xxxxxxxxx",
|
||
"Content-Type": "application/json"
|
||
}
|
||
|
||
data = {
|
||
"inputs": {
|
||
"orig_mail": [{
|
||
"transfer_method": "local_file",
|
||
"upload_file_id": file_id,
|
||
"type": "document"
|
||
}]
|
||
},
|
||
"response_mode": response_mode,
|
||
"user": user
|
||
}
|
||
|
||
try:
|
||
print("ワークフローを実行...")
|
||
response = requests.post(workflow_url, headers=headers, json=data)
|
||
if response.status_code == 200:
|
||
print("ワークフローが正常に実行されました")
|
||
return response.json()
|
||
else:
|
||
print(f"ワークフローの実行がステータス コードで失敗しました: {response.status_code}")
|
||
return {"status": "error", "message": f"Failed to execute workflow, status code: {response.status_code}"}
|
||
except Exception as e:
|
||
print(f"エラーが発生しました: {str(e)}")
|
||
return {"status": "error", "message": str(e)}
|
||
|
||
# 使用例
|
||
file_path = "{your_file_path}"
|
||
user = "difyuser"
|
||
|
||
# ファイルをアップロードする
|
||
file_id = upload_file(file_path, user)
|
||
if file_id:
|
||
# ファイルは正常にアップロードされました。ワークフローの実行を続行します
|
||
result = run_workflow(file_id, user)
|
||
print(result)
|
||
else:
|
||
print("ファイルのアップロードに失敗し、ワークフローを実行できません")
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/workflows/:workflow_id/run'
|
||
method='POST'
|
||
title='特定バージョンのワークフローを実行'
|
||
name='#Execute-Specific-Workflow'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
パスパラメータでワークフローIDを指定して、特定バージョンのワークフローを実行します。
|
||
|
||
### パス
|
||
- `workflow_id` (string) 必須 特定バージョンのワークフローを指定するためのワークフローID
|
||
|
||
取得方法:バージョン履歴インターフェースで、各バージョンエントリの右側にあるコピーアイコンをクリックすると、完全なワークフローIDをコピーできます。
|
||
|
||
### リクエストボディ
|
||
- `inputs` (object) 必須
|
||
App で定義された各変数値を入力できます。
|
||
inputs パラメータには複数のキー/値ペアが含まれており、各キーは特定の変数に対応し、各値はその変数の具体的な値です。変数はファイルリスト型にすることができます。
|
||
ファイルリスト型変数は、ファイルをテキスト理解と組み合わせて質問に答えるために入力するのに適しており、モデルがファイル解析機能をサポートしている場合のみ使用できます。変数がファイルリスト型の場合、その変数に対応する値はリスト形式である必要があり、各要素には以下の内容が含まれます:
|
||
- `type` (string) サポートされるタイプ:
|
||
- `document` 具体的なタイプには以下が含まれます:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
|
||
- `image` 具体的なタイプには以下が含まれます:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
|
||
- `audio` 具体的なタイプには以下が含まれます:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
|
||
- `video` 具体的なタイプには以下が含まれます:'MP4', 'MOV', 'MPEG', 'MPGA'
|
||
- `custom` 具体的なタイプには以下が含まれます:その他のファイルタイプ
|
||
- `transfer_method` (string) 転送方法、`remote_url` 画像URL / `local_file` ファイルアップロード
|
||
- `url` (string) 画像URL(転送方法が `remote_url` の場合のみ)
|
||
- `upload_file_id` (string) アップロードされたファイルID(転送方法が `local_file` の場合のみ)
|
||
- `response_mode` (string) 必須
|
||
応答返却モード、以下をサポート:
|
||
- `streaming` ストリーミングモード(推奨)。SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)をベースにタイプライター風の出力を実現。
|
||
- `blocking` ブロッキングモード、実行完了後に結果を返却。(プロセスが長い場合、リクエストが中断される可能性があります)。
|
||
<i>Cloudflare の制限により、100秒後に応答がない場合、リクエストは中断されます。</i>
|
||
- `user` (string) 必須
|
||
ユーザー識別子、エンドユーザーのアイデンティティを定義し、検索・統計を容易にするために使用されます。
|
||
開発者が定義するルールで、アプリケーション内でユーザー識別子が一意である必要があります。API は WebApp で作成されたセッションにアクセスできません。
|
||
- `files` (array[object]) オプション
|
||
- `trace_id` (string) オプション
|
||
トレースID。既存のビジネスシステムのトレースコンポーネントと統合して、エンドツーエンドの分散トレーシングを実現するために使用されます。指定されていない場合、システムは自動的に `trace_id` を生成します。以下の3つの方法で渡すことができ、優先順位は以下の通りです:
|
||
1. ヘッダー:HTTP ヘッダー `X-Trace-Id` で渡すことを推奨、最高優先度。
|
||
2. クエリパラメータ:URL クエリパラメータ `trace_id` で渡す。
|
||
3. リクエストボディ:リクエストボディフィールド `trace_id` で渡す(つまり、このフィールド)。
|
||
|
||
### 応答
|
||
`response_mode` が `blocking` の場合、CompletionResponse オブジェクトを返します。
|
||
`response_mode` が `streaming` の場合、ChunkCompletionResponse オブジェクトのストリーミングシーケンスを返します。
|
||
|
||
### CompletionResponse
|
||
完全な App 結果を返し、`Content-Type` は `application/json` です。
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `data` (object) 詳細内容
|
||
- `id` (string) ワークフロー実行ID
|
||
- `workflow_id` (string) 関連するワークフローID
|
||
- `status` (string) 実行ステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `outputs` (json) オプション 出力内容
|
||
- `error` (string) オプション エラー理由
|
||
- `elapsed_time` (float) オプション 使用時間(s)
|
||
- `total_tokens` (int) オプション 使用されるトークンの総数
|
||
- `total_steps` (int) 総ステップ数(冗長)、デフォルト 0
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
|
||
### ChunkCompletionResponse
|
||
App の出力ストリーミングチャンクを返し、`Content-Type` は `text/event-stream` です。
|
||
各ストリーミングチャンクは `data:` で始まり、チャンク間は `\n\n` つまり2つの改行文字で区切られます。以下のようになります:
|
||
<CodeGroup>
|
||
```streaming {{ title: '応答' }}
|
||
data: {"event": "text_chunk", "workflow_run_id": "b85e5fc5-751b-454d-b14e-dc5f240b0a31", "task_id": "bd029338-b068-4d34-a331-fc85478922c2", "data": {"text": "\u4e3a\u4e86", "from_variable_selector": ["1745912968134", "text"]}}\n\n
|
||
```
|
||
</CodeGroup>
|
||
ストリーミングチャンクは `event` によって構造が異なり、以下のタイプが含まれます:
|
||
- `event: workflow_started` ワークフロー実行開始
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `event` (string) `workflow_started` に固定
|
||
- `data` (object) 詳細内容
|
||
- `id` (string) ワークフロー実行ID
|
||
- `workflow_id` (string) 関連するワークフローID
|
||
- `created_at` (timestamp) 開始時間
|
||
- `event: node_started` ノード実行開始
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `event` (string) `node_started` に固定
|
||
- `data` (object) 詳細内容
|
||
- `id` (string) ワークフロー実行ID
|
||
- `node_id` (string) ノードID
|
||
- `node_type` (string) ノードタイプ
|
||
- `title` (string) ノード名
|
||
- `index` (int) 実行シーケンス番号、Tracing Node シーケンスの表示に使用
|
||
- `predecessor_node_id` (string) 前置ノードID、キャンバス表示実行パスに使用
|
||
- `inputs` (object) ノードで使用されるすべての前置ノード変数の内容
|
||
- `created_at` (timestamp) 開始時間
|
||
- `event: text_chunk` テキストフラグメント
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `event` (string) `text_chunk` に固定
|
||
- `data` (object) 詳細内容
|
||
- `text` (string) テキスト内容
|
||
- `from_variable_selector` (array) テキストソースパス、開発者がテキストがどのノードのどの変数から生成されたかを理解するのに役立ちます
|
||
- `event: node_finished` ノード実行終了、成功と失敗は同じイベント内の異なる状態
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `event` (string) `node_finished` に固定
|
||
- `data` (object) 詳細内容
|
||
- `id` (string) ノード実行ID
|
||
- `node_id` (string) ノードID
|
||
- `index` (int) 実行シーケンス番号、Tracing Node シーケンスの表示に使用
|
||
- `predecessor_node_id` (string) オプション 前置ノードID、キャンバス表示実行パスに使用
|
||
- `inputs` (object) ノードで使用されるすべての前置ノード変数の内容
|
||
- `process_data` (json) オプション ノードプロセスデータ
|
||
- `outputs` (json) オプション 出力内容
|
||
- `status` (string) 実行ステータス `running` / `succeeded` / `failed` / `stopped`
|
||
- `error` (string) オプション エラー理由
|
||
- `elapsed_time` (float) オプション 使用時間(s)
|
||
- `execution_metadata` (json) メタデータ
|
||
- `total_tokens` (int) オプション 使用されるトークンの総数
|
||
- `total_price` (decimal) オプション 総費用
|
||
- `currency` (string) オプション 通貨、例:`USD` / `RMB`
|
||
- `created_at` (timestamp) 開始時間
|
||
- `event: human_input_required` ワークフローが一時停止し、Human-in-the-Loop 入力が必要
|
||
- `task_id` (string) タスク ID、リクエスト追跡に使用
|
||
- `workflow_run_id` (string) ワークフロー実行 ID
|
||
- `event` (string) `human_input_required` に固定
|
||
- `data` (object) 詳細内容
|
||
- `form_id` (string) ヒューマン入力フォーム ID
|
||
- `node_id` (string) Human Input ノード ID
|
||
- `node_title` (string) Human Input ノードタイトル
|
||
- `form_content` (string) レンダリング済みフォーム内容
|
||
- `inputs` (array[object]) フォーム入力項目の定義
|
||
- `actions` (array[object]) ユーザーが選択できるアクションボタン
|
||
- `id` (string) アクション ID
|
||
- `title` (string) ボタンラベル
|
||
- `button_style` (string) ボタンスタイル
|
||
- `display_in_ui` (bool) UI にこのフォームを表示するかどうか
|
||
- `form_token` (string) `/form/human_input/:form_token` API で使用するトークン
|
||
- `resolved_default_values` (object) 実行時に解決されたデフォルト値
|
||
- `expiration_time` (timestamp) フォームの有効期限(Unix 秒)
|
||
- `event: workflow_finished` ワークフロー実行終了、成功と失敗は同じイベント内の異なる状態
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `workflow_run_id` (string) ワークフロー実行ID
|
||
- `event` (string) `workflow_finished` に固定
|
||
- `data` (object) 詳細内容
|
||
- `id` (string) ワークフロー実行ID
|
||
- `workflow_id` (string) 関連するワークフローID
|
||
- `status` (string) 実行ステータス `running` / `succeeded` / `failed` / `stopped`
|
||
- `outputs` (json) オプション 出力内容
|
||
- `error` (string) オプション エラー理由
|
||
- `elapsed_time` (float) オプション 使用時間(s)
|
||
- `total_tokens` (int) オプション 使用されるトークンの総数
|
||
- `total_steps` (int) 総ステップ数(冗長)、デフォルト 0
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
- `event: tts_message` TTS オーディオストリームイベント、つまり:音声合成出力。内容はMp3形式のオーディオブロックで、base64エンコードされた文字列として、再生時に直接デコードできます。(自動再生が有効な場合のみこのメッセージがあります)
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `message_id` (string) メッセージ一意ID
|
||
- `audio` (string) 音声合成後のオーディオブロックはbase64エンコードされたテキスト内容として、再生時に直接base64デコードしてプレーヤーに送信できます
|
||
- `created_at` (int) 作成タイムスタンプ、例:1705395332
|
||
- `event: tts_message_end` TTS オーディオストリーム終了イベント、このイベントを受信すると、オーディオストリームの返却が終了したことを示します。
|
||
- `task_id` (string) タスクID、リクエスト追跡と以下の停止応答インターフェースに使用
|
||
- `message_id` (string) メッセージ一意ID
|
||
- `audio` (string) 終了イベントにはオーディオがないため、ここは空文字列です
|
||
- `created_at` (int) 作成タイムスタンプ、例:1705395332
|
||
- `event: ping` 10秒ごとのpingイベント、接続を維持します。
|
||
|
||
### エラー
|
||
- 400,`invalid_param`,入力パラメータ異常
|
||
- 400,`app_unavailable`,App 設定が利用できません
|
||
- 400,`provider_not_initialize`,利用可能なモデル認証情報設定がありません
|
||
- 400,`provider_quota_exceeded`,モデル呼び出しクォータが不足しています
|
||
- 400,`model_currently_not_support`,現在のモデルが利用できません
|
||
- 400,`workflow_not_found`,指定されたワークフローバージョンが見つかりません
|
||
- 400,`draft_workflow_error`,ドラフトワークフローバージョンを使用できません
|
||
- 400,`workflow_id_format_error`,ワークフローID形式エラー、UUID形式が必要です
|
||
- 400,`workflow_request_error`,ワークフロー実行に失敗しました
|
||
- 500,サービス内部異常
|
||
|
||
</Col>
|
||
<Col sticky>
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="POST"
|
||
label="/workflows/:workflow_id/run"
|
||
targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/{workflow_id}/run' \\
|
||
--header 'Authorization: Bearer {api_key}' \\
|
||
--header 'Content-Type: application/json' \\
|
||
--data-raw '{
|
||
"inputs": ${JSON.stringify(props.inputs)},
|
||
"response_mode": "streaming",
|
||
"user": "abc-123"
|
||
}'`}
|
||
/>
|
||
<CodeGroup title="例:入力変数としてのファイル配列">
|
||
```json {{ title: 'ファイル変数の例' }}
|
||
{
|
||
"inputs": {
|
||
"{variable_name}":
|
||
[
|
||
{
|
||
"transfer_method": "local_file",
|
||
"upload_file_id": "{upload_file_id}",
|
||
"type": "{document_type}"
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
### ブロッキングモード
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"workflow_run_id": "djflajgkldjgd",
|
||
"task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
|
||
"data": {
|
||
"id": "fdlsjfjejkghjda",
|
||
"workflow_id": "fldjaslkfjlsda",
|
||
"status": "succeeded",
|
||
"outputs": {
|
||
"text": "Nice to meet you."
|
||
},
|
||
"error": null,
|
||
"elapsed_time": 0.875,
|
||
"total_tokens": 3562,
|
||
"total_steps": 8,
|
||
"created_at": 1705407629,
|
||
"finished_at": 1727807631
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
### ストリーミングモード
|
||
<CodeGroup title="応答">
|
||
```streaming {{ title: '応答' }}
|
||
data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
|
||
data: {"event": "node_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "created_at": 1679586595}}
|
||
data: {"event": "node_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "execution_metadata": {"total_tokens": 63127864, "total_price": 2.378, "currency": "USD"}, "created_at": 1679586595}}
|
||
data: {"event": "workflow_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "total_tokens": 63127864, "total_steps": "1", "created_at": 1679586595, "finished_at": 1679976595}}
|
||
data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
|
||
data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/workflows/run/:workflow_run_id'
|
||
method='GET'
|
||
title='ワークフロー実行詳細を取得'
|
||
name='#get-workflow-run-detail'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
ワークフロー実行 ID に基づいて、ワークフロータスクの現在の実行結果を取得します。
|
||
### パス
|
||
- `workflow_run_id` (string) ワークフロー実行ID、ストリーミングチャンクの返り値から取得可能
|
||
### 応答
|
||
- `id` (string) ワークフロー実行の ID
|
||
- `workflow_id` (string) 関連するワークフローの ID
|
||
- `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `inputs` (json) 入力内容
|
||
- `outputs` (json) 出力内容
|
||
- `error` (string) エラー理由
|
||
- `total_steps` (int) タスクの総ステップ数
|
||
- `total_tokens` (int) 使用されるトークンの総数
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
- `elapsed_time` (float) 使用される総秒数
|
||
</Col>
|
||
<Col sticky>
|
||
### リクエスト例
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="GET"
|
||
label="/workflows/run/:workflow_run_id"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id' \\
|
||
-H 'Authorization: Bearer {api_key}' \\
|
||
-H 'Content-Type: application/json'`}
|
||
/>
|
||
|
||
### 応答例
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
|
||
"workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
|
||
"status": "succeeded",
|
||
"inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
|
||
"outputs": null,
|
||
"error": null,
|
||
"total_steps": 3,
|
||
"total_tokens": 0,
|
||
"created_at": 1705407629,
|
||
"finished_at": 1727807631,
|
||
"elapsed_time": 30.098514399956912
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/workflows/tasks/:task_id/stop'
|
||
method='POST'
|
||
title='生成を停止'
|
||
name='#stop-generatebacks'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
ストリーミングモードでのみサポートされています。
|
||
### パス
|
||
- `task_id` (string) タスク ID、ストリーミングチャンクの返り値から取得可能
|
||
### リクエストボディ
|
||
- `user` (string) 必須
|
||
ユーザー識別子、エンドユーザーのアイデンティティを定義するために使用され、送信メッセージインターフェースで渡されたユーザーと一致している必要があります。サービス API は WebApp によって作成された会話を共有しません。
|
||
### 応答
|
||
- `result` (string) 常に"success"を返します
|
||
</Col>
|
||
<Col sticky>
|
||
### リクエスト例
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="POST"
|
||
label="/workflows/tasks/:task_id/stop"
|
||
targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \\
|
||
-H 'Authorization: Bearer {api_key}' \\
|
||
-H 'Content-Type: application/json' \\
|
||
--data-raw '{"user": "abc-123"}'`}
|
||
/>
|
||
|
||
### 応答例
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"result": "success"
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/form/human_input/:form_token'
|
||
method='GET'
|
||
title='Human Input フォームを取得'
|
||
name='#get-human-input-form'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
`form_token` から保留中の Human-in-the-Loop フォームを取得します。
|
||
|
||
Workflow が `human_input_required`(`form_token` を含む)で一時停止した際に使用します。
|
||
|
||
### パス
|
||
- `form_token` (string) 必須、一時停止イベントで返されたフォームトークン
|
||
|
||
### 応答
|
||
- `form_content` (string) レンダリング済みフォーム内容(markdown/plain text)
|
||
- `inputs` (array[object]) 入力項目定義
|
||
- `resolved_default_values` (object) 解決済みデフォルト値(文字列)
|
||
- `user_actions` (array[object]) アクションボタン一覧
|
||
- `expiration_time` (timestamp) フォーム有効期限(Unix 秒)
|
||
|
||
### エラー
|
||
- 404, フォームが存在しない、または現在のアプリに属していない
|
||
- 412, `human_input_form_submitted`, 既に送信済み
|
||
- 412, `human_input_form_expired`, 期限切れ
|
||
</Col>
|
||
<Col sticky>
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="GET"
|
||
label="/form/human_input/:form_token"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/form/human_input/{form_token}' \\
|
||
--header 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"form_content": "最終回答を確認してください: {{#$output.answer#}}",
|
||
"inputs": [
|
||
{
|
||
"label": "回答",
|
||
"type": "text-input",
|
||
"required": true,
|
||
"output_variable_name": "answer"
|
||
}
|
||
],
|
||
"resolved_default_values": {
|
||
"answer": "初期値"
|
||
},
|
||
"user_actions": [
|
||
{ "id": "approve", "title": "承認", "button_style": "primary" },
|
||
{ "id": "reject", "title": "却下", "button_style": "warning" }
|
||
],
|
||
"expiration_time": 1735689600
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/form/human_input/:form_token'
|
||
method='POST'
|
||
title='Human Input フォームを送信'
|
||
name='#submit-human-input-form'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
保留中の Human-in-the-Loop フォームを送信します。
|
||
|
||
### パス
|
||
- `form_token` (string) 必須、一時停止イベントで返されたフォームトークン
|
||
|
||
### リクエストボディ
|
||
- `inputs` (object) 必須、フォーム項目の key/value
|
||
- `action` (string) 必須、`user_actions` から選択したアクション ID
|
||
- `user` (string) 必須、エンドユーザー識別子
|
||
|
||
### 応答
|
||
成功時は空オブジェクトを返します。
|
||
|
||
### エラー
|
||
- 400, `invalid_form_data`, 送信データがフォームスキーマに一致しない
|
||
- 404, フォームが存在しない、または現在のアプリに属していない
|
||
- 412, `human_input_form_submitted`, 既に送信済み
|
||
- 412, `human_input_form_expired`, 期限切れ
|
||
</Col>
|
||
<Col sticky>
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="POST"
|
||
label="/form/human_input/:form_token"
|
||
targetCode={`curl -X POST '${props.appDetail.api_base_url}/form/human_input/{form_token}' \\
|
||
--header 'Authorization: Bearer {api_key}' \\
|
||
--header 'Content-Type: application/json' \\
|
||
--data-raw '{
|
||
"inputs": {"answer": "承認済み回答"},
|
||
"action": "approve",
|
||
"user": "abc-123"
|
||
}'`}
|
||
/>
|
||
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/workflow/:task_id/events'
|
||
method='GET'
|
||
title='再開後の Workflow イベントを取得'
|
||
name='#get-workflow-resume-events'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
Human Input フォーム送信後に、ワークフロー再開後のイベントを継続受信します。
|
||
|
||
このエンドポイントは `text/event-stream` を返し、完了までイベントを購読できます。
|
||
|
||
### パス
|
||
- `task_id` (string) 必須、workflow 実行 ID(`workflow_run_id`)
|
||
|
||
### クエリ
|
||
- `user` (string) 必須、エンドユーザー識別子
|
||
- `include_state_snapshot` (bool) 任意、`true` の場合は永続化済み状態スナップショットを先に再生してからリアルタイムイベントへ移行
|
||
- `continue_on_pause` (bool) 任意、`true` にすると `workflow_paused` イベントをまたいでもストリームを維持し、`workflow_finished` で終了します
|
||
|
||
### 応答
|
||
Server-Sent Events ストリーム(`text/event-stream`)。
|
||
主なイベントは `workflow_paused`、`node_started`、`node_finished`、`human_input_form_filled`、`human_input_form_timeout`、`workflow_finished` です。
|
||
呼び出し時点でワークフローがすでに完了している場合、このエンドポイントは完了イベントを 1 件だけ即座に返します。
|
||
</Col>
|
||
<Col sticky>
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="GET"
|
||
label="/workflow/:task_id/events"
|
||
targetCode={`curl -N -X GET '${props.appDetail.api_base_url}/workflow/{workflow_run_id}/events?user=abc-123&continue_on_pause=true' \\
|
||
--header 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
|
||
<CodeGroup title="応答">
|
||
```streaming {{ title: '応答' }}
|
||
event: ping
|
||
|
||
data: {"event":"workflow_started","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","workflow_id":"e46514f1-c008-41ff-94b0-4f33d4b97d36","inputs":{"sys.files":[],"sys.user_id":"abc-123","sys.app_id":"d1074979-f67e-4114-8691-e35878df9a89","sys.workflow_id":"e46514f1-c008-41ff-94b0-4f33d4b97d36","sys.workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","sys.timestamp":1776087863},"created_at":1776087863,"reason":"initial"}}
|
||
|
||
data: {"event":"node_started","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"id":"b552d685-1119-4e6a-9a81-e91a23e5324b","node_id":"1775717266623","node_type":"start","title":"User Input","index":1,"predecessor_node_id":null,"inputs":null,"created_at":1776087863,"extras":{},"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"node_finished","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"id":"b552d685-1119-4e6a-9a81-e91a23e5324b","node_id":"1775717266623","node_type":"start","title":"User Input","index":1,"predecessor_node_id":null,"inputs":null,"process_data":null,"outputs":null,"status":"succeeded","error":null,"elapsed_time":0.00032,"execution_metadata":null,"created_at":1776087863,"finished_at":1776087863,"files":[],"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"node_started","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"id":"8d7e8e01-5159-4089-a4b6-3aa394992cc2","node_id":"1775717346519","node_type":"human-input","title":"Human Input","index":2,"predecessor_node_id":null,"inputs":null,"created_at":1776087863,"extras":{},"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"node_finished","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"id":"8d7e8e01-5159-4089-a4b6-3aa394992cc2","node_id":"1775717346519","node_type":"human-input","title":"Human Input","index":2,"predecessor_node_id":null,"inputs":null,"process_data":null,"outputs":null,"status":"paused","error":null,"elapsed_time":0.007381,"execution_metadata":null,"created_at":1776087863,"finished_at":1776087863,"files":[],"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"workflow_paused","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","data":{"workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","paused_nodes":["1775717346519"],"outputs":{},"reasons":[{"form_id":"019d8716-0fde-75da-8207-1458ccde76e5","form_content":"this is form 1:\n{{#$output.some_field#}}\n","inputs":[{"type":"paragraph","output_variable_name":"some_field","default":{"type":"variable","selector":["sys","workflow_run_id"],"value":""}}],"actions":[{"id":"approve","title":"YES","button_style":"default"},{"id":"reject","title":"NO","button_style":"default"}],"display_in_ui":true,"node_id":"1775717346519","node_title":"Human Input","resolved_default_values":{"some_field":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c"},"form_token":"n7hFG4ZDYdGcgZ5VDc7EGM","type":"human_input_required"}],"status":"paused","created_at":1776087863,"elapsed_time":0.0,"total_tokens":0,"total_steps":2}}
|
||
|
||
data: {"event":"workflow_started","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","workflow_id":"e46514f1-c008-41ff-94b0-4f33d4b97d36","inputs":{"sys.files":[],"sys.user_id":"abc-123","sys.app_id":"d1074979-f67e-4114-8691-e35878df9a89","sys.workflow_id":"e46514f1-c008-41ff-94b0-4f33d4b97d36","sys.workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c"},"created_at":1776087877,"reason":"resumption"}}
|
||
|
||
data: {"event":"node_started","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"8d7e8e01-5159-4089-a4b6-3aa394992cc2","node_id":"1775717346519","node_type":"human-input","title":"Human Input","index":1,"predecessor_node_id":null,"inputs":null,"inputs_truncated":false,"created_at":1776087877,"extras":{},"iteration_id":null,"loop_id":null,"agent_strategy":null}}
|
||
|
||
data: {"event":"human_input_form_filled","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"node_id":"1775717346519","node_title":"Human Input","rendered_content":"this is form 1:\nfield 1 filled!\n","action_id":"approve","action_text":"YES"}}
|
||
|
||
data: {"event":"node_finished","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"8d7e8e01-5159-4089-a4b6-3aa394992cc2","node_id":"1775717346519","node_type":"human-input","title":"Human Input","index":1,"predecessor_node_id":null,"inputs":{},"inputs_truncated":false,"process_data":{},"process_data_truncated":false,"outputs":{"some_field":"field 1 filled!","some_field_2":"from bruno with love","__action_id":"approve","__rendered_content":"this is form 1:\nfield 1 filled!\n"},"outputs_truncated":false,"status":"succeeded","error":null,"elapsed_time":0.004431,"execution_metadata":null,"created_at":1776087877,"finished_at":1776087877,"files":[],"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"node_started","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"6d8fc3cb-19f7-440b-b83e-eed4e847a332","node_id":"1775717350710","node_type":"template-transform","title":"Template","index":1,"predecessor_node_id":null,"inputs":null,"inputs_truncated":false,"created_at":1776087877,"extras":{},"iteration_id":null,"loop_id":null,"agent_strategy":null}}
|
||
|
||
data: {"event":"text_chunk","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"text":"field 1 filled!","from_variable_selector":["1775717350710","output"]}}
|
||
|
||
data: {"event":"node_finished","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"6d8fc3cb-19f7-440b-b83e-eed4e847a332","node_id":"1775717350710","node_type":"template-transform","title":"Template","index":1,"predecessor_node_id":null,"inputs":{"some_field":"field 1 filled!"},"inputs_truncated":false,"process_data":{},"process_data_truncated":false,"outputs":{"output":"field 1 filled!"},"outputs_truncated":false,"status":"succeeded","error":null,"elapsed_time":0.264614,"execution_metadata":null,"created_at":1776087877,"finished_at":1776087877,"files":[],"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"node_started","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"e88dec7e-aa2c-41f7-8d73-032b749e23f5","node_id":"1775717354177","node_type":"end","title":"Output","index":1,"predecessor_node_id":null,"inputs":null,"inputs_truncated":false,"created_at":1776087877,"extras":{},"iteration_id":null,"loop_id":null,"agent_strategy":null}}
|
||
|
||
data: {"event":"node_finished","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"e88dec7e-aa2c-41f7-8d73-032b749e23f5","node_id":"1775717354177","node_type":"end","title":"Output","index":1,"predecessor_node_id":null,"inputs":{"output":"field 1 filled!"},"inputs_truncated":false,"process_data":{},"process_data_truncated":false,"outputs":{"output":"field 1 filled!"},"outputs_truncated":false,"status":"succeeded","error":null,"elapsed_time":0.00003,"execution_metadata":null,"created_at":1776087877,"finished_at":1776087877,"files":[],"iteration_id":null,"loop_id":null}}
|
||
|
||
data: {"event":"workflow_finished","workflow_run_id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","task_id":"1784c3dd-20eb-4919-bd5d-a8d800b74ada","data":{"id":"5d7ef348-e1c1-4f6d-bb9b-62cc2fb2ef3c","workflow_id":"e46514f1-c008-41ff-94b0-4f33d4b97d36","status":"succeeded","outputs":{"output":"field 1 filled!"},"error":null,"elapsed_time":0.364935,"total_tokens":0,"total_steps":5,"created_by":{"id":"7932d34c-dcf4-4fba-b770-f2a9de88c0a0","user":"abc-123"},"created_at":1776087877,"finished_at":1776087877,"exceptions_count":0,"files":[]}}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/files/upload'
|
||
method='POST'
|
||
title='ファイルアップロード'
|
||
name='#file-upload'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
メッセージ送信時に使用するためのファイルをアップロードし、画像とテキストのマルチモーダル理解を可能にします。
|
||
ワークフローでサポートされている任意の形式をサポートします。
|
||
アップロードされたファイルは、現在のエンドユーザーのみが使用できます。
|
||
|
||
### リクエストボディ
|
||
このインターフェースは`multipart/form-data`リクエストを必要とします。
|
||
- `file` (File) 必須
|
||
アップロードするファイル。
|
||
- `user` (string) 必須
|
||
ユーザー識別子、開発者のルールで定義され、アプリケーション内で一意でなければなりません。サービス API は WebApp によって作成された会話を共有しません。
|
||
|
||
### 応答
|
||
アップロードが成功すると、サーバーはファイルの ID と関連情報を返します。
|
||
- `id` (uuid) ID
|
||
- `name` (string) ファイル名
|
||
- `size` (int) ファイルサイズ(バイト)
|
||
- `extension` (string) ファイル拡張子
|
||
- `mime_type` (string) ファイルの MIME タイプ
|
||
- `created_by` (uuid) エンドユーザーID
|
||
- `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
|
||
|
||
### エラー
|
||
- 400, `no_file_uploaded`, ファイルが提供されていません
|
||
- 400, `too_many_files`, 現在は 1 つのファイルのみ受け付けています
|
||
- 400, `unsupported_preview`, ファイルはプレビューをサポートしていません
|
||
- 400, `unsupported_estimate`, ファイルは推定をサポートしていません
|
||
- 413, `file_too_large`, ファイルが大きすぎます
|
||
- 415, `unsupported_file_type`, サポートされていない拡張子、現在はドキュメントファイルのみ受け付けています
|
||
- 503, `s3_connection_failed`, S3 サービスに接続できません
|
||
- 503, `s3_permission_denied`, S3 にファイルをアップロードする権限がありません
|
||
- 503, `s3_file_too_large`, ファイルが S3 のサイズ制限を超えています
|
||
- 500, 内部サーバーエラー
|
||
|
||
|
||
</Col>
|
||
<Col sticky>
|
||
### リクエスト例
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="POST"
|
||
label="/files/upload"
|
||
targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\
|
||
--header 'Authorization: Bearer {api_key}' \\
|
||
--form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\
|
||
--form 'user=abc-123'`}
|
||
/>
|
||
|
||
|
||
### 応答例
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
|
||
"name": "example.png",
|
||
"size": 1024,
|
||
"extension": "png",
|
||
"mime_type": "image/png",
|
||
"created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
|
||
"created_at": 1577836800,
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/end-users/:end_user_id'
|
||
method='GET'
|
||
title='エンドユーザーを取得'
|
||
name='#end-user'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
エンドユーザー ID からエンドユーザー情報を取得します。
|
||
|
||
他の API がエンドユーザー ID(例:ファイルアップロードの `created_by`)を返す場合に利用できます。
|
||
|
||
### パスパラメータ
|
||
- `end_user_id` (uuid) 必須
|
||
エンドユーザー ID。
|
||
|
||
### レスポンス
|
||
EndUser オブジェクトを返します。
|
||
- `id` (uuid) ID
|
||
- `tenant_id` (uuid) テナント ID
|
||
- `app_id` (uuid) アプリ ID
|
||
- `type` (string) エンドユーザー種別
|
||
- `external_user_id` (string) 外部ユーザー ID
|
||
- `name` (string) 名前
|
||
- `is_anonymous` (boolean) 匿名ユーザーかどうか
|
||
- `session_id` (string) セッション ID
|
||
- `created_at` (string) ISO 8601 日時
|
||
- `updated_at` (string) ISO 8601 日時
|
||
|
||
### エラー
|
||
- 404, `end_user_not_found`, エンドユーザーが見つかりません
|
||
- 500, 内部サーバーエラー
|
||
|
||
</Col>
|
||
<Col sticky>
|
||
### リクエスト例
|
||
<CodeGroup
|
||
title="Request"
|
||
tag="GET"
|
||
label="/end-users/:end_user_id"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/end-users/6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13' \\
|
||
--header 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
|
||
### レスポンス例
|
||
<CodeGroup title="Response">
|
||
```json {{ title: 'Response' }}
|
||
{
|
||
"id": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
|
||
"tenant_id": "8c0f3f3a-66b0-4b55-a0bf-8b8e0d6aee7d",
|
||
"app_id": "6c8c3f41-2c6f-4e1b-8f4f-7f11c8f2ad2a",
|
||
"type": "service_api",
|
||
"external_user_id": "abc-123",
|
||
"name": "Alice",
|
||
"is_anonymous": false,
|
||
"session_id": "abc-123",
|
||
"created_at": "2024-01-01T00:00:00Z",
|
||
"updated_at": "2024-01-01T00:00:00Z"
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
---
|
||
|
||
<Heading
|
||
url='/workflows/logs'
|
||
method='GET'
|
||
title='ワークフローログを取得'
|
||
name='#Get-Workflow-Logs'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
ワークフローログを返します。最初のページは最新の`{limit}`メッセージを返します。つまり、逆順です。
|
||
|
||
### クエリ
|
||
|
||
<Properties>
|
||
<Property name='keyword' type='string' key='keyword'>
|
||
検索するキーワード
|
||
</Property>
|
||
<Property name='status' type='string' key='status'>
|
||
succeeded/failed/stopped
|
||
</Property>
|
||
<Property name='page' type='int' key='page'>
|
||
現在のページ、デフォルトは1。
|
||
</Property>
|
||
<Property name='limit' type='int' key='limit'>
|
||
1回のリクエストで返すチャット履歴メッセージの数、デフォルトは20。
|
||
</Property>
|
||
<Property name='created_by_end_user_session_id' type='str' key='created_by_end_user_session_id'>
|
||
どのendUserによって作成されたか、例えば、`abc-123`。
|
||
</Property>
|
||
<Property name='created_by_account' type='str' key='created_by_account'>
|
||
どのメールアカウントによって作成されたか、例えば、lizb@test.com。
|
||
</Property>
|
||
</Properties>
|
||
|
||
### 応答
|
||
- `page` (int) 現在のページ
|
||
- `limit` (int) 返されたアイテムの数、入力がシステム制限を超える場合、システム制限量を返します
|
||
- `total` (int) 合計アイテム数
|
||
- `has_more` (bool) 次のページがあるかどうか
|
||
- `data` (array[object]) ログリスト
|
||
- `id` (string) ID
|
||
- `workflow_run` (object) ワークフロー実行
|
||
- `id` (string) ID
|
||
- `version` (string) バージョン
|
||
- `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
|
||
- `error` (string) オプションのエラー理由
|
||
- `elapsed_time` (float) 使用される総秒数
|
||
- `total_tokens` (int) 使用されるトークン数
|
||
- `total_steps` (int) デフォルト 0
|
||
- `created_at` (timestamp) 開始時間
|
||
- `finished_at` (timestamp) 終了時間
|
||
- `created_from` (string) 作成元
|
||
- `created_by_role` (string) 作成者の役割
|
||
- `created_by_account` (string) オプションの作成者アカウント
|
||
- `created_by_end_user` (object) エンドユーザーによって作成
|
||
- `id` (string) ID
|
||
- `type` (string) タイプ
|
||
- `is_anonymous` (bool) 匿名かどうか
|
||
- `session_id` (string) セッション ID
|
||
- `created_at` (timestamp) 作成時間
|
||
</Col>
|
||
<Col sticky>
|
||
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="GET"
|
||
label="/workflows/logs"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/logs'\\
|
||
--header 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
### 応答例
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"page": 1,
|
||
"limit": 1,
|
||
"total": 7,
|
||
"has_more": true,
|
||
"data": [
|
||
{
|
||
"id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
|
||
"workflow_run": {
|
||
"id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
|
||
"version": "2024-08-01 12:17:09.771832",
|
||
"status": "succeeded",
|
||
"error": null,
|
||
"elapsed_time": 1.3588523610014818,
|
||
"total_tokens": 0,
|
||
"total_steps": 3,
|
||
"created_at": 1726139643,
|
||
"finished_at": 1726139644
|
||
},
|
||
"created_from": "service-api",
|
||
"created_by_role": "end_user",
|
||
"created_by_account": null,
|
||
"created_by_end_user": {
|
||
"id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
|
||
"type": "service_api",
|
||
"is_anonymous": false,
|
||
"session_id": "abc-123"
|
||
},
|
||
"created_at": 1726139644
|
||
}
|
||
]
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
---
|
||
|
||
<Heading
|
||
url='/info'
|
||
method='GET'
|
||
title='アプリケーションの基本情報を取得'
|
||
name='#info'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
このアプリケーションの基本情報を取得するために使用されます
|
||
|
||
### Response
|
||
- `name` (string) アプリケーションの名前
|
||
- `description` (string) アプリケーションの説明
|
||
- `tags` (array[string]) アプリケーションのタグ
|
||
- `mode` (string) アプリケーションのモード
|
||
- `author_name` (string) 作者の名前
|
||
</Col>
|
||
<Col>
|
||
<CodeGroup
|
||
title="Request"
|
||
tag="GET"
|
||
label="/info"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\
|
||
-H 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
<CodeGroup title="Response">
|
||
```json {{ title: 'Response' }}
|
||
{
|
||
"name": "My App",
|
||
"description": "This is my app.",
|
||
"tags": [
|
||
"tag1",
|
||
"tag2"
|
||
],
|
||
"mode": "workflow",
|
||
"author_name": "Dify"
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
|
||
---
|
||
|
||
<Heading
|
||
url='/parameters'
|
||
method='GET'
|
||
title='アプリケーションのパラメータ情報を取得'
|
||
name='#parameters'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
ページに入る際に、機能、入力パラメータ名、タイプ、デフォルト値などの情報を取得するために使用されます。
|
||
|
||
### 応答
|
||
- `user_input_form` (array[object]) ユーザー入力フォームの設定
|
||
- `text-input` (object) テキスト入力コントロール
|
||
- `label` (string) 変数表示ラベル名
|
||
- `variable` (string) 変数ID
|
||
- `required` (bool) 必須かどうか
|
||
- `default` (string) デフォルト値
|
||
- `paragraph` (object) 段落テキスト入力コントロール
|
||
- `label` (string) 変数表示ラベル名
|
||
- `variable` (string) 変数ID
|
||
- `required` (bool) 必須かどうか
|
||
- `default` (string) デフォルト値
|
||
- `select` (object) ドロップダウンコントロール
|
||
- `label` (string) 変数表示ラベル名
|
||
- `variable` (string) 変数ID
|
||
- `required` (bool) 必須かどうか
|
||
- `default` (string) デフォルト値
|
||
- `options` (array[string]) オプション値
|
||
- `file_upload` (object) ファイルアップロード設定
|
||
- `document` (object) ドキュメント設定
|
||
現在サポートされているドキュメントタイプ:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
|
||
- `enabled` (bool) 有効かどうか
|
||
- `number_limits` (int) ドキュメント数の上限。デフォルトは 3
|
||
- `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
|
||
- `image` (object) 画像設定
|
||
現在サポートされている画像タイプ:`png`, `jpg`, `jpeg`, `webp`, `gif`。
|
||
- `enabled` (bool) 有効かどうか
|
||
- `number_limits` (int) 画像数の上限。デフォルトは 3
|
||
- `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
|
||
- `audio` (object) オーディオ設定
|
||
現在サポートされているオーディオタイプ:`mp3`, `m4a`, `wav`, `webm`, `amr`。
|
||
- `enabled` (bool) 有効かどうか
|
||
- `number_limits` (int) オーディオ数の上限。デフォルトは 3
|
||
- `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
|
||
- `video` (object) ビデオ設定
|
||
現在サポートされているビデオタイプ:`mp4`, `mov`, `mpeg`, `mpga`。
|
||
- `enabled` (bool) 有効かどうか
|
||
- `number_limits` (int) ビデオ数の上限。デフォルトは 3
|
||
- `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
|
||
- `custom` (object) カスタム設定
|
||
- `enabled` (bool) 有効かどうか
|
||
- `number_limits` (int) カスタム数の上限。デフォルトは 3
|
||
- `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
|
||
- `system_parameters` (object) システムパラメータ
|
||
- `file_size_limit` (int) ドキュメントアップロードサイズ制限(MB)
|
||
- `image_file_size_limit` (int) 画像ファイルアップロードサイズ制限(MB)
|
||
- `audio_file_size_limit` (int) オーディオファイルアップロードサイズ制限(MB)
|
||
- `video_file_size_limit` (int) ビデオファイルアップロードサイズ制限(MB)
|
||
|
||
</Col>
|
||
<Col sticky>
|
||
|
||
<CodeGroup
|
||
title="リクエスト"
|
||
tag="GET"
|
||
label="/parameters"
|
||
targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}
|
||
/>
|
||
|
||
<CodeGroup title="応答">
|
||
```json {{ title: '応答' }}
|
||
{
|
||
"user_input_form": [
|
||
{
|
||
"paragraph": {
|
||
"label": "Query",
|
||
"variable": "query",
|
||
"required": true,
|
||
"default": ""
|
||
}
|
||
}
|
||
],
|
||
"file_upload": {
|
||
"image": {
|
||
"enabled": false,
|
||
"number_limits": 3,
|
||
"detail": "high",
|
||
"transfer_methods": [
|
||
"remote_url",
|
||
"local_file"
|
||
]
|
||
}
|
||
},
|
||
"system_parameters": {
|
||
"file_size_limit": 15,
|
||
"image_file_size_limit": 10,
|
||
"audio_file_size_limit": 50,
|
||
"video_file_size_limit": 100
|
||
}
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
———
|
||
|
||
<Heading
|
||
url='/site'
|
||
method='GET'
|
||
title='アプリのWebApp設定を取得'
|
||
name='#site'
|
||
/>
|
||
<Row>
|
||
<Col>
|
||
アプリの WebApp 設定を取得するために使用します。
|
||
### 応答
|
||
- `title` (string) WebApp 名
|
||
- `icon_type` (string) アイコンタイプ、`emoji`-絵文字、`image`-画像
|
||
- `icon` (string) アイコン。`emoji`タイプの場合は絵文字、`image`タイプの場合は画像 URL
|
||
- `icon_background` (string) 16 進数形式の背景色
|
||
- `icon_url` (string) アイコンの URL
|
||
- `description` (string) 説明
|
||
- `copyright` (string) 著作権情報
|
||
- `privacy_policy` (string) プライバシーポリシーのリンク
|
||
- `custom_disclaimer` (string) カスタム免責事項
|
||
- `default_language` (string) デフォルト言語
|
||
- `show_workflow_steps` (bool) ワークフローの詳細を表示するかどうか
|
||
</Col>
|
||
<Col>
|
||
<CodeGroup
|
||
title="Request"
|
||
tag="GET"
|
||
label="/site"
|
||
targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\
|
||
-H 'Authorization: Bearer {api_key}'`}
|
||
/>
|
||
|
||
<CodeGroup title="Response">
|
||
```json {{ title: 'Response' }}
|
||
{
|
||
"title": "My App",
|
||
"icon_type": "emoji",
|
||
"icon": "😄",
|
||
"icon_background": "#FFEAD5",
|
||
"icon_url": null,
|
||
"description": "This is my app.",
|
||
"copyright": "all rights reserved",
|
||
"privacy_policy": "",
|
||
"custom_disclaimer": "All generated by AI",
|
||
"default_language": "en-US",
|
||
"show_workflow_steps": false,
|
||
}
|
||
```
|
||
</CodeGroup>
|
||
</Col>
|
||
</Row>
|
||
___
|