template_chat.zh.mdx 43 KB

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