You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_workflow.ja.mdx 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # ワークフローアプリ API
  4. ワークフローアプリケーションは、セッションをサポートせず、翻訳、記事作成、要約 AI などに最適です。
  5. <div>
  6. ### ベース URL
  7. <CodeGroup title="コード" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### 認証
  12. サービス API は `API-Key` 認証を使用します。
  13. <i>**API キーの漏洩を防ぐため、API キーはクライアント側で共有または保存せず、サーバー側で保存することを強くお勧めします。**</i>
  14. すべての API リクエストにおいて、以下のように `Authorization`HTTP ヘッダーに API キーを含めてください:
  15. <CodeGroup title="コード">
  16. ```javascript
  17. Authorization: Bearer {API_KEY}
  18. ```
  19. </CodeGroup>
  20. </div>
  21. ---
  22. <Heading
  23. url='/workflows/run'
  24. method='POST'
  25. title='ワークフローを実行'
  26. name='#Execute-Workflow'
  27. />
  28. <Row>
  29. <Col>
  30. ワークフローを実行します。公開されたワークフローがないと実行できません。
  31. ### リクエストボディ
  32. - `inputs` (object) 必須
  33. アプリで定義されたさまざまな変数値の入力を許可します。
  34. `inputs`パラメータには複数のキー/値ペアが含まれ、各キーは特定の変数に対応し、各値はその変数の特定の値です。
  35. ワークフローアプリケーションは少なくとも1つのキー/値ペアの入力を必要とします。値はファイルリストである場合もあります。
  36. ファイルリストは、テキスト理解と質問への回答を組み合わせたファイルの入力に適しています。モデルがファイルの解析と理解機能をサポートしている場合にのみ使用できます。
  37. 変数がファイルリストの場合、リストの各要素は以下の属性を持つ必要があります。
  38. - `type` (string) サポートされているタイプ:
  39. - `document` ('TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB')
  40. - `image` ('JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG')
  41. - `audio` ('MP3', 'M4A', 'WAV', 'WEBM', 'AMR')
  42. - `video` ('MP4', 'MOV', 'MPEG', 'MPGA')
  43. - `custom` (他のファイルタイプ)
  44. - `transfer_method` (string) 転送方法、画像URLの場合は`remote_url` / ファイルアップロードの場合は`local_file`
  45. - `url` (string) 画像URL(転送方法が`remote_url`の場合)
  46. - `upload_file_id` (string) アップロードされたファイルID、事前にファイルアップロードAPIを通じて取得する必要があります(転送方法が`local_file`の場合)
  47. - `response_mode` (string) 必須
  48. 応答の返却モードを指定します。サポートされているモード:
  49. - `streaming` ストリーミングモード(推奨)、SSE([Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events))を通じてタイプライターのような出力を実装します。
  50. - `blocking` ブロッキングモード、実行完了後に結果を返します。(プロセスが長い場合、リクエストが中断される可能性があります)
  51. <i>Cloudflare の制限により、100 秒後に応答がない場合、リクエストは中断されます。</i>
  52. - `user` (string) 必須
  53. ユーザー識別子、エンドユーザーのアイデンティティを定義するために使用されます。
  54. アプリケーション内で開発者によって一意に定義される必要があります。
  55. - `files` (array[object]) オプション
  56. ### 応答
  57. `response_mode`が`blocking`の場合、CompletionResponse オブジェクトを返します。
  58. `response_mode`が`streaming`の場合、ChunkCompletionResponse ストリームを返します。
  59. ### CompletionResponse
  60. アプリの結果を返します。`Content-Type`は`application/json`です。
  61. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  62. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  63. - `data` (object) 結果の詳細
  64. - `id` (string) ワークフロー実行の ID
  65. - `workflow_id` (string) 関連するワークフローの ID
  66. - `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
  67. - `outputs` (json) オプションの出力内容
  68. - `error` (string) オプションのエラー理由
  69. - `elapsed_time` (float) オプションの使用時間(秒)
  70. - `total_tokens` (int) オプションの使用トークン数
  71. - `total_steps` (int) デフォルト 0
  72. - `created_at` (timestamp) 開始時間
  73. - `finished_at` (timestamp) 終了時間
  74. ### ChunkCompletionResponse
  75. アプリによって出力されたストリームチャンクを返します。`Content-Type`は`text/event-stream`です。
  76. 各ストリーミングチャンクは`data:`で始まり、2 つの改行文字`\n\n`で区切られます。以下のように表示されます:
  77. <CodeGroup>
  78. ```streaming {{ title: '応答' }}
  79. 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
  80. ```
  81. </CodeGroup>
  82. ストリーミングチャンクの構造は`event`に応じて異なります:
  83. - `event: workflow_started` ワークフローが実行を開始
  84. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  85. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  86. - `event` (string) `workflow_started`に固定
  87. - `data` (object) 詳細
  88. - `id` (string) ワークフロー実行の一意の ID
  89. - `workflow_id` (string) 関連するワークフローの ID
  90. - `sequence_number` (int) 自己増加シリアル番号、アプリ内で自己増加し、1 から始まります
  91. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  92. - `event: node_started` ノード実行開始
  93. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  94. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  95. - `event` (string) `node_started`に固定
  96. - `data` (object) 詳細
  97. - `id` (string) ワークフロー実行の一意の ID
  98. - `node_id` (string) ノードの ID
  99. - `node_type` (string) ノードのタイプ
  100. - `title` (string) ノードの名前
  101. - `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
  102. - `predecessor_node_id` (string) オプションのプレフィックスノード ID、キャンバス表示実行パスに使用
  103. - `inputs` (object) ノードで使用されるすべての前のノード変数の内容
  104. - `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
  105. - `event: text_chunk` テキストフラグメント
  106. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  107. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  108. - `event` (string) `text_chunk`に固定
  109. - `data` (object) 詳細
  110. - `text` (string) テキスト内容
  111. - `from_variable_selector` (array) テキスト生成元パス(開発者がどのノードのどの変数から生成されたかを理解するための情報)
  112. - `event: node_finished` ノード実行終了、同じイベントで異なる状態で成功または失敗
  113. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  114. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  115. - `event` (string) `node_finished`に固定
  116. - `data` (object) 詳細
  117. - `id` (string) ワークフロー実行の一意の ID
  118. - `node_id` (string) ノードの ID
  119. - `node_type` (string) ノードのタイプ
  120. - `title` (string) ノードの名前
  121. - `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
  122. - `predecessor_node_id` (string) オプションのプレフィックスノード ID、キャンバス表示実行パスに使用
  123. - `inputs` (object) ノードで使用されるすべての前のノード変数の内容
  124. - `process_data` (json) オプションのノードプロセスデータ
  125. - `outputs` (json) オプションの出力内容
  126. - `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
  127. - `error` (string) オプションのエラー理由
  128. - `elapsed_time` (float) オプションの使用時間(秒)
  129. - `execution_metadata` (json) メタデータ
  130. - `total_tokens` (int) オプションの使用トークン数
  131. - `total_price` (decimal) オプションの総コスト
  132. - `currency` (string) オプション 例:`USD` / `RMB`
  133. - `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
  134. - `event: workflow_finished` ワークフロー実行終了、同じイベントで異なる状態で成功または失敗
  135. - `task_id` (string) タスク ID、リクエスト追跡と以下の Stop Generate API に使用
  136. - `workflow_run_id` (string) ワークフロー実行の一意の ID
  137. - `event` (string) `workflow_finished`に固定
  138. - `data` (object) 詳細
  139. - `id` (string) ワークフロー実行の ID
  140. - `workflow_id` (string) 関連するワークフローの ID
  141. - `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
  142. - `outputs` (json) オプションの出力内容
  143. - `error` (string) オプションのエラー理由
  144. - `elapsed_time` (float) オプションの使用時間(秒)
  145. - `total_tokens` (int) オプションの使用トークン数
  146. - `total_steps` (int) デフォルト 0
  147. - `created_at` (timestamp) 開始時間
  148. - `finished_at` (timestamp) 終了時間
  149. - `event: tts_message` TTS オーディオストリームイベント、つまり音声合成出力。内容は Mp3 形式のオーディオブロックで、base64 文字列としてエンコードされています。再生時には、base64 をデコードしてプレーヤーに入力するだけです。(このメッセージは自動再生が有効な場合にのみ利用可能)
  150. - `task_id` (string) タスク ID、リクエスト追跡と以下の停止応答インターフェースに使用
  151. - `message_id` (string) 一意のメッセージ ID
  152. - `audio` (string) 音声合成後のオーディオ、base64 テキストコンテンツとしてエンコードされており、再生時には base64 をデコードしてプレーヤーに入力するだけです
  153. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  154. - `event: tts_message_end` TTS オーディオストリーム終了イベント。このイベントを受信すると、オーディオストリームの終了を示します。
  155. - `task_id` (string) タスク ID、リクエスト追跡と以下の停止応答インターフェースに使用
  156. - `message_id` (string) 一意のメッセージ ID
  157. - `audio` (string) 終了イベントにはオーディオがないため、これは空の文字列です
  158. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  159. - `event: ping` 接続を維持するために 10 秒ごとに送信される Ping イベント。
  160. ### エラー
  161. - 400, `invalid_param`, 異常なパラメータ入力
  162. - 400, `app_unavailable`, アプリの設定が利用できません
  163. - 400, `provider_not_initialize`, 利用可能なモデル資格情報の設定がありません
  164. - 400, `provider_quota_exceeded`, モデル呼び出しのクォータが不足しています
  165. - 400, `model_currently_not_support`, 現在のモデルは利用できません
  166. - 400, `workflow_request_error`, ワークフロー実行に失敗しました
  167. - 500, 内部サーバーエラー
  168. </Col>
  169. <Col sticky>
  170. <CodeGroup title="リクエスト" tag="POST" label="/workflows/run" targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/run' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "response_mode": "streaming",\n "user": "abc-123"\n}'\n`}>
  171. ```bash {{ title: 'cURL' }}
  172. curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
  173. --header 'Authorization: Bearer {api_key}' \
  174. --header 'Content-Type: application/json' \
  175. --data-raw '{
  176. "inputs": {},
  177. "response_mode": "streaming",
  178. "user": "abc-123"
  179. }'
  180. ```
  181. </CodeGroup>
  182. <CodeGroup title="ファイル変数の例">
  183. ```json {{ title: 'ファイル変数の例' }}
  184. {
  185. "inputs": {
  186. "{variable_name}":
  187. [
  188. {
  189. "transfer_method": "local_file",
  190. "upload_file_id": "{upload_file_id}",
  191. "type": "{document_type}"
  192. }
  193. ]
  194. }
  195. }
  196. ```
  197. </CodeGroup>
  198. ### ブロッキングモード
  199. <CodeGroup title="応答">
  200. ```json {{ title: '応答' }}
  201. {
  202. "workflow_run_id": "djflajgkldjgd",
  203. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  204. "data": {
  205. "id": "fdlsjfjejkghjda",
  206. "workflow_id": "fldjaslkfjlsda",
  207. "status": "succeeded",
  208. "outputs": {
  209. "text": "Nice to meet you."
  210. },
  211. "error": null,
  212. "elapsed_time": 0.875,
  213. "total_tokens": 3562,
  214. "total_steps": 8,
  215. "created_at": 1705407629,
  216. "finished_at": 1727807631
  217. }
  218. }
  219. ```
  220. </CodeGroup>
  221. ### ストリーミングモード
  222. <CodeGroup title="応答">
  223. ```streaming {{ title: '応答' }}
  224. 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", "sequence_number": 1, "created_at": 1679586595}}
  225. 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}}
  226. 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}}
  227. 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}}
  228. 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"}
  229. 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": ""}
  230. ```
  231. </CodeGroup>
  232. <CodeGroup title="ファイルアップロードのサンプルコード">
  233. ```json {{ title: 'ファイルアップロードのサンプルコード' }}
  234. import requests
  235. import json
  236. def upload_file(file_path, user):
  237. upload_url = "https://api.dify.ai/v1/files/upload"
  238. headers = {
  239. "Authorization": "Bearer app-xxxxxxxx",
  240. }
  241. try:
  242. print("ファイルをアップロードしています...")
  243. with open(file_path, 'rb') as file:
  244. files = {
  245. 'file': (file_path, file, 'text/plain') # ファイルが適切な MIME タイプでアップロードされていることを確認してください
  246. }
  247. data = {
  248. "user": user,
  249. "type": "TXT" # ファイルタイプをTXTに設定します
  250. }
  251. response = requests.post(upload_url, headers=headers, files=files, data=data)
  252. if response.status_code == 201: # 201 は作成が成功したことを意味します
  253. print("ファイルが正常にアップロードされました")
  254. return response.json().get("id") # アップロードされたファイルIDを取得する
  255. else:
  256. print(f"ファイルのアップロードに失敗しました。ステータス コード: {response.status_code}")
  257. return None
  258. except Exception as e:
  259. print(f"エラーが発生しました: {str(e)}")
  260. return None
  261. def run_workflow(file_id, user, response_mode="blocking"):
  262. workflow_url = "https://api.dify.ai/v1/workflows/run"
  263. headers = {
  264. "Authorization": "Bearer app-xxxxxxxxx",
  265. "Content-Type": "application/json"
  266. }
  267. data = {
  268. "inputs": {
  269. "orig_mail": [{
  270. "transfer_method": "local_file",
  271. "upload_file_id": file_id,
  272. "type": "document"
  273. }]
  274. },
  275. "response_mode": response_mode,
  276. "user": user
  277. }
  278. try:
  279. print("ワークフローを実行...")
  280. response = requests.post(workflow_url, headers=headers, json=data)
  281. if response.status_code == 200:
  282. print("ワークフローが正常に実行されました")
  283. return response.json()
  284. else:
  285. print(f"ワークフローの実行がステータス コードで失敗しました: {response.status_code}")
  286. return {"status": "error", "message": f"Failed to execute workflow, status code: {response.status_code}"}
  287. except Exception as e:
  288. print(f"エラーが発生しました: {str(e)}")
  289. return {"status": "error", "message": str(e)}
  290. # 使用例
  291. file_path = "{your_file_path}"
  292. user = "difyuser"
  293. # ファイルをアップロードする
  294. file_id = upload_file(file_path, user)
  295. if file_id:
  296. # ファイルは正常にアップロードされました。ワークフローの実行を続行します
  297. result = run_workflow(file_id, user)
  298. print(result)
  299. else:
  300. print("ファイルのアップロードに失敗し、ワークフローを実行できません")
  301. ```
  302. </CodeGroup>
  303. </Col>
  304. </Row>
  305. ---
  306. <Heading
  307. url='/workflows/run/:workflow_id'
  308. method='GET'
  309. title='ワークフロー実行詳細を取得'
  310. name='#get-workflow-run-detail'
  311. />
  312. <Row>
  313. <Col>
  314. ワークフロー実行 ID に基づいて、ワークフロータスクの現在の実行結果を取得します。
  315. ### パス
  316. - `workflow_id` (string) ワークフローID、ストリーミングチャンクの返り値から取得可能
  317. ### 応答
  318. - `id` (string) ワークフロー実行の ID
  319. - `workflow_id` (string) 関連するワークフローの ID
  320. - `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
  321. - `inputs` (json) 入力内容
  322. - `outputs` (json) 出力内容
  323. - `error` (string) エラー理由
  324. - `total_steps` (int) タスクの総ステップ数
  325. - `total_tokens` (int) 使用されるトークンの総数
  326. - `created_at` (timestamp) 開始時間
  327. - `finished_at` (timestamp) 終了時間
  328. - `elapsed_time` (float) 使用される総秒数
  329. </Col>
  330. <Col sticky>
  331. ### リクエスト例
  332. <CodeGroup title="リクエスト" tag="GET" label="/workflows/run/:workflow_id" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json'`}>
  333. ```bash {{ title: 'cURL' }}
  334. curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \
  335. -H 'Authorization: Bearer {api_key}' \
  336. -H 'Content-Type: application/json'
  337. ```
  338. </CodeGroup>
  339. ### 応答例
  340. <CodeGroup title="応答">
  341. ```json {{ title: '応答' }}
  342. {
  343. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  344. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  345. "status": "succeeded",
  346. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  347. "outputs": null,
  348. "error": null,
  349. "total_steps": 3,
  350. "total_tokens": 0,
  351. "created_at": 1705407629,
  352. "finished_at": 1727807631,
  353. "elapsed_time": 30.098514399956912
  354. }
  355. ```
  356. </CodeGroup>
  357. </Col>
  358. </Row>
  359. ---
  360. <Heading
  361. url='/workflows/tasks/:task_id/stop'
  362. method='POST'
  363. title='生成を停止'
  364. name='#stop-generatebacks'
  365. />
  366. <Row>
  367. <Col>
  368. ストリーミングモードでのみサポートされています。
  369. ### パス
  370. - `task_id` (string) タスク ID、ストリーミングチャンクの返り値から取得可能
  371. ### リクエストボディ
  372. - `user` (string) 必須
  373. ユーザー識別子、エンドユーザーのアイデンティティを定義するために使用され、送信メッセージインターフェースで渡されたユーザーと一致している必要があります。
  374. ### 応答
  375. - `result` (string) 常に"success"を返します
  376. </Col>
  377. <Col sticky>
  378. ### リクエスト例
  379. <CodeGroup title="リクエスト" tag="POST" label="/workflows/tasks/:task_id/stop" targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{"user": "abc-123"}'`}>
  380. ```bash {{ title: 'cURL' }}
  381. curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \
  382. -H 'Authorization: Bearer {api_key}' \
  383. -H 'Content-Type: application/json' \
  384. --data-raw '{
  385. "user": "abc-123"
  386. }'
  387. ```
  388. </CodeGroup>
  389. ### 応答例
  390. <CodeGroup title="応答">
  391. ```json {{ title: '応答' }}
  392. {
  393. "result": "success"
  394. }
  395. ```
  396. </CodeGroup>
  397. </Col>
  398. </Row>
  399. ---
  400. <Heading
  401. url='/files/upload'
  402. method='POST'
  403. title='ファイルアップロード'
  404. name='#file-upload'
  405. />
  406. <Row>
  407. <Col>
  408. メッセージ送信時に使用するためのファイルをアップロードし、画像とテキストのマルチモーダル理解を可能にします。
  409. ワークフローでサポートされている任意の形式をサポートします。
  410. アップロードされたファイルは、現在のエンドユーザーのみが使用できます。
  411. ### リクエストボディ
  412. このインターフェースは`multipart/form-data`リクエストを必要とします。
  413. - `file` (File) 必須
  414. アップロードするファイル。
  415. - `user` (string) 必須
  416. ユーザー識別子、開発者のルールで定義され、アプリケーション内で一意でなければなりません。
  417. ### 応答
  418. アップロードが成功すると、サーバーはファイルの ID と関連情報を返します。
  419. - `id` (uuid) ID
  420. - `name` (string) ファイル名
  421. - `size` (int) ファイルサイズ(バイト)
  422. - `extension` (string) ファイル拡張子
  423. - `mime_type` (string) ファイルの MIME タイプ
  424. - `created_by` (uuid) エンドユーザーID
  425. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  426. ### エラー
  427. - 400, `no_file_uploaded`, ファイルが提供されていません
  428. - 400, `too_many_files`, 現在は 1 つのファイルのみ受け付けています
  429. - 400, `unsupported_preview`, ファイルはプレビューをサポートしていません
  430. - 400, `unsupported_estimate`, ファイルは推定をサポートしていません
  431. - 413, `file_too_large`, ファイルが大きすぎます
  432. - 415, `unsupported_file_type`, サポートされていない拡張子、現在はドキュメントファイルのみ受け付けています
  433. - 503, `s3_connection_failed`, S3 サービスに接続できません
  434. - 503, `s3_permission_denied`, S3 にファイルをアップロードする権限がありません
  435. - 503, `s3_file_too_large`, ファイルが S3 のサイズ制限を超えています
  436. - 500, 内部サーバーエラー
  437. </Col>
  438. <Col sticky>
  439. ### リクエスト例
  440. <CodeGroup title="リクエスト" tag="POST" label="/files/upload" targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\\n--form 'user=abc-123'`}>
  441. ```bash {{ title: 'cURL' }}
  442. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  443. --header 'Authorization: Bearer {api_key}' \
  444. --form 'file=@"/path/to/file"'
  445. ```
  446. </CodeGroup>
  447. ### 応答例
  448. <CodeGroup title="応答">
  449. ```json {{ title: '応答' }}
  450. {
  451. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  452. "name": "example.png",
  453. "size": 1024,
  454. "extension": "png",
  455. "mime_type": "image/png",
  456. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  457. "created_at": 1577836800,
  458. }
  459. ```
  460. </CodeGroup>
  461. </Col>
  462. </Row>
  463. ---
  464. <Heading
  465. url='/workflows/logs'
  466. method='GET'
  467. title='ワークフローログを取得'
  468. name='#Get-Workflow-Logs'
  469. />
  470. <Row>
  471. <Col>
  472. ワークフローログを返します。最初のページは最新の`{limit}`メッセージを返します。つまり、逆順です。
  473. ### クエリ
  474. <Properties>
  475. <Property name='keyword' type='string' key='keyword'>
  476. 検索するキーワード
  477. </Property>
  478. <Property name='status' type='string' key='status'>
  479. succeeded/failed/stopped
  480. </Property>
  481. <Property name='page' type='int' key='page'>
  482. 現在のページ、デフォルトは1。
  483. </Property>
  484. <Property name='limit' type='int' key='limit'>
  485. 1回のリクエストで返すチャット履歴メッセージの数、デフォルトは20。
  486. </Property>
  487. </Properties>
  488. ### 応答
  489. - `page` (int) 現在のページ
  490. - `limit` (int) 返されたアイテムの数、入力がシステム制限を超える場合、システム制限量を返します
  491. - `total` (int) 合計アイテム数
  492. - `has_more` (bool) 次のページがあるかどうか
  493. - `data` (array[object]) ログリスト
  494. - `id` (string) ID
  495. - `workflow_run` (object) ワークフロー実行
  496. - `id` (string) ID
  497. - `version` (string) バージョン
  498. - `status` (string) 実行のステータス、`running` / `succeeded` / `failed` / `stopped`
  499. - `error` (string) オプションのエラー理由
  500. - `elapsed_time` (float) 使用される総秒数
  501. - `total_tokens` (int) 使用されるトークン数
  502. - `total_steps` (int) デフォルト 0
  503. - `created_at` (timestamp) 開始時間
  504. - `finished_at` (timestamp) 終了時間
  505. - `created_from` (string) 作成元
  506. - `created_by_role` (string) 作成者の役割
  507. - `created_by_account` (string) オプションの作成者アカウント
  508. - `created_by_end_user` (object) エンドユーザーによって作成
  509. - `id` (string) ID
  510. - `type` (string) タイプ
  511. - `is_anonymous` (bool) 匿名かどうか
  512. - `session_id` (string) セッション ID
  513. - `created_at` (timestamp) 作成時間
  514. </Col>
  515. <Col sticky>
  516. <CodeGroup title="リクエスト" tag="GET" label="/workflows/logs" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/logs'\\\n --header 'Authorization: Bearer {api_key}'`}>
  517. ```bash {{ title: 'cURL' }}
  518. curl -X GET '${props.appDetail.api_base_url}/workflows/logs?limit=1'
  519. --header 'Authorization: Bearer {api_key}'
  520. ```
  521. </CodeGroup>
  522. ### 応答例
  523. <CodeGroup title="応答">
  524. ```json {{ title: '応答' }}
  525. {
  526. "page": 1,
  527. "limit": 1,
  528. "total": 7,
  529. "has_more": true,
  530. "data": [
  531. {
  532. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  533. "workflow_run": {
  534. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  535. "version": "2024-08-01 12:17:09.771832",
  536. "status": "succeeded",
  537. "error": null,
  538. "elapsed_time": 1.3588523610014818,
  539. "total_tokens": 0,
  540. "total_steps": 3,
  541. "created_at": 1726139643,
  542. "finished_at": 1726139644
  543. },
  544. "created_from": "service-api",
  545. "created_by_role": "end_user",
  546. "created_by_account": null,
  547. "created_by_end_user": {
  548. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  549. "type": "service_api",
  550. "is_anonymous": false,
  551. "session_id": "abc-123"
  552. },
  553. "created_at": 1726139644
  554. }
  555. ]
  556. }
  557. ```
  558. </CodeGroup>
  559. </Col>
  560. </Row>
  561. ---
  562. <Heading
  563. url='/info'
  564. method='GET'
  565. title='アプリケーションの基本情報を取得'
  566. name='#info'
  567. />
  568. <Row>
  569. <Col>
  570. このアプリケーションの基本情報を取得するために使用されます
  571. ### Response
  572. - `name` (string) アプリケーションの名前
  573. - `description` (string) アプリケーションの説明
  574. - `tags` (array[string]) アプリケーションのタグ
  575. - `mode` (string) アプリケーションのモード
  576. - `author_name` (string) 作者の名前
  577. </Col>
  578. <Col>
  579. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  580. ```bash {{ title: 'cURL' }}
  581. curl -X GET '${props.appDetail.api_base_url}/info' \
  582. -H 'Authorization: Bearer {api_key}'
  583. ```
  584. </CodeGroup>
  585. <CodeGroup title="Response">
  586. ```json {{ title: 'Response' }}
  587. {
  588. "name": "My App",
  589. "description": "This is my app.",
  590. "tags": [
  591. "tag1",
  592. "tag2"
  593. ],
  594. "mode": "workflow",
  595. "author_name": "Dify"
  596. }
  597. ```
  598. </CodeGroup>
  599. </Col>
  600. </Row>
  601. ---
  602. <Heading
  603. url='/parameters'
  604. method='GET'
  605. title='アプリケーションのパラメータ情報を取得'
  606. name='#parameters'
  607. />
  608. <Row>
  609. <Col>
  610. ページに入る際に、機能、入力パラメータ名、タイプ、デフォルト値などの情報を取得するために使用されます。
  611. ### 応答
  612. - `user_input_form` (array[object]) ユーザー入力フォームの設定
  613. - `text-input` (object) テキスト入力コントロール
  614. - `label` (string) 変数表示ラベル名
  615. - `variable` (string) 変数ID
  616. - `required` (bool) 必須かどうか
  617. - `default` (string) デフォルト値
  618. - `paragraph` (object) 段落テキスト入力コントロール
  619. - `label` (string) 変数表示ラベル名
  620. - `variable` (string) 変数ID
  621. - `required` (bool) 必須かどうか
  622. - `default` (string) デフォルト値
  623. - `select` (object) ドロップダウンコントロール
  624. - `label` (string) 変数表示ラベル名
  625. - `variable` (string) 変数ID
  626. - `required` (bool) 必須かどうか
  627. - `default` (string) デフォルト値
  628. - `options` (array[string]) オプション値
  629. - `file_upload` (object) ファイルアップロード設定
  630. - `image` (object) 画像設定
  631. 現在サポートされている画像タイプのみ:`png`, `jpg`, `jpeg`, `webp`, `gif`
  632. - `enabled` (bool) 有効かどうか
  633. - `number_limits` (int) 画像数の制限、デフォルトは3
  634. - `transfer_methods` (array[string]) 転送方法のリスト、remote_url, local_file、いずれかを選択する必要があります
  635. - `system_parameters` (object) システムパラメータ
  636. - `file_size_limit` (int) ドキュメントアップロードサイズ制限(MB)
  637. - `image_file_size_limit` (int) 画像ファイルアップロードサイズ制限(MB)
  638. - `audio_file_size_limit` (int) オーディオファイルアップロードサイズ制限(MB)
  639. - `video_file_size_limit` (int) ビデオファイルアップロードサイズ制限(MB)
  640. </Col>
  641. <Col sticky>
  642. <CodeGroup title="リクエスト" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  643. ```bash {{ title: 'cURL' }}
  644. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  645. --header 'Authorization: Bearer {api_key}'
  646. ```
  647. </CodeGroup>
  648. <CodeGroup title="応答">
  649. ```json {{ title: '応答' }}
  650. {
  651. "user_input_form": [
  652. {
  653. "paragraph": {
  654. "label": "Query",
  655. "variable": "query",
  656. "required": true,
  657. "default": ""
  658. }
  659. }
  660. ],
  661. "file_upload": {
  662. "image": {
  663. "enabled": false,
  664. "number_limits": 3,
  665. "detail": "high",
  666. "transfer_methods": [
  667. "remote_url",
  668. "local_file"
  669. ]
  670. }
  671. },
  672. "system_parameters": {
  673. "file_size_limit": 15,
  674. "image_file_size_limit": 10,
  675. "audio_file_size_limit": 50,
  676. "video_file_size_limit": 100
  677. }
  678. }
  679. ```
  680. </CodeGroup>
  681. </Col>
  682. </Row>
  683. ———
  684. <Heading
  685. url='/site'
  686. method='GET'
  687. title='アプリのWebApp設定を取得'
  688. name='#site'
  689. />
  690. <Row>
  691. <Col>
  692. アプリの WebApp 設定を取得するために使用します。
  693. ### 応答
  694. - `title` (string) WebApp 名
  695. - `icon_type` (string) アイコンタイプ、`emoji`-絵文字、`image`-画像
  696. - `icon` (string) アイコン。`emoji`タイプの場合は絵文字、`image`タイプの場合は画像 URL
  697. - `icon_background` (string) 16 進数形式の背景色
  698. - `icon_url` (string) アイコンの URL
  699. - `description` (string) 説明
  700. - `copyright` (string) 著作権情報
  701. - `privacy_policy` (string) プライバシーポリシーのリンク
  702. - `custom_disclaimer` (string) カスタム免責事項
  703. - `default_language` (string) デフォルト言語
  704. - `show_workflow_steps` (bool) ワークフローの詳細を表示するかどうか
  705. </Col>
  706. <Col>
  707. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  708. ```bash {{ title: 'cURL' }}
  709. curl -X GET '${props.appDetail.api_base_url}/site' \
  710. -H 'Authorization: Bearer {api_key}'
  711. ```
  712. </CodeGroup>
  713. <CodeGroup title="Response">
  714. ```json {{ title: 'Response' }}
  715. {
  716. "title": "My App",
  717. "icon_type": "emoji",
  718. "icon": "😄",
  719. "icon_background": "#FFEAD5",
  720. "icon_url": null,
  721. "description": "This is my app.",
  722. "copyright": "all rights reserved",
  723. "privacy_policy": "",
  724. "custom_disclaimer": "All generated by AI",
  725. "default_language": "en-US",
  726. "show_workflow_steps": false,
  727. }
  728. ```
  729. </CodeGroup>
  730. </Col>
  731. </Row>
  732. ___