template_chat.zh.mdx 43 KB

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