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 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  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 保持一致。
  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. - `image` (object) 图片设置
  500. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  501. - `enabled` (bool) 是否开启
  502. - `number_limits` (int) 图片数量限制,默认 3
  503. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  504. - `system_parameters` (object) 系统参数
  505. - `file_size_limit` (int) 文档上传大小限制 (MB)
  506. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  507. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  508. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  509. </Col>
  510. <Col sticky>
  511. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  512. ```bash {{ title: 'cURL' }}
  513. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  514. --header 'Authorization: Bearer {api_key}'
  515. ```
  516. </CodeGroup>
  517. <CodeGroup title="Response">
  518. ```json {{ title: 'Response' }}
  519. {
  520. "introduction": "nice to meet you",
  521. "user_input_form": [
  522. {
  523. "text-input": {
  524. "label": "a",
  525. "variable": "a",
  526. "required": true,
  527. "max_length": 48,
  528. "default": ""
  529. }
  530. },
  531. {
  532. // ...
  533. }
  534. ],
  535. "file_upload": {
  536. "image": {
  537. "enabled": true,
  538. "number_limits": 3,
  539. "transfer_methods": [
  540. "remote_url",
  541. "local_file"
  542. ]
  543. }
  544. },
  545. "system_parameters": {
  546. "file_size_limit": 15,
  547. "image_file_size_limit": 10,
  548. "audio_file_size_limit": 50,
  549. "video_file_size_limit": 100
  550. }
  551. }
  552. ```
  553. </CodeGroup>
  554. </Col>
  555. </Row>
  556. ---
  557. <Heading
  558. url='/site'
  559. method='GET'
  560. title='获取应用 WebApp 设置'
  561. name='#site'
  562. />
  563. <Row>
  564. <Col>
  565. 用于获取应用的 WebApp 设置
  566. ### Response
  567. - `title` (string) WebApp 名称
  568. - `chat_color_theme` (string) 聊天颜色主题,hex 格式
  569. - `chat_color_theme_inverted` (bool) 聊天颜色主题是否反转
  570. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  571. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  572. - `icon_background` (string) hex 格式的背景色
  573. - `icon_url` (string) 图标 URL
  574. - `description` (string) 描述
  575. - `copyright` (string) 版权信息
  576. - `privacy_policy` (string) 隐私政策链接
  577. - `custom_disclaimer` (string) 自定义免责声明
  578. - `default_language` (string) 默认语言
  579. - `show_workflow_steps` (bool) 是否显示工作流详情
  580. - `use_icon_as_answer_icon` (bool) 是否使用 WebApp 图标替换聊天中的 🤖
  581. </Col>
  582. <Col>
  583. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  584. ```bash {{ title: 'cURL' }}
  585. curl -X GET '${props.appDetail.api_base_url}/site' \
  586. -H 'Authorization: Bearer {api_key}'
  587. ```
  588. </CodeGroup>
  589. <CodeGroup title="Response">
  590. ```json {{ title: 'Response' }}
  591. {
  592. "title": "My App",
  593. "chat_color_theme": "#ff4a4a",
  594. "chat_color_theme_inverted": false,
  595. "icon_type": "emoji",
  596. "icon": "😄",
  597. "icon_background": "#FFEAD5",
  598. "icon_url": null,
  599. "description": "This is my app.",
  600. "copyright": "all rights reserved",
  601. "privacy_policy": "",
  602. "custom_disclaimer": "All generated by AI",
  603. "default_language": "en-US",
  604. "show_workflow_steps": false,
  605. "use_icon_as_answer_icon": false,
  606. }
  607. ```
  608. </CodeGroup>
  609. </Col>
  610. </Row>
  611. ___
  612. <Heading
  613. url='/apps/annotations'
  614. method='GET'
  615. title='获取标注列表'
  616. name='#annotation_list'
  617. />
  618. <Row>
  619. <Col>
  620. ### Query
  621. <Properties>
  622. <Property name='page' type='string' key='page'>
  623. 页码
  624. </Property>
  625. <Property name='limit' type='string' key='limit'>
  626. 每页数量
  627. </Property>
  628. </Properties>
  629. </Col>
  630. <Col sticky>
  631. <CodeGroup
  632. title="Request"
  633. tag="GET"
  634. label="/apps/annotations"
  635. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  636. >
  637. ```bash {{ title: 'cURL' }}
  638. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  639. --header 'Authorization: Bearer {api_key}'
  640. ```
  641. </CodeGroup>
  642. <CodeGroup title="Response">
  643. ```json {{ title: 'Response' }}
  644. {
  645. "data": [
  646. {
  647. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  648. "question": "What is your name?",
  649. "answer": "I am Dify.",
  650. "hit_count": 0,
  651. "created_at": 1735625869
  652. }
  653. ],
  654. "has_more": false,
  655. "limit": 20,
  656. "total": 1,
  657. "page": 1
  658. }
  659. ```
  660. </CodeGroup>
  661. </Col>
  662. </Row>
  663. ---
  664. <Heading
  665. url='/apps/annotations'
  666. method='POST'
  667. title='创建标注'
  668. name='#create_annotation'
  669. />
  670. <Row>
  671. <Col>
  672. ### Query
  673. <Properties>
  674. <Property name='question' type='string' key='question'>
  675. 问题
  676. </Property>
  677. <Property name='answer' type='string' key='answer'>
  678. 答案内容
  679. </Property>
  680. </Properties>
  681. </Col>
  682. <Col sticky>
  683. <CodeGroup
  684. title="Request"
  685. tag="POST"
  686. label="/apps/annotations"
  687. 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."}'`}
  688. >
  689. ```bash {{ title: 'cURL' }}
  690. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  691. --header 'Authorization: Bearer {api_key}' \
  692. --header 'Content-Type: application/json' \
  693. --data-raw '{
  694. "question": "What is your name?",
  695. "answer": "I am Dify."
  696. }'
  697. ```
  698. </CodeGroup>
  699. <CodeGroup title="Response">
  700. ```json {{ title: 'Response' }}
  701. {
  702. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  703. "question": "What is your name?",
  704. "answer": "I am Dify.",
  705. "hit_count": 0,
  706. "created_at": 1735625869
  707. }
  708. ```
  709. </CodeGroup>
  710. </Col>
  711. </Row>
  712. ---
  713. <Heading
  714. url='/apps/annotations/{annotation_id}'
  715. method='PUT'
  716. title='更新标注'
  717. name='#update_annotation'
  718. />
  719. <Row>
  720. <Col>
  721. ### Query
  722. <Properties>
  723. <Property name='annotation_id' type='string' key='annotation_id'>
  724. 标注 ID
  725. </Property>
  726. <Property name='question' type='string' key='question'>
  727. 问题
  728. </Property>
  729. <Property name='answer' type='string' key='answer'>
  730. 答案内容
  731. </Property>
  732. </Properties>
  733. </Col>
  734. <Col sticky>
  735. <CodeGroup
  736. title="Request"
  737. tag="PUT"
  738. label="/apps/annotations/{annotation_id}"
  739. 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."}'`}
  740. >
  741. ```bash {{ title: 'cURL' }}
  742. curl --location --request PUT '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  743. --header 'Authorization: Bearer {api_key}' \
  744. --header 'Content-Type: application/json' \
  745. --data-raw '{
  746. "question": "What is your name?",
  747. "answer": "I am Dify."
  748. }'
  749. ```
  750. </CodeGroup>
  751. <CodeGroup title="Response">
  752. ```json {{ title: 'Response' }}
  753. {
  754. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  755. "question": "What is your name?",
  756. "answer": "I am Dify.",
  757. "hit_count": 0,
  758. "created_at": 1735625869
  759. }
  760. ```
  761. </CodeGroup>
  762. </Col>
  763. </Row>
  764. ---
  765. <Heading
  766. url='/apps/annotations/{annotation_id}'
  767. method='DELETE'
  768. title='删除标注'
  769. name='#delete_annotation'
  770. />
  771. <Row>
  772. <Col>
  773. ### Query
  774. <Properties>
  775. <Property name='annotation_id' type='string' key='annotation_id'>
  776. 标注 ID
  777. </Property>
  778. </Properties>
  779. </Col>
  780. <Col sticky>
  781. <CodeGroup
  782. title="Request"
  783. tag="PUT"
  784. label="/apps/annotations/{annotation_id}"
  785. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  786. >
  787. ```bash {{ title: 'cURL' }}
  788. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  789. --header 'Authorization: Bearer {api_key}'
  790. ```
  791. </CodeGroup>
  792. <CodeGroup title="Response">
  793. ```text {{ title: 'Response' }}
  794. 204 No Content
  795. ```
  796. </CodeGroup>
  797. </Col>
  798. </Row>
  799. ---
  800. <Heading
  801. url='/apps/annotation-reply/{action}'
  802. method='POST'
  803. title='标注回复初始设置'
  804. name='#initial_annotation_reply_settings'
  805. />
  806. <Row>
  807. <Col>
  808. ### Query
  809. <Properties>
  810. <Property name='action' type='string' key='action'>
  811. 动作,只能是 'enable' 或 'disable'
  812. </Property>
  813. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  814. 指定的嵌入模型提供商,必须先在系统内设定好接入的模型,对应的是 provider 字段
  815. </Property>
  816. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  817. 指定的嵌入模型,对应的是 model 字段
  818. </Property>
  819. <Property name='score_threshold' type='number' key='score_threshold'>
  820. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  821. </Property>
  822. </Properties>
  823. </Col>
  824. <Col sticky>
  825. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding,具体见:通过 API 维护知识库。使用的 Authorization 是 Dataset 的 API Token。
  826. 该接口是异步执行,所以会返回一个 job_id,通过查询 job 状态接口可以获取到最终的执行结果。
  827. <CodeGroup
  828. title="Request"
  829. tag="POST"
  830. label="/apps/annotation-reply/{action}"
  831. 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"}'`}
  832. >
  833. ```bash {{ title: 'cURL' }}
  834. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  835. --header 'Authorization: Bearer {api_key}' \
  836. --header 'Content-Type: application/json' \
  837. --data-raw '{
  838. "score_threshold": 0.9,
  839. "embedding_provider_name": "zhipu",
  840. "embedding_model_name": "embedding_3"
  841. }'
  842. ```
  843. </CodeGroup>
  844. <CodeGroup title="Response">
  845. ```json {{ title: 'Response' }}
  846. {
  847. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  848. "job_status": "waiting"
  849. }
  850. ```
  851. </CodeGroup>
  852. </Col>
  853. </Row>
  854. ---
  855. <Heading
  856. url='/apps/annotation-reply/{action}/status/{job_id}'
  857. method='GET'
  858. title='查询标注回复初始设置任务状态'
  859. name='#initial_annotation_reply_settings_task_status'
  860. />
  861. <Row>
  862. <Col>
  863. ### Query
  864. <Properties>
  865. <Property name='action' type='string' key='action'>
  866. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  867. </Property>
  868. <Property name='job_id' type='string' key='job_id'>
  869. 任务 ID,从标注回复初始设置接口返回的 job_id
  870. </Property>
  871. </Properties>
  872. </Col>
  873. <Col sticky>
  874. <CodeGroup
  875. title="Request"
  876. tag="GET"
  877. label="/apps/annotations"
  878. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  879. >
  880. ```bash {{ title: 'cURL' }}
  881. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  882. --header 'Authorization: Bearer {api_key}'
  883. ```
  884. </CodeGroup>
  885. <CodeGroup title="Response">
  886. ```json {{ title: 'Response' }}
  887. {
  888. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  889. "job_status": "waiting",
  890. "error_msg": ""
  891. }
  892. ```
  893. </CodeGroup>
  894. </Col>
  895. </Row>