template_advanced_chat.zh.mdx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  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` (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` (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` (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. (选填)一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。
  627. </Property>
  628. <Property name='sort_by' type='string' key='sort_by'>
  629. (选填)排序字段,默认 -updated_at(按更新时间倒序排列)
  630. - 可选值:created_at, -created_at, updated_at, -updated_at
  631. - 字段前面的符号代表顺序或倒序,-代表倒序
  632. </Property>
  633. </Properties>
  634. ### Response
  635. - `data` (array[object]) 会话列表
  636. - `id` (string) 会话 ID
  637. - `name` (string) 会话名称,默认由大语言模型生成。
  638. - `inputs` (object) 用户输入参数。
  639. - `status` (string) 会话状态
  640. - `introduction` (string) 开场白
  641. - `created_at` (timestamp) 创建时间
  642. - `updated_at` (timestamp) 更新时间
  643. - `has_more` (bool)
  644. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  645. </Col>
  646. <Col sticky>
  647. <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}'`}>
  648. ```bash {{ title: 'cURL' }}
  649. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  650. --header 'Authorization: Bearer {api_key}'
  651. ```
  652. </CodeGroup>
  653. <CodeGroup title="Response">
  654. ```json {{ title: 'Response' }}
  655. {
  656. "limit": 20,
  657. "has_more": false,
  658. "data": [
  659. {
  660. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  661. "name": "New chat",
  662. "inputs": {
  663. "book": "book",
  664. "myName": "Lucy"
  665. },
  666. "status": "normal",
  667. "created_at": 1679667915,
  668. "updated_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='bool' 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` (object) 用户输入参数
  750. - `status` (string) 会话状态
  751. - `introduction` (string) 开场白
  752. - `created_at` (timestamp) 创建时间
  753. - `updated_at` (timestamp) 更新时间
  754. </Col>
  755. <Col sticky>
  756. <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 "auto_generate": true, \n "user": "abc-123"\n}'`}>
  757. ```bash {{ title: 'cURL' }}
  758. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  759. --header 'Authorization: Bearer {api_key}' \
  760. --header 'Content-Type: application/json' \
  761. --data-raw '{
  762. "name": "",
  763. "auto_generate": true,
  764. "user": "abc-123"
  765. }'
  766. ```
  767. </CodeGroup>
  768. <CodeGroup title="Response">
  769. ```json {{ title: 'Response' }}
  770. {
  771. "id": "34d511d5-56de-4f16-a997-57b379508443",
  772. "name": "hello",
  773. "inputs": {},
  774. "status": "normal",
  775. "introduction": "",
  776. "created_at": 1732731141,
  777. "updated_at": 1732734510
  778. }
  779. ```
  780. </CodeGroup>
  781. </Col>
  782. </Row>
  783. ---
  784. <Heading
  785. url='/audio-to-text'
  786. method='POST'
  787. title='语音转文字'
  788. name='#audio'
  789. />
  790. <Row>
  791. <Col>
  792. ### Request Body
  793. 该接口需使用 `multipart/form-data` 进行请求。
  794. <Properties>
  795. <Property name='file' type='file' key='file'>
  796. 语音文件。
  797. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  798. 文件大小限制:15MB
  799. </Property>
  800. <Property name='user' type='string' key='user'>
  801. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  802. </Property>
  803. </Properties>
  804. ### Response
  805. - `text` (string) 输出文字
  806. </Col>
  807. <Col sticky>
  808. <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]`}>
  809. ```bash {{ title: 'cURL' }}
  810. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  811. --header 'Authorization: Bearer {api_key}' \
  812. --form 'file=@localfile;type=audio/mp3'
  813. ```
  814. </CodeGroup>
  815. <CodeGroup title="Response">
  816. ```json {{ title: 'Response' }}
  817. {
  818. "text": "hello"
  819. }
  820. ```
  821. </CodeGroup>
  822. </Col>
  823. </Row>
  824. ---
  825. <Heading
  826. url='/text-to-audio'
  827. method='POST'
  828. title='文字转语音'
  829. name='#audio'
  830. />
  831. <Row>
  832. <Col>
  833. 文字转语音。
  834. ### Request Body
  835. <Properties>
  836. <Property name='message_id' type='str' key='text'>
  837. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  838. </Property>
  839. <Property name='text' type='str' key='text'>
  840. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  841. </Property>
  842. <Property name='user' type='string' key='user'>
  843. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  844. </Property>
  845. </Properties>
  846. </Col>
  847. <Col sticky>
  848. <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}'`}>
  849. ```bash {{ title: 'cURL' }}
  850. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  851. --header 'Authorization: Bearer {api_key}' \
  852. --header 'Content-Type: application/json' \
  853. --data-raw '{
  854. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  855. "text": "你好Dify",
  856. "user": "abc-123"
  857. }'
  858. ```
  859. </CodeGroup>
  860. <CodeGroup title="headers">
  861. ```json {{ title: 'headers' }}
  862. {
  863. "Content-Type": "audio/wav"
  864. }
  865. ```
  866. </CodeGroup>
  867. </Col>
  868. </Row>
  869. ---
  870. <Heading
  871. url='/info'
  872. method='GET'
  873. title='获取应用基本信息'
  874. name='#info'
  875. />
  876. <Row>
  877. <Col>
  878. 用于获取应用的基本信息
  879. ### Query
  880. <Properties>
  881. <Property name='user' type='string' key='user'>
  882. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  883. </Property>
  884. </Properties>
  885. ### Response
  886. - `name` (string) 应用名称
  887. - `description` (string) 应用描述
  888. - `tags` (array[string]) 应用标签
  889. </Col>
  890. <Col>
  891. <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}'`}>
  892. ```bash {{ title: 'cURL' }}
  893. curl -X GET '${props.appDetail.api_base_url}/info?user=abc-123' \
  894. -H 'Authorization: Bearer {api_key}'
  895. ```
  896. </CodeGroup>
  897. <CodeGroup title="Response">
  898. ```json {{ title: 'Response' }}
  899. {
  900. "name": "My App",
  901. "description": "This is my app.",
  902. "tags": [
  903. "tag1",
  904. "tag2"
  905. ]
  906. }
  907. ```
  908. </CodeGroup>
  909. </Col>
  910. </Row>
  911. ---
  912. <Heading
  913. url='/parameters'
  914. method='GET'
  915. title='获取应用参数'
  916. name='#parameters'
  917. />
  918. <Row>
  919. <Col>
  920. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  921. ### Query
  922. <Properties>
  923. <Property name='user' type='string' key='user'>
  924. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  925. </Property>
  926. </Properties>
  927. ### Response
  928. - `opening_statement` (string) 开场白
  929. - `suggested_questions` (array[string]) 开场推荐问题列表
  930. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  931. - `enabled` (bool) 是否开启
  932. - `speech_to_text` (object) 语音转文本
  933. - `enabled` (bool) 是否开启
  934. - `retriever_resource` (object) 引用和归属
  935. - `enabled` (bool) 是否开启
  936. - `annotation_reply` (object) 标记回复
  937. - `enabled` (bool) 是否开启
  938. - `user_input_form` (array[object]) 用户输入表单配置
  939. - `text-input` (object) 文本输入控件
  940. - `label` (string) 控件展示标签名
  941. - `variable` (string) 控件 ID
  942. - `required` (bool) 是否必填
  943. - `default` (string) 默认值
  944. - `paragraph` (object) 段落文本输入控件
  945. - `label` (string) 控件展示标签名
  946. - `variable` (string) 控件 ID
  947. - `required` (bool) 是否必填
  948. - `default` (string) 默认值
  949. - `select` (object) 下拉控件
  950. - `label` (string) 控件展示标签名
  951. - `variable` (string) 控件 ID
  952. - `required` (bool) 是否必填
  953. - `default` (string) 默认值
  954. - `options` (array[string]) 选项值
  955. - `file_upload` (object) 文件上传配置
  956. - `image` (object) 图片设置
  957. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  958. - `enabled` (bool) 是否开启
  959. - `number_limits` (int) 图片数量限制,默认 3
  960. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  961. - `system_parameters` (object) 系统参数
  962. - `file_size_limit` (int) Document upload size limit (MB)
  963. - `image_file_size_limit` (int) Image file upload size limit (MB)
  964. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  965. - `video_file_size_limit` (int) Video file upload size limit (MB)
  966. </Col>
  967. <Col sticky>
  968. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  969. ```bash {{ title: 'cURL' }}
  970. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  971. --header 'Authorization: Bearer {api_key}'
  972. ```
  973. </CodeGroup>
  974. <CodeGroup title="Response">
  975. ```json {{ title: 'Response' }}
  976. {
  977. "introduction": "nice to meet you",
  978. "user_input_form": [
  979. {
  980. "text-input": {
  981. "label": "a",
  982. "variable": "a",
  983. "required": true,
  984. "max_length": 48,
  985. "default": ""
  986. }
  987. },
  988. {
  989. // ...
  990. }
  991. ],
  992. "file_upload": {
  993. "image": {
  994. "enabled": true,
  995. "number_limits": 3,
  996. "transfer_methods": [
  997. "remote_url",
  998. "local_file"
  999. ]
  1000. }
  1001. },
  1002. "system_parameters": {
  1003. "file_size_limit": 15,
  1004. "image_file_size_limit": 10,
  1005. "audio_file_size_limit": 50,
  1006. "video_file_size_limit": 100
  1007. }
  1008. }
  1009. ```
  1010. </CodeGroup>
  1011. </Col>
  1012. </Row>
  1013. ---
  1014. <Heading
  1015. url='/meta'
  1016. method='GET'
  1017. title='获取应用Meta信息'
  1018. name='#meta'
  1019. />
  1020. <Row>
  1021. <Col>
  1022. 用于获取工具icon
  1023. ### Query
  1024. <Properties>
  1025. <Property name='user' type='string' key='user'>
  1026. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  1027. </Property>
  1028. </Properties>
  1029. ### Response
  1030. - `tool_icons`(object[string]) 工具图标
  1031. - `工具名称` (string)
  1032. - `icon` (object|string)
  1033. - (object) 图标
  1034. - `background` (string) hex格式的背景色
  1035. - `content`(string) emoji
  1036. - (string) 图标URL
  1037. </Col>
  1038. <Col>
  1039. <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}'`}>
  1040. ```bash {{ title: 'cURL' }}
  1041. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  1042. -H 'Authorization: Bearer {api_key}'
  1043. ```
  1044. </CodeGroup>
  1045. <CodeGroup title="Response">
  1046. ```json {{ title: 'Response' }}
  1047. {
  1048. "tool_icons": {
  1049. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1050. "api_tool": {
  1051. "background": "#252525",
  1052. "content": "\ud83d\ude01"
  1053. }
  1054. }
  1055. }
  1056. ```
  1057. </CodeGroup>
  1058. </Col>
  1059. </Row>