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

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