template_chat.zh.mdx 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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. (选填)自动生成标题,默认 `true`。 若设置为 `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/{message_id}/suggested'
  404. method='GET'
  405. title='获取下一轮建议问题列表'
  406. name='#suggested'
  407. />
  408. <Row>
  409. <Col>
  410. 获取下一轮建议问题列表。
  411. ### Path Params
  412. <Properties>
  413. <Property name='message_id' type='string' key='message_id'>
  414. Message ID
  415. </Property>
  416. </Properties>
  417. ### Query
  418. <Properties>
  419. <Property name='user' type='string' key='user'>
  420. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  421. </Property>
  422. </Properties>
  423. </Col>
  424. <Col sticky>
  425. <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123 \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
  426. ```bash {{ title: 'cURL' }}
  427. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  428. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  429. --header 'Content-Type: application/json' \
  430. ```
  431. </CodeGroup>
  432. <CodeGroup title="Response">
  433. ```json {{ title: 'Response' }}
  434. {
  435. "result": "success",
  436. "data": [
  437. "a",
  438. "b",
  439. "c"
  440. ]
  441. }
  442. ```
  443. </CodeGroup>
  444. </Col>
  445. </Row>
  446. ---
  447. ---
  448. <Heading
  449. url='/messages'
  450. method='GET'
  451. title='获取会话历史消息'
  452. name='#messages'
  453. />
  454. <Row>
  455. <Col>
  456. 滚动加载形式返回历史聊天记录,第一页返回最新 `limit` 条,即:倒序返回。
  457. ### Query
  458. <Properties>
  459. <Property name='conversation_id' type='string' key='conversation_id'>
  460. 会话 ID
  461. </Property>
  462. <Property name='user' type='string' key='user'>
  463. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  464. </Property>
  465. <Property name='first_id' type='string' key='first_id'>
  466. 当前页第一条聊天记录的 ID,默认 null
  467. </Property>
  468. <Property name='limit' type='int' key='limit'>
  469. 一次请求返回多少条聊天记录,默认 20 条。
  470. </Property>
  471. </Properties>
  472. ### Response
  473. - `data` (array[object]) 消息列表
  474. - `id` (string) 消息 ID
  475. - `conversation_id` (string) 会话 ID
  476. - `inputs` (array[object]) 用户输入参数。
  477. - `query` (string) 用户输入 / 提问内容。
  478. - `message_files` (array[object]) 消息文件
  479. - `id` (string) ID
  480. - `type` (string) 文件类型,image 图片
  481. - `url` (string) 预览图片地址
  482. - `belongs_to` (string) 文件归属方,user 或 assistant
  483. - `agent_thoughts` (array[object]) Agent思考内容(仅Agent模式下不为空)
  484. - `id` (string) agent_thought ID,每一轮Agent迭代都会有一个唯一的id
  485. - `message_id` (string) 消息唯一ID
  486. - `position` (int) agent_thought在消息中的位置,如第一轮迭代position为1
  487. - `thought` (string) agent的思考内容
  488. - `observation` (string) 工具调用的返回结果
  489. - `tool` (string) 使用的工具列表,以 ; 分割多个工具
  490. - `tool_input` (string) 工具的输入,JSON格式的字符串(object)。如:`{"dalle3": {"prompt": "a cute cat"}}`
  491. - `created_at` (int) 创建时间戳,如:1705395332
  492. - `message_files` (array[string]) 当前agent_thought 关联的文件ID
  493. - `file_id` (string) 文件ID
  494. - `conversation_id` (string) 会话ID
  495. - `answer` (string) 回答消息内容
  496. - `created_at` (timestamp) 创建时间
  497. - `feedback` (object) 反馈信息
  498. - `rating` (string) 点赞 like / 点踩 dislike
  499. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  500. - `has_more` (bool) 是否存在下一页
  501. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  502. </Col>
  503. <Col sticky>
  504. ### Request Example
  505. <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}'`}>
  506. ```bash {{ title: 'cURL' }}
  507. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  508. --header 'Authorization: Bearer {api_key}'
  509. ```
  510. </CodeGroup>
  511. ### Response Example(基础助手)
  512. <CodeGroup title="Response">
  513. ```json {{ title: 'Response' }}
  514. {
  515. "limit": 20,
  516. "has_more": false,
  517. "data": [
  518. {
  519. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  520. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  521. "inputs": {
  522. "name": "dify"
  523. },
  524. "query": "iphone 13 pro",
  525. "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.",
  526. "message_files": [],
  527. "feedback": null,
  528. "retriever_resources": [
  529. {
  530. "position": 1,
  531. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  532. "dataset_name": "iPhone",
  533. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  534. "document_name": "iPhone List",
  535. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  536. "score": 0.98457545,
  537. "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\""
  538. }
  539. ],
  540. "agent_thoughts": [],
  541. "created_at": 1705569239
  542. }
  543. ]
  544. }
  545. ```
  546. </CodeGroup>
  547. ### Response Example(智能助手)
  548. <CodeGroup title="Response">
  549. ```json {{ title: 'Response' }}
  550. {
  551. "limit": 20,
  552. "has_more": false,
  553. "data": [
  554. {
  555. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  556. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  557. "inputs": {},
  558. "query": "draw a cat",
  559. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  560. "message_files": [
  561. {
  562. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  563. "type": "image",
  564. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  565. "belongs_to": "assistant"
  566. }
  567. ],
  568. "feedback": null,
  569. "retriever_resources": [],
  570. "created_at": 1705988187,
  571. "agent_thoughts": [
  572. {
  573. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  574. "chain_id": null,
  575. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  576. "position": 1,
  577. "thought": "",
  578. "tool": "dalle2",
  579. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  580. "created_at": 1705988186,
  581. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  582. "message_files": [
  583. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  584. ]
  585. },
  586. {
  587. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  588. "chain_id": null,
  589. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  590. "position": 2,
  591. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  592. "tool": "",
  593. "tool_input": "",
  594. "created_at": 1705988199,
  595. "observation": "",
  596. "message_files": []
  597. }
  598. ]
  599. }
  600. ]
  601. }
  602. ```
  603. </CodeGroup>
  604. </Col>
  605. </Row>
  606. ---
  607. <Heading
  608. url='/conversations'
  609. method='GET'
  610. title='获取会话列表'
  611. name='#conversations'
  612. />
  613. <Row>
  614. <Col>
  615. 获取当前用户的会话列表,默认返回最近的 20 条。
  616. ### Query
  617. <Properties>
  618. <Property name='user' type='string' key='user'>
  619. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  620. </Property>
  621. <Property name='last_id' type='string' key='last_id'>
  622. 当前页最后面一条记录的 ID,默认 null
  623. </Property>
  624. <Property name='limit' type='int' key='limit'>
  625. 一次请求返回多少条记录
  626. </Property>
  627. <Property name='pinned' type='bool' key='pinned'>
  628. 只返回置顶 true,只返回非置顶 false
  629. </Property>
  630. </Properties>
  631. ### Response
  632. - `data` (array[object]) 会话列表
  633. - `id` (string) 会话 ID
  634. - `name` (string) 会话名称,默认为会话中用户最开始问题的截取。
  635. - `inputs` (array[object]) 用户输入参数。
  636. - `introduction` (string) 开场白
  637. - `created_at` (timestamp) 创建时间
  638. - `has_more` (bool)
  639. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  640. </Col>
  641. <Col sticky>
  642. <CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'\\\n--header 'Authorization: Bearer {api_key}'`}>
  643. ```bash {{ title: 'cURL' }}
  644. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  645. --header 'Authorization: Bearer {api_key}'
  646. ```
  647. </CodeGroup>
  648. <CodeGroup title="Response">
  649. ```json {{ title: 'Response' }}
  650. {
  651. "limit": 20,
  652. "has_more": false,
  653. "data": [
  654. {
  655. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  656. "name": "New chat",
  657. "inputs": {
  658. "book": "book",
  659. "myName": "Lucy"
  660. },
  661. "status": "normal",
  662. "created_at": 1679667915
  663. },
  664. {
  665. "id": "hSIhXBhNe8X1d8Et"
  666. // ...
  667. }
  668. ]
  669. }
  670. ```
  671. </CodeGroup>
  672. </Col>
  673. </Row>
  674. ---
  675. <Heading
  676. url='/conversations/:conversation_id'
  677. method='DELETE'
  678. title='删除会话'
  679. name='#delete'
  680. />
  681. <Row>
  682. <Col>
  683. 删除会话。
  684. ### Path
  685. - `conversation_id` (string) 会话 ID
  686. ### Request Body
  687. <Properties>
  688. <Property name='user' type='string' key='user'>
  689. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  690. </Property>
  691. </Properties>
  692. ### Response
  693. - `result` (string) 固定返回 success
  694. </Col>
  695. <Col sticky>
  696. <CodeGroup title="Request" tag="DELETE" label="/conversations/:conversation_id" targetCode={`curl -X DELETE '${props.appDetail.api_base_url}/conversations/:conversation_id' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "user": "abc-123"\n}'`}>
  697. ```bash {{ title: 'cURL' }}
  698. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{convsation_id}' \
  699. --header 'Content-Type: application/json' \
  700. --header 'Accept: application/json' \
  701. --header 'Authorization: Bearer {api_key}' \
  702. --data '{
  703. "user": "abc-123"
  704. }'
  705. ```
  706. </CodeGroup>
  707. <CodeGroup title="Response">
  708. ```json {{ title: 'Response' }}
  709. {
  710. "result": "success"
  711. }
  712. ```
  713. </CodeGroup>
  714. </Col>
  715. </Row>
  716. ---
  717. <Heading
  718. url='/conversations/:conversation_id/name'
  719. method='POST'
  720. title='会话重命名'
  721. name='#rename'
  722. />
  723. <Row>
  724. <Col>
  725. 对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
  726. ### Request Body
  727. <Properties>
  728. <Property name='name' type='string' key='name'>
  729. 名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  730. </Property>
  731. <Property name='auto_generate' type='string' key='auto_generate'>
  732. 自动生成标题,默认 false。
  733. </Property>
  734. <Property name='user' type='string' key='user'>
  735. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  736. </Property>
  737. </Properties>
  738. ### Response
  739. - `id` (string) 会话 ID
  740. - `name` (string) 会话名称
  741. - `inputs` array[object] 用户输入参数。
  742. - `introduction` (string) 开场白
  743. - `created_at` (timestamp) 创建时间
  744. </Col>
  745. <Col sticky>
  746. <CodeGroup title="Request" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
  747. ```bash {{ title: 'cURL' }}
  748. curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \
  749. --header 'Authorization: Bearer {api_key}' \
  750. --header 'Content-Type: application/json' \
  751. --data-raw '{
  752. "name": "",
  753. "user": "abc-123"
  754. }'
  755. ```
  756. </CodeGroup>
  757. <CodeGroup title="Response">
  758. ```json {{ title: 'Response' }}
  759. {
  760. "result": "success"
  761. }
  762. ```
  763. </CodeGroup>
  764. </Col>
  765. </Row>
  766. ---
  767. <Heading
  768. url='/audio-to-text'
  769. method='POST'
  770. title='语音转文字'
  771. name='#audio'
  772. />
  773. <Row>
  774. <Col>
  775. ### Request Body
  776. 该接口需使用 `multipart/form-data` 进行请求。
  777. <Properties>
  778. <Property name='file' type='file' key='file'>
  779. 语音文件。
  780. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  781. 文件大小限制:15MB
  782. </Property>
  783. <Property name='user' type='string' key='user'>
  784. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  785. </Property>
  786. </Properties>
  787. ### Response
  788. - `text` (string) 输出文字
  789. </Col>
  790. <Col sticky>
  791. <CodeGroup title="Request" tag="POST" label="/audio-to-text" targetCode={`curl -X POST '${props.appDetail.api_base_url}/audio-to-text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]`}>
  792. ```bash {{ title: 'cURL' }}
  793. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  794. --header 'Authorization: Bearer {api_key}' \
  795. --form 'file=@localfile;type=audio/mp3'
  796. ```
  797. </CodeGroup>
  798. <CodeGroup title="Response">
  799. ```json {{ title: 'Response' }}
  800. {
  801. "text": "hello"
  802. }
  803. ```
  804. </CodeGroup>
  805. </Col>
  806. </Row>
  807. ---
  808. <Heading
  809. url='/text-to-audio'
  810. method='POST'
  811. title='文字转语音'
  812. name='#audio'
  813. />
  814. <Row>
  815. <Col>
  816. 文字转语音。
  817. ### Request Body
  818. <Properties>
  819. <Property name='text' type='str' key='text'>
  820. 语音生成内容。
  821. </Property>
  822. <Property name='user' type='string' key='user'>
  823. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  824. </Property>
  825. <Property name='streaming' type='bool' key='streaming'>
  826. 是否启用流式输出true、false。
  827. </Property>
  828. </Properties>
  829. </Col>
  830. <Col sticky>
  831. <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`}>
  832. ```bash {{ title: 'cURL' }}
  833. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  834. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  835. --form 'file=你好Dify;user=abc-123;streaming=false'
  836. ```
  837. </CodeGroup>
  838. <CodeGroup title="headers">
  839. ```json {{ title: 'headers' }}
  840. {
  841. "Content-Type": "audio/wav"
  842. }
  843. ```
  844. </CodeGroup>
  845. </Col>
  846. </Row>
  847. ---
  848. <Heading
  849. url='/parameters'
  850. method='GET'
  851. title='获取应用配置信息'
  852. name='#parameters'
  853. />
  854. <Row>
  855. <Col>
  856. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  857. ### Query
  858. <Properties>
  859. <Property name='user' type='string' key='user'>
  860. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  861. </Property>
  862. </Properties>
  863. ### Response
  864. - `opening_statement` (string) 开场白
  865. - `suggested_questions` (array[string]) 开场推荐问题列表
  866. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  867. - `enabled` (bool) 是否开启
  868. - `speech_to_text` (object) 语音转文本
  869. - `enabled` (bool) 是否开启
  870. - `retriever_resource` (object) 引用和归属
  871. - `enabled` (bool) 是否开启
  872. - `annotation_reply` (object) 标记回复
  873. - `enabled` (bool) 是否开启
  874. - `user_input_form` (array[object]) 用户输入表单配置
  875. - `text-input` (object) 文本输入控件
  876. - `label` (string) 控件展示标签名
  877. - `variable` (string) 控件 ID
  878. - `required` (bool) 是否必填
  879. - `default` (string) 默认值
  880. - `paragraph` (object) 段落文本输入控件
  881. - `label` (string) 控件展示标签名
  882. - `variable` (string) 控件 ID
  883. - `required` (bool) 是否必填
  884. - `default` (string) 默认值
  885. - `select` (object) 下拉控件
  886. - `label` (string) 控件展示标签名
  887. - `variable` (string) 控件 ID
  888. - `required` (bool) 是否必填
  889. - `default` (string) 默认值
  890. - `options` (array[string]) 选项值
  891. - `file_upload` (object) 文件上传配置
  892. - `image` (object) 图片设置
  893. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  894. - `enabled` (bool) 是否开启
  895. - `number_limits` (int) 图片数量限制,默认 3
  896. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  897. - `system_parameters` (object) 系统参数
  898. - `image_file_size_limit` (string) 图片文件上传大小限制(MB)
  899. </Col>
  900. <Col sticky>
  901. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  902. ```bash {{ title: 'cURL' }}
  903. curl -X GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \
  904. --header 'Authorization: Bearer {api_key}'
  905. ```
  906. </CodeGroup>
  907. <CodeGroup title="Response">
  908. ```json {{ title: 'Response' }}
  909. {
  910. "introduction": "nice to meet you",
  911. "user_input_form": [
  912. {
  913. "text-input": {
  914. "label": "a",
  915. "variable": "a",
  916. "required": true,
  917. "max_length": 48,
  918. "default": ""
  919. }
  920. },
  921. {
  922. // ...
  923. }
  924. ],
  925. "file_upload": {
  926. "image": {
  927. "enabled": true,
  928. "number_limits": 3,
  929. "transfer_methods": [
  930. "remote_url",
  931. "local_file"
  932. ]
  933. }
  934. }
  935. }
  936. ```
  937. </CodeGroup>
  938. </Col>
  939. </Row>
  940. ---
  941. <Heading
  942. url='/meta'
  943. method='GET'
  944. title='获取应用Meta信息'
  945. name='#meta'
  946. />
  947. <Row>
  948. <Col>
  949. 用于获取工具icon
  950. ### Query
  951. <Properties>
  952. <Property name='user' type='string' key='user'>
  953. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  954. </Property>
  955. </Properties>
  956. ### Response
  957. - `tool_icons`(object[string]) 工具图标
  958. - `工具名称` (string)
  959. - `icon` (object|string)
  960. - (object) 图标
  961. - `background` (string) hex格式的背景色
  962. - `content`(string) emoji
  963. - (string) 图标URL
  964. </Col>
  965. <Col>
  966. <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}'`}>
  967. ```bash {{ title: 'cURL' }}
  968. curl -X GET '${props.appDetail.api_base_url}/meta?user=abc-123' \
  969. -H 'Authorization: Bearer {api_key}'
  970. ```
  971. </CodeGroup>
  972. <CodeGroup title="Response">
  973. ```json {{ title: 'Response' }}
  974. {
  975. "tool_icons": {
  976. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  977. "api_tool": {
  978. "background": "#252525",
  979. "content": "\ud83d\ude01"
  980. }
  981. }
  982. }
  983. ```
  984. </CodeGroup>
  985. </Col>
  986. </Row>