template_chat.zh.mdx 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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='last_id' type='string' key='last_id'>
  572. 当前页最后面一条记录的 ID,默认 none
  573. </Property>
  574. <Property name='limit' type='int' key='limit'>
  575. 一次请求返回多少条记录
  576. </Property>
  577. <Property name='user' type='string' key='user'>
  578. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  579. </Property>
  580. </Properties>
  581. </Col>
  582. <Col sticky>
  583. <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}'`}>
  584. ```bash {{ title: 'cURL' }}
  585. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  586. --header 'Authorization: Bearer {api_key}'
  587. ```
  588. </CodeGroup>
  589. <CodeGroup title="Response">
  590. ```json {{ title: 'Response' }}
  591. {
  592. "limit": 20,
  593. "has_more": false,
  594. "data": [
  595. {
  596. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  597. "name": "New chat",
  598. "inputs": {
  599. "book": "book",
  600. "myName": "Lucy"
  601. },
  602. "status": "normal",
  603. "created_at": 1679667915
  604. },
  605. {
  606. "id": "hSIhXBhNe8X1d8Et"
  607. // ...
  608. }
  609. ]
  610. }
  611. ```
  612. </CodeGroup>
  613. </Col>
  614. </Row>
  615. ---
  616. <Heading
  617. url='/conversations'
  618. method='GET'
  619. title='获取会话列表'
  620. name='#conversations'
  621. />
  622. <Row>
  623. <Col>
  624. 获取当前用户的会话列表,默认返回最近的 20 条。
  625. ### Query
  626. <Properties>
  627. <Property name='user' type='string' key='user'>
  628. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  629. </Property>
  630. <Property name='last_id' type='string' key='last_id'>
  631. 当前页最后面一条记录的 ID,默认 null
  632. </Property>
  633. <Property name='limit' type='int' key='limit'>
  634. 一次请求返回多少条记录
  635. </Property>
  636. <Property name='pinned' type='bool' key='pinned'>
  637. 只返回置顶 true,只返回非置顶 false
  638. </Property>
  639. </Properties>
  640. ### Response
  641. - `data` (array[object]) 会话列表
  642. - `id` (string) 会话 ID
  643. - `name` (string) 会话名称,默认为会话中用户最开始问题的截取。
  644. - `inputs` (array[object]) 用户输入参数。
  645. - `introduction` (string) 开场白
  646. - `created_at` (timestamp) 创建时间
  647. - `has_more` (bool)
  648. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  649. </Col>
  650. <Col sticky>
  651. <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}'`}>
  652. ```bash {{ title: 'cURL' }}
  653. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  654. --header 'Authorization: Bearer {api_key}'
  655. ```
  656. </CodeGroup>
  657. <CodeGroup title="Response">
  658. ```json {{ title: 'Response' }}
  659. {
  660. "limit": 20,
  661. "has_more": false,
  662. "data": [
  663. {
  664. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  665. "name": "New chat",
  666. "inputs": {
  667. "book": "book",
  668. "myName": "Lucy"
  669. },
  670. "status": "normal",
  671. "created_at": 1679667915
  672. },
  673. {
  674. "id": "hSIhXBhNe8X1d8Et"
  675. // ...
  676. }
  677. ]
  678. }
  679. ```
  680. </CodeGroup>
  681. </Col>
  682. </Row>
  683. ---
  684. <Heading
  685. url='/conversations/{conversation_id}'
  686. method='DELETE'
  687. title='删除会话'
  688. name='#delete'
  689. />
  690. <Row>
  691. <Col>
  692. 删除会话。
  693. ### Path
  694. - `conversation_id` (string) 会话 ID
  695. ### Request Body
  696. <Properties>
  697. <Property name='user' type='string' key='user'>
  698. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  699. </Property>
  700. </Properties>
  701. ### Response
  702. - `result` (string) 固定返回 success
  703. </Col>
  704. <Col sticky>
  705. <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}'`}>
  706. ```bash {{ title: 'cURL' }}
  707. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{convsation_id}' \
  708. --header 'Content-Type: application/json' \
  709. --header 'Accept: application/json' \
  710. --header 'Authorization: Bearer {api_key}' \
  711. --data '{
  712. "user": "abc-123"
  713. }'
  714. ```
  715. </CodeGroup>
  716. <CodeGroup title="Response">
  717. ```json {{ title: 'Response' }}
  718. {
  719. "result": "success"
  720. }
  721. ```
  722. </CodeGroup>
  723. </Col>
  724. </Row>
  725. ---
  726. <Heading
  727. url='/conversations/{conversation_id}/name'
  728. method='POST'
  729. title='会话重命名'
  730. name='#rename'
  731. />
  732. <Row>
  733. <Col>
  734. 对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
  735. ### Request Body
  736. <Properties>
  737. <Property name='name' type='string' key='name'>
  738. 名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  739. </Property>
  740. <Property name='auto_generate' type='string' key='auto_generate'>
  741. 自动生成标题,默认 false。
  742. </Property>
  743. <Property name='user' type='string' key='user'>
  744. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  745. </Property>
  746. </Properties>
  747. ### Response
  748. - `id` (string) 会话 ID
  749. - `name` (string) 会话名称
  750. - `inputs` array[object] 用户输入参数。
  751. - `introduction` (string) 开场白
  752. - `created_at` (timestamp) 创建时间
  753. </Col>
  754. <Col sticky>
  755. <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}'`}>
  756. ```bash {{ title: 'cURL' }}
  757. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  758. --header 'Authorization: Bearer {api_key}' \
  759. --header 'Content-Type: application/json' \
  760. --data-raw '{
  761. "name": "",
  762. "user": "abc-123"
  763. }'
  764. ```
  765. </CodeGroup>
  766. <CodeGroup title="Response">
  767. ```json {{ title: 'Response' }}
  768. {
  769. "result": "success"
  770. }
  771. ```
  772. </CodeGroup>
  773. </Col>
  774. </Row>
  775. ---
  776. <Heading
  777. url='/audio-to-text'
  778. method='POST'
  779. title='语音转文字'
  780. name='#audio'
  781. />
  782. <Row>
  783. <Col>
  784. ### Request Body
  785. 该接口需使用 `multipart/form-data` 进行请求。
  786. <Properties>
  787. <Property name='file' type='file' key='file'>
  788. 语音文件。
  789. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  790. 文件大小限制:15MB
  791. </Property>
  792. <Property name='user' type='string' key='user'>
  793. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  794. </Property>
  795. </Properties>
  796. ### Response
  797. - `text` (string) 输出文字
  798. </Col>
  799. <Col sticky>
  800. <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]`}>
  801. ```bash {{ title: 'cURL' }}
  802. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  803. --header 'Authorization: Bearer {api_key}' \
  804. --form 'file=@localfile;type=audio/mp3'
  805. ```
  806. </CodeGroup>
  807. <CodeGroup title="Response">
  808. ```json {{ title: 'Response' }}
  809. {
  810. "text": "hello"
  811. }
  812. ```
  813. </CodeGroup>
  814. </Col>
  815. </Row>
  816. ---
  817. <Heading
  818. url='/text-to-audio'
  819. method='POST'
  820. title='文字转语音'
  821. name='#audio'
  822. />
  823. <Row>
  824. <Col>
  825. 文字转语音。
  826. ### Request Body
  827. <Properties>
  828. <Property name='text' type='str' key='text'>
  829. 语音生成内容。
  830. </Property>
  831. <Property name='user' type='string' key='user'>
  832. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  833. </Property>
  834. <Property name='streaming' type='bool' key='streaming'>
  835. 是否启用流式输出true、false。
  836. </Property>
  837. </Properties>
  838. </Col>
  839. <Col sticky>
  840. <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`}>
  841. ```bash {{ title: 'cURL' }}
  842. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  843. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  844. --form 'file=你好Dify;user=abc-123;streaming=false'
  845. ```
  846. </CodeGroup>
  847. <CodeGroup title="headers">
  848. ```json {{ title: 'headers' }}
  849. {
  850. "Content-Type": "audio/wav"
  851. }
  852. ```
  853. </CodeGroup>
  854. </Col>
  855. </Row>
  856. ---
  857. <Heading
  858. url='/parameters'
  859. method='GET'
  860. title='获取应用配置信息'
  861. name='#parameters'
  862. />
  863. <Row>
  864. <Col>
  865. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  866. ### Query
  867. <Properties>
  868. <Property name='user' type='string' key='user'>
  869. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  870. </Property>
  871. </Properties>
  872. ### Response
  873. - `opening_statement` (string) 开场白
  874. - `suggested_questions` (array[string]) 开场推荐问题列表
  875. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  876. - `enabled` (bool) 是否开启
  877. - `speech_to_text` (object) 语音转文本
  878. - `enabled` (bool) 是否开启
  879. - `retriever_resource` (object) 引用和归属
  880. - `enabled` (bool) 是否开启
  881. - `annotation_reply` (object) 标记回复
  882. - `enabled` (bool) 是否开启
  883. - `user_input_form` (array[object]) 用户输入表单配置
  884. - `text-input` (object) 文本输入控件
  885. - `label` (string) 控件展示标签名
  886. - `variable` (string) 控件 ID
  887. - `required` (bool) 是否必填
  888. - `default` (string) 默认值
  889. - `paragraph` (object) 段落文本输入控件
  890. - `label` (string) 控件展示标签名
  891. - `variable` (string) 控件 ID
  892. - `required` (bool) 是否必填
  893. - `default` (string) 默认值
  894. - `select` (object) 下拉控件
  895. - `label` (string) 控件展示标签名
  896. - `variable` (string) 控件 ID
  897. - `required` (bool) 是否必填
  898. - `default` (string) 默认值
  899. - `options` (array[string]) 选项值
  900. - `file_upload` (object) 文件上传配置
  901. - `image` (object) 图片设置
  902. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  903. - `enabled` (bool) 是否开启
  904. - `number_limits` (int) 图片数量限制,默认 3
  905. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  906. - `system_parameters` (object) 系统参数
  907. - `image_file_size_limit` (string) 图片文件上传大小限制(MB)
  908. </Col>
  909. <Col sticky>
  910. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  911. ```bash {{ title: 'cURL' }}
  912. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  913. --header 'Authorization: Bearer {api_key}'
  914. ```
  915. </CodeGroup>
  916. <CodeGroup title="Response">
  917. ```json {{ title: 'Response' }}
  918. {
  919. "introduction": "nice to meet you",
  920. "user_input_form": [
  921. {
  922. "text-input": {
  923. "label": "a",
  924. "variable": "a",
  925. "required": true,
  926. "max_length": 48,
  927. "default": ""
  928. }
  929. }
  930. {
  931. // ...
  932. }
  933. ],
  934. "file_upload": {
  935. "image": {
  936. "enabled": true,
  937. "number_limits": 3,
  938. "transfer_methods": [
  939. "remote_url",
  940. "local_file"
  941. ]
  942. }
  943. }
  944. }
  945. ```
  946. </CodeGroup>
  947. </Col>
  948. </Row>
  949. ---
  950. <Heading
  951. url='/meta'
  952. method='GET'
  953. title='获取应用Meta信息'
  954. name='#meta'
  955. />
  956. <Row>
  957. <Col>
  958. 用于获取工具icon
  959. ### Query
  960. <Properties>
  961. <Property name='user' type='string' key='user'>
  962. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  963. </Property>
  964. </Properties>
  965. ### Response
  966. - `tool_icons`(object[string]) 工具图标
  967. - `工具名称` (string)
  968. - `icon` (object|string)
  969. - (object) 图标
  970. - `background` (string) hex格式的背景色
  971. - `content`(string) emoji
  972. - (string) 图标URL
  973. </Col>
  974. <Col>
  975. <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}'`}>
  976. ```bash {{ title: 'cURL' }}
  977. curl -X GET 'https://cloud.dify.ai/v1/meta?user=abc-123' \
  978. -H 'Authorization: Bearer {api_key}'
  979. ```
  980. </CodeGroup>
  981. <CodeGroup title="Response">
  982. ```json {{ title: 'Response' }}
  983. {
  984. "tool_icons": {
  985. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  986. "api_tool": {
  987. "background": "#252525",
  988. "content": "\ud83d\ude01"
  989. }
  990. }
  991. }
  992. ```
  993. </CodeGroup>
  994. </Col>
  995. </Row>