template_advanced_chat.zh.mdx 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
  3. # 工作流编排对话型应用 API
  4. 对话应用支持会话持久化,可将之前的聊天记录作为上下进行回答,可适用于聊天/客服 AI 等。
  5. <div>
  6. ### 基础 URL
  7. <CodeGroup title="Code" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### 鉴权
  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='/chat-messages'
  24. method='POST'
  25. title='发送对话消息'
  26. name='#Create-Chat-Message'
  27. />
  28. <Row>
  29. <Col>
  30. 创建会话消息。
  31. ### Request Body
  32. <Properties>
  33. <Property name='query' type='string' key='query'>
  34. 用户输入/提问内容。
  35. </Property>
  36. <Property name='inputs' type='object' key='inputs'>
  37. 允许传入 App 定义的各变量值。
  38. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。
  39. 如果变量是文件类型,请指定一个包含以下 `files` 中所述键的对象。
  40. 默认 `{}`
  41. </Property>
  42. <Property name='response_mode' type='string' key='response_mode'>
  43. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  44. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  45. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  46. </Property>
  47. <Property name='user' type='string' key='user'>
  48. 用户标识,用于定义终端用户的身份,方便检索、统计。
  49. 由开发者定义规则,需保证用户标识在应用内唯一。
  50. </Property>
  51. <Property name='conversation_id' type='string' key='conversation_id'>
  52. (选填)会话 ID,需要基于之前的聊天记录继续对话,必须传之前消息的 conversation_id。
  53. </Property>
  54. <Property name='files' type='array[object]' key='files'>
  55. 文件列表,适用于传入文件结合文本理解并回答问题,仅当模型支持 Vision 能力时可用。
  56. - `type` (string) 支持类型:
  57. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  58. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  59. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
  60. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'MPGA'
  61. - `transfer_method` (string) 传递方式:
  62. - `remote_url`: 图片地址。
  63. - `local_file`: 上传文件。
  64. - `url` 图片地址。(仅当传递方式为 `remote_url` 时)。
  65. - `upload_file_id` 上传文件 ID。(仅当传递方式为 `local_file `时)。
  66. </Property>
  67. <Property name='auto_generate_name' type='bool' key='auto_generate_name'>
  68. (选填)自动生成标题,默认 `true`。 若设置为 `false`,则可通过调用会话重命名接口并设置 `auto_generate` 为 `true` 实现异步生成标题。
  69. </Property>
  70. </Properties>
  71. ### Response
  72. <Properties>
  73. 当 `response_mode` 为 `blocking` 时,返回 ChatCompletionResponse object。
  74. 当 `response_mode` 为 `streaming`时,返回 ChunkChatCompletionResponse object 流式序列。
  75. ### ChatCompletionResponse
  76. 返回完整的 App 结果,`Content-Type` 为 `application/json`。
  77. - `message_id` (string) 消息唯一 ID
  78. - `conversation_id` (string) 会话 ID
  79. - `mode` (string) App 模式,固定为 chat
  80. - `answer` (string) 完整回复内容
  81. - `metadata` (object) 元数据
  82. - `usage` (Usage) 模型用量信息
  83. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  84. - `created_at` (int) 消息创建时间戳,如:1705395332
  85. ### ChunkChatCompletionResponse
  86. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  87. 每个流式块均为 data: 开头,块之间以 \n\n 即两个换行符分隔,如下所示:
  88. <CodeGroup>
  89. ```streaming {{ title: 'Response' }}
  90. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  91. ```
  92. </CodeGroup>
  93. 流式块中根据 event 不同,结构也不同:
  94. - `event: message` LLM 返回文本块事件,即:完整的文本以分块的方式输出。
  95. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  96. - `message_id` (string) 消息唯一 ID
  97. - `conversation_id` (string) 会话 ID
  98. - `answer` (string) LLM 返回文本块内容
  99. - `created_at` (int) 创建时间戳,如:1705395332
  100. - `event: message_file` 文件事件,表示有新文件需要展示
  101. - `id` (string) 文件唯一ID
  102. - `type` (string) 文件类型,目前仅为image
  103. - `belongs_to` (string) 文件归属,user或assistant,该接口返回仅为 `assistant`
  104. - `url` (string) 文件访问地址
  105. - `conversation_id` (string) 会话ID
  106. - `event: message_end` 消息结束事件,收到此事件则代表流式返回结束。
  107. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  108. - `message_id` (string) 消息唯一 ID
  109. - `conversation_id` (string) 会话 ID
  110. - `metadata` (object) 元数据
  111. - `usage` (Usage) 模型用量信息
  112. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  113. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  114. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  115. - `message_id` (string) 消息唯一 ID
  116. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  117. - `created_at` (int) 创建时间戳,如:1705395332
  118. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  119. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  120. - `message_id` (string) 消息唯一 ID
  121. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  122. - `created_at` (int) 创建时间戳,如:1705395332
  123. - `event: message_replace` 消息内容替换事件。
  124. 开启内容审查和审查输出内容时,若命中了审查条件,则会通过此事件替换消息内容为预设回复。
  125. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  126. - `message_id` (string) 消息唯一 ID
  127. - `conversation_id` (string) 会话 ID
  128. - `answer` (string) 替换内容(直接替换 LLM 所有回复文本)
  129. - `created_at` (int) 创建时间戳,如:1705395332
  130. - `event: workflow_started` workflow 开始执行
  131. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  132. - `workflow_run_id` (string) workflow 执行 ID
  133. - `event` (string) 固定为 `workflow_started`
  134. - `data` (object) 详细内容
  135. - `id` (string) workflow 执行 ID
  136. - `workflow_id` (string) 关联 Workflow ID
  137. - `sequence_number` (int) 自增序号,App 内自增,从 1 开始
  138. - `created_at` (timestamp) 开始时间
  139. - `event: node_started` node 开始执行
  140. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  141. - `workflow_run_id` (string) workflow 执行 ID
  142. - `event` (string) 固定为 `node_started`
  143. - `data` (object) 详细内容
  144. - `id` (string) workflow 执行 ID
  145. - `node_id` (string) 节点 ID
  146. - `node_type` (string) 节点类型
  147. - `title` (string) 节点名称
  148. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  149. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  150. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  151. - `created_at` (timestamp) 开始时间
  152. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  153. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  154. - `workflow_run_id` (string) workflow 执行 ID
  155. - `event` (string) 固定为 `node_finished`
  156. - `data` (object) 详细内容
  157. - `id` (string) node 执行 ID
  158. - `node_id` (string) 节点 ID
  159. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  160. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  161. - `inputs` (array[object]) 节点中所有使用到的前置节点变量内容
  162. - `process_data` (json) Optional 节点过程数据
  163. - `outputs` (json) Optional 输出内容
  164. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  165. - `error` (string) Optional 错误原因
  166. - `elapsed_time` (float) Optional 耗时(s)
  167. - `execution_metadata` (json) 元数据
  168. - `total_tokens` (int) optional 总使用 tokens
  169. - `total_price` (decimal) optional 总费用
  170. - `currency` (string) optional 货币,如 `USD` / `RMB`
  171. - `created_at` (timestamp) 开始时间
  172. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  173. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  174. - `workflow_run_id` (string) workflow 执行 ID
  175. - `event` (string) 固定为 `workflow_finished`
  176. - `data` (object) 详细内容
  177. - `id` (string) workflow 执行 ID
  178. - `workflow_id` (string) 关联 Workflow ID
  179. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  180. - `outputs` (json) Optional 输出内容
  181. - `error` (string) Optional 错误原因
  182. - `elapsed_time` (float) Optional 耗时(s)
  183. - `total_tokens` (int) Optional 总使用 tokens
  184. - `total_steps` (int) 总步数(冗余),默认 0
  185. - `created_at` (timestamp) 开始时间
  186. - `finished_at` (timestamp) 结束时间
  187. - `event: error`
  188. 流式输出过程中出现的异常会以 stream event 形式输出,收到异常事件后即结束。
  189. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  190. - `message_id` (string) 消息唯一 ID
  191. - `status` (int) HTTP 状态码
  192. - `code` (string) 错误码
  193. - `message` (string) 错误消息
  194. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  195. ### Errors
  196. - 404,对话不存在
  197. - 400,`invalid_param`,传入参数异常
  198. - 400,`app_unavailable`,App 配置不可用
  199. - 400,`provider_not_initialize`,无可用模型凭据配置
  200. - 400,`provider_quota_exceeded`,模型调用额度不足
  201. - 400,`model_currently_not_support`,当前模型不可用
  202. - 400,`completion_request_error`,文本生成失败
  203. - 500,服务内部异常
  204. </Properties>
  205. </Col>
  206. <Col sticky>
  207. <CodeGroup title="Request" tag="POST" label="/chat-messages" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "What are the specs of the iPhone 13 Pro Max?",\n "response_mode": "streaming",\n "conversation_id": "",\n "user": "abc-123",\n "files": [\n {\n "type": "image",\n "transfer_method": "remote_url",\n "url": "https://cloud.dify.ai/logo/logo-site.png"\n }\n ]\n}'`}>
  208. ```bash {{ title: 'cURL' }}
  209. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  210. -H 'Authorization: Bearer {api_key}' \
  211. -H 'Content-Type: application/json' \
  212. --data-raw '{
  213. "inputs": {
  214. "name": "dify"
  215. },
  216. "query": "What are the specs of the iPhone 13 Pro Max?",
  217. "conversation_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  218. "response_mode": "streaming",
  219. "user": "abc-123",
  220. "files": [
  221. {
  222. "type": "image",
  223. "transfer_method": "remote_url",
  224. "url": "https://cloud.dify.ai/logo/logo-site.png"
  225. }
  226. ]
  227. }'
  228. ```
  229. </CodeGroup>
  230. ### 阻塞模式
  231. <CodeGroup title="Response">
  232. ```json {{ title: 'Response' }}
  233. {
  234. "event": "message",
  235. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  236. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  237. "mode": "chat",
  238. "answer": "iPhone 13 Pro Max specs are listed here:...",
  239. "metadata": {
  240. "usage": {
  241. "prompt_tokens": 1033,
  242. "prompt_unit_price": "0.001",
  243. "prompt_price_unit": "0.001",
  244. "prompt_price": "0.0010330",
  245. "completion_tokens": 128,
  246. "completion_unit_price": "0.002",
  247. "completion_price_unit": "0.001",
  248. "completion_price": "0.0002560",
  249. "total_tokens": 1161,
  250. "total_price": "0.0012890",
  251. "currency": "USD",
  252. "latency": 0.7682376249867957
  253. },
  254. "retriever_resources": [
  255. {
  256. "position": 1,
  257. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  258. "dataset_name": "iPhone",
  259. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  260. "document_name": "iPhone List",
  261. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  262. "score": 0.98457545,
  263. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  264. }
  265. ]
  266. },
  267. "created_at": 1705407629
  268. }
  269. ```
  270. </CodeGroup>
  271. ### 流式模式
  272. <CodeGroup title="Response">
  273. ```streaming {{ title: 'Response' }}
  274. 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}}
  275. 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}}
  276. 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}}
  277. 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}}
  278. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  279. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  280. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  281. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  282. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  283. data: {"event": "message", "message_id": : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  284. data: {"event": "message_end", "id": "5e52ce04-874b-4d27-9045-b3bc80def685", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "metadata": {"usage": {"prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 135, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002700", "total_tokens": 1168, "total_price": "0.0013030", "currency": "USD", "latency": 1.381760165997548}, "retriever_resources": [{"position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""}]}}
  285. 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"}
  286. 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": ""}
  287. ```
  288. </CodeGroup>
  289. </Col>
  290. </Row>
  291. ---
  292. <Heading
  293. url='/files/upload'
  294. method='POST'
  295. title='上传文件'
  296. name='#files-upload'
  297. />
  298. <Row>
  299. <Col>
  300. 上传文件并在发送消息时使用,可实现图文多模态理解。
  301. 支持您的应用程序所支持的所有格式。
  302. <i>上传的文件仅供当前终端用户使用。</i>
  303. ### Request Body
  304. 该接口需使用 `multipart/form-data` 进行请求。
  305. <Properties>
  306. <Property name='file' type='file' key='file'>
  307. 要上传的文件。
  308. </Property>
  309. <Property name='user' type='string' key='user'>
  310. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  311. </Property>
  312. </Properties>
  313. ### Response
  314. 成功上传后,服务器会返回文件的 ID 和相关信息。
  315. - `id` (uuid) ID
  316. - `name` (string) 文件名
  317. - `size` (int) 文件大小(byte)
  318. - `extension` (string) 文件后缀
  319. - `mime_type` (string) 文件 mime-type
  320. - `created_by` (uuid) 上传人 ID
  321. - `created_at` (timestamp) 上传时间
  322. ### Errors
  323. - 400,`no_file_uploaded`,必须提供文件
  324. - 400,`too_many_files`,目前只接受一个文件
  325. - 400,`unsupported_preview`,该文件不支持预览
  326. - 400,`unsupported_estimate`,该文件不支持估算
  327. - 413,`file_too_large`,文件太大
  328. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  329. - 503,`s3_connection_failed`,无法连接到 S3 服务
  330. - 503,`s3_permission_denied`,无权限上传文件到 S3
  331. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  332. </Col>
  333. <Col sticky>
  334. <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'`}>
  335. ```bash {{ title: 'cURL' }}
  336. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  337. --header 'Authorization: Bearer {api_key}' \
  338. --form 'file=@"/path/to/file"'
  339. ```
  340. </CodeGroup>
  341. <CodeGroup title="Response">
  342. ```json {{ title: 'Response' }}
  343. {
  344. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  345. "name": "example.png",
  346. "size": 1024,
  347. "extension": "png",
  348. "mime_type": "image/png",
  349. "created_by": 123,
  350. "created_at": 1577836800,
  351. }
  352. ```
  353. </CodeGroup>
  354. </Col>
  355. </Row>
  356. ---
  357. <Heading
  358. url='/chat-messages/:task_id/stop'
  359. method='POST'
  360. title='停止响应'
  361. name='#Stop'
  362. />
  363. <Row>
  364. <Col>
  365. 仅支持流式模式。
  366. ### Path
  367. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  368. ### Request Body
  369. - `user` (string) Required
  370. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  371. ### Response
  372. - `result` (string) 固定返回 success
  373. </Col>
  374. <Col sticky>
  375. <CodeGroup title="Request" tag="POST" label="/chat-messages/:task_id/stop" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{ "user": "abc-123"}'`}>
  376. ```bash {{ title: 'cURL' }}
  377. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  378. -H 'Authorization: Bearer {api_key}' \
  379. -H 'Content-Type: application/json' \
  380. --data-raw '{
  381. "user": "abc-123"
  382. }'
  383. ```
  384. </CodeGroup>
  385. <CodeGroup title="Response">
  386. ```json {{ title: 'Response' }}
  387. {
  388. "result": "success"
  389. }
  390. ```
  391. </CodeGroup>
  392. </Col>
  393. </Row>
  394. ---
  395. <Heading
  396. url='/messages/:message_id/feedbacks'
  397. method='POST'
  398. title='消息反馈(点赞)'
  399. name='#feedbacks'
  400. />
  401. <Row>
  402. <Col>
  403. 消息终端用户反馈、点赞,方便应用开发者优化输出预期。
  404. ### Path Params
  405. <Properties>
  406. <Property name='message_id' type='string' key='message_id'>
  407. 消息 ID
  408. </Property>
  409. </Properties>
  410. ### Request Body
  411. <Properties>
  412. <Property name='rating' type='string' key='rating'>
  413. 点赞 like, 点踩 dislike, 撤销点赞 null
  414. </Property>
  415. <Property name='user' type='string' key='user'>
  416. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  417. </Property>
  418. </Properties>
  419. ### Response
  420. - `result` (string) 固定返回 success
  421. </Col>
  422. <Col sticky>
  423. <CodeGroup title="Request" tag="POST" label="/messages/:message_id/feedbacks" targetCode={`curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "rating": "like",\n "user": "abc-123"\n}'`}>
  424. ```bash {{ title: 'cURL' }}
  425. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  426. --header 'Authorization: Bearer {api_key}' \
  427. --header 'Content-Type: application/json' \
  428. --data-raw '{
  429. "rating": "like",
  430. "user": "abc-123"
  431. }'
  432. ```
  433. </CodeGroup>
  434. <CodeGroup title="Response">
  435. ```json {{ title: 'Response' }}
  436. {
  437. "result": "success"
  438. }
  439. ```
  440. </CodeGroup>
  441. </Col>
  442. </Row>
  443. ---
  444. <Heading
  445. url='/messages/{message_id}/suggested'
  446. method='GET'
  447. title='获取下一轮建议问题列表'
  448. name='#suggested'
  449. />
  450. <Row>
  451. <Col>
  452. 获取下一轮建议问题列表。
  453. ### Path Params
  454. <Properties>
  455. <Property name='message_id' type='string' key='message_id'>
  456. Message ID
  457. </Property>
  458. </Properties>
  459. ### Query
  460. <Properties>
  461. <Property name='user' type='string' key='user'>
  462. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  463. </Property>
  464. </Properties>
  465. </Col>
  466. <Col sticky>
  467. <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123 \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
  468. ```bash {{ title: 'cURL' }}
  469. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested'?user=abc-123 \
  470. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  471. --header 'Content-Type: application/json' \
  472. ```
  473. </CodeGroup>
  474. <CodeGroup title="Response">
  475. ```json {{ title: 'Response' }}
  476. {
  477. "result": "success",
  478. "data": [
  479. "a",
  480. "b",
  481. "c"
  482. ]
  483. }
  484. ```
  485. </CodeGroup>
  486. </Col>
  487. </Row>
  488. ---
  489. ---
  490. <Heading
  491. url='/messages'
  492. method='GET'
  493. title='获取会话历史消息'
  494. name='#messages'
  495. />
  496. <Row>
  497. <Col>
  498. 滚动加载形式返回历史聊天记录,第一页返回最新 `limit` 条,即:倒序返回。
  499. ### Query
  500. <Properties>
  501. <Property name='conversation_id' type='string' key='conversation_id'>
  502. 会话 ID
  503. </Property>
  504. <Property name='user' type='string' key='user'>
  505. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  506. </Property>
  507. <Property name='first_id' type='string' key='first_id'>
  508. 当前页第一条聊天记录的 ID,默认 null
  509. </Property>
  510. <Property name='limit' type='int' key='limit'>
  511. 一次请求返回多少条聊天记录,默认 20 条。
  512. </Property>
  513. </Properties>
  514. ### Response
  515. - `data` (array[object]) 消息列表
  516. - `id` (string) 消息 ID
  517. - `conversation_id` (string) 会话 ID
  518. - `inputs` (array[object]) 用户输入参数。
  519. - `query` (string) 用户输入 / 提问内容。
  520. - `message_files` (array[object]) 消息文件
  521. - `id` (string) ID
  522. - `type` (string) 文件类型,image 图片
  523. - `url` (string) 预览图片地址
  524. - `belongs_to` (string) 文件归属方,user 或 assistant
  525. - `answer` (string) 回答消息内容
  526. - `created_at` (timestamp) 创建时间
  527. - `feedback` (object) 反馈信息
  528. - `rating` (string) 点赞 like / 点踩 dislike
  529. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  530. - `has_more` (bool) 是否存在下一页
  531. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  532. </Col>
  533. <Col sticky>
  534. ### Request Example
  535. <CodeGroup title="Request" tag="GET" label="/messages" targetCode={`curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id=' \\\n--header 'Authorization: Bearer {api_key}'`}>
  536. ```bash {{ title: 'cURL' }}
  537. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  538. --header 'Authorization: Bearer {api_key}'
  539. ```
  540. </CodeGroup>
  541. ### Response Example
  542. <CodeGroup title="Response">
  543. ```json {{ title: 'Response' }}
  544. {
  545. "limit": 20,
  546. "has_more": false,
  547. "data": [
  548. {
  549. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  550. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  551. "inputs": {
  552. "name": "dify"
  553. },
  554. "query": "iphone 13 pro",
  555. "answer": "The iPhone 13 Pro, released on September 24, 2021, features a 6.1-inch display with a resolution of 1170 x 2532. It is equipped with a Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard) processor, 6 GB of RAM, and offers storage options of 128 GB, 256 GB, 512 GB, and 1 TB. The camera is 12 MP, the battery capacity is 3095 mAh, and it runs on iOS 15.",
  556. "message_files": [],
  557. "feedback": null,
  558. "retriever_resources": [
  559. {
  560. "position": 1,
  561. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  562. "dataset_name": "iPhone",
  563. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  564. "document_name": "iPhone List",
  565. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  566. "score": 0.98457545,
  567. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  568. }
  569. ],
  570. "created_at": 1705569239
  571. }
  572. ]
  573. }
  574. ```
  575. </CodeGroup>
  576. ### Response Example(智能助手)
  577. <CodeGroup title="Response">
  578. ```json {{ title: 'Response' }}
  579. {
  580. "limit": 20,
  581. "has_more": false,
  582. "data": [
  583. {
  584. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  585. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  586. "inputs": {},
  587. "query": "draw a cat",
  588. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  589. "message_files": [
  590. {
  591. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  592. "type": "image",
  593. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  594. "belongs_to": "assistant"
  595. }
  596. ],
  597. "feedback": null,
  598. "retriever_resources": [],
  599. "created_at": 1705988187
  600. }
  601. ]
  602. }
  603. ```
  604. </CodeGroup>
  605. </Col>
  606. </Row>
  607. ---
  608. <Heading
  609. url='/conversations'
  610. method='GET'
  611. title='获取会话列表'
  612. name='#conversations'
  613. />
  614. <Row>
  615. <Col>
  616. 获取当前用户的会话列表,默认返回最近的 20 条。
  617. ### Query
  618. <Properties>
  619. <Property name='user' type='string' key='user'>
  620. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  621. </Property>
  622. <Property name='last_id' type='string' key='last_id'>
  623. 当前页最后面一条记录的 ID,默认 null
  624. </Property>
  625. <Property name='limit' type='int' key='limit'>
  626. 一次请求返回多少条记录
  627. </Property>
  628. <Property name='pinned' type='bool' key='pinned'>
  629. 只返回置顶 true,只返回非置顶 false
  630. </Property>
  631. <Property name='sort_by' type='string' key='sort_by'>
  632. 排序字段(选题),默认 -updated_at(按更新时间倒序排列)
  633. - 可选值:created_at, -created_at, updated_at, -updated_at
  634. - 字段前面的符号代表顺序或倒序,-代表倒序
  635. </Property>
  636. </Properties>
  637. ### Response
  638. - `data` (array[object]) 会话列表
  639. - `id` (string) 会话 ID
  640. - `name` (string) 会话名称,默认由大语言模型生成。
  641. - `inputs` (array[object]) 用户输入参数。
  642. - `introduction` (string) 开场白
  643. - `created_at` (timestamp) 创建时间
  644. - `has_more` (bool)
  645. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  646. </Col>
  647. <Col sticky>
  648. <CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'\\\n--header 'Authorization: Bearer {api_key}'`}>
  649. ```bash {{ title: 'cURL' }}
  650. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  651. --header 'Authorization: Bearer {api_key}'
  652. ```
  653. </CodeGroup>
  654. <CodeGroup title="Response">
  655. ```json {{ title: 'Response' }}
  656. {
  657. "limit": 20,
  658. "has_more": false,
  659. "data": [
  660. {
  661. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  662. "name": "New chat",
  663. "inputs": {
  664. "book": "book",
  665. "myName": "Lucy"
  666. },
  667. "status": "normal",
  668. "created_at": 1679667915
  669. },
  670. {
  671. "id": "hSIhXBhNe8X1d8Et"
  672. // ...
  673. }
  674. ]
  675. }
  676. ```
  677. </CodeGroup>
  678. </Col>
  679. </Row>
  680. ---
  681. <Heading
  682. url='/conversations/:conversation_id'
  683. method='DELETE'
  684. title='删除会话'
  685. name='#delete'
  686. />
  687. <Row>
  688. <Col>
  689. 删除会话。
  690. ### Path
  691. - `conversation_id` (string) 会话 ID
  692. ### Request Body
  693. <Properties>
  694. <Property name='user' type='string' key='user'>
  695. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  696. </Property>
  697. </Properties>
  698. ### Response
  699. - `result` (string) 固定返回 success
  700. </Col>
  701. <Col sticky>
  702. <CodeGroup title="Request" tag="DELETE" label="/conversations/:conversation_id" targetCode={`curl -X DELETE '${props.appDetail.api_base_url}/conversations/:conversation_id' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "user": "abc-123"\n}'`}>
  703. ```bash {{ title: 'cURL' }}
  704. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  705. --header 'Content-Type: application/json' \
  706. --header 'Accept: application/json' \
  707. --header 'Authorization: Bearer {api_key}' \
  708. --data '{
  709. "user": "abc-123"
  710. }'
  711. ```
  712. </CodeGroup>
  713. <CodeGroup title="Response">
  714. ```json {{ title: 'Response' }}
  715. {
  716. "result": "success"
  717. }
  718. ```
  719. </CodeGroup>
  720. </Col>
  721. </Row>
  722. ---
  723. <Heading
  724. url='/conversations/:conversation_id/name'
  725. method='POST'
  726. title='会话重命名'
  727. name='#rename'
  728. />
  729. <Row>
  730. <Col>
  731. 对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
  732. ### Path
  733. - `conversation_id` (string) 会话 ID
  734. ### Request Body
  735. <Properties>
  736. <Property name='name' type='string' key='name'>
  737. 名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  738. </Property>
  739. <Property name='auto_generate' type='string' key='auto_generate'>
  740. 自动生成标题,默认 false。
  741. </Property>
  742. <Property name='user' type='string' key='user'>
  743. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  744. </Property>
  745. </Properties>
  746. ### Response
  747. - `id` (string) 会话 ID
  748. - `name` (string) 会话名称
  749. - `inputs` array[object] 用户输入参数。
  750. - `introduction` (string) 开场白
  751. - `created_at` (timestamp) 创建时间
  752. </Col>
  753. <Col sticky>
  754. <CodeGroup title="Request" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
  755. ```bash {{ title: 'cURL' }}
  756. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  757. --header 'Authorization: Bearer {api_key}' \
  758. --header 'Content-Type: application/json' \
  759. --data-raw '{
  760. "name": "",
  761. "user": "abc-123"
  762. }'
  763. ```
  764. </CodeGroup>
  765. <CodeGroup title="Response">
  766. ```json {{ title: 'Response' }}
  767. {
  768. "result": "success"
  769. }
  770. ```
  771. </CodeGroup>
  772. </Col>
  773. </Row>
  774. ---
  775. <Heading
  776. url='/audio-to-text'
  777. method='POST'
  778. title='语音转文字'
  779. name='#audio'
  780. />
  781. <Row>
  782. <Col>
  783. ### Request Body
  784. 该接口需使用 `multipart/form-data` 进行请求。
  785. <Properties>
  786. <Property name='file' type='file' key='file'>
  787. 语音文件。
  788. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  789. 文件大小限制:15MB
  790. </Property>
  791. <Property name='user' type='string' key='user'>
  792. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  793. </Property>
  794. </Properties>
  795. ### Response
  796. - `text` (string) 输出文字
  797. </Col>
  798. <Col sticky>
  799. <CodeGroup title="Request" tag="POST" label="/audio-to-text" targetCode={`curl -X POST '${props.appDetail.api_base_url}/audio-to-text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]`}>
  800. ```bash {{ title: 'cURL' }}
  801. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  802. --header 'Authorization: Bearer {api_key}' \
  803. --form 'file=@localfile;type=audio/mp3'
  804. ```
  805. </CodeGroup>
  806. <CodeGroup title="Response">
  807. ```json {{ title: 'Response' }}
  808. {
  809. "text": "hello"
  810. }
  811. ```
  812. </CodeGroup>
  813. </Col>
  814. </Row>
  815. ---
  816. <Heading
  817. url='/text-to-audio'
  818. method='POST'
  819. title='文字转语音'
  820. name='#audio'
  821. />
  822. <Row>
  823. <Col>
  824. 文字转语音。
  825. ### Request Body
  826. <Properties>
  827. <Property name='message_id' type='str' key='text'>
  828. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  829. </Property>
  830. <Property name='text' type='str' key='text'>
  831. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  832. </Property>
  833. <Property name='user' type='string' key='user'>
  834. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  835. </Property>
  836. </Properties>
  837. </Col>
  838. <Col sticky>
  839. <CodeGroup title="Request" tag="POST" label="/text-to-audio" targetCode={`curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",\n "text": "你好Dify",\n "user": "abc-123"\n}'`}>
  840. ```bash {{ title: 'cURL' }}
  841. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  842. --header 'Authorization: Bearer {api_key}' \
  843. --header 'Content-Type: application/json' \
  844. --data-raw '{
  845. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  846. "text": "你好Dify",
  847. "user": "abc-123"
  848. }'
  849. ```
  850. </CodeGroup>
  851. <CodeGroup title="headers">
  852. ```json {{ title: 'headers' }}
  853. {
  854. "Content-Type": "audio/wav"
  855. }
  856. ```
  857. </CodeGroup>
  858. </Col>
  859. </Row>
  860. ---
  861. <Heading
  862. url='/parameters'
  863. method='GET'
  864. title='获取应用配置信息'
  865. name='#parameters'
  866. />
  867. <Row>
  868. <Col>
  869. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  870. ### Query
  871. <Properties>
  872. <Property name='user' type='string' key='user'>
  873. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  874. </Property>
  875. </Properties>
  876. ### Response
  877. - `opening_statement` (string) 开场白
  878. - `suggested_questions` (array[string]) 开场推荐问题列表
  879. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  880. - `enabled` (bool) 是否开启
  881. - `speech_to_text` (object) 语音转文本
  882. - `enabled` (bool) 是否开启
  883. - `retriever_resource` (object) 引用和归属
  884. - `enabled` (bool) 是否开启
  885. - `annotation_reply` (object) 标记回复
  886. - `enabled` (bool) 是否开启
  887. - `user_input_form` (array[object]) 用户输入表单配置
  888. - `text-input` (object) 文本输入控件
  889. - `label` (string) 控件展示标签名
  890. - `variable` (string) 控件 ID
  891. - `required` (bool) 是否必填
  892. - `default` (string) 默认值
  893. - `paragraph` (object) 段落文本输入控件
  894. - `label` (string) 控件展示标签名
  895. - `variable` (string) 控件 ID
  896. - `required` (bool) 是否必填
  897. - `default` (string) 默认值
  898. - `select` (object) 下拉控件
  899. - `label` (string) 控件展示标签名
  900. - `variable` (string) 控件 ID
  901. - `required` (bool) 是否必填
  902. - `default` (string) 默认值
  903. - `options` (array[string]) 选项值
  904. - `file_upload` (object) 文件上传配置
  905. - `image` (object) 图片设置
  906. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  907. - `enabled` (bool) 是否开启
  908. - `number_limits` (int) 图片数量限制,默认 3
  909. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  910. - `system_parameters` (object) 系统参数
  911. - `file_size_limit` (int) Document upload size limit (MB)
  912. - `image_file_size_limit` (int) Image file upload size limit (MB)
  913. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  914. - `video_file_size_limit` (int) Video file upload size limit (MB)
  915. </Col>
  916. <Col sticky>
  917. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  918. ```bash {{ title: 'cURL' }}
  919. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  920. --header 'Authorization: Bearer {api_key}'
  921. ```
  922. </CodeGroup>
  923. <CodeGroup title="Response">
  924. ```json {{ title: 'Response' }}
  925. {
  926. "introduction": "nice to meet you",
  927. "user_input_form": [
  928. {
  929. "text-input": {
  930. "label": "a",
  931. "variable": "a",
  932. "required": true,
  933. "max_length": 48,
  934. "default": ""
  935. }
  936. },
  937. {
  938. // ...
  939. }
  940. ],
  941. "file_upload": {
  942. "image": {
  943. "enabled": true,
  944. "number_limits": 3,
  945. "transfer_methods": [
  946. "remote_url",
  947. "local_file"
  948. ]
  949. }
  950. },
  951. "system_parameters": {
  952. "file_size_limit": 15,
  953. "image_file_size_limit": 10,
  954. "audio_file_size_limit": 50,
  955. "video_file_size_limit": 100
  956. }
  957. }
  958. ```
  959. </CodeGroup>
  960. </Col>
  961. </Row>
  962. ---
  963. <Heading
  964. url='/meta'
  965. method='GET'
  966. title='获取应用Meta信息'
  967. name='#meta'
  968. />
  969. <Row>
  970. <Col>
  971. 用于获取工具icon
  972. ### Query
  973. <Properties>
  974. <Property name='user' type='string' key='user'>
  975. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  976. </Property>
  977. </Properties>
  978. ### Response
  979. - `tool_icons`(object[string]) 工具图标
  980. - `工具名称` (string)
  981. - `icon` (object|string)
  982. - (object) 图标
  983. - `background` (string) hex格式的背景色
  984. - `content`(string) emoji
  985. - (string) 图标URL
  986. </Col>
  987. <Col>
  988. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \\\n-H 'Authorization: Bearer {api_key}'`}>
  989. ```bash {{ title: 'cURL' }}
  990. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  991. -H 'Authorization: Bearer {api_key}'
  992. ```
  993. </CodeGroup>
  994. <CodeGroup title="Response">
  995. ```json {{ title: 'Response' }}
  996. {
  997. "tool_icons": {
  998. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  999. "api_tool": {
  1000. "background": "#252525",
  1001. "content": "\ud83d\ude01"
  1002. }
  1003. }
  1004. }
  1005. ```
  1006. </CodeGroup>
  1007. </Col>
  1008. </Row>