template_workflow.zh.mdx 29 KB

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