template_advanced_chat.zh.mdx 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. ### Request Body
  733. <Properties>
  734. <Property name='name' type='string' key='name'>
  735. 名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  736. </Property>
  737. <Property name='auto_generate' type='string' key='auto_generate'>
  738. 自动生成标题,默认 false。
  739. </Property>
  740. <Property name='user' type='string' key='user'>
  741. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  742. </Property>
  743. </Properties>
  744. ### Response
  745. - `id` (string) 会话 ID
  746. - `name` (string) 会话名称
  747. - `inputs` array[object] 用户输入参数。
  748. - `introduction` (string) 开场白
  749. - `created_at` (timestamp) 创建时间
  750. </Col>
  751. <Col sticky>
  752. <CodeGroup title="Request" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
  753. ```bash {{ title: 'cURL' }}
  754. curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \
  755. --header 'Authorization: Bearer {api_key}' \
  756. --header 'Content-Type: application/json' \
  757. --data-raw '{
  758. "name": "",
  759. "user": "abc-123"
  760. }'
  761. ```
  762. </CodeGroup>
  763. <CodeGroup title="Response">
  764. ```json {{ title: 'Response' }}
  765. {
  766. "result": "success"
  767. }
  768. ```
  769. </CodeGroup>
  770. </Col>
  771. </Row>
  772. ---
  773. <Heading
  774. url='/audio-to-text'
  775. method='POST'
  776. title='语音转文字'
  777. name='#audio'
  778. />
  779. <Row>
  780. <Col>
  781. ### Request Body
  782. 该接口需使用 `multipart/form-data` 进行请求。
  783. <Properties>
  784. <Property name='file' type='file' key='file'>
  785. 语音文件。
  786. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  787. 文件大小限制:15MB
  788. </Property>
  789. <Property name='user' type='string' key='user'>
  790. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  791. </Property>
  792. </Properties>
  793. ### Response
  794. - `text` (string) 输出文字
  795. </Col>
  796. <Col sticky>
  797. <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]`}>
  798. ```bash {{ title: 'cURL' }}
  799. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  800. --header 'Authorization: Bearer {api_key}' \
  801. --form 'file=@localfile;type=audio/mp3'
  802. ```
  803. </CodeGroup>
  804. <CodeGroup title="Response">
  805. ```json {{ title: 'Response' }}
  806. {
  807. "text": "hello"
  808. }
  809. ```
  810. </CodeGroup>
  811. </Col>
  812. </Row>
  813. ---
  814. <Heading
  815. url='/text-to-audio'
  816. method='POST'
  817. title='文字转语音'
  818. name='#audio'
  819. />
  820. <Row>
  821. <Col>
  822. 文字转语音。
  823. ### Request Body
  824. <Properties>
  825. <Property name='message_id' type='str' key='text'>
  826. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  827. </Property>
  828. <Property name='text' type='str' key='text'>
  829. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  830. </Property>
  831. <Property name='user' type='string' key='user'>
  832. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  833. </Property>
  834. </Properties>
  835. </Col>
  836. <Col sticky>
  837. <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}'`}>
  838. ```bash {{ title: 'cURL' }}
  839. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  840. --header 'Authorization: Bearer {api_key}' \
  841. --header 'Content-Type: application/json' \
  842. --data-raw '{
  843. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  844. "text": "你好Dify",
  845. "user": "abc-123"
  846. }'
  847. ```
  848. </CodeGroup>
  849. <CodeGroup title="headers">
  850. ```json {{ title: 'headers' }}
  851. {
  852. "Content-Type": "audio/wav"
  853. }
  854. ```
  855. </CodeGroup>
  856. </Col>
  857. </Row>
  858. ---
  859. <Heading
  860. url='/parameters'
  861. method='GET'
  862. title='获取应用配置信息'
  863. name='#parameters'
  864. />
  865. <Row>
  866. <Col>
  867. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  868. ### Query
  869. <Properties>
  870. <Property name='user' type='string' key='user'>
  871. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  872. </Property>
  873. </Properties>
  874. ### Response
  875. - `opening_statement` (string) 开场白
  876. - `suggested_questions` (array[string]) 开场推荐问题列表
  877. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  878. - `enabled` (bool) 是否开启
  879. - `speech_to_text` (object) 语音转文本
  880. - `enabled` (bool) 是否开启
  881. - `retriever_resource` (object) 引用和归属
  882. - `enabled` (bool) 是否开启
  883. - `annotation_reply` (object) 标记回复
  884. - `enabled` (bool) 是否开启
  885. - `user_input_form` (array[object]) 用户输入表单配置
  886. - `text-input` (object) 文本输入控件
  887. - `label` (string) 控件展示标签名
  888. - `variable` (string) 控件 ID
  889. - `required` (bool) 是否必填
  890. - `default` (string) 默认值
  891. - `paragraph` (object) 段落文本输入控件
  892. - `label` (string) 控件展示标签名
  893. - `variable` (string) 控件 ID
  894. - `required` (bool) 是否必填
  895. - `default` (string) 默认值
  896. - `select` (object) 下拉控件
  897. - `label` (string) 控件展示标签名
  898. - `variable` (string) 控件 ID
  899. - `required` (bool) 是否必填
  900. - `default` (string) 默认值
  901. - `options` (array[string]) 选项值
  902. - `file_upload` (object) 文件上传配置
  903. - `image` (object) 图片设置
  904. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  905. - `enabled` (bool) 是否开启
  906. - `number_limits` (int) 图片数量限制,默认 3
  907. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  908. - `system_parameters` (object) 系统参数
  909. - `file_size_limit` (int) Document upload size limit (MB)
  910. - `image_file_size_limit` (int) Image file upload size limit (MB)
  911. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  912. - `video_file_size_limit` (int) Video file upload size limit (MB)
  913. </Col>
  914. <Col sticky>
  915. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  916. ```bash {{ title: 'cURL' }}
  917. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  918. --header 'Authorization: Bearer {api_key}'
  919. ```
  920. </CodeGroup>
  921. <CodeGroup title="Response">
  922. ```json {{ title: 'Response' }}
  923. {
  924. "introduction": "nice to meet you",
  925. "user_input_form": [
  926. {
  927. "text-input": {
  928. "label": "a",
  929. "variable": "a",
  930. "required": true,
  931. "max_length": 48,
  932. "default": ""
  933. }
  934. },
  935. {
  936. // ...
  937. }
  938. ],
  939. "file_upload": {
  940. "image": {
  941. "enabled": true,
  942. "number_limits": 3,
  943. "transfer_methods": [
  944. "remote_url",
  945. "local_file"
  946. ]
  947. }
  948. },
  949. "system_parameters": {
  950. "file_size_limit": 15,
  951. "image_file_size_limit": 10,
  952. "audio_file_size_limit": 50,
  953. "video_file_size_limit": 100
  954. }
  955. }
  956. ```
  957. </CodeGroup>
  958. </Col>
  959. </Row>
  960. ---
  961. <Heading
  962. url='/meta'
  963. method='GET'
  964. title='获取应用Meta信息'
  965. name='#meta'
  966. />
  967. <Row>
  968. <Col>
  969. 用于获取工具icon
  970. ### Query
  971. <Properties>
  972. <Property name='user' type='string' key='user'>
  973. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  974. </Property>
  975. </Properties>
  976. ### Response
  977. - `tool_icons`(object[string]) 工具图标
  978. - `工具名称` (string)
  979. - `icon` (object|string)
  980. - (object) 图标
  981. - `background` (string) hex格式的背景色
  982. - `content`(string) emoji
  983. - (string) 图标URL
  984. </Col>
  985. <Col>
  986. <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}'`}>
  987. ```bash {{ title: 'cURL' }}
  988. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  989. -H 'Authorization: Bearer {api_key}'
  990. ```
  991. </CodeGroup>
  992. <CodeGroup title="Response">
  993. ```json {{ title: 'Response' }}
  994. {
  995. "tool_icons": {
  996. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  997. "api_tool": {
  998. "background": "#252525",
  999. "content": "\ud83d\ude01"
  1000. }
  1001. }
  1002. }
  1003. ```
  1004. </CodeGroup>
  1005. </Col>
  1006. </Row>