template_advanced_chat.zh.mdx 43 KB

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