Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

template_workflow.zh.mdx 48KB

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