You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template.zh.mdx 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. ### 鉴权
  9. Service API 使用 `API-Key` 进行鉴权。
  10. <i>**强烈建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。**</i>
  11. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  12. <CodeGroup title="Code" targetCode='Authorization: Bearer {API_KEY}' />
  13. </div>
  14. ---
  15. <Heading
  16. url='/completion-messages'
  17. method='POST'
  18. title='发送消息'
  19. name='#Create-Completion-Message'
  20. />
  21. <Row>
  22. <Col>
  23. 发送请求给文本生成型应用。
  24. ### Request Body
  25. <Properties>
  26. <Property name='inputs' type='object' key='inputs'>
  27. (选填)允许传入 App 定义的各变量值。
  28. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。
  29. 文本生成型应用要求至少传入一组键值对。
  30. - `query` (string) 必填
  31. 用户输入的文本内容。
  32. </Property>
  33. <Property name='response_mode' type='string' key='response_mode'>
  34. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  35. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  36. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  37. </Property>
  38. <Property name='user' type='string' key='user'>
  39. 用户标识,用于定义终端用户的身份,方便检索、统计。
  40. 由开发者定义规则,需保证用户标识在应用内唯一。
  41. </Property>
  42. <Property name='files' type='array[object]' key='files'>
  43. 文件列表,适用于传入文件结合文本理解并回答问题,仅当模型支持 Vision/Video 能力时可用。
  44. - `type` (string) 支持类型:
  45. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'MDX', 'PDF', 'HTML', 'XLSX', 'XLS', 'VTT', 'PROPERTIES', 'DOC', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  46. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  47. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'MPGA'
  48. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'WEBM'
  49. - `custom` 具体类型包含:其他文件类型
  50. - `transfer_method` (string) 传递方式:
  51. - `remote_url`: 文件地址。
  52. - `local_file`: 上传文件。
  53. - `url` 文件地址。(仅当传递方式为 `remote_url` 时)。
  54. - `upload_file_id` 上传文件 ID。(仅当传递方式为 `local_file `时)。
  55. </Property>
  56. </Properties>
  57. ### Response
  58. <Properties>
  59. 当 `response_mode` 为 `blocking` 时,返回 ChatCompletionResponse object。
  60. 当 `response_mode` 为 `streaming`时,返回 ChunkChatCompletionResponse object 流式序列。
  61. ### ChatCompletionResponse
  62. 返回完整的 App 结果,`Content-Type` 为 `application/json`。
  63. - `message_id` (string) 消息唯一 ID
  64. - `mode` (string) App 模式,固定为 chat
  65. - `answer` (string) 完整回复内容
  66. - `metadata` (object) 元数据
  67. - `usage` (Usage) 模型用量信息
  68. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  69. - `created_at` (int) 消息创建时间戳,如:1705395332
  70. ### ChunkChatCompletionResponse
  71. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  72. 每个流式块均为 data: 开头,块之间以 `\n\n` 即两个换行符分隔,如下所示:
  73. <CodeGroup>
  74. ```streaming {{ title: 'Response' }}
  75. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  76. ```
  77. </CodeGroup>
  78. 流式块中根据 `event` 不同,结构也不同:
  79. - `event: message` LLM 返回文本块事件,即:完整的文本以分块的方式输出。
  80. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  81. - `message_id` (string) 消息唯一 ID
  82. - `answer` (string) LLM 返回文本块内容
  83. - `created_at` (int) 创建时间戳,如:1705395332
  84. - `event: message_end` 消息结束事件,收到此事件则代表文本流式返回结束。
  85. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  86. - `message_id` (string) 消息唯一 ID
  87. - `metadata` (object) 元数据
  88. - `usage` (Usage) 模型用量信息
  89. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  90. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  91. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  92. - `message_id` (string) 消息唯一 ID
  93. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  94. - `created_at` (int) 创建时间戳,如:1705395332
  95. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  96. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  97. - `message_id` (string) 消息唯一 ID
  98. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  99. - `created_at` (int) 创建时间戳,如:1705395332
  100. - `event: message_replace` 消息内容替换事件。
  101. 开启内容审查和审查输出内容时,若命中了审查条件,则会通过此事件替换消息内容为预设回复。
  102. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  103. - `message_id` (string) 消息唯一 ID
  104. - `answer` (string) 替换内容(直接替换 LLM 所有回复文本)
  105. - `created_at` (int) 创建时间戳,如:1705395332
  106. - `event: error`
  107. 流式输出过程中出现的异常会以 stream event 形式输出,收到异常事件后即结束。
  108. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  109. - `message_id` (string) 消息唯一 ID
  110. - `status` (int) HTTP 状态码
  111. - `code` (string) 错误码
  112. - `message` (string) 错误消息
  113. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  114. ### Errors
  115. - 404,对话不存在
  116. - 400,`invalid_param`,传入参数异常
  117. - 400,`app_unavailable`,App 配置不可用
  118. - 400,`provider_not_initialize`,无可用模型凭据配置
  119. - 400,`provider_quota_exceeded`,模型调用额度不足
  120. - 400,`model_currently_not_support`,当前模型不可用
  121. - 400,`completion_request_error`,文本生成失败
  122. - 500,服务内部异常
  123. </Properties>
  124. </Col>
  125. <Col sticky>
  126. <CodeGroup
  127. title="Request"
  128. tag="POST"
  129. label="/completion-messages"
  130. targetCode={`curl -X POST '${props.appDetail.api_base_url}/completion-messages' \\
  131. --header 'Authorization: Bearer {api_key}' \\
  132. --header 'Content-Type: application/json' \\
  133. --data-raw '{
  134. "inputs": {"query": "Hello, world!"},
  135. "response_mode": "streaming",
  136. "user": "abc-123"
  137. }'`}
  138. />
  139. ### blocking
  140. <CodeGroup title="Response">
  141. ```json {{ title: 'Response' }}
  142. {
  143. "id": "0b089b9a-24d9-48cc-94f8-762677276261",
  144. "answer": "how are you?",
  145. "created_at": 1679586667
  146. }
  147. ```
  148. </CodeGroup>
  149. ### streaming
  150. <CodeGroup title="Response">
  151. ```streaming {{ title: 'Response' }}
  152. data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
  153. data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
  154. data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
  155. data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
  156. ```
  157. </CodeGroup>
  158. </Col>
  159. </Row>
  160. ---
  161. <Heading
  162. url='/files/upload'
  163. method='POST'
  164. title='上传文件'
  165. name='#files-upload'
  166. />
  167. <Row>
  168. <Col>
  169. 上传文件(目前仅支持图片)并在发送消息时使用,可实现图文多模态理解。
  170. 支持 png, jpg, jpeg, webp, gif 格式。
  171. <i>上传的文件仅供当前终端用户使用。</i>
  172. ### Request Body
  173. 该接口需使用 `multipart/form-data` 进行请求。
  174. <Properties>
  175. <Property name='file' type='file' key='file'>
  176. 要上传的文件。
  177. </Property>
  178. <Property name='user' type='string' key='user'>
  179. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  180. </Property>
  181. </Properties>
  182. ### Response
  183. 成功上传后,服务器会返回文件的 ID 和相关信息。
  184. - `id` (uuid) ID
  185. - `name` (string) 文件名
  186. - `size` (int) 文件大小(byte)
  187. - `extension` (string) 文件后缀
  188. - `mime_type` (string) 文件 mime-type
  189. - `created_by` (uuid) 上传人 ID
  190. - `created_at` (timestamp) 上传时间
  191. ### Errors
  192. - 400,`no_file_uploaded`,必须提供文件
  193. - 400,`too_many_files`,目前只接受一个文件
  194. - 400,`unsupported_preview`,该文件不支持预览
  195. - 400,`unsupported_estimate`,该文件不支持估算
  196. - 413,`file_too_large`,文件太大
  197. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  198. - 503,`s3_connection_failed`,无法连接到 S3 服务
  199. - 503,`s3_permission_denied`,无权限上传文件到 S3
  200. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  201. </Col>
  202. <Col sticky>
  203. <CodeGroup
  204. title="Request"
  205. tag="POST"
  206. label="/files/upload"
  207. targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\
  208. --header 'Authorization: Bearer {api_key}' \\
  209. --form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\
  210. --form 'user=abc-123'`}
  211. />
  212. <CodeGroup title="Response">
  213. ```json {{ title: 'Response' }}
  214. {
  215. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  216. "name": "example.png",
  217. "size": 1024,
  218. "extension": "png",
  219. "mime_type": "image/png",
  220. "created_by": 123,
  221. "created_at": 1577836800,
  222. }
  223. ```
  224. </CodeGroup>
  225. </Col>
  226. </Row>
  227. ---
  228. <Heading
  229. url='/files/:file_id/preview'
  230. method='GET'
  231. title='文件预览'
  232. name='#file-preview'
  233. />
  234. <Row>
  235. <Col>
  236. 预览或下载已上传的文件。此端点允许您访问先前通过文件上传 API 上传的文件。
  237. <i>文件只能在属于请求应用程序的消息范围内访问。</i>
  238. ### 路径参数
  239. - `file_id` (string) 必需
  240. 要预览的文件的唯一标识符,从文件上传 API 响应中获得。
  241. ### 查询参数
  242. - `as_attachment` (boolean) 可选
  243. 是否强制将文件作为附件下载。默认为 `false`(在浏览器中预览)。
  244. ### 响应
  245. 返回带有适当浏览器显示或下载标头的文件内容。
  246. - `Content-Type` 根据文件 MIME 类型设置
  247. - `Content-Length` 文件大小(以字节为单位,如果可用)
  248. - `Content-Disposition` 如果 `as_attachment=true` 则设置为 "attachment"
  249. - `Cache-Control` 用于性能的缓存标头
  250. - `Accept-Ranges` 对于音频/视频文件设置为 "bytes"
  251. ### 错误
  252. - 400, `invalid_param`, 参数输入异常
  253. - 403, `file_access_denied`, 文件访问被拒绝或文件不属于当前应用程序
  254. - 404, `file_not_found`, 文件未找到或已被删除
  255. - 500, 服务内部错误
  256. </Col>
  257. <Col sticky>
  258. ### 请求示例
  259. <CodeGroup
  260. title="Request"
  261. tag="GET"
  262. label="/files/:file_id/preview"
  263. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \\
  264. --header 'Authorization: Bearer {api_key}'`}
  265. />
  266. ### 作为附件下载
  267. <CodeGroup
  268. title="下载请求"
  269. tag="GET"
  270. label="/files/:file_id/preview?as_attachment=true"
  271. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \\
  272. --header 'Authorization: Bearer {api_key}' \\
  273. --output downloaded_file.png`}
  274. />
  275. ### 响应标头示例
  276. <CodeGroup title="Response Headers">
  277. ```http {{ title: 'Headers - 图片预览' }}
  278. Content-Type: image/png
  279. Content-Length: 1024
  280. Cache-Control: public, max-age=3600
  281. ```
  282. </CodeGroup>
  283. ### 文件下载响应标头
  284. <CodeGroup title="Download Response Headers">
  285. ```http {{ title: 'Headers - 文件下载' }}
  286. Content-Type: image/png
  287. Content-Length: 1024
  288. Content-Disposition: attachment; filename*=UTF-8''example.png
  289. Cache-Control: public, max-age=3600
  290. ```
  291. </CodeGroup>
  292. </Col>
  293. </Row>
  294. ---
  295. <Heading
  296. url='/completion-messages/:task_id/stop'
  297. method='POST'
  298. title='停止响应'
  299. name='#Stop'
  300. />
  301. <Row>
  302. <Col>
  303. 仅支持流式模式。
  304. ### Path
  305. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  306. ### Request Body
  307. - `user` (string) Required
  308. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。API 无法访问 WebApp 创建的会话。
  309. ### Response
  310. - `result` (string) 固定返回 success
  311. </Col>
  312. <Col sticky>
  313. <CodeGroup
  314. title="Request"
  315. tag="POST"
  316. label="/completion-messages/:task_id/stop"
  317. targetCode={`curl -X POST '${props.appDetail.api_base_url}/completion-messages/:task_id/stop' \\
  318. -H 'Authorization: Bearer {api_key}' \\
  319. -H 'Content-Type: application/json' \\
  320. --data-raw '{ "user": "abc-123"}'`}
  321. />
  322. <CodeGroup title="Response">
  323. ```json {{ title: 'Response' }}
  324. {
  325. "result": "success"
  326. }
  327. ```
  328. </CodeGroup>
  329. </Col>
  330. </Row>
  331. ---
  332. <Heading
  333. url='/messages/:message_id/feedbacks'
  334. method='POST'
  335. title='消息反馈(点赞)'
  336. name='#feedbacks'
  337. />
  338. <Row>
  339. <Col>
  340. 消息终端用户反馈、点赞,方便应用开发者优化输出预期。
  341. ### Path Params
  342. <Properties>
  343. <Property name='message_id' type='string' key='message_id'>
  344. 消息 ID
  345. </Property>
  346. </Properties>
  347. ### Request Body
  348. <Properties>
  349. <Property name='rating' type='string' key='rating'>
  350. 点赞 like, 点踩 dislike, 撤销点赞 null
  351. </Property>
  352. <Property name='user' type='string' key='user'>
  353. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  354. </Property>
  355. <Property name='content' type='string' key='content'>
  356. 消息反馈的具体信息。
  357. </Property>
  358. </Properties>
  359. ### Response
  360. - `result` (string) 固定返回 success
  361. </Col>
  362. <Col sticky>
  363. <CodeGroup
  364. title="Request"
  365. tag="POST"
  366. label="/messages/:message_id/feedbacks"
  367. targetCode={`curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks \\
  368. --header 'Authorization: Bearer {api_key}' \\
  369. --header 'Content-Type: application/json' \\
  370. --data-raw '{
  371. "rating": "like",
  372. "user": "abc-123",
  373. "content": "message feedback information"
  374. }'`}
  375. />
  376. <CodeGroup title="Response">
  377. ```json {{ title: 'Response' }}
  378. {
  379. "result": "success"
  380. }
  381. ```
  382. </CodeGroup>
  383. </Col>
  384. </Row>
  385. ---
  386. <Heading
  387. url='/app/feedbacks'
  388. method='GET'
  389. title='Get feedbacks of application'
  390. name='#app-feedbacks'
  391. />
  392. <Row>
  393. <Col>
  394. Get application's feedbacks.
  395. ### Query
  396. <Properties>
  397. <Property name='page' type='string' key='page'>
  398. (optional)pagination,default:1
  399. </Property>
  400. </Properties>
  401. <Properties>
  402. <Property name='limit' type='string' key='limit'>
  403. (optional) records per page default:20
  404. </Property>
  405. </Properties>
  406. ### Response
  407. - `data` (List) return apps feedback list.
  408. </Col>
  409. <Col sticky>
  410. <CodeGroup
  411. title="Request"
  412. tag="GET"
  413. label="/app/feedbacks"
  414. targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}
  415. />
  416. <CodeGroup title="Response">
  417. ```json {{ title: 'Response' }}
  418. {
  419. "data": [
  420. {
  421. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  422. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  423. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  424. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  425. "rating": "like",
  426. "content": "message feedback information-3",
  427. "from_source": "user",
  428. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  429. "from_account_id": null,
  430. "created_at": "2025-04-24T09:24:38",
  431. "updated_at": "2025-04-24T09:24:38"
  432. }
  433. ]
  434. }
  435. ```
  436. </CodeGroup>
  437. </Col>
  438. </Row>
  439. ---
  440. <Heading
  441. url='/text-to-audio'
  442. method='POST'
  443. title='文字转语音'
  444. name='#text-to-audio'
  445. />
  446. <Row>
  447. <Col>
  448. 文字转语音。
  449. ### Request Body
  450. <Properties>
  451. <Property name='message_id' type='str' key='message_id'>
  452. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  453. </Property>
  454. <Property name='text' type='str' key='text'>
  455. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  456. </Property>
  457. <Property name='user' type='string' key='user'>
  458. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  459. </Property>
  460. </Properties>
  461. </Col>
  462. <Col sticky>
  463. <CodeGroup
  464. title="Request"
  465. tag="POST"
  466. label="/text-to-audio"
  467. targetCode={`curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \\
  468. --header 'Authorization: Bearer {api_key}' \\
  469. --header 'Content-Type: application/json' \\
  470. --data-raw '{
  471. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  472. "text": "你好Dify",
  473. "user": "abc-123"
  474. }'`}
  475. />
  476. <CodeGroup title="headers">
  477. ```json {{ title: 'headers' }}
  478. {
  479. "Content-Type": "audio/wav"
  480. }
  481. ```
  482. </CodeGroup>
  483. </Col>
  484. </Row>
  485. ---
  486. <Heading
  487. url='/info'
  488. method='GET'
  489. title='获取应用基本信息'
  490. name='#info'
  491. />
  492. <Row>
  493. <Col>
  494. 用于获取应用的基本信息
  495. ### Response
  496. - `name` (string) 应用名称
  497. - `description` (string) 应用描述
  498. - `tags` (array[string]) 应用标签
  499. - `mode` (string) 应用模式
  500. - 'author_name' (string) 作者名称
  501. </Col>
  502. <Col>
  503. <CodeGroup
  504. title="Request"
  505. tag="GET"
  506. label="/info"
  507. targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\
  508. -H 'Authorization: Bearer {api_key}'`}
  509. />
  510. <CodeGroup title="Response">
  511. ```json {{ title: 'Response' }}
  512. {
  513. "name": "My App",
  514. "description": "This is my app.",
  515. "tags": [
  516. "tag1",
  517. "tag2"
  518. ],
  519. "mode": "chat",
  520. "author_name": "Dify"
  521. }
  522. ```
  523. </CodeGroup>
  524. </Col>
  525. </Row>
  526. ---
  527. <Heading
  528. url='/parameters'
  529. method='GET'
  530. title='获取应用参数'
  531. name='#parameters'
  532. />
  533. <Row>
  534. <Col>
  535. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  536. ### Response
  537. - `opening_statement` (string) 开场白
  538. - `suggested_questions` (array[string]) 开场推荐问题列表
  539. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  540. - `enabled` (bool) 是否开启
  541. - `speech_to_text` (object) 语音转文本
  542. - `enabled` (bool) 是否开启
  543. - `retriever_resource` (object) 引用和归属
  544. - `enabled` (bool) 是否开启
  545. - `annotation_reply` (object) 标记回复
  546. - `enabled` (bool) 是否开启
  547. - `user_input_form` (array[object]) 用户输入表单配置
  548. - `text-input` (object) 文本输入控件
  549. - `label` (string) 控件展示标签名
  550. - `variable` (string) 控件 ID
  551. - `required` (bool) 是否必填
  552. - `default` (string) 默认值
  553. - `paragraph` (object) 段落文本输入控件
  554. - `label` (string) 控件展示标签名
  555. - `variable` (string) 控件 ID
  556. - `required` (bool) 是否必填
  557. - `default` (string) 默认值
  558. - `select` (object) 下拉控件
  559. - `label` (string) 控件展示标签名
  560. - `variable` (string) 控件 ID
  561. - `required` (bool) 是否必填
  562. - `default` (string) 默认值
  563. - `options` (array[string]) 选项值
  564. - `file_upload` (object) 文件上传配置
  565. - `document` (object) 文档设置
  566. 当前仅支持文档类型:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  567. - `enabled` (bool) 是否启用
  568. - `number_limits` (int) 文档数量限制,默认为 3
  569. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  570. - `image` (object) 图片设置
  571. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  572. - `enabled` (bool) 是否启用
  573. - `number_limits` (int) 图片数量限制,默认为 3
  574. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  575. - `audio` (object) 音频设置
  576. 当前仅支持音频类型:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  577. - `enabled` (bool) 是否启用
  578. - `number_limits` (int) 音频数量限制,默认为 3
  579. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  580. - `video` (object) 视频设置
  581. 当前仅支持视频类型:`mp4`, `mov`, `mpeg`, `mpga`。
  582. - `enabled` (bool) 是否启用
  583. - `number_limits` (int) 视频数量限制,默认为 3
  584. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  585. - `custom` (object) 自定义设置
  586. - `enabled` (bool) 是否启用
  587. - `number_limits` (int) 自定义数量限制,默认为 3
  588. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  589. - `system_parameters` (object) 系统参数
  590. - `file_size_limit` (int) 文档上传大小限制 (MB)
  591. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  592. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  593. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  594. </Col>
  595. <Col sticky>
  596. <CodeGroup
  597. title="Request"
  598. tag="GET"
  599. label="/parameters"
  600. targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\
  601. --header 'Authorization: Bearer {api_key}'`}
  602. />
  603. <CodeGroup title="Response">
  604. ```json {{ title: 'Response' }}
  605. {
  606. "introduction": "nice to meet you",
  607. "user_input_form": [
  608. {
  609. "text-input": {
  610. "label": "a",
  611. "variable": "a",
  612. "required": true,
  613. "max_length": 48,
  614. "default": ""
  615. }
  616. },
  617. {
  618. // ...
  619. }
  620. ],
  621. "file_upload": {
  622. "image": {
  623. "enabled": true,
  624. "number_limits": 3,
  625. "transfer_methods": [
  626. "remote_url",
  627. "local_file"
  628. ]
  629. }
  630. },
  631. "system_parameters": {
  632. "file_size_limit": 15,
  633. "image_file_size_limit": 10,
  634. "audio_file_size_limit": 50,
  635. "video_file_size_limit": 100
  636. }
  637. }
  638. ```
  639. </CodeGroup>
  640. </Col>
  641. </Row>
  642. ---
  643. <Heading
  644. url='/site'
  645. method='GET'
  646. title='获取应用 WebApp 设置'
  647. name='#site'
  648. />
  649. <Row>
  650. <Col>
  651. 用于获取应用的 WebApp 设置
  652. ### Response
  653. - `title` (string) WebApp 名称
  654. - `chat_color_theme` (string) 聊天颜色主题,hex 格式
  655. - `chat_color_theme_inverted` (bool) 聊天颜色主题是否反转
  656. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  657. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  658. - `icon_background` (string) hex 格式的背景色
  659. - `icon_url` (string) 图标 URL
  660. - `description` (string) 描述
  661. - `copyright` (string) 版权信息
  662. - `privacy_policy` (string) 隐私政策链接
  663. - `custom_disclaimer` (string) 自定义免责声明
  664. - `default_language` (string) 默认语言
  665. - `show_workflow_steps` (bool) 是否显示工作流详情
  666. - `use_icon_as_answer_icon` (bool) 是否使用 WebApp 图标替换聊天中的 🤖
  667. </Col>
  668. <Col>
  669. <CodeGroup
  670. title="Request"
  671. tag="POST"
  672. label="/meta"
  673. targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\
  674. -H 'Authorization: Bearer {api_key}'`}
  675. />
  676. <CodeGroup title="Response">
  677. ```json {{ title: 'Response' }}
  678. {
  679. "title": "My App",
  680. "chat_color_theme": "#ff4a4a",
  681. "chat_color_theme_inverted": false,
  682. "icon_type": "emoji",
  683. "icon": "😄",
  684. "icon_background": "#FFEAD5",
  685. "icon_url": null,
  686. "description": "This is my app.",
  687. "copyright": "all rights reserved",
  688. "privacy_policy": "",
  689. "custom_disclaimer": "All generated by AI",
  690. "default_language": "en-US",
  691. "show_workflow_steps": false,
  692. "use_icon_as_answer_icon": false,
  693. }
  694. ```
  695. </CodeGroup>
  696. </Col>
  697. </Row>
  698. ___
  699. <Heading
  700. url='/apps/annotations'
  701. method='GET'
  702. title='获取标注列表'
  703. name='#annotation_list'
  704. />
  705. <Row>
  706. <Col>
  707. ### Query
  708. <Properties>
  709. <Property name='page' type='string' key='page'>
  710. 页码
  711. </Property>
  712. <Property name='limit' type='string' key='limit'>
  713. 每页数量
  714. </Property>
  715. </Properties>
  716. </Col>
  717. <Col sticky>
  718. <CodeGroup
  719. title="Request"
  720. tag="GET"
  721. label="/apps/annotations"
  722. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  723. >
  724. ```bash {{ title: 'cURL' }}
  725. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  726. --header 'Authorization: Bearer {api_key}'
  727. ```
  728. </CodeGroup>
  729. <CodeGroup title="Response">
  730. ```json {{ title: 'Response' }}
  731. {
  732. "data": [
  733. {
  734. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  735. "question": "What is your name?",
  736. "answer": "I am Dify.",
  737. "hit_count": 0,
  738. "created_at": 1735625869
  739. }
  740. ],
  741. "has_more": false,
  742. "limit": 20,
  743. "total": 1,
  744. "page": 1
  745. }
  746. ```
  747. </CodeGroup>
  748. </Col>
  749. </Row>
  750. ---
  751. <Heading
  752. url='/apps/annotations'
  753. method='POST'
  754. title='创建标注'
  755. name='#create_annotation'
  756. />
  757. <Row>
  758. <Col>
  759. ### Query
  760. <Properties>
  761. <Property name='question' type='string' key='question'>
  762. 问题
  763. </Property>
  764. <Property name='answer' type='string' key='answer'>
  765. 答案内容
  766. </Property>
  767. </Properties>
  768. </Col>
  769. <Col sticky>
  770. <CodeGroup
  771. title="Request"
  772. tag="POST"
  773. label="/apps/annotations"
  774. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \\
  775. --header 'Authorization: Bearer {api_key}' \\
  776. --header 'Content-Type: application/json' \\
  777. --data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  778. />
  779. <CodeGroup title="Response">
  780. ```json {{ title: 'Response' }}
  781. {
  782. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  783. "question": "What is your name?",
  784. "answer": "I am Dify.",
  785. "hit_count": 0,
  786. "created_at": 1735625869
  787. }
  788. ```
  789. </CodeGroup>
  790. </Col>
  791. </Row>
  792. ---
  793. <Heading
  794. url='/apps/annotations/{annotation_id}'
  795. method='PUT'
  796. title='更新标注'
  797. name='#update_annotation'
  798. />
  799. <Row>
  800. <Col>
  801. ### Query
  802. <Properties>
  803. <Property name='annotation_id' type='string' key='annotation_id'>
  804. 标注 ID
  805. </Property>
  806. <Property name='question' type='string' key='question'>
  807. 问题
  808. </Property>
  809. <Property name='answer' type='string' key='answer'>
  810. 答案内容
  811. </Property>
  812. </Properties>
  813. </Col>
  814. <Col sticky>
  815. <CodeGroup
  816. title="Request"
  817. tag="PUT"
  818. label="/apps/annotations/{annotation_id}"
  819. targetCode={`curl --location --request PUT '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\
  820. --header 'Authorization: Bearer {api_key}' \\
  821. --header 'Content-Type: application/json' \\
  822. --data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  823. />
  824. <CodeGroup title="Response">
  825. ```json {{ title: 'Response' }}
  826. {
  827. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  828. "question": "What is your name?",
  829. "answer": "I am Dify.",
  830. "hit_count": 0,
  831. "created_at": 1735625869
  832. }
  833. ```
  834. </CodeGroup>
  835. </Col>
  836. </Row>
  837. ---
  838. <Heading
  839. url='/apps/annotations/{annotation_id}'
  840. method='DELETE'
  841. title='删除标注'
  842. name='#delete_annotation'
  843. />
  844. <Row>
  845. <Col>
  846. ### Query
  847. <Properties>
  848. <Property name='annotation_id' type='string' key='annotation_id'>
  849. 标注 ID
  850. </Property>
  851. </Properties>
  852. </Col>
  853. <Col sticky>
  854. <CodeGroup
  855. title="Request"
  856. tag="PUT"
  857. label="/apps/annotations/{annotation_id}"
  858. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\
  859. --header 'Authorization: Bearer {api_key}' \\
  860. --header 'Content-Type: application/json'`}
  861. >
  862. ```bash {{ title: 'cURL' }}
  863. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  864. --header 'Authorization: Bearer {api_key}'
  865. ```
  866. </CodeGroup>
  867. <CodeGroup title="Response">
  868. ```text {{ title: 'Response' }}
  869. 204 No Content
  870. ```
  871. </CodeGroup>
  872. </Col>
  873. </Row>
  874. ---
  875. <Heading
  876. url='/apps/annotation-reply/{action}'
  877. method='POST'
  878. title='标注回复初始设置'
  879. name='#initial_annotation_reply_settings'
  880. />
  881. <Row>
  882. <Col>
  883. ### Query
  884. <Properties>
  885. <Property name='action' type='string' key='action'>
  886. 动作,只能是 'enable' 或 'disable'
  887. </Property>
  888. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  889. 指定的嵌入模型提供商,必须先在系统内设定好接入的模型,对应的是 provider 字段
  890. </Property>
  891. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  892. 指定的嵌入模型,对应的是 model 字段
  893. </Property>
  894. <Property name='score_threshold' type='number' key='score_threshold'>
  895. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  896. </Property>
  897. </Properties>
  898. </Col>
  899. <Col sticky>
  900. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding,具体见:通过 API 维护知识库。使用的 Authorization 是 Dataset 的 API Token。
  901. 该接口是异步执行,所以会返回一个 job_id,通过查询 job 状态接口可以获取到最终的执行结果。
  902. <CodeGroup
  903. title="Request"
  904. tag="POST"
  905. label="/apps/annotation-reply/{action}"
  906. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotation-reply/{action}' \\
  907. --header 'Authorization: Bearer {api_key}' \\
  908. --header 'Content-Type: application/json' \\
  909. --data-raw '{"score_threshold": 0.9, "embedding_provider_name": "zhipu", "embedding_model_name": "embedding_3"}'`}
  910. />
  911. <CodeGroup title="Response">
  912. ```json {{ title: 'Response' }}
  913. {
  914. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  915. "job_status": "waiting"
  916. }
  917. ```
  918. </CodeGroup>
  919. </Col>
  920. </Row>
  921. ---
  922. <Heading
  923. url='/apps/annotation-reply/{action}/status/{job_id}'
  924. method='GET'
  925. title='查询标注回复初始设置任务状态'
  926. name='#initial_annotation_reply_settings_task_status'
  927. />
  928. <Row>
  929. <Col>
  930. ### Query
  931. <Properties>
  932. <Property name='action' type='string' key='action'>
  933. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  934. </Property>
  935. <Property name='job_id' type='string' key='job_id'>
  936. 任务 ID,从标注回复初始设置接口返回的 job_id
  937. </Property>
  938. </Properties>
  939. </Col>
  940. <Col sticky>
  941. <CodeGroup
  942. title="Request"
  943. tag="GET"
  944. label="/apps/annotations"
  945. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\
  946. --header 'Authorization: Bearer {api_key}'`}
  947. />
  948. <CodeGroup title="Response">
  949. ```json {{ title: 'Response' }}
  950. {
  951. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  952. "job_status": "waiting",
  953. "error_msg": ""
  954. }
  955. ```
  956. </CodeGroup>
  957. </Col>
  958. </Row>