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

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