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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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='/text-to-audio'
  322. method='POST'
  323. title='文字转语音'
  324. name='#audio'
  325. />
  326. <Row>
  327. <Col>
  328. 文字转语音。
  329. ### Request Body
  330. <Properties>
  331. <Property name='message_id' type='str' key='message_id'>
  332. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  333. </Property>
  334. <Property name='text' type='str' key='text'>
  335. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  336. </Property>
  337. <Property name='user' type='string' key='user'>
  338. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  339. </Property>
  340. </Properties>
  341. </Col>
  342. <Col sticky>
  343. <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}'`}>
  344. ```bash {{ title: 'cURL' }}
  345. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  346. --header 'Authorization: Bearer {api_key}' \
  347. --header 'Content-Type: application/json' \
  348. --data-raw '{
  349. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  350. "text": "你好Dify",
  351. "user": "abc-123",
  352. "streaming": false
  353. }'
  354. ```
  355. </CodeGroup>
  356. <CodeGroup title="headers">
  357. ```json {{ title: 'headers' }}
  358. {
  359. "Content-Type": "audio/wav"
  360. }
  361. ```
  362. </CodeGroup>
  363. </Col>
  364. </Row>
  365. ---
  366. <Heading
  367. url='/info'
  368. method='GET'
  369. title='获取应用基本信息'
  370. name='#info'
  371. />
  372. <Row>
  373. <Col>
  374. 用于获取应用的基本信息
  375. ### Response
  376. - `name` (string) 应用名称
  377. - `description` (string) 应用描述
  378. - `tags` (array[string]) 应用标签
  379. </Col>
  380. <Col>
  381. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  382. ```bash {{ title: 'cURL' }}
  383. curl -X GET '${props.appDetail.api_base_url}/info' \
  384. -H 'Authorization: Bearer {api_key}'
  385. ```
  386. </CodeGroup>
  387. <CodeGroup title="Response">
  388. ```json {{ title: 'Response' }}
  389. {
  390. "name": "My App",
  391. "description": "This is my app.",
  392. "tags": [
  393. "tag1",
  394. "tag2"
  395. ]
  396. }
  397. ```
  398. </CodeGroup>
  399. </Col>
  400. </Row>
  401. ---
  402. <Heading
  403. url='/parameters'
  404. method='GET'
  405. title='获取应用参数'
  406. name='#parameters'
  407. />
  408. <Row>
  409. <Col>
  410. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  411. ### Response
  412. - `opening_statement` (string) 开场白
  413. - `suggested_questions` (array[string]) 开场推荐问题列表
  414. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  415. - `enabled` (bool) 是否开启
  416. - `speech_to_text` (object) 语音转文本
  417. - `enabled` (bool) 是否开启
  418. - `retriever_resource` (object) 引用和归属
  419. - `enabled` (bool) 是否开启
  420. - `annotation_reply` (object) 标记回复
  421. - `enabled` (bool) 是否开启
  422. - `user_input_form` (array[object]) 用户输入表单配置
  423. - `text-input` (object) 文本输入控件
  424. - `label` (string) 控件展示标签名
  425. - `variable` (string) 控件 ID
  426. - `required` (bool) 是否必填
  427. - `default` (string) 默认值
  428. - `paragraph` (object) 段落文本输入控件
  429. - `label` (string) 控件展示标签名
  430. - `variable` (string) 控件 ID
  431. - `required` (bool) 是否必填
  432. - `default` (string) 默认值
  433. - `select` (object) 下拉控件
  434. - `label` (string) 控件展示标签名
  435. - `variable` (string) 控件 ID
  436. - `required` (bool) 是否必填
  437. - `default` (string) 默认值
  438. - `options` (array[string]) 选项值
  439. - `file_upload` (object) 文件上传配置
  440. - `image` (object) 图片设置
  441. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  442. - `enabled` (bool) 是否开启
  443. - `number_limits` (int) 图片数量限制,默认 3
  444. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  445. - `system_parameters` (object) 系统参数
  446. - `file_size_limit` (int) 文档上传大小限制 (MB)
  447. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  448. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  449. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  450. </Col>
  451. <Col sticky>
  452. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  453. ```bash {{ title: 'cURL' }}
  454. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  455. --header 'Authorization: Bearer {api_key}'
  456. ```
  457. </CodeGroup>
  458. <CodeGroup title="Response">
  459. ```json {{ title: 'Response' }}
  460. {
  461. "introduction": "nice to meet you",
  462. "user_input_form": [
  463. {
  464. "text-input": {
  465. "label": "a",
  466. "variable": "a",
  467. "required": true,
  468. "max_length": 48,
  469. "default": ""
  470. }
  471. },
  472. {
  473. // ...
  474. }
  475. ],
  476. "file_upload": {
  477. "image": {
  478. "enabled": true,
  479. "number_limits": 3,
  480. "transfer_methods": [
  481. "remote_url",
  482. "local_file"
  483. ]
  484. }
  485. },
  486. "system_parameters": {
  487. "file_size_limit": 15,
  488. "image_file_size_limit": 10,
  489. "audio_file_size_limit": 50,
  490. "video_file_size_limit": 100
  491. }
  492. }
  493. ```
  494. </CodeGroup>
  495. </Col>
  496. </Row>
  497. ---
  498. <Heading
  499. url='/apps/annotations'
  500. method='GET'
  501. title='获取标注列表'
  502. name='#annotation_list'
  503. />
  504. <Row>
  505. <Col>
  506. ### Query
  507. <Properties>
  508. <Property name='page' type='string' key='page'>
  509. 页码
  510. </Property>
  511. <Property name='limit' type='string' key='limit'>
  512. 每页数量
  513. </Property>
  514. </Properties>
  515. </Col>
  516. <Col sticky>
  517. <CodeGroup
  518. title="Request"
  519. tag="GET"
  520. label="/apps/annotations"
  521. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  522. >
  523. ```bash {{ title: 'cURL' }}
  524. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  525. --header 'Authorization: Bearer {api_key}'
  526. ```
  527. </CodeGroup>
  528. <CodeGroup title="Response">
  529. ```json {{ title: 'Response' }}
  530. {
  531. "data": [
  532. {
  533. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  534. "question": "What is your name?",
  535. "answer": "I am Dify.",
  536. "hit_count": 0,
  537. "created_at": 1735625869
  538. }
  539. ],
  540. "has_more": false,
  541. "limit": 20,
  542. "total": 1,
  543. "page": 1
  544. }
  545. ```
  546. </CodeGroup>
  547. </Col>
  548. </Row>
  549. ---
  550. <Heading
  551. url='/apps/annotations'
  552. method='POST'
  553. title='创建标注'
  554. name='#create_annotation'
  555. />
  556. <Row>
  557. <Col>
  558. ### Query
  559. <Properties>
  560. <Property name='question' type='string' key='question'>
  561. 问题
  562. </Property>
  563. <Property name='answer' type='string' key='answer'>
  564. 答案内容
  565. </Property>
  566. </Properties>
  567. </Col>
  568. <Col sticky>
  569. <CodeGroup
  570. title="Request"
  571. tag="POST"
  572. label="/apps/annotations"
  573. 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."}'`}
  574. >
  575. ```bash {{ title: 'cURL' }}
  576. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  577. --header 'Authorization: Bearer {api_key}' \
  578. --header 'Content-Type: application/json' \
  579. --data-raw '{
  580. "question": "What is your name?",
  581. "answer": "I am Dify."
  582. }'
  583. ```
  584. </CodeGroup>
  585. <CodeGroup title="Response">
  586. ```json {{ title: 'Response' }}
  587. {
  588. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  589. "question": "What is your name?",
  590. "answer": "I am Dify.",
  591. "hit_count": 0,
  592. "created_at": 1735625869
  593. }
  594. ```
  595. </CodeGroup>
  596. </Col>
  597. </Row>
  598. ---
  599. <Heading
  600. url='/apps/annotations/{annotation_id}'
  601. method='PUT'
  602. title='更新标注'
  603. name='#update_annotation'
  604. />
  605. <Row>
  606. <Col>
  607. ### Query
  608. <Properties>
  609. <Property name='annotation_id' type='string' key='annotation_id'>
  610. 标注 ID
  611. </Property>
  612. <Property name='question' type='string' key='question'>
  613. 问题
  614. </Property>
  615. <Property name='answer' type='string' key='answer'>
  616. 答案内容
  617. </Property>
  618. </Properties>
  619. </Col>
  620. <Col sticky>
  621. <CodeGroup
  622. title="Request"
  623. tag="PUT"
  624. label="/apps/annotations/{annotation_id}"
  625. 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."}'`}
  626. >
  627. ```bash {{ title: 'cURL' }}
  628. curl --location --request PUT '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  629. --header 'Authorization: Bearer {api_key}' \
  630. --header 'Content-Type: application/json' \
  631. --data-raw '{
  632. "question": "What is your name?",
  633. "answer": "I am Dify."
  634. }'
  635. ```
  636. </CodeGroup>
  637. <CodeGroup title="Response">
  638. ```json {{ title: 'Response' }}
  639. {
  640. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  641. "question": "What is your name?",
  642. "answer": "I am Dify.",
  643. "hit_count": 0,
  644. "created_at": 1735625869
  645. }
  646. ```
  647. </CodeGroup>
  648. </Col>
  649. </Row>
  650. ---
  651. <Heading
  652. url='/apps/annotations/{annotation_id}'
  653. method='DELETE'
  654. title='删除标注'
  655. name='#delete_annotation'
  656. />
  657. <Row>
  658. <Col>
  659. ### Query
  660. <Properties>
  661. <Property name='annotation_id' type='string' key='annotation_id'>
  662. 标注 ID
  663. </Property>
  664. </Properties>
  665. </Col>
  666. <Col sticky>
  667. <CodeGroup
  668. title="Request"
  669. tag="PUT"
  670. label="/apps/annotations/{annotation_id}"
  671. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  672. >
  673. ```bash {{ title: 'cURL' }}
  674. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  675. --header 'Authorization: Bearer {api_key}'
  676. ```
  677. </CodeGroup>
  678. <CodeGroup title="Response">
  679. ```json {{ title: 'Response' }}
  680. {"result": "success"}
  681. ```
  682. </CodeGroup>
  683. </Col>
  684. </Row>
  685. ---
  686. <Heading
  687. url='/apps/annotation-reply/{action}'
  688. method='POST'
  689. title='标注回复初始设置'
  690. name='#initial_annotation_reply_settings'
  691. />
  692. <Row>
  693. <Col>
  694. ### Query
  695. <Properties>
  696. <Property name='action' type='string' key='action'>
  697. 动作,只能是 'enable' 或 'disable'
  698. </Property>
  699. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  700. 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段
  701. </Property>
  702. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  703. 指定的嵌入模型,对应的是model字段
  704. </Property>
  705. <Property name='score_threshold' type='number' key='score_threshold'>
  706. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  707. </Property>
  708. </Properties>
  709. </Col>
  710. <Col sticky>
  711. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding, 具体见:通过 API 维护知识库。 使用的Authorization是Dataset的API Token。
  712. 该接口是异步执行,所以会返回一个job_id,通过查询job状态接口可以获取到最终的执行结果。
  713. <CodeGroup
  714. title="Request"
  715. tag="POST"
  716. label="/apps/annotation-reply/{action}"
  717. 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"}'`}
  718. >
  719. ```bash {{ title: 'cURL' }}
  720. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  721. --header 'Authorization: Bearer {api_key}' \
  722. --header 'Content-Type: application/json' \
  723. --data-raw '{
  724. "score_threshold": 0.9,
  725. "embedding_provider_name": "zhipu",
  726. "embedding_model_name": "embedding_3"
  727. }'
  728. ```
  729. </CodeGroup>
  730. <CodeGroup title="Response">
  731. ```json {{ title: 'Response' }}
  732. {
  733. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  734. "job_status": "waiting"
  735. }
  736. ```
  737. </CodeGroup>
  738. </Col>
  739. </Row>
  740. ---
  741. <Heading
  742. url='/apps/annotation-reply/{action}/status/{job_id}'
  743. method='GET'
  744. title='查询标注回复初始设置任务状态'
  745. name='#initial_annotation_reply_settings_task_status'
  746. />
  747. <Row>
  748. <Col>
  749. ### Query
  750. <Properties>
  751. <Property name='action' type='string' key='action'>
  752. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  753. </Property>
  754. <Property name='job_id' type='string' key='job_id'>
  755. 任务 ID,从标注回复初始设置接口返回的 job_id
  756. </Property>
  757. </Properties>
  758. </Col>
  759. <Col sticky>
  760. <CodeGroup
  761. title="Request"
  762. tag="GET"
  763. label="/apps/annotations"
  764. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  765. >
  766. ```bash {{ title: 'cURL' }}
  767. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  768. --header 'Authorization: Bearer {api_key}'
  769. ```
  770. </CodeGroup>
  771. <CodeGroup title="Response">
  772. ```json {{ title: 'Response' }}
  773. {
  774. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  775. "job_status": "waiting",
  776. "error_msg": ""
  777. }
  778. ```
  779. </CodeGroup>
  780. </Col>
  781. </Row>