Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

template_workflow.zh.mdx 48KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. ### Authentication
  9. Service API 使用 `API-Key` 进行鉴权。
  10. <i>**强烈建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。**</i>
  11. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  12. <CodeGroup title="Code" targetCode='Authorization: Bearer {API_KEY}' />
  13. </div>
  14. ---
  15. <Heading
  16. url='/workflows/run'
  17. method='POST'
  18. title='执行 Workflow'
  19. name='#Execute-Workflow'
  20. />
  21. <Row>
  22. <Col>
  23. 执行 workflow,没有已发布的 workflow,不可执行。
  24. ### Request Body
  25. - `inputs` (object) Required
  26. 允许传入 App 定义的各变量值。
  27. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。变量可以是文件列表类型。
  28. 文件列表类型变量适用于传入文件结合文本理解并回答问题,仅当模型支持该类型文件解析能力时可用。如果该变量是文件列表类型,该变量对应的值应是列表格式,其中每个元素应包含以下内容:
  29. - `type` (string) 支持类型:
  30. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  31. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  32. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  33. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  34. - `custom` 具体类型包含:其他文件类型
  35. - `transfer_method` (string) 传递方式,`remote_url` 图片地址 / `local_file` 上传文件
  36. - `url` (string) 图片地址(仅当传递方式为 `remote_url` 时)
  37. - `upload_file_id` (string) 上传文件 ID(仅当传递方式为 `local_file` 时)
  38. - `response_mode` (string) Required
  39. 返回响应模式,支持:
  40. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  41. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  42. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  43. - `user` (string) Required
  44. 用户标识,用于定义终端用户的身份,方便检索、统计。
  45. 由开发者定义规则,需保证用户标识在应用内唯一。API 无法访问 WebApp 创建的会话。
  46. - `files` (array[object]) 可选
  47. - `trace_id` (string) Optional
  48. 链路追踪ID。适用于与业务系统已有的trace组件打通,实现端到端分布式追踪等场景。如果未指定,系统将自动生成 `trace_id`。支持以下三种方式传递,具体优先级依次为:
  49. 1. Header:推荐通过 HTTP Header `X-Trace-Id` 传递,优先级最高。
  50. 2. Query 参数:通过 URL 查询参数 `trace_id` 传递。
  51. 3. Request Body:通过请求体字段 `trace_id` 传递(即本字段)。
  52. ### Response
  53. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  54. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  55. ### CompletionResponse
  56. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  57. - `workflow_run_id` (string) workflow 执行 ID
  58. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  59. - `data` (object) 详细内容
  60. - `id` (string) workflow 执行 ID
  61. - `workflow_id` (string) 关联 Workflow ID
  62. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  63. - `outputs` (json) Optional 输出内容
  64. - `error` (string) Optional 错误原因
  65. - `elapsed_time` (float) Optional 耗时(s)
  66. - `total_tokens` (int) Optional 总使用 tokens
  67. - `total_steps` (int) 总步数(冗余),默认 0
  68. - `created_at` (timestamp) 开始时间
  69. - `finished_at` (timestamp) 结束时间
  70. ### ChunkCompletionResponse
  71. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  72. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  73. <CodeGroup>
  74. ```streaming {{ title: 'Response' }}
  75. 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
  76. ```
  77. </CodeGroup>
  78. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  79. - `event: workflow_started` workflow 开始执行
  80. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  81. - `workflow_run_id` (string) workflow 执行 ID
  82. - `event` (string) 固定为 `workflow_started`
  83. - `data` (object) 详细内容
  84. - `id` (string) workflow 执行 ID
  85. - `workflow_id` (string) 关联 Workflow ID
  86. - `created_at` (timestamp) 开始时间
  87. - `event: node_started` node 开始执行
  88. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  89. - `workflow_run_id` (string) workflow 执行 ID
  90. - `event` (string) 固定为 `node_started`
  91. - `data` (object) 详细内容
  92. - `id` (string) workflow 执行 ID
  93. - `node_id` (string) 节点 ID
  94. - `node_type` (string) 节点类型
  95. - `title` (string) 节点名称
  96. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  97. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  98. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  99. - `created_at` (timestamp) 开始时间
  100. - `event: text_chunk` 文本片段
  101. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  102. - `workflow_run_id` (string) workflow 执行 ID
  103. - `event` (string) 固定为 `text_chunk`
  104. - `data` (object) 详细内容
  105. - `text` (string) 文本内容
  106. - `from_variable_selector` (array) 文本来源路径,帮助开发者了解文本是由哪个节点的哪个变量生成的
  107. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  108. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  109. - `workflow_run_id` (string) workflow 执行 ID
  110. - `event` (string) 固定为 `node_finished`
  111. - `data` (object) 详细内容
  112. - `id` (string) node 执行 ID
  113. - `node_id` (string) 节点 ID
  114. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  115. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  116. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  117. - `process_data` (json) Optional 节点过程数据
  118. - `outputs` (json) Optional 输出内容
  119. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  120. - `error` (string) Optional 错误原因
  121. - `elapsed_time` (float) Optional 耗时(s)
  122. - `execution_metadata` (json) 元数据
  123. - `total_tokens` (int) optional 总使用 tokens
  124. - `total_price` (decimal) optional 总费用
  125. - `currency` (string) optional 货币,如 `USD` / `RMB`
  126. - `created_at` (timestamp) 开始时间
  127. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  128. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  129. - `workflow_run_id` (string) workflow 执行 ID
  130. - `event` (string) 固定为 `workflow_finished`
  131. - `data` (object) 详细内容
  132. - `id` (string) workflow 执行 ID
  133. - `workflow_id` (string) 关联 Workflow ID
  134. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  135. - `outputs` (json) Optional 输出内容
  136. - `error` (string) Optional 错误原因
  137. - `elapsed_time` (float) Optional 耗时(s)
  138. - `total_tokens` (int) Optional 总使用 tokens
  139. - `total_steps` (int) 总步数(冗余),默认 0
  140. - `created_at` (timestamp) 开始时间
  141. - `finished_at` (timestamp) 结束时间
  142. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  143. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  144. - `message_id` (string) 消息唯一 ID
  145. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  146. - `created_at` (int) 创建时间戳,如:1705395332
  147. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  148. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  149. - `message_id` (string) 消息唯一 ID
  150. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  151. - `created_at` (int) 创建时间戳,如:1705395332
  152. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  153. ### Errors
  154. - 400,`invalid_param`,传入参数异常
  155. - 400,`app_unavailable`,App 配置不可用
  156. - 400,`provider_not_initialize`,无可用模型凭据配置
  157. - 400,`provider_quota_exceeded`,模型调用额度不足
  158. - 400,`model_currently_not_support`,当前模型不可用
  159. - 400,`workflow_request_error`,workflow 执行失败
  160. - 500,服务内部异常
  161. </Col>
  162. <Col sticky>
  163. <CodeGroup
  164. title="Request"
  165. tag="POST"
  166. label="/workflows/run"
  167. targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/run' \\
  168. --header 'Authorization: Bearer {api_key}' \\
  169. --header 'Content-Type: application/json' \\
  170. --data-raw '{
  171. "inputs": ${JSON.stringify(props.inputs)},
  172. "response_mode": "streaming",
  173. "user": "abc-123"
  174. }'`}
  175. />
  176. <CodeGroup title="Example: file array as an input variable">
  177. ```json {{ title: 'File variable example' }}
  178. {
  179. "inputs": {
  180. "{variable_name}":
  181. [
  182. {
  183. "transfer_method": "local_file",
  184. "upload_file_id": "{upload_file_id}",
  185. "type": "{document_type}"
  186. }
  187. ]
  188. }
  189. }
  190. ```
  191. </CodeGroup>
  192. ### Blocking Mode
  193. <CodeGroup title="Response">
  194. ```json {{ title: 'Response' }}
  195. {
  196. "workflow_run_id": "djflajgkldjgd",
  197. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  198. "data": {
  199. "id": "fdlsjfjejkghjda",
  200. "workflow_id": "fldjaslkfjlsda",
  201. "status": "succeeded",
  202. "outputs": {
  203. "text": "Nice to meet you."
  204. },
  205. "error": null,
  206. "elapsed_time": 0.875,
  207. "total_tokens": 3562,
  208. "total_steps": 8,
  209. "created_at": 1705407629,
  210. "finished_at": 1727807631
  211. }
  212. }
  213. ```
  214. </CodeGroup>
  215. ### Streaming Mode
  216. <CodeGroup title="Response">
  217. ```streaming {{ title: 'Response' }}
  218. 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}}
  219. 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}}
  220. 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}}
  221. 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}}
  222. 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"}
  223. 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": ""}
  224. ```
  225. </CodeGroup>
  226. <CodeGroup title="File upload sample code">
  227. ```json {{ title: 'File upload sample code' }}
  228. import requests
  229. import json
  230. def upload_file(file_path, user):
  231. upload_url = "https://api.dify.ai/v1/files/upload"
  232. headers = {
  233. "Authorization": "Bearer app-xxxxxxxx",
  234. }
  235. try:
  236. print("上传文件中...")
  237. with open(file_path, 'rb') as file:
  238. files = {
  239. 'file': (file_path, file, 'text/plain') # 确保文件以适当的MIME类型上传
  240. }
  241. data = {
  242. "user": user,
  243. "type": "TXT" # 设置文件类型为TXT
  244. }
  245. response = requests.post(upload_url, headers=headers, files=files, data=data)
  246. if response.status_code == 201: # 201 表示创建成功
  247. print("文件上传成功")
  248. return response.json().get("id") # 获取上传的文件 ID
  249. else:
  250. print(f"文件上传失败,状态码: {response.status_code}")
  251. return None
  252. except Exception as e:
  253. print(f"发生错误: {str(e)}")
  254. return None
  255. def run_workflow(file_id, user, response_mode="blocking"):
  256. workflow_url = "https://api.dify.ai/v1/workflows/run"
  257. headers = {
  258. "Authorization": "Bearer app-xxxxxxxxx",
  259. "Content-Type": "application/json"
  260. }
  261. data = {
  262. "inputs": {
  263. "orig_mail": [{
  264. "transfer_method": "local_file",
  265. "upload_file_id": file_id,
  266. "type": "document"
  267. }]
  268. },
  269. "response_mode": response_mode,
  270. "user": user
  271. }
  272. try:
  273. print("运行工作流...")
  274. response = requests.post(workflow_url, headers=headers, json=data)
  275. if response.status_code == 200:
  276. print("工作流执行成功")
  277. return response.json()
  278. else:
  279. print(f"工作流执行失败,状态码: {response.status_code}")
  280. return {"status": "error", "message": f"Failed to execute workflow, status code: {response.status_code}"}
  281. except Exception as e:
  282. print(f"发生错误: {str(e)}")
  283. return {"status": "error", "message": str(e)}
  284. # 使用示例
  285. file_path = "{your_file_path}"
  286. user = "difyuser"
  287. # 上传文件
  288. file_id = upload_file(file_path, user)
  289. if file_id:
  290. # 文件上传成功,继续运行工作流
  291. result = run_workflow(file_id, user)
  292. print(result)
  293. else:
  294. print("文件上传失败,无法执行工作流")
  295. ```
  296. </CodeGroup>
  297. </Col>
  298. </Row>
  299. ---
  300. <Heading
  301. url='/workflows/:workflow_id/run'
  302. method='POST'
  303. title='执行指定版本 Workflow'
  304. name='#Execute-Specific-Workflow'
  305. />
  306. <Row>
  307. <Col>
  308. 执行指定版本的工作流,通过路径参数指定工作流ID。
  309. ### Path
  310. - `workflow_id` (string) Required 工作流ID,用于指定特定版本的工作流
  311. 获取方式:可以在版本历史中查询特定版本的工作流ID。
  312. ### Request Body
  313. - `inputs` (object) Required
  314. 允许传入 App 定义的各变量值。
  315. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。变量可以是文件列表类型。
  316. 文件列表类型变量适用于传入文件结合文本理解并回答问题,仅当模型支持该类型文件解析能力时可用。如果该变量是文件列表类型,该变量对应的值应是列表格式,其中每个元素应包含以下内容:
  317. - `type` (string) 支持类型:
  318. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'MDX', 'PDF', 'HTML', 'XLSX', 'XLS', 'VTT', 'PROPERTIES', 'DOC', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  319. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  320. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'MPGA'
  321. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'WEBM'
  322. - `custom` 具体类型包含:其他文件类型
  323. - `transfer_method` (string) 传递方式:
  324. - `remote_url`: 文件地址。
  325. - `local_file`: 上传文件。
  326. - `url` 文件地址。(仅当传递方式为 `remote_url` 时)。
  327. - `upload_file_id` 上传文件 ID。(仅当传递方式为 `local_file `时)。
  328. - `response_mode` (string) Required
  329. 返回响应模式,支持:
  330. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  331. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  332. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  333. - `user` (string) Required
  334. 用户标识,用于定义终端用户的身份,方便检索、统计。
  335. 由开发者定义规则,需保证用户标识在应用内唯一。API 无法访问 WebApp 创建的会话。
  336. - `files` (array[object]) 可选
  337. - `trace_id` (string) Optional
  338. 链路追踪ID。适用于与业务系统已有的trace组件打通,实现端到端分布式追踪等场景。如果未指定,系统将自动生成 `trace_id`。支持以下三种方式传递,具体优先级依次为:
  339. 1. Header:推荐通过 HTTP Header `X-Trace-Id` 传递,优先级最高。
  340. 2. Query 参数:通过 URL 查询参数 `trace_id` 传递。
  341. 3. Request Body:通过请求体字段 `trace_id` 传递(即本字段)。
  342. ### Response
  343. 当 `response_mode` 为 `blocking` 时,返回 CompletionResponse object。
  344. 当 `response_mode` 为 `streaming`时,返回 ChunkCompletionResponse object 流式序列。
  345. ### CompletionResponse
  346. 返回完整的 App 结果,`Content-Type` 为 `application/json` 。
  347. - `workflow_run_id` (string) workflow 执行 ID
  348. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  349. - `data` (object) 详细内容
  350. - `id` (string) workflow 执行 ID
  351. - `workflow_id` (string) 关联 Workflow ID
  352. - `status` (string) 执行状态, `running` / `succeeded` / `failed` / `stopped`
  353. - `outputs` (json) Optional 输出内容
  354. - `error` (string) Optional 错误原因
  355. - `elapsed_time` (float) Optional 耗时(s)
  356. - `total_tokens` (int) Optional 总使用 tokens
  357. - `total_steps` (int) 总步数(冗余),默认 0
  358. - `created_at` (timestamp) 开始时间
  359. - `finished_at` (timestamp) 结束时间
  360. ### ChunkCompletionResponse
  361. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  362. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  363. <CodeGroup>
  364. ```streaming {{ title: 'Response' }}
  365. 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
  366. ```
  367. </CodeGroup>
  368. 流式块中根据 `event` 不同,结构也不同,包含以下类型:
  369. - `event: workflow_started` workflow 开始执行
  370. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  371. - `workflow_run_id` (string) workflow 执行 ID
  372. - `event` (string) 固定为 `workflow_started`
  373. - `data` (object) 详细内容
  374. - `id` (string) workflow 执行 ID
  375. - `workflow_id` (string) 关联 Workflow ID
  376. - `created_at` (timestamp) 开始时间
  377. - `event: node_started` node 开始执行
  378. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  379. - `workflow_run_id` (string) workflow 执行 ID
  380. - `event` (string) 固定为 `node_started`
  381. - `data` (object) 详细内容
  382. - `id` (string) workflow 执行 ID
  383. - `node_id` (string) 节点 ID
  384. - `node_type` (string) 节点类型
  385. - `title` (string) 节点名称
  386. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  387. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  388. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  389. - `created_at` (timestamp) 开始时间
  390. - `event: text_chunk` 文本片段
  391. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  392. - `workflow_run_id` (string) workflow 执行 ID
  393. - `event` (string) 固定为 `text_chunk`
  394. - `data` (object) 详细内容
  395. - `text` (string) 文本内容
  396. - `from_variable_selector` (array) 文本来源路径,帮助开发者了解文本是由哪个节点的哪个变量生成的
  397. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  398. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  399. - `workflow_run_id` (string) workflow 执行 ID
  400. - `event` (string) 固定为 `node_finished`
  401. - `data` (object) 详细内容
  402. - `id` (string) node 执行 ID
  403. - `node_id` (string) 节点 ID
  404. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  405. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  406. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  407. - `process_data` (json) Optional 节点过程数据
  408. - `outputs` (json) Optional 输出内容
  409. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  410. - `error` (string) Optional 错误原因
  411. - `elapsed_time` (float) Optional 耗时(s)
  412. - `execution_metadata` (json) 元数据
  413. - `total_tokens` (int) optional 总使用 tokens
  414. - `total_price` (decimal) optional 总费用
  415. - `currency` (string) optional 货币,如 `USD` / `RMB`
  416. - `created_at` (timestamp) 开始时间
  417. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  418. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  419. - `workflow_run_id` (string) workflow 执行 ID
  420. - `event` (string) 固定为 `workflow_finished`
  421. - `data` (object) 详细内容
  422. - `id` (string) workflow 执行 ID
  423. - `workflow_id` (string) 关联 Workflow ID
  424. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  425. - `outputs` (json) Optional 输出内容
  426. - `error` (string) Optional 错误原因
  427. - `elapsed_time` (float) Optional 耗时(s)
  428. - `total_tokens` (int) Optional 总使用 tokens
  429. - `total_steps` (int) 总步数(冗余),默认 0
  430. - `created_at` (timestamp) 开始时间
  431. - `finished_at` (timestamp) 结束时间
  432. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  433. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  434. - `message_id` (string) 消息唯一 ID
  435. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  436. - `created_at` (int) 创建时间戳,如:1705395332
  437. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  438. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  439. - `message_id` (string) 消息唯一 ID
  440. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  441. - `created_at` (int) 创建时间戳,如:1705395332
  442. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  443. ### Errors
  444. - 400,`invalid_param`,传入参数异常
  445. - 400,`app_unavailable`,App 配置不可用
  446. - 400,`provider_not_initialize`,无可用模型凭据配置
  447. - 400,`provider_quota_exceeded`,模型调用额度不足
  448. - 400,`model_currently_not_support`,当前模型不可用
  449. - 400,`workflow_not_found`,指定的工作流版本未找到
  450. - 400,`draft_workflow_error`,无法使用草稿工作流版本
  451. - 400,`workflow_id_format_error`,工作流ID格式错误,需要UUID格式
  452. - 400,`workflow_request_error`,workflow 执行失败
  453. - 500,服务内部异常
  454. </Col>
  455. <Col sticky>
  456. <CodeGroup
  457. title="Request"
  458. tag="POST"
  459. label="/workflows/:workflow_id/run"
  460. targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/{workflow_id}/run' \\
  461. --header 'Authorization: Bearer {api_key}' \\
  462. --header 'Content-Type: application/json' \\
  463. --data-raw '{
  464. "inputs": ${JSON.stringify(props.inputs)},
  465. "response_mode": "streaming",
  466. "user": "abc-123"
  467. }'`}
  468. />
  469. <CodeGroup title="Example: file array as an input variable">
  470. ```json {{ title: 'File variable example' }}
  471. {
  472. "inputs": {
  473. "{variable_name}":
  474. [
  475. {
  476. "transfer_method": "local_file",
  477. "upload_file_id": "{upload_file_id}",
  478. "type": "{document_type}"
  479. }
  480. ]
  481. }
  482. }
  483. ```
  484. </CodeGroup>
  485. ### Blocking Mode
  486. <CodeGroup title="Response">
  487. ```json {{ title: 'Response' }}
  488. {
  489. "workflow_run_id": "djflajgkldjgd",
  490. "task_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  491. "data": {
  492. "id": "fdlsjfjejkghjda",
  493. "workflow_id": "fldjaslkfjlsda",
  494. "status": "succeeded",
  495. "outputs": {
  496. "text": "Nice to meet you."
  497. },
  498. "error": null,
  499. "elapsed_time": 0.875,
  500. "total_tokens": 3562,
  501. "total_steps": 8,
  502. "created_at": 1705407629,
  503. "finished_at": 1727807631
  504. }
  505. }
  506. ```
  507. </CodeGroup>
  508. ### Streaming Mode
  509. <CodeGroup title="Response">
  510. ```streaming {{ title: 'Response' }}
  511. 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}}
  512. 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}}
  513. 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}}
  514. 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}}
  515. 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"}
  516. 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": ""}
  517. ```
  518. </CodeGroup>
  519. </Col>
  520. </Row>
  521. ---
  522. <Heading
  523. url='/workflows/run/:workflow_run_id'
  524. method='GET'
  525. title='获取 Workflow 执行情况'
  526. name='#get-workflow-run-detail'
  527. />
  528. <Row>
  529. <Col>
  530. 根据 workflow 执行 ID 获取 workflow 任务当前执行结果
  531. ### Path
  532. - `workflow_run_id` (string) workflow 执行 ID,可在流式返回 Chunk 中获取
  533. ### Response
  534. - `id` (string) workflow 执行 ID
  535. - `workflow_id` (string) 关联的 Workflow ID
  536. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  537. - `inputs` (json) 任务输入内容
  538. - `outputs` (json) 任务输出内容
  539. - `error` (string) 错误原因
  540. - `total_steps` (int) 任务执行总步数
  541. - `total_tokens` (int) 任务执行总 tokens
  542. - `created_at` (timestamp) 任务开始时间
  543. - `finished_at` (timestamp) 任务结束时间
  544. - `elapsed_time` (float) 耗时 (s)
  545. </Col>
  546. <Col sticky>
  547. ### Request Example
  548. <CodeGroup
  549. title="Request"
  550. tag="GET"
  551. label="/workflows/run/:workflow_run_id"
  552. targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id' \\
  553. -H 'Authorization: Bearer {api_key}' \\
  554. -H 'Content-Type: application/json'`}
  555. />
  556. ### Response Example
  557. <CodeGroup title="Response">
  558. ```json {{ title: 'Response' }}
  559. {
  560. "id": "b1ad3277-089e-42c6-9dff-6820d94fbc76",
  561. "workflow_id": "19eff89f-ec03-4f75-b0fc-897e7effea02",
  562. "status": "succeeded",
  563. "inputs": "{\"sys.files\": [], \"sys.user_id\": \"abc-123\"}",
  564. "outputs": null,
  565. "error": null,
  566. "total_steps": 3,
  567. "total_tokens": 0,
  568. "created_at": 1705407629,
  569. "finished_at": 1727807631,
  570. "elapsed_time": 30.098514399956912
  571. }
  572. ```
  573. </CodeGroup>
  574. </Col>
  575. </Row>
  576. ---
  577. <Heading
  578. url='/workflows/tasks/:task_id/stop'
  579. method='POST'
  580. title='停止响应'
  581. name='#stop-generatebacks'
  582. />
  583. <Row>
  584. <Col>
  585. 仅支持流式模式。
  586. ### Path
  587. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  588. ### Request Body
  589. - `user` (string) Required
  590. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。API 无法访问 WebApp 创建的会话。
  591. ### Response
  592. - `result` (string) 固定返回 "success"
  593. </Col>
  594. <Col sticky>
  595. ### Request Example
  596. <CodeGroup
  597. title="Request"
  598. tag="POST"
  599. label="/workflows/tasks/:task_id/stop"
  600. targetCode={`curl -X POST '${props.appDetail.api_base_url}/workflows/tasks/:task_id/stop' \\
  601. -H 'Authorization: Bearer {api_key}' \\
  602. -H 'Content-Type: application/json' \\
  603. --data-raw '{"user": "abc-123"}'`}
  604. />
  605. ### Response Example
  606. <CodeGroup title="Response">
  607. ```json {{ title: 'Response' }}
  608. {
  609. "result": "success"
  610. }
  611. ```
  612. </CodeGroup>
  613. </Col>
  614. </Row>
  615. ---
  616. <Heading
  617. url='/files/upload'
  618. method='POST'
  619. title='上传文件'
  620. name='#files-upload'
  621. />
  622. <Row>
  623. <Col>
  624. 上传文件并在发送消息时使用,可实现图文多模态理解。
  625. 支持您的工作流程所支持的任何格式。
  626. <i>上传的文件仅供当前终端用户使用。</i>
  627. ### Request Body
  628. 该接口需使用 `multipart/form-data` 进行请求。
  629. <Properties>
  630. <Property name='file' type='file' key='file'>
  631. 要上传的文件。
  632. </Property>
  633. <Property name='user' type='string' key='user'>
  634. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。服务 API 不会共享 WebApp 创建的对话。
  635. </Property>
  636. </Properties>
  637. ### Response
  638. 成功上传后,服务器会返回文件的 ID 和相关信息。
  639. - `id` (uuid) ID
  640. - `name` (string) 文件名
  641. - `size` (int) 文件大小(byte)
  642. - `extension` (string) 文件后缀
  643. - `mime_type` (string) 文件 mime-type
  644. - `created_by` (uuid) 上传人 ID
  645. - `created_at` (timestamp) 上传时间
  646. ### Errors
  647. - 400,`no_file_uploaded`,必须提供文件
  648. - 400,`too_many_files`,目前只接受一个文件
  649. - 400,`unsupported_preview`,该文件不支持预览
  650. - 400,`unsupported_estimate`,该文件不支持估算
  651. - 413,`file_too_large`,文件太大
  652. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  653. - 503,`s3_connection_failed`,无法连接到 S3 服务
  654. - 503,`s3_permission_denied`,无权限上传文件到 S3
  655. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  656. </Col>
  657. <Col sticky>
  658. <CodeGroup
  659. title="Request"
  660. tag="POST"
  661. label="/files/upload"
  662. targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\
  663. --header 'Authorization: Bearer {api_key}' \\
  664. --form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\
  665. --form 'user=abc-123'`}
  666. />
  667. <CodeGroup title="Response">
  668. ```json {{ title: 'Response' }}
  669. {
  670. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  671. "name": "example.png",
  672. "size": 1024,
  673. "extension": "png",
  674. "mime_type": "image/png",
  675. "created_by": 123,
  676. "created_at": 1577836800,
  677. }
  678. ```
  679. </CodeGroup>
  680. </Col>
  681. </Row>
  682. ---
  683. <Heading
  684. url='/files/:file_id/preview'
  685. method='GET'
  686. title='文件预览'
  687. name='#file-preview'
  688. />
  689. <Row>
  690. <Col>
  691. 预览或下载已上传的文件。此端点允许您访问先前通过文件上传 API 上传的文件。
  692. <i>文件只能在属于请求应用程序的消息范围内访问。</i>
  693. ### 路径参数
  694. - `file_id` (string) 必需
  695. 要预览的文件的唯一标识符,从文件上传 API 响应中获得。
  696. ### 查询参数
  697. - `as_attachment` (boolean) 可选
  698. 是否强制将文件作为附件下载。默认为 `false`(在浏览器中预览)。
  699. ### 响应
  700. 返回带有适当浏览器显示或下载标头的文件内容。
  701. - `Content-Type` 根据文件 MIME 类型设置
  702. - `Content-Length` 文件大小(以字节为单位,如果可用)
  703. - `Content-Disposition` 如果 `as_attachment=true` 则设置为 "attachment"
  704. - `Cache-Control` 用于性能的缓存标头
  705. - `Accept-Ranges` 对于音频/视频文件设置为 "bytes"
  706. ### 错误
  707. - 400, `invalid_param`, 参数输入异常
  708. - 403, `file_access_denied`, 文件访问被拒绝或文件不属于当前应用程序
  709. - 404, `file_not_found`, 文件未找到或已被删除
  710. - 500, 服务内部错误
  711. </Col>
  712. <Col sticky>
  713. ### 请求示例
  714. <CodeGroup
  715. title="Request"
  716. tag="GET"
  717. label="/files/:file_id/preview"
  718. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \\
  719. --header 'Authorization: Bearer {api_key}'`}
  720. />
  721. ### 作为附件下载
  722. <CodeGroup
  723. title="Request"
  724. tag="GET"
  725. label="/files/:file_id/preview?as_attachment=true"
  726. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \\
  727. --header 'Authorization: Bearer {api_key}' \\
  728. --output downloaded_file.png`}
  729. />
  730. ### 响应标头示例
  731. <CodeGroup title="Response Headers">
  732. ```http {{ title: 'Headers - 图片预览' }}
  733. Content-Type: image/png
  734. Content-Length: 1024
  735. Cache-Control: public, max-age=3600
  736. ```
  737. </CodeGroup>
  738. ### 文件下载响应标头
  739. <CodeGroup title="Download Response Headers">
  740. ```http {{ title: 'Headers - 文件下载' }}
  741. Content-Type: image/png
  742. Content-Length: 1024
  743. Content-Disposition: attachment; filename*=UTF-8''example.png
  744. Cache-Control: public, max-age=3600
  745. ```
  746. </CodeGroup>
  747. </Col>
  748. </Row>
  749. ---
  750. <Heading
  751. url='/workflows/logs'
  752. method='GET'
  753. title='获取 Workflow 日志'
  754. name='#Get-Workflow-Logs'
  755. />
  756. <Row>
  757. <Col>
  758. 倒序返回 workflow 日志
  759. ### Query
  760. <Properties>
  761. <Property name='keyword' type='string' key='keyword'>
  762. 关键字
  763. </Property>
  764. <Property name='status' type='string' key='status'>
  765. 执行状态 succeeded/failed/stopped
  766. </Property>
  767. <Property name='page' type='int' key='page'>
  768. 当前页码, 默认1.
  769. </Property>
  770. <Property name='limit' type='int' key='limit'>
  771. 每页条数, 默认20.
  772. </Property>
  773. <Property name='created_by_end_user_session_id' type='str' key='created_by_end_user_session_id'>
  774. 由哪个endUser创建,例如,`abc-123`.
  775. </Property>
  776. <Property name='created_by_account' type='str' key='created_by_account'>
  777. 由哪个邮箱账户创建,例如,lizb@test.com.
  778. </Property>
  779. </Properties>
  780. ### Response
  781. - `page` (int) 当前页码
  782. - `limit` (int) 每页条数
  783. - `total` (int) 总条数
  784. - `has_more` (bool) 是否还有更多数据
  785. - `data` (array[object]) 当前页码的数据
  786. - `id` (string) 标识
  787. - `workflow_run` (object) Workflow 执行日志
  788. - `id` (string) 标识
  789. - `version` (string) 版本
  790. - `status` (string) 执行状态,`running` / `succeeded` / `failed` / `stopped`
  791. - `error` (string) (可选) 错误
  792. - `elapsed_time` (float) 耗时,单位秒
  793. - `total_tokens` (int) 消耗的 token 数量
  794. - `total_steps` (int) 执行步骤长度
  795. - `created_at` (timestamp) 开始时间
  796. - `finished_at` (timestamp) 结束时间
  797. - `created_from` (string) 来源
  798. - `created_by_role` (string) 角色
  799. - `created_by_account` (string) (可选) 帐号
  800. - `created_by_end_user` (object) 用户
  801. - `id` (string) 标识
  802. - `type` (string) 类型
  803. - `is_anonymous` (bool) 是否匿名
  804. - `session_id` (string) 会话标识
  805. - `created_at` (timestamp) 创建时间
  806. </Col>
  807. <Col sticky>
  808. <CodeGroup
  809. title="Request"
  810. tag="GET"
  811. label="/workflows/logs"
  812. targetCode={`curl -X GET '${props.appDetail.api_base_url}/workflows/logs'\\
  813. --header 'Authorization: Bearer {api_key}'`}
  814. />
  815. ### Response Example
  816. <CodeGroup title="Response">
  817. ```json {{ title: 'Response' }}
  818. {
  819. "page": 1,
  820. "limit": 1,
  821. "total": 7,
  822. "has_more": true,
  823. "data": [
  824. {
  825. "id": "e41b93f1-7ca2-40fd-b3a8-999aeb499cc0",
  826. "workflow_run": {
  827. "id": "c0640fc8-03ef-4481-a96c-8a13b732a36e",
  828. "version": "2024-08-01 12:17:09.771832",
  829. "status": "succeeded",
  830. "error": null,
  831. "elapsed_time": 1.3588523610014818,
  832. "total_tokens": 0,
  833. "total_steps": 3,
  834. "created_at": 1726139643,
  835. "finished_at": 1726139644
  836. },
  837. "created_from": "service-api",
  838. "created_by_role": "end_user",
  839. "created_by_account": null,
  840. "created_by_end_user": {
  841. "id": "7f7d9117-dd9d-441d-8970-87e5e7e687a3",
  842. "type": "service_api",
  843. "is_anonymous": false,
  844. "session_id": "abc-123"
  845. },
  846. "created_at": 1726139644
  847. }
  848. ]
  849. }
  850. ```
  851. </CodeGroup>
  852. </Col>
  853. </Row>
  854. ---
  855. <Heading
  856. url='/info'
  857. method='GET'
  858. title='获取应用基本信息'
  859. name='#info'
  860. />
  861. <Row>
  862. <Col>
  863. 用于获取应用的基本信息
  864. ### Response
  865. - `name` (string) 应用名称
  866. - `description` (string) 应用描述
  867. - `tags` (array[string]) 应用标签
  868. - `mode` (string) 应用模式
  869. - 'author_name' (string) 作者名称
  870. </Col>
  871. <Col>
  872. <CodeGroup
  873. title="Request"
  874. tag="GET"
  875. label="/info"
  876. targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\
  877. -H 'Authorization: Bearer {api_key}'`}
  878. />
  879. <CodeGroup title="Response">
  880. ```json {{ title: 'Response' }}
  881. {
  882. "name": "My App",
  883. "description": "This is my app.",
  884. "tags": [
  885. "tag1",
  886. "tag2"
  887. ],
  888. "mode": "workflow",
  889. "author_name": "Dify"
  890. }
  891. ```
  892. </CodeGroup>
  893. </Col>
  894. </Row>
  895. ---
  896. <Heading
  897. url='/parameters'
  898. method='GET'
  899. title='获取应用参数'
  900. name='#parameters'
  901. />
  902. <Row>
  903. <Col>
  904. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  905. ### Response
  906. - `user_input_form` (array[object]) 用户输入表单配置
  907. - `text-input` (object) 文本输入控件
  908. - `label` (string) 控件展示标签名
  909. - `variable` (string) 控件 ID
  910. - `required` (bool) 是否必填
  911. - `default` (string) 默认值
  912. - `paragraph` (object) 段落文本输入控件
  913. - `label` (string) 控件展示标签名
  914. - `variable` (string) 控件 ID
  915. - `required` (bool) 是否必填
  916. - `default` (string) 默认值
  917. - `select` (object) 下拉控件
  918. - `label` (string) 控件展示标签名
  919. - `variable` (string) 控件 ID
  920. - `required` (bool) 是否必填
  921. - `default` (string) 默认值
  922. - `options` (array[string]) 选项值
  923. - `file_upload` (object) 文件上传配置
  924. - `document` (object) 文档设置
  925. 当前仅支持文档类型:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  926. - `enabled` (bool) 是否启用
  927. - `number_limits` (int) 文档数量限制,默认为 3
  928. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  929. - `image` (object) 图片设置
  930. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  931. - `enabled` (bool) 是否启用
  932. - `number_limits` (int) 图片数量限制,默认为 3
  933. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  934. - `audio` (object) 音频设置
  935. 当前仅支持音频类型:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  936. - `enabled` (bool) 是否启用
  937. - `number_limits` (int) 音频数量限制,默认为 3
  938. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  939. - `video` (object) 视频设置
  940. 当前仅支持视频类型:`mp4`, `mov`, `mpeg`, `mpga`。
  941. - `enabled` (bool) 是否启用
  942. - `number_limits` (int) 视频数量限制,默认为 3
  943. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  944. - `custom` (object) 自定义设置
  945. - `enabled` (bool) 是否启用
  946. - `number_limits` (int) 自定义数量限制,默认为 3
  947. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  948. - `system_parameters` (object) 系统参数
  949. - `file_size_limit` (int) 文档上传大小限制 (MB)
  950. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  951. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  952. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  953. </Col>
  954. <Col sticky>
  955. <CodeGroup
  956. title="Request"
  957. tag="GET"
  958. label="/parameters"
  959. targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}
  960. />
  961. <CodeGroup title="Response">
  962. ```json {{ title: 'Response' }}
  963. {
  964. "user_input_form": [
  965. {
  966. "paragraph": {
  967. "label": "Query",
  968. "variable": "query",
  969. "required": true,
  970. "default": ""
  971. }
  972. }
  973. ],
  974. "file_upload": {
  975. "image": {
  976. "enabled": false,
  977. "number_limits": 3,
  978. "detail": "high",
  979. "transfer_methods": [
  980. "remote_url",
  981. "local_file"
  982. ]
  983. }
  984. },
  985. "system_parameters": {
  986. "file_size_limit": 15,
  987. "image_file_size_limit": 10,
  988. "audio_file_size_limit": 50,
  989. "video_file_size_limit": 100
  990. }
  991. }
  992. ```
  993. </CodeGroup>
  994. </Col>
  995. </Row>
  996. ---
  997. <Heading
  998. url='/site'
  999. method='GET'
  1000. title='获取应用 WebApp 设置'
  1001. name='#site'
  1002. />
  1003. <Row>
  1004. <Col>
  1005. 用于获取应用的 WebApp 设置
  1006. ### Response
  1007. - `title` (string) WebApp 名称
  1008. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  1009. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  1010. - `icon_background` (string) hex 格式的背景色
  1011. - `icon_url` (string) 图标 URL
  1012. - `description` (string) 描述
  1013. - `copyright` (string) 版权信息
  1014. - `privacy_policy` (string) 隐私政策链接
  1015. - `custom_disclaimer` (string) 自定义免责声明
  1016. - `default_language` (string) 默认语言
  1017. - `show_workflow_steps` (bool) 是否显示工作流详情
  1018. </Col>
  1019. <Col>
  1020. <CodeGroup
  1021. title="Request"
  1022. tag="POST"
  1023. label="/meta"
  1024. targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\
  1025. -H 'Authorization: Bearer {api_key}'`}
  1026. />
  1027. <CodeGroup title="Response">
  1028. ```json {{ title: 'Response' }}
  1029. {
  1030. "title": "My App",
  1031. "icon_type": "emoji",
  1032. "icon": "😄",
  1033. "icon_background": "#FFEAD5",
  1034. "icon_url": null,
  1035. "description": "This is my app.",
  1036. "copyright": "all rights reserved",
  1037. "privacy_policy": "",
  1038. "custom_disclaimer": "All generated by AI",
  1039. "default_language": "en-US",
  1040. "show_workflow_steps": false,
  1041. }
  1042. ```
  1043. </CodeGroup>
  1044. </Col>
  1045. </Row>
  1046. ___