template_advanced_chat.zh.mdx 44 KB

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