template_advanced_chat.zh.mdx 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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. <Property name='content' type='string' key='content'>
  419. 消息反馈的具体信息。
  420. </Property>
  421. </Properties>
  422. ### Response
  423. - `result` (string) 固定返回 success
  424. </Col>
  425. <Col sticky>
  426. <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 "content": "message feedback information"\n}'`}>
  427. ```bash {{ title: 'cURL' }}
  428. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  429. --header 'Authorization: Bearer {api_key}' \
  430. --header 'Content-Type: application/json' \
  431. --data-raw '{
  432. "rating": "like",
  433. "user": "abc-123",
  434. "content": "message feedback information"
  435. }'
  436. ```
  437. </CodeGroup>
  438. <CodeGroup title="Response">
  439. ```json {{ title: 'Response' }}
  440. {
  441. "result": "success"
  442. }
  443. ```
  444. </CodeGroup>
  445. </Col>
  446. </Row>
  447. ---
  448. <Heading
  449. url='/messages/{message_id}/suggested'
  450. method='GET'
  451. title='获取下一轮建议问题列表'
  452. name='#suggested'
  453. />
  454. <Row>
  455. <Col>
  456. 获取下一轮建议问题列表。
  457. ### Path Params
  458. <Properties>
  459. <Property name='message_id' type='string' key='message_id'>
  460. Message ID
  461. </Property>
  462. </Properties>
  463. ### Query
  464. <Properties>
  465. <Property name='user' type='string' key='user'>
  466. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  467. </Property>
  468. </Properties>
  469. </Col>
  470. <Col sticky>
  471. <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'`}>
  472. ```bash {{ title: 'cURL' }}
  473. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested'?user=abc-123 \
  474. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  475. --header 'Content-Type: application/json' \
  476. ```
  477. </CodeGroup>
  478. <CodeGroup title="Response">
  479. ```json {{ title: 'Response' }}
  480. {
  481. "result": "success",
  482. "data": [
  483. "a",
  484. "b",
  485. "c"
  486. ]
  487. }
  488. ```
  489. </CodeGroup>
  490. </Col>
  491. </Row>
  492. ---
  493. ---
  494. <Heading
  495. url='/messages'
  496. method='GET'
  497. title='获取会话历史消息'
  498. name='#messages'
  499. />
  500. <Row>
  501. <Col>
  502. 滚动加载形式返回历史聊天记录,第一页返回最新 `limit` 条,即:倒序返回。
  503. ### Query
  504. <Properties>
  505. <Property name='conversation_id' type='string' key='conversation_id'>
  506. 会话 ID
  507. </Property>
  508. <Property name='user' type='string' key='user'>
  509. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  510. </Property>
  511. <Property name='first_id' type='string' key='first_id'>
  512. 当前页第一条聊天记录的 ID,默认 null
  513. </Property>
  514. <Property name='limit' type='int' key='limit'>
  515. 一次请求返回多少条聊天记录,默认 20 条。
  516. </Property>
  517. </Properties>
  518. ### Response
  519. - `data` (array[object]) 消息列表
  520. - `id` (string) 消息 ID
  521. - `conversation_id` (string) 会话 ID
  522. - `inputs` (object) 用户输入参数。
  523. - `query` (string) 用户输入 / 提问内容。
  524. - `message_files` (array[object]) 消息文件
  525. - `id` (string) ID
  526. - `type` (string) 文件类型,image 图片
  527. - `url` (string) 预览图片地址
  528. - `belongs_to` (string) 文件归属方,user 或 assistant
  529. - `answer` (string) 回答消息内容
  530. - `created_at` (timestamp) 创建时间
  531. - `feedback` (object) 反馈信息
  532. - `rating` (string) 点赞 like / 点踩 dislike
  533. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  534. - `has_more` (bool) 是否存在下一页
  535. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  536. </Col>
  537. <Col sticky>
  538. ### Request Example
  539. <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}'`}>
  540. ```bash {{ title: 'cURL' }}
  541. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  542. --header 'Authorization: Bearer {api_key}'
  543. ```
  544. </CodeGroup>
  545. ### Response Example
  546. <CodeGroup title="Response">
  547. ```json {{ title: 'Response' }}
  548. {
  549. "limit": 20,
  550. "has_more": false,
  551. "data": [
  552. {
  553. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  554. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  555. "inputs": {
  556. "name": "dify"
  557. },
  558. "query": "iphone 13 pro",
  559. "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.",
  560. "message_files": [],
  561. "feedback": null,
  562. "retriever_resources": [
  563. {
  564. "position": 1,
  565. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  566. "dataset_name": "iPhone",
  567. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  568. "document_name": "iPhone List",
  569. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  570. "score": 0.98457545,
  571. "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\""
  572. }
  573. ],
  574. "created_at": 1705569239
  575. }
  576. ]
  577. }
  578. ```
  579. </CodeGroup>
  580. ### Response Example(智能助手)
  581. <CodeGroup title="Response">
  582. ```json {{ title: 'Response' }}
  583. {
  584. "limit": 20,
  585. "has_more": false,
  586. "data": [
  587. {
  588. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  589. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  590. "inputs": {},
  591. "query": "draw a cat",
  592. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  593. "message_files": [
  594. {
  595. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  596. "type": "image",
  597. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  598. "belongs_to": "assistant"
  599. }
  600. ],
  601. "feedback": null,
  602. "retriever_resources": [],
  603. "created_at": 1705988187
  604. }
  605. ]
  606. }
  607. ```
  608. </CodeGroup>
  609. </Col>
  610. </Row>
  611. ---
  612. <Heading
  613. url='/conversations'
  614. method='GET'
  615. title='获取会话列表'
  616. name='#conversations'
  617. />
  618. <Row>
  619. <Col>
  620. 获取当前用户的会话列表,默认返回最近的 20 条。
  621. ### Query
  622. <Properties>
  623. <Property name='user' type='string' key='user'>
  624. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  625. </Property>
  626. <Property name='last_id' type='string' key='last_id'>
  627. (选填)当前页最后面一条记录的 ID,默认 null
  628. </Property>
  629. <Property name='limit' type='int' key='limit'>
  630. (选填)一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。
  631. </Property>
  632. <Property name='sort_by' type='string' key='sort_by'>
  633. (选填)排序字段,默认 -updated_at(按更新时间倒序排列)
  634. - 可选值:created_at, -created_at, updated_at, -updated_at
  635. - 字段前面的符号代表顺序或倒序,-代表倒序
  636. </Property>
  637. </Properties>
  638. ### Response
  639. - `data` (array[object]) 会话列表
  640. - `id` (string) 会话 ID
  641. - `name` (string) 会话名称,默认由大语言模型生成。
  642. - `inputs` (object) 用户输入参数。
  643. - `status` (string) 会话状态
  644. - `introduction` (string) 开场白
  645. - `created_at` (timestamp) 创建时间
  646. - `updated_at` (timestamp) 更新时间
  647. - `has_more` (bool)
  648. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  649. </Col>
  650. <Col sticky>
  651. <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}'`}>
  652. ```bash {{ title: 'cURL' }}
  653. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  654. --header 'Authorization: Bearer {api_key}'
  655. ```
  656. </CodeGroup>
  657. <CodeGroup title="Response">
  658. ```json {{ title: 'Response' }}
  659. {
  660. "limit": 20,
  661. "has_more": false,
  662. "data": [
  663. {
  664. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  665. "name": "New chat",
  666. "inputs": {
  667. "book": "book",
  668. "myName": "Lucy"
  669. },
  670. "status": "normal",
  671. "created_at": 1679667915,
  672. "updated_at": 1679667915
  673. },
  674. {
  675. "id": "hSIhXBhNe8X1d8Et"
  676. // ...
  677. }
  678. ]
  679. }
  680. ```
  681. </CodeGroup>
  682. </Col>
  683. </Row>
  684. ---
  685. <Heading
  686. url='/conversations/:conversation_id'
  687. method='DELETE'
  688. title='删除会话'
  689. name='#delete'
  690. />
  691. <Row>
  692. <Col>
  693. 删除会话。
  694. ### Path
  695. - `conversation_id` (string) 会话 ID
  696. ### Request Body
  697. <Properties>
  698. <Property name='user' type='string' key='user'>
  699. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  700. </Property>
  701. </Properties>
  702. ### Response
  703. - `result` (string) 固定返回 success
  704. </Col>
  705. <Col sticky>
  706. <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}'`}>
  707. ```bash {{ title: 'cURL' }}
  708. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  709. --header 'Content-Type: application/json' \
  710. --header 'Accept: application/json' \
  711. --header 'Authorization: Bearer {api_key}' \
  712. --data '{
  713. "user": "abc-123"
  714. }'
  715. ```
  716. </CodeGroup>
  717. <CodeGroup title="Response">
  718. ```json {{ title: 'Response' }}
  719. {
  720. "result": "success"
  721. }
  722. ```
  723. </CodeGroup>
  724. </Col>
  725. </Row>
  726. ---
  727. <Heading
  728. url='/conversations/:conversation_id/name'
  729. method='POST'
  730. title='会话重命名'
  731. name='#rename'
  732. />
  733. <Row>
  734. <Col>
  735. 对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
  736. ### Path
  737. - `conversation_id` (string) 会话 ID
  738. ### Request Body
  739. <Properties>
  740. <Property name='name' type='string' key='name'>
  741. (选填)名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  742. </Property>
  743. <Property name='auto_generate' type='bool' key='auto_generate'>
  744. (选填)自动生成标题,默认 false。
  745. </Property>
  746. <Property name='user' type='string' key='user'>
  747. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  748. </Property>
  749. </Properties>
  750. ### Response
  751. - `id` (string) 会话 ID
  752. - `name` (string) 会话名称
  753. - `inputs` (object) 用户输入参数
  754. - `status` (string) 会话状态
  755. - `introduction` (string) 开场白
  756. - `created_at` (timestamp) 创建时间
  757. - `updated_at` (timestamp) 更新时间
  758. </Col>
  759. <Col sticky>
  760. <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}'`}>
  761. ```bash {{ title: 'cURL' }}
  762. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  763. --header 'Authorization: Bearer {api_key}' \
  764. --header 'Content-Type: application/json' \
  765. --data-raw '{
  766. "name": "",
  767. "auto_generate": true,
  768. "user": "abc-123"
  769. }'
  770. ```
  771. </CodeGroup>
  772. <CodeGroup title="Response">
  773. ```json {{ title: 'Response' }}
  774. {
  775. "id": "34d511d5-56de-4f16-a997-57b379508443",
  776. "name": "hello",
  777. "inputs": {},
  778. "status": "normal",
  779. "introduction": "",
  780. "created_at": 1732731141,
  781. "updated_at": 1732734510
  782. }
  783. ```
  784. </CodeGroup>
  785. </Col>
  786. </Row>
  787. ---
  788. <Heading
  789. url='/audio-to-text'
  790. method='POST'
  791. title='语音转文字'
  792. name='#audio'
  793. />
  794. <Row>
  795. <Col>
  796. ### Request Body
  797. 该接口需使用 `multipart/form-data` 进行请求。
  798. <Properties>
  799. <Property name='file' type='file' key='file'>
  800. 语音文件。
  801. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  802. 文件大小限制:15MB
  803. </Property>
  804. <Property name='user' type='string' key='user'>
  805. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  806. </Property>
  807. </Properties>
  808. ### Response
  809. - `text` (string) 输出文字
  810. </Col>
  811. <Col sticky>
  812. <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]`}>
  813. ```bash {{ title: 'cURL' }}
  814. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  815. --header 'Authorization: Bearer {api_key}' \
  816. --form 'file=@localfile;type=audio/mp3'
  817. ```
  818. </CodeGroup>
  819. <CodeGroup title="Response">
  820. ```json {{ title: 'Response' }}
  821. {
  822. "text": "hello"
  823. }
  824. ```
  825. </CodeGroup>
  826. </Col>
  827. </Row>
  828. ---
  829. <Heading
  830. url='/text-to-audio'
  831. method='POST'
  832. title='文字转语音'
  833. name='#audio'
  834. />
  835. <Row>
  836. <Col>
  837. 文字转语音。
  838. ### Request Body
  839. <Properties>
  840. <Property name='message_id' type='str' key='text'>
  841. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  842. </Property>
  843. <Property name='text' type='str' key='text'>
  844. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  845. </Property>
  846. <Property name='user' type='string' key='user'>
  847. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  848. </Property>
  849. </Properties>
  850. </Col>
  851. <Col sticky>
  852. <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}'`}>
  853. ```bash {{ title: 'cURL' }}
  854. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  855. --header 'Authorization: Bearer {api_key}' \
  856. --header 'Content-Type: application/json' \
  857. --data-raw '{
  858. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  859. "text": "你好Dify",
  860. "user": "abc-123"
  861. }'
  862. ```
  863. </CodeGroup>
  864. <CodeGroup title="headers">
  865. ```json {{ title: 'headers' }}
  866. {
  867. "Content-Type": "audio/wav"
  868. }
  869. ```
  870. </CodeGroup>
  871. </Col>
  872. </Row>
  873. ---
  874. <Heading
  875. url='/info'
  876. method='GET'
  877. title='获取应用基本信息'
  878. name='#info'
  879. />
  880. <Row>
  881. <Col>
  882. 用于获取应用的基本信息
  883. ### Query
  884. <Properties>
  885. <Property name='user' type='string' key='user'>
  886. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  887. </Property>
  888. </Properties>
  889. ### Response
  890. - `name` (string) 应用名称
  891. - `description` (string) 应用描述
  892. - `tags` (array[string]) 应用标签
  893. </Col>
  894. <Col>
  895. <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}'`}>
  896. ```bash {{ title: 'cURL' }}
  897. curl -X GET '${props.appDetail.api_base_url}/info?user=abc-123' \
  898. -H 'Authorization: Bearer {api_key}'
  899. ```
  900. </CodeGroup>
  901. <CodeGroup title="Response">
  902. ```json {{ title: 'Response' }}
  903. {
  904. "name": "My App",
  905. "description": "This is my app.",
  906. "tags": [
  907. "tag1",
  908. "tag2"
  909. ]
  910. }
  911. ```
  912. </CodeGroup>
  913. </Col>
  914. </Row>
  915. ---
  916. <Heading
  917. url='/parameters'
  918. method='GET'
  919. title='获取应用参数'
  920. name='#parameters'
  921. />
  922. <Row>
  923. <Col>
  924. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  925. ### Query
  926. <Properties>
  927. <Property name='user' type='string' key='user'>
  928. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  929. </Property>
  930. </Properties>
  931. ### Response
  932. - `opening_statement` (string) 开场白
  933. - `suggested_questions` (array[string]) 开场推荐问题列表
  934. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  935. - `enabled` (bool) 是否开启
  936. - `speech_to_text` (object) 语音转文本
  937. - `enabled` (bool) 是否开启
  938. - `retriever_resource` (object) 引用和归属
  939. - `enabled` (bool) 是否开启
  940. - `annotation_reply` (object) 标记回复
  941. - `enabled` (bool) 是否开启
  942. - `user_input_form` (array[object]) 用户输入表单配置
  943. - `text-input` (object) 文本输入控件
  944. - `label` (string) 控件展示标签名
  945. - `variable` (string) 控件 ID
  946. - `required` (bool) 是否必填
  947. - `default` (string) 默认值
  948. - `paragraph` (object) 段落文本输入控件
  949. - `label` (string) 控件展示标签名
  950. - `variable` (string) 控件 ID
  951. - `required` (bool) 是否必填
  952. - `default` (string) 默认值
  953. - `select` (object) 下拉控件
  954. - `label` (string) 控件展示标签名
  955. - `variable` (string) 控件 ID
  956. - `required` (bool) 是否必填
  957. - `default` (string) 默认值
  958. - `options` (array[string]) 选项值
  959. - `file_upload` (object) 文件上传配置
  960. - `image` (object) 图片设置
  961. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  962. - `enabled` (bool) 是否开启
  963. - `number_limits` (int) 图片数量限制,默认 3
  964. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  965. - `system_parameters` (object) 系统参数
  966. - `file_size_limit` (int) Document upload size limit (MB)
  967. - `image_file_size_limit` (int) Image file upload size limit (MB)
  968. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  969. - `video_file_size_limit` (int) Video file upload size limit (MB)
  970. </Col>
  971. <Col sticky>
  972. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  973. ```bash {{ title: 'cURL' }}
  974. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  975. --header 'Authorization: Bearer {api_key}'
  976. ```
  977. </CodeGroup>
  978. <CodeGroup title="Response">
  979. ```json {{ title: 'Response' }}
  980. {
  981. "introduction": "nice to meet you",
  982. "user_input_form": [
  983. {
  984. "text-input": {
  985. "label": "a",
  986. "variable": "a",
  987. "required": true,
  988. "max_length": 48,
  989. "default": ""
  990. }
  991. },
  992. {
  993. // ...
  994. }
  995. ],
  996. "file_upload": {
  997. "image": {
  998. "enabled": true,
  999. "number_limits": 3,
  1000. "transfer_methods": [
  1001. "remote_url",
  1002. "local_file"
  1003. ]
  1004. }
  1005. },
  1006. "system_parameters": {
  1007. "file_size_limit": 15,
  1008. "image_file_size_limit": 10,
  1009. "audio_file_size_limit": 50,
  1010. "video_file_size_limit": 100
  1011. }
  1012. }
  1013. ```
  1014. </CodeGroup>
  1015. </Col>
  1016. </Row>
  1017. ---
  1018. <Heading
  1019. url='/meta'
  1020. method='GET'
  1021. title='获取应用Meta信息'
  1022. name='#meta'
  1023. />
  1024. <Row>
  1025. <Col>
  1026. 用于获取工具icon
  1027. ### Query
  1028. <Properties>
  1029. <Property name='user' type='string' key='user'>
  1030. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  1031. </Property>
  1032. </Properties>
  1033. ### Response
  1034. - `tool_icons`(object[string]) 工具图标
  1035. - `工具名称` (string)
  1036. - `icon` (object|string)
  1037. - (object) 图标
  1038. - `background` (string) hex格式的背景色
  1039. - `content`(string) emoji
  1040. - (string) 图标URL
  1041. </Col>
  1042. <Col>
  1043. <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}'`}>
  1044. ```bash {{ title: 'cURL' }}
  1045. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  1046. -H 'Authorization: Bearer {api_key}'
  1047. ```
  1048. </CodeGroup>
  1049. <CodeGroup title="Response">
  1050. ```json {{ title: 'Response' }}
  1051. {
  1052. "tool_icons": {
  1053. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1054. "api_tool": {
  1055. "background": "#252525",
  1056. "content": "\ud83d\ude01"
  1057. }
  1058. }
  1059. }
  1060. ```
  1061. </CodeGroup>
  1062. </Col>
  1063. </Row>