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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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='/files/:file_id/preview'
  231. method='GET'
  232. title='文件预览'
  233. name='#file-preview'
  234. />
  235. <Row>
  236. <Col>
  237. 预览或下载已上传的文件。此端点允许您访问先前通过文件上传 API 上传的文件。
  238. <i>文件只能在属于请求应用程序的消息范围内访问。</i>
  239. ### 路径参数
  240. - `file_id` (string) 必需
  241. 要预览的文件的唯一标识符,从文件上传 API 响应中获得。
  242. ### 查询参数
  243. - `as_attachment` (boolean) 可选
  244. 是否强制将文件作为附件下载。默认为 `false`(在浏览器中预览)。
  245. ### 响应
  246. 返回带有适当浏览器显示或下载标头的文件内容。
  247. - `Content-Type` 根据文件 MIME 类型设置
  248. - `Content-Length` 文件大小(以字节为单位,如果可用)
  249. - `Content-Disposition` 如果 `as_attachment=true` 则设置为 "attachment"
  250. - `Cache-Control` 用于性能的缓存标头
  251. - `Accept-Ranges` 对于音频/视频文件设置为 "bytes"
  252. ### 错误
  253. - 400, `invalid_param`, 参数输入异常
  254. - 403, `file_access_denied`, 文件访问被拒绝或文件不属于当前应用程序
  255. - 404, `file_not_found`, 文件未找到或已被删除
  256. - 500, 服务内部错误
  257. </Col>
  258. <Col sticky>
  259. ### 请求示例
  260. <CodeGroup title="Request" tag="GET" label="/files/:file_id/preview" targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \\\n--header 'Authorization: Bearer {api_key}'`}>
  261. ```bash {{ title: 'cURL' }}
  262. curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \
  263. --header 'Authorization: Bearer {api_key}'
  264. ```
  265. </CodeGroup>
  266. ### 作为附件下载
  267. <CodeGroup title="下载请求" tag="GET" label="/files/:file_id/preview?as_attachment=true" targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \\\n--header 'Authorization: Bearer {api_key}' \\\n--output downloaded_file.png`}>
  268. ```bash {{ title: 'cURL' }}
  269. curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \
  270. --header 'Authorization: Bearer {api_key}' \
  271. --output downloaded_file.png
  272. ```
  273. </CodeGroup>
  274. ### 响应标头示例
  275. <CodeGroup title="Response Headers">
  276. ```http {{ title: 'Headers - 图片预览' }}
  277. Content-Type: image/png
  278. Content-Length: 1024
  279. Cache-Control: public, max-age=3600
  280. ```
  281. </CodeGroup>
  282. ### 文件下载响应标头
  283. <CodeGroup title="Download Response Headers">
  284. ```http {{ title: 'Headers - 文件下载' }}
  285. Content-Type: image/png
  286. Content-Length: 1024
  287. Content-Disposition: attachment; filename*=UTF-8''example.png
  288. Cache-Control: public, max-age=3600
  289. ```
  290. </CodeGroup>
  291. </Col>
  292. </Row>
  293. ---
  294. <Heading
  295. url='/completion-messages/:task_id/stop'
  296. method='POST'
  297. title='停止响应'
  298. name='#Stop'
  299. />
  300. <Row>
  301. <Col>
  302. 仅支持流式模式。
  303. ### Path
  304. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  305. ### Request Body
  306. - `user` (string) Required
  307. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。API 无法访问 WebApp 创建的会话。
  308. ### Response
  309. - `result` (string) 固定返回 success
  310. </Col>
  311. <Col sticky>
  312. <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"}'`}>
  313. ```bash {{ title: 'cURL' }}
  314. curl -X POST '${props.appDetail.api_base_url}/completion-messages/:task_id/stop' \
  315. -H 'Authorization: Bearer {api_key}' \
  316. -H 'Content-Type: application/json' \
  317. --data-raw '{
  318. "user": "abc-123"
  319. }'
  320. ```
  321. </CodeGroup>
  322. <CodeGroup title="Response">
  323. ```json {{ title: 'Response' }}
  324. {
  325. "result": "success"
  326. }
  327. ```
  328. </CodeGroup>
  329. </Col>
  330. </Row>
  331. ---
  332. <Heading
  333. url='/messages/:message_id/feedbacks'
  334. method='POST'
  335. title='消息反馈(点赞)'
  336. name='#feedbacks'
  337. />
  338. <Row>
  339. <Col>
  340. 消息终端用户反馈、点赞,方便应用开发者优化输出预期。
  341. ### Path Params
  342. <Properties>
  343. <Property name='message_id' type='string' key='message_id'>
  344. 消息 ID
  345. </Property>
  346. </Properties>
  347. ### Request Body
  348. <Properties>
  349. <Property name='rating' type='string' key='rating'>
  350. 点赞 like, 点踩 dislike, 撤销点赞 null
  351. </Property>
  352. <Property name='user' type='string' key='user'>
  353. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  354. </Property>
  355. <Property name='content' type='string' key='content'>
  356. 消息反馈的具体信息。
  357. </Property>
  358. </Properties>
  359. ### Response
  360. - `result` (string) 固定返回 success
  361. </Col>
  362. <Col sticky>
  363. <CodeGroup 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}'`}>
  364. ```bash {{ title: 'cURL' }}
  365. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  366. --header 'Authorization: Bearer {api_key}' \
  367. --header 'Content-Type: application/json' \
  368. --data-raw '{
  369. "rating": "like",
  370. "user": "abc-123",
  371. "content": "message feedback information"
  372. }'
  373. ```
  374. </CodeGroup>
  375. <CodeGroup title="Response">
  376. ```json {{ title: 'Response' }}
  377. {
  378. "result": "success"
  379. }
  380. ```
  381. </CodeGroup>
  382. </Col>
  383. </Row>
  384. ---
  385. <Heading
  386. url='/app/feedbacks'
  387. method='GET'
  388. title='Get feedbacks of application'
  389. name='#app-feedbacks'
  390. />
  391. <Row>
  392. <Col>
  393. Get application's feedbacks.
  394. ### Query
  395. <Properties>
  396. <Property name='page' type='string' key='page'>
  397. (optional)pagination,default:1
  398. </Property>
  399. </Properties>
  400. <Properties>
  401. <Property name='limit' type='string' key='limit'>
  402. (optional) records per page default:20
  403. </Property>
  404. </Properties>
  405. ### Response
  406. - `data` (List) return apps feedback list.
  407. </Col>
  408. <Col sticky>
  409. <CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
  410. ```bash {{ title: 'cURL' }}
  411. curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
  412. --header 'Authorization: Bearer {api_key}' \
  413. --header 'Content-Type: application/json'
  414. ```
  415. </CodeGroup>
  416. <CodeGroup title="Response">
  417. ```json {{ title: 'Response' }}
  418. {
  419. "data": [
  420. {
  421. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  422. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  423. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  424. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  425. "rating": "like",
  426. "content": "message feedback information-3",
  427. "from_source": "user",
  428. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  429. "from_account_id": null,
  430. "created_at": "2025-04-24T09:24:38",
  431. "updated_at": "2025-04-24T09:24:38"
  432. }
  433. ]
  434. }
  435. ```
  436. </CodeGroup>
  437. </Col>
  438. </Row>
  439. ---
  440. <Heading
  441. url='/text-to-audio'
  442. method='POST'
  443. title='文字转语音'
  444. name='#text-to-audio'
  445. />
  446. <Row>
  447. <Col>
  448. 文字转语音。
  449. ### Request Body
  450. <Properties>
  451. <Property name='message_id' type='str' key='message_id'>
  452. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  453. </Property>
  454. <Property name='text' type='str' key='text'>
  455. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  456. </Property>
  457. <Property name='user' type='string' key='user'>
  458. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  459. </Property>
  460. </Properties>
  461. </Col>
  462. <Col sticky>
  463. <CodeGroup 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}'`}>
  464. ```bash {{ title: 'cURL' }}
  465. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  466. --header 'Authorization: Bearer {api_key}' \
  467. --header 'Content-Type: application/json' \
  468. --data-raw '{
  469. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  470. "text": "你好Dify",
  471. "user": "abc-123",
  472. "streaming": false
  473. }'
  474. ```
  475. </CodeGroup>
  476. <CodeGroup title="headers">
  477. ```json {{ title: 'headers' }}
  478. {
  479. "Content-Type": "audio/wav"
  480. }
  481. ```
  482. </CodeGroup>
  483. </Col>
  484. </Row>
  485. ---
  486. <Heading
  487. url='/info'
  488. method='GET'
  489. title='获取应用基本信息'
  490. name='#info'
  491. />
  492. <Row>
  493. <Col>
  494. 用于获取应用的基本信息
  495. ### Response
  496. - `name` (string) 应用名称
  497. - `description` (string) 应用描述
  498. - `tags` (array[string]) 应用标签
  499. - `mode` (string) 应用模式
  500. - 'author_name' (string) 作者名称
  501. </Col>
  502. <Col>
  503. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  504. ```bash {{ title: 'cURL' }}
  505. curl -X GET '${props.appDetail.api_base_url}/info' \
  506. -H 'Authorization: Bearer {api_key}'
  507. ```
  508. </CodeGroup>
  509. <CodeGroup title="Response">
  510. ```json {{ title: 'Response' }}
  511. {
  512. "name": "My App",
  513. "description": "This is my app.",
  514. "tags": [
  515. "tag1",
  516. "tag2"
  517. ],
  518. "mode": "chat",
  519. "author_name": "Dify"
  520. }
  521. ```
  522. </CodeGroup>
  523. </Col>
  524. </Row>
  525. ---
  526. <Heading
  527. url='/parameters'
  528. method='GET'
  529. title='获取应用参数'
  530. name='#parameters'
  531. />
  532. <Row>
  533. <Col>
  534. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  535. ### Response
  536. - `opening_statement` (string) 开场白
  537. - `suggested_questions` (array[string]) 开场推荐问题列表
  538. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  539. - `enabled` (bool) 是否开启
  540. - `speech_to_text` (object) 语音转文本
  541. - `enabled` (bool) 是否开启
  542. - `retriever_resource` (object) 引用和归属
  543. - `enabled` (bool) 是否开启
  544. - `annotation_reply` (object) 标记回复
  545. - `enabled` (bool) 是否开启
  546. - `user_input_form` (array[object]) 用户输入表单配置
  547. - `text-input` (object) 文本输入控件
  548. - `label` (string) 控件展示标签名
  549. - `variable` (string) 控件 ID
  550. - `required` (bool) 是否必填
  551. - `default` (string) 默认值
  552. - `paragraph` (object) 段落文本输入控件
  553. - `label` (string) 控件展示标签名
  554. - `variable` (string) 控件 ID
  555. - `required` (bool) 是否必填
  556. - `default` (string) 默认值
  557. - `select` (object) 下拉控件
  558. - `label` (string) 控件展示标签名
  559. - `variable` (string) 控件 ID
  560. - `required` (bool) 是否必填
  561. - `default` (string) 默认值
  562. - `options` (array[string]) 选项值
  563. - `file_upload` (object) 文件上传配置
  564. - `document` (object) 文档设置
  565. 当前仅支持文档类型:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  566. - `enabled` (bool) 是否启用
  567. - `number_limits` (int) 文档数量限制,默认为 3
  568. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  569. - `image` (object) 图片设置
  570. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  571. - `enabled` (bool) 是否启用
  572. - `number_limits` (int) 图片数量限制,默认为 3
  573. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  574. - `audio` (object) 音频设置
  575. 当前仅支持音频类型:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  576. - `enabled` (bool) 是否启用
  577. - `number_limits` (int) 音频数量限制,默认为 3
  578. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  579. - `video` (object) 视频设置
  580. 当前仅支持视频类型:`mp4`, `mov`, `mpeg`, `mpga`。
  581. - `enabled` (bool) 是否启用
  582. - `number_limits` (int) 视频数量限制,默认为 3
  583. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  584. - `custom` (object) 自定义设置
  585. - `enabled` (bool) 是否启用
  586. - `number_limits` (int) 自定义数量限制,默认为 3
  587. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  588. - `system_parameters` (object) 系统参数
  589. - `file_size_limit` (int) 文档上传大小限制 (MB)
  590. - `image_file_size_limit` (int) 图片文件上传大小限制(MB)
  591. - `audio_file_size_limit` (int) 音频文件上传大小限制 (MB)
  592. - `video_file_size_limit` (int) 视频文件上传大小限制 (MB)
  593. </Col>
  594. <Col sticky>
  595. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  596. ```bash {{ title: 'cURL' }}
  597. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  598. --header 'Authorization: Bearer {api_key}'
  599. ```
  600. </CodeGroup>
  601. <CodeGroup title="Response">
  602. ```json {{ title: 'Response' }}
  603. {
  604. "introduction": "nice to meet you",
  605. "user_input_form": [
  606. {
  607. "text-input": {
  608. "label": "a",
  609. "variable": "a",
  610. "required": true,
  611. "max_length": 48,
  612. "default": ""
  613. }
  614. },
  615. {
  616. // ...
  617. }
  618. ],
  619. "file_upload": {
  620. "image": {
  621. "enabled": true,
  622. "number_limits": 3,
  623. "transfer_methods": [
  624. "remote_url",
  625. "local_file"
  626. ]
  627. }
  628. },
  629. "system_parameters": {
  630. "file_size_limit": 15,
  631. "image_file_size_limit": 10,
  632. "audio_file_size_limit": 50,
  633. "video_file_size_limit": 100
  634. }
  635. }
  636. ```
  637. </CodeGroup>
  638. </Col>
  639. </Row>
  640. ---
  641. <Heading
  642. url='/site'
  643. method='GET'
  644. title='获取应用 WebApp 设置'
  645. name='#site'
  646. />
  647. <Row>
  648. <Col>
  649. 用于获取应用的 WebApp 设置
  650. ### Response
  651. - `title` (string) WebApp 名称
  652. - `chat_color_theme` (string) 聊天颜色主题,hex 格式
  653. - `chat_color_theme_inverted` (bool) 聊天颜色主题是否反转
  654. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  655. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  656. - `icon_background` (string) hex 格式的背景色
  657. - `icon_url` (string) 图标 URL
  658. - `description` (string) 描述
  659. - `copyright` (string) 版权信息
  660. - `privacy_policy` (string) 隐私政策链接
  661. - `custom_disclaimer` (string) 自定义免责声明
  662. - `default_language` (string) 默认语言
  663. - `show_workflow_steps` (bool) 是否显示工作流详情
  664. - `use_icon_as_answer_icon` (bool) 是否使用 WebApp 图标替换聊天中的 🤖
  665. </Col>
  666. <Col>
  667. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  668. ```bash {{ title: 'cURL' }}
  669. curl -X GET '${props.appDetail.api_base_url}/site' \
  670. -H 'Authorization: Bearer {api_key}'
  671. ```
  672. </CodeGroup>
  673. <CodeGroup title="Response">
  674. ```json {{ title: 'Response' }}
  675. {
  676. "title": "My App",
  677. "chat_color_theme": "#ff4a4a",
  678. "chat_color_theme_inverted": false,
  679. "icon_type": "emoji",
  680. "icon": "😄",
  681. "icon_background": "#FFEAD5",
  682. "icon_url": null,
  683. "description": "This is my app.",
  684. "copyright": "all rights reserved",
  685. "privacy_policy": "",
  686. "custom_disclaimer": "All generated by AI",
  687. "default_language": "en-US",
  688. "show_workflow_steps": false,
  689. "use_icon_as_answer_icon": false,
  690. }
  691. ```
  692. </CodeGroup>
  693. </Col>
  694. </Row>
  695. ___
  696. <Heading
  697. url='/apps/annotations'
  698. method='GET'
  699. title='获取标注列表'
  700. name='#annotation_list'
  701. />
  702. <Row>
  703. <Col>
  704. ### Query
  705. <Properties>
  706. <Property name='page' type='string' key='page'>
  707. 页码
  708. </Property>
  709. <Property name='limit' type='string' key='limit'>
  710. 每页数量
  711. </Property>
  712. </Properties>
  713. </Col>
  714. <Col sticky>
  715. <CodeGroup
  716. title="Request"
  717. tag="GET"
  718. label="/apps/annotations"
  719. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  720. >
  721. ```bash {{ title: 'cURL' }}
  722. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  723. --header 'Authorization: Bearer {api_key}'
  724. ```
  725. </CodeGroup>
  726. <CodeGroup title="Response">
  727. ```json {{ title: 'Response' }}
  728. {
  729. "data": [
  730. {
  731. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  732. "question": "What is your name?",
  733. "answer": "I am Dify.",
  734. "hit_count": 0,
  735. "created_at": 1735625869
  736. }
  737. ],
  738. "has_more": false,
  739. "limit": 20,
  740. "total": 1,
  741. "page": 1
  742. }
  743. ```
  744. </CodeGroup>
  745. </Col>
  746. </Row>
  747. ---
  748. <Heading
  749. url='/apps/annotations'
  750. method='POST'
  751. title='创建标注'
  752. name='#create_annotation'
  753. />
  754. <Row>
  755. <Col>
  756. ### Query
  757. <Properties>
  758. <Property name='question' type='string' key='question'>
  759. 问题
  760. </Property>
  761. <Property name='answer' type='string' key='answer'>
  762. 答案内容
  763. </Property>
  764. </Properties>
  765. </Col>
  766. <Col sticky>
  767. <CodeGroup
  768. title="Request"
  769. tag="POST"
  770. label="/apps/annotations"
  771. 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."}'`}
  772. >
  773. ```bash {{ title: 'cURL' }}
  774. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  775. --header 'Authorization: Bearer {api_key}' \
  776. --header 'Content-Type: application/json' \
  777. --data-raw '{
  778. "question": "What is your name?",
  779. "answer": "I am Dify."
  780. }'
  781. ```
  782. </CodeGroup>
  783. <CodeGroup title="Response">
  784. ```json {{ title: 'Response' }}
  785. {
  786. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  787. "question": "What is your name?",
  788. "answer": "I am Dify.",
  789. "hit_count": 0,
  790. "created_at": 1735625869
  791. }
  792. ```
  793. </CodeGroup>
  794. </Col>
  795. </Row>
  796. ---
  797. <Heading
  798. url='/apps/annotations/{annotation_id}'
  799. method='PUT'
  800. title='更新标注'
  801. name='#update_annotation'
  802. />
  803. <Row>
  804. <Col>
  805. ### Query
  806. <Properties>
  807. <Property name='annotation_id' type='string' key='annotation_id'>
  808. 标注 ID
  809. </Property>
  810. <Property name='question' type='string' key='question'>
  811. 问题
  812. </Property>
  813. <Property name='answer' type='string' key='answer'>
  814. 答案内容
  815. </Property>
  816. </Properties>
  817. </Col>
  818. <Col sticky>
  819. <CodeGroup
  820. title="Request"
  821. tag="PUT"
  822. label="/apps/annotations/{annotation_id}"
  823. 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."}'`}
  824. >
  825. ```bash {{ title: 'cURL' }}
  826. curl --location --request PUT '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  827. --header 'Authorization: Bearer {api_key}' \
  828. --header 'Content-Type: application/json' \
  829. --data-raw '{
  830. "question": "What is your name?",
  831. "answer": "I am Dify."
  832. }'
  833. ```
  834. </CodeGroup>
  835. <CodeGroup title="Response">
  836. ```json {{ title: 'Response' }}
  837. {
  838. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  839. "question": "What is your name?",
  840. "answer": "I am Dify.",
  841. "hit_count": 0,
  842. "created_at": 1735625869
  843. }
  844. ```
  845. </CodeGroup>
  846. </Col>
  847. </Row>
  848. ---
  849. <Heading
  850. url='/apps/annotations/{annotation_id}'
  851. method='DELETE'
  852. title='删除标注'
  853. name='#delete_annotation'
  854. />
  855. <Row>
  856. <Col>
  857. ### Query
  858. <Properties>
  859. <Property name='annotation_id' type='string' key='annotation_id'>
  860. 标注 ID
  861. </Property>
  862. </Properties>
  863. </Col>
  864. <Col sticky>
  865. <CodeGroup
  866. title="Request"
  867. tag="PUT"
  868. label="/apps/annotations/{annotation_id}"
  869. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  870. >
  871. ```bash {{ title: 'cURL' }}
  872. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  873. --header 'Authorization: Bearer {api_key}'
  874. ```
  875. </CodeGroup>
  876. <CodeGroup title="Response">
  877. ```text {{ title: 'Response' }}
  878. 204 No Content
  879. ```
  880. </CodeGroup>
  881. </Col>
  882. </Row>
  883. ---
  884. <Heading
  885. url='/apps/annotation-reply/{action}'
  886. method='POST'
  887. title='标注回复初始设置'
  888. name='#initial_annotation_reply_settings'
  889. />
  890. <Row>
  891. <Col>
  892. ### Query
  893. <Properties>
  894. <Property name='action' type='string' key='action'>
  895. 动作,只能是 'enable' 或 'disable'
  896. </Property>
  897. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  898. 指定的嵌入模型提供商,必须先在系统内设定好接入的模型,对应的是 provider 字段
  899. </Property>
  900. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  901. 指定的嵌入模型,对应的是 model 字段
  902. </Property>
  903. <Property name='score_threshold' type='number' key='score_threshold'>
  904. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  905. </Property>
  906. </Properties>
  907. </Col>
  908. <Col sticky>
  909. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding,具体见:通过 API 维护知识库。使用的 Authorization 是 Dataset 的 API Token。
  910. 该接口是异步执行,所以会返回一个 job_id,通过查询 job 状态接口可以获取到最终的执行结果。
  911. <CodeGroup
  912. title="Request"
  913. tag="POST"
  914. label="/apps/annotation-reply/{action}"
  915. 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"}'`}
  916. >
  917. ```bash {{ title: 'cURL' }}
  918. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  919. --header 'Authorization: Bearer {api_key}' \
  920. --header 'Content-Type: application/json' \
  921. --data-raw '{
  922. "score_threshold": 0.9,
  923. "embedding_provider_name": "zhipu",
  924. "embedding_model_name": "embedding_3"
  925. }'
  926. ```
  927. </CodeGroup>
  928. <CodeGroup title="Response">
  929. ```json {{ title: 'Response' }}
  930. {
  931. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  932. "job_status": "waiting"
  933. }
  934. ```
  935. </CodeGroup>
  936. </Col>
  937. </Row>
  938. ---
  939. <Heading
  940. url='/apps/annotation-reply/{action}/status/{job_id}'
  941. method='GET'
  942. title='查询标注回复初始设置任务状态'
  943. name='#initial_annotation_reply_settings_task_status'
  944. />
  945. <Row>
  946. <Col>
  947. ### Query
  948. <Properties>
  949. <Property name='action' type='string' key='action'>
  950. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  951. </Property>
  952. <Property name='job_id' type='string' key='job_id'>
  953. 任务 ID,从标注回复初始设置接口返回的 job_id
  954. </Property>
  955. </Properties>
  956. </Col>
  957. <Col sticky>
  958. <CodeGroup
  959. title="Request"
  960. tag="GET"
  961. label="/apps/annotations"
  962. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  963. >
  964. ```bash {{ title: 'cURL' }}
  965. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  966. --header 'Authorization: Bearer {api_key}'
  967. ```
  968. </CodeGroup>
  969. <CodeGroup title="Response">
  970. ```json {{ title: 'Response' }}
  971. {
  972. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  973. "job_status": "waiting",
  974. "error_msg": ""
  975. }
  976. ```
  977. </CodeGroup>
  978. </Col>
  979. </Row>