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

template_workflow.zh.mdx 47KB

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