template_workflow.zh.mdx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Workflow 应用 API
  4. Workflow 应用无会话支持,适合用于翻译/文章写作/总结 AI 等等。
  5. <div>
  6. ### Base URL
  7. <CodeGroup title="Code" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### Authentication
  12. Dify Service API 使用 `API-Key` 进行鉴权。
  13. <i>**强烈建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。**</i>
  14. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  15. <CodeGroup title="Code">
  16. ```javascript
  17. Authorization: Bearer {API_KEY}
  18. ```
  19. </CodeGroup>
  20. </div>
  21. ---
  22. <Heading
  23. url='/workflows/run'
  24. method='POST'
  25. title='执行 workflow'
  26. name='#Execute-Workflow'
  27. />
  28. <Row>
  29. <Col>
  30. 执行 workflow,没有已发布的 workflow,不可执行。
  31. ### Request Body
  32. - `inputs` (object) Required
  33. 允许传入 App 定义的各变量值。
  34. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。
  35. 如果变量是文件类型,请指定一个包含以下 `files` 中所述键的对象。
  36. - `response_mode` (string) Required
  37. 返回响应模式,支持:
  38. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  39. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  40. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  41. - `user` (string) Required
  42. 用户标识,用于定义终端用户的身份,方便检索、统计。
  43. 由开发者定义规则,需保证用户标识在应用内唯一。
  44. - `files` (array[object]) Optional
  45. 文件列表,适用于传入文件结合文本理解并回答问题,仅当模型支持 Vision 能力时可用。
  46. - `type` (string) 支持类型:
  47. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  48. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  49. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  50. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  51. - `transfer_method` (string) 传递方式,`remote_url` 图片地址 / `local_file` 上传文件
  52. - `url` (string) 图片地址(仅当传递方式为 `remote_url` 时)
  53. - `upload_file_id` (string) (string) 上传文件 ID(仅当传递方式为 `local_file` 时)
  54. ### Response
  55. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  56. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  57. ### CompletionResponse
  58. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  59. - `workflow_run_id` (string) workflow 执行 ID
  60. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  61. - `data` (object) 详细内容
  62. - `id` (string) workflow 执行 ID
  63. - `workflow_id` (string) 关联 Workflow ID
  64. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  65. - `outputs` (json) Optional 输出内容
  66. - `error` (string) Optional 错误原因
  67. - `elapsed_time` (float) Optional 耗时(s)
  68. - `total_tokens` (int) Optional 总使用 tokens
  69. - `total_steps` (int) 总步数(冗余),默认 0
  70. - `created_at` (timestamp) 开始时间
  71. - `finished_at` (timestamp) 结束时间
  72. ### ChunkCompletionResponse
  73. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  74. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  75. <CodeGroup>
  76. ```streaming {{ title: 'Response' }}
  77. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  78. ```
  79. </CodeGroup>
  80. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  81. - `event: workflow_started` workflow 开始执行
  82. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  83. - `workflow_run_id` (string) workflow 执行 ID
  84. - `event` (string) 固定为 `workflow_started`
  85. - `data` (object) 详细内容
  86. - `id` (string) workflow 执行 ID
  87. - `workflow_id` (string) 关联 Workflow ID
  88. - `sequence_number` (int) 自增序号,App 内自增,从 1 开始
  89. - `created_at` (timestamp) 开始时间
  90. - `event: node_started` node 开始执行
  91. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  92. - `workflow_run_id` (string) workflow 执行 ID
  93. - `event` (string) 固定为 `node_started`
  94. - `data` (object) 详细内容
  95. - `id` (string) workflow 执行 ID
  96. - `node_id` (string) 节点 ID
  97. - `node_type` (string) 节点类型
  98. - `title` (string) 节点名称
  99. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  100. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  101. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  102. - `created_at` (timestamp) 开始时间
  103. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  104. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  105. - `workflow_run_id` (string) workflow 执行 ID
  106. - `event` (string) 固定为 `node_finished`
  107. - `data` (object) 详细内容
  108. - `id` (string) node 执行 ID
  109. - `node_id` (string) 节点 ID
  110. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  111. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  112. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  113. - `process_data` (json) Optional 节点过程数据
  114. - `outputs` (json) Optional 输出内容
  115. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  116. - `error` (string) Optional 错误原因
  117. - `elapsed_time` (float) Optional 耗时(s)
  118. - `execution_metadata` (json) 元数据
  119. - `total_tokens` (int) optional 总使用 tokens
  120. - `total_price` (decimal) optional 总费用
  121. - `currency` (string) optional 货币,如 `USD` / `RMB`
  122. - `created_at` (timestamp) 开始时间
  123. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  124. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  125. - `workflow_run_id` (string) workflow 执行 ID
  126. - `event` (string) 固定为 `workflow_finished`
  127. - `data` (object) 详细内容
  128. - `id` (string) workflow 执行 ID
  129. - `workflow_id` (string) 关联 Workflow ID
  130. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  131. - `outputs` (json) Optional 输出内容
  132. - `error` (string) Optional 错误原因
  133. - `elapsed_time` (float) Optional 耗时(s)
  134. - `total_tokens` (int) Optional 总使用 tokens
  135. - `total_steps` (int) 总步数(冗余),默认 0
  136. - `created_at` (timestamp) 开始时间
  137. - `finished_at` (timestamp) 结束时间
  138. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  139. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  140. - `message_id` (string) 消息唯一 ID
  141. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  142. - `created_at` (int) 创建时间戳,如:1705395332
  143. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  144. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  145. - `message_id` (string) 消息唯一 ID
  146. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  147. - `created_at` (int) 创建时间戳,如:1705395332
  148. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  149. ### Errors
  150. - 400,`invalid_param`,传入参数异常
  151. - 400,`app_unavailable`,App 配置不可用
  152. - 400,`provider_not_initialize`,无可用模型凭据配置
  153. - 400,`provider_quota_exceeded`,模型调用额度不足
  154. - 400,`model_currently_not_support`,当前模型不可用
  155. - 400,`workflow_request_error`,workflow 执行失败
  156. - 500,服务内部异常
  157. </Col>
  158. <Col sticky>
  159. <CodeGroup title="Request" 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`}>
  160. ```bash {{ title: 'cURL' }}
  161. curl -X POST '${props.appDetail.api_base_url}/workflows/run' \
  162. --header 'Authorization: Bearer {api_key}' \
  163. --header 'Content-Type: application/json' \
  164. --data-raw '{
  165. "inputs": {},
  166. "response_mode": "streaming",
  167. "user": "abc-123"
  168. }'
  169. ```
  170. </CodeGroup>
  171. ### Blocking Mode
  172. <CodeGroup title="Response">
  173. ```json {{ title: 'Response' }}
  174. {
  175. "workflow_run_id": "djflajgkldjgd",
  176. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  177. "data": {
  178. "id": "fdlsjfjejkghjda",
  179. "workflow_id": "fldjaslkfjlsda",
  180. "status": "succeeded",
  181. "outputs": {
  182. "text": "Nice to meet you."
  183. },
  184. "error": null,
  185. "elapsed_time": 0.875,
  186. "total_tokens": 3562,
  187. "total_steps": 8,
  188. "created_at": 1705407629,
  189. "finished_at": 1727807631
  190. }
  191. }
  192. ```
  193. </CodeGroup>
  194. ### Streaming Mode
  195. <CodeGroup title="Response">
  196. ```streaming {{ title: 'Response' }}
  197. 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}}
  198. 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}}
  199. 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}}
  200. 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}}
  201. 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"}
  202. 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": ""}
  203. ```
  204. </CodeGroup>
  205. </Col>
  206. </Row>
  207. ---
  208. <Heading
  209. url='/workflows/run/:workflow_id'
  210. method='GET'
  211. title='获取workflow执行情况'
  212. name='#get-workflow-run-detail'
  213. />
  214. <Row>
  215. <Col>
  216. 根据 workflow 执行 ID 获取 workflow 任务当前执行结果
  217. ### Path
  218. - `workflow_id` (string) workflow 执行 ID,可在流式返回 Chunk 中获取
  219. ### Response
  220. - `id` (string) workflow 执行 ID
  221. - `workflow_id` (string) 关联的 Workflow ID
  222. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  223. - `inputs` (json) 任务输入内容
  224. - `outputs` (json) 任务输出内容
  225. - `error` (string) 错误原因
  226. - `total_steps` (int) 任务执行总步数
  227. - `total_tokens` (int) 任务执行总 tokens
  228. - `created_at` (timestamp) 任务开始时间
  229. - `finished_at` (timestamp) 任务结束时间
  230. - `elapsed_time` (float) 耗时(s)
  231. </Col>
  232. <Col sticky>
  233. ### Request Example
  234. <CodeGroup title="Request" 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'`}>
  235. ```bash {{ title: 'cURL' }}
  236. curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \
  237. -H 'Authorization: Bearer {api_key}' \
  238. -H 'Content-Type: application/json'
  239. ```
  240. </CodeGroup>
  241. ### Response Example
  242. <CodeGroup title="Response">
  243. ```json {{ title: 'Response' }}
  244. {
  245. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  246. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  247. "status": "succeeded",
  248. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  249. "outputs": null,
  250. "error": null,
  251. "total_steps": 3,
  252. "total_tokens": 0,
  253. "created_at": "Thu, 18 Jul 2024 03:17:40 -0000",
  254. "finished_at": "Thu, 18 Jul 2024 03:18:10 -0000",
  255. "elapsed_time": 30.098514399956912
  256. }
  257. ```
  258. </CodeGroup>
  259. </Col>
  260. </Row>
  261. ---
  262. <Heading
  263. url='/workflows/tasks/:task_id/stop'
  264. method='POST'
  265. title='停止响应'
  266. name='#stop-generatebacks'
  267. />
  268. <Row>
  269. <Col>
  270. 仅支持流式模式。
  271. ### Path
  272. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  273. ### Request Body
  274. - `user` (string) Required
  275. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  276. ### Response
  277. - `result` (string) 固定返回 "success"
  278. </Col>
  279. <Col sticky>
  280. ### Request Example
  281. <CodeGroup title="Request" 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"}'`}>
  282. ```bash {{ title: 'cURL' }}
  283. curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \
  284. -H 'Authorization: Bearer {api_key}' \
  285. -H 'Content-Type: application/json' \
  286. --data-raw '{
  287. "user": "abc-123"
  288. }'
  289. ```
  290. </CodeGroup>
  291. ### Response Example
  292. <CodeGroup title="Response">
  293. ```json {{ title: 'Response' }}
  294. {
  295. "result": "success"
  296. }
  297. ```
  298. </CodeGroup>
  299. </Col>
  300. </Row>
  301. ---
  302. <Heading
  303. url='/files/upload'
  304. method='POST'
  305. title='上传文件'
  306. name='#files-upload'
  307. />
  308. <Row>
  309. <Col>
  310. 上传文件并在发送消息时使用,可实现图文多模态理解。
  311. 支持您的工作流程所支持的任何格式。
  312. <i>上传的文件仅供当前终端用户使用。</i>
  313. ### Request Body
  314. 该接口需使用 `multipart/form-data` 进行请求。
  315. <Properties>
  316. <Property name='file' type='file' key='file'>
  317. 要上传的文件。
  318. </Property>
  319. <Property name='user' type='string' key='user'>
  320. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  321. </Property>
  322. </Properties>
  323. ### Response
  324. 成功上传后,服务器会返回文件的 ID 和相关信息。
  325. - `id` (uuid) ID
  326. - `name` (string) 文件名
  327. - `size` (int) 文件大小(byte)
  328. - `extension` (string) 文件后缀
  329. - `mime_type` (string) 文件 mime-type
  330. - `created_by` (uuid) 上传人 ID
  331. - `created_at` (timestamp) 上传时间
  332. ### Errors
  333. - 400,`no_file_uploaded`,必须提供文件
  334. - 400,`too_many_files`,目前只接受一个文件
  335. - 400,`unsupported_preview`,该文件不支持预览
  336. - 400,`unsupported_estimate`,该文件不支持估算
  337. - 413,`file_too_large`,文件太大
  338. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  339. - 503,`s3_connection_failed`,无法连接到 S3 服务
  340. - 503,`s3_permission_denied`,无权限上传文件到 S3
  341. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  342. </Col>
  343. <Col sticky>
  344. <CodeGroup title="Request" 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'`}>
  345. ```bash {{ title: 'cURL' }}
  346. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  347. --header 'Authorization: Bearer {api_key}' \
  348. --form 'file=@"/path/to/file"'
  349. ```
  350. </CodeGroup>
  351. <CodeGroup title="Response">
  352. ```json {{ title: 'Response' }}
  353. {
  354. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  355. "name": "example.png",
  356. "size": 1024,
  357. "extension": "png",
  358. "mime_type": "image/png",
  359. "created_by": 123,
  360. "created_at": 1577836800,
  361. }
  362. ```
  363. </CodeGroup>
  364. </Col>
  365. </Row>
  366. ---
  367. <Heading
  368. url='/parameters'
  369. method='GET'
  370. title='获取应用配置信息'
  371. name='#parameters'
  372. />
  373. <Row>
  374. <Col>
  375. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  376. ### Query
  377. <Properties>
  378. <Property name='user' type='string' key='user'>
  379. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  380. </Property>
  381. </Properties>
  382. ### Response
  383. - `user_input_form` (array[object]) 用户输入表单配置
  384. - `text-input` (object) 文本输入控件
  385. - `label` (string) 控件展示标签名
  386. - `variable` (string) 控件 ID
  387. - `required` (bool) 是否必填
  388. - `default` (string) 默认值
  389. - `paragraph` (object) 段落文本输入控件
  390. - `label` (string) 控件展示标签名
  391. - `variable` (string) 控件 ID
  392. - `required` (bool) 是否必填
  393. - `default` (string) 默认值
  394. - `select` (object) 下拉控件
  395. - `label` (string) 控件展示标签名
  396. - `variable` (string) 控件 ID
  397. - `required` (bool) 是否必填
  398. - `default` (string) 默认值
  399. - `options` (array[string]) 选项值
  400. - `file_upload` (object) 文件上传配置
  401. - `image` (object) 图片设置
  402. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  403. - `enabled` (bool) 是否开启
  404. - `number_limits` (int) 图片数量限制,默认 3
  405. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  406. - `system_parameters` (object) 系统参数
  407. - `file_size_limit` (int) 文档上传大小限制 (MB)
  408. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  409. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  410. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  411. </Col>
  412. <Col sticky>
  413. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123'`}>
  414. ```bash {{ title: 'cURL' }}
  415. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  416. --header 'Authorization: Bearer {api_key}'
  417. ```
  418. </CodeGroup>
  419. <CodeGroup title="Response">
  420. ```json {{ title: 'Response' }}
  421. {
  422. "user_input_form": [
  423. {
  424. "paragraph": {
  425. "label": "Query",
  426. "variable": "query",
  427. "required": true,
  428. "default": ""
  429. }
  430. }
  431. ],
  432. "file_upload": {
  433. "image": {
  434. "enabled": false,
  435. "number_limits": 3,
  436. "detail": "high",
  437. "transfer_methods": [
  438. "remote_url",
  439. "local_file"
  440. ]
  441. }
  442. },
  443. "system_parameters": {
  444. "file_size_limit": 15,
  445. "image_file_size_limit": 10,
  446. "audio_file_size_limit": 50,
  447. "video_file_size_limit": 100
  448. }
  449. }
  450. ```
  451. </CodeGroup>
  452. </Col>
  453. </Row>
  454. ---
  455. <Heading
  456. url='/workflows/logs'
  457. method='GET'
  458. title='获取 workflow 日志'
  459. name='#Get-Workflow-Logs'
  460. />
  461. <Row>
  462. <Col>
  463. 倒序返回workflow日志
  464. ### Query
  465. <Properties>
  466. <Property name='keyword' type='string' key='keyword'>
  467. 关键字
  468. </Property>
  469. <Property name='status' type='string' key='status'>
  470. 执行状态 succeeded/failed/stopped
  471. </Property>
  472. <Property name='page' type='int' key='page'>
  473. 当前页码, 默认1.
  474. </Property>
  475. <Property name='limit' type='int' key='limit'>
  476. 每页条数, 默认20.
  477. </Property>
  478. </Properties>
  479. ### Response
  480. - `page` (int) 当前页码
  481. - `limit` (int) 每页条数
  482. - `total` (int) 总条数
  483. - `has_more` (bool) 是否还有更多数据
  484. - `data` (array[object]) 当前页码的数据
  485. - `id` (string) 标识
  486. - `workflow_run` (object) Workflow 执行日志
  487. - `id` (string) 标识
  488. - `version` (string) 版本
  489. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  490. - `error` (string) (可选) 错误
  491. - `elapsed_time` (float) 耗时,单位秒
  492. - `total_tokens` (int) 消耗的token数量
  493. - `total_steps` (int) 执行步骤长度
  494. - `created_at` (timestamp) 开始时间
  495. - `finished_at` (timestamp) 结束时间
  496. - `created_from` (string) 来源
  497. - `created_by_role` (string) 角色
  498. - `created_by_account` (string) (可选) 帐号
  499. - `created_by_end_user` (object) 用户
  500. - `id` (string) 标识
  501. - `type` (string) 类型
  502. - `is_anonymous` (bool) 是否匿名
  503. - `session_id` (string) 会话标识
  504. - `created_at` (timestamp) 创建时间
  505. </Col>
  506. <Col sticky>
  507. <CodeGroup title="Request" tag="GET" label="/workflows/logs" targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/logs'\\\n --header 'Authorization: Bearer {api_key}'`}>
  508. ```bash {{ title: 'cURL' }}
  509. curl -X GET '${props.appDetail.api_base_url}/workflows/logs?limit=1'
  510. --header 'Authorization: Bearer {api_key}'
  511. ```
  512. </CodeGroup>
  513. ### Response Example
  514. <CodeGroup title="Response">
  515. ```json {{ title: 'Response' }}
  516. {
  517. "page": 1,
  518. "limit": 1,
  519. "total": 7,
  520. "has_more": true,
  521. "data": [
  522. {
  523. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  524. "workflow_run": {
  525. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  526. "version": "2024-08-01 12:17:09.771832",
  527. "status": "succeeded",
  528. "error": null,
  529. "elapsed_time": 1.3588523610014818,
  530. "total_tokens": 0,
  531. "total_steps": 3,
  532. "created_at": 1726139643,
  533. "finished_at": 1726139644
  534. },
  535. "created_from": "service-api",
  536. "created_by_role": "end_user",
  537. "created_by_account": null,
  538. "created_by_end_user": {
  539. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  540. "type": "service_api",
  541. "is_anonymous": false,
  542. "session_id": "abc-123"
  543. },
  544. "created_at": 1726139644
  545. }
  546. ]
  547. }
  548. ```
  549. </CodeGroup>
  550. </Col>
  551. </Row>