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_advanced_chat.zh.mdx 64KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  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. ### 鉴权
  9. Service API 使用 `API-Key` 进行鉴权。
  10. <i>**强烈建议开发者把 `API-Key` 放在后端存储,而非分享或者放在客户端存储,以免 `API-Key` 泄露,导致财产损失。**</i>
  11. 所有 API 请求都应在 **`Authorization`** HTTP Header 中包含您的 `API-Key`,如下所示:
  12. <CodeGroup title="Code" targetCode='Authorization: Bearer {API_KEY}' />
  13. </div>
  14. ---
  15. <Heading
  16. url='/chat-messages'
  17. method='POST'
  18. title='发送对话消息'
  19. name='#Create-Chat-Message'
  20. />
  21. <Row>
  22. <Col>
  23. 创建会话消息。
  24. ### Request Body
  25. <Properties>
  26. <Property name='query' type='string' key='query'>
  27. 用户输入/提问内容。
  28. </Property>
  29. <Property name='inputs' type='object' key='inputs'>
  30. 允许传入 App 定义的各变量值。
  31. inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。
  32. 如果变量是文件类型,请指定一个包含以下 `files` 中所述键的对象。
  33. 默认 `{}`
  34. </Property>
  35. <Property name='response_mode' type='string' key='response_mode'>
  36. - `streaming` 流式模式(推荐)。基于 SSE(**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现类似打字机输出方式的流式返回。
  37. - `blocking` 阻塞模式,等待执行完毕后返回结果。(请求若流程较长可能会被中断)。
  38. <i>由于 Cloudflare 限制,请求会在 100 秒超时无返回后中断。</i>
  39. </Property>
  40. <Property name='user' type='string' key='user'>
  41. 用户标识,用于定义终端用户的身份,方便检索、统计。
  42. 由开发者定义规则,需保证用户标识在应用内唯一。服务 API 不会共享 WebApp 创建的对话。
  43. </Property>
  44. <Property name='conversation_id' type='string' key='conversation_id'>
  45. (选填)会话 ID,需要基于之前的聊天记录继续对话,必须传之前消息的 conversation_id。
  46. </Property>
  47. <Property name='files' type='array[object]' key='files'>
  48. 文件列表,适用于传入文件结合文本理解并回答问题,仅当模型支持 Vision/Video 能力时可用。
  49. - `type` (string) 支持类型:
  50. - `document` 具体类型包含:'TXT', 'MD', 'MARKDOWN', 'MDX', 'PDF', 'HTML', 'XLSX', 'XLS', 'VTT', 'PROPERTIES', 'DOC', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
  51. - `image` 具体类型包含:'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
  52. - `audio` 具体类型包含:'MP3', 'M4A', 'WAV', 'WEBM', 'MPGA'
  53. - `video` 具体类型包含:'MP4', 'MOV', 'MPEG', 'WEBM'
  54. - `custom` 具体类型包含:其他文件类型
  55. - `transfer_method` (string) 传递方式:
  56. - `remote_url`: 文件地址。
  57. - `local_file`: 上传文件。
  58. - `url` 文件地址。(仅当传递方式为 `remote_url` 时)。
  59. - `upload_file_id` 上传文件 ID。(仅当传递方式为 `local_file `时)。
  60. </Property>
  61. <Property name='auto_generate_name' type='bool' key='auto_generate_name'>
  62. (选填)自动生成标题,默认 `true`。 若设置为 `false`,则可通过调用会话重命名接口并设置 `auto_generate` 为 `true` 实现异步生成标题。
  63. </Property>
  64. <Property name='workflow_id' type='string' key='workflow_id'>
  65. (选填)工作流ID,用于指定特定版本,如果不提供则使用默认的已发布版本。
  66. </Property>
  67. <Property name='trace_id' type='string' key='trace_id'>
  68. (选填)链路追踪ID。适用于与业务系统已有的trace组件打通,实现端到端分布式追踪等场景。如果未指定,系统会自动生成<code>trace_id</code>。支持以下三种方式传递,具体优先级依次为:<br/>
  69. - Header:通过 HTTP Header <code>X-Trace-Id</code> 传递,优先级最高。<br/>
  70. - Query 参数:通过 URL 查询参数 <code>trace_id</code> 传递。<br/>
  71. - Request Body:通过请求体字段 <code>trace_id</code> 传递(即本字段)。<br/>
  72. </Property>
  73. </Properties>
  74. ### Response
  75. <Properties>
  76. 当 `response_mode` 为 `blocking` 时,返回 ChatCompletionResponse object。
  77. 当 `response_mode` 为 `streaming`时,返回 ChunkChatCompletionResponse object 流式序列。
  78. ### ChatCompletionResponse
  79. 返回完整的 App 结果,`Content-Type` 为 `application/json`。
  80. - `event` (string) 事件类型,固定为 `message`
  81. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  82. - `id` (string) 唯一ID
  83. - `message_id` (string) 消息唯一 ID
  84. - `conversation_id` (string) 会话 ID
  85. - `mode` (string) App 模式,固定为 chat
  86. - `answer` (string) 完整回复内容
  87. - `metadata` (object) 元数据
  88. - `usage` (Usage) 模型用量信息
  89. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  90. - `created_at` (int) 消息创建时间戳,如:1705395332
  91. ### ChunkChatCompletionResponse
  92. 返回 App 输出的流式块,`Content-Type` 为 `text/event-stream`。
  93. 每个流式块均为 data: 开头,块之间以 \n\n 即两个换行符分隔,如下所示:
  94. <CodeGroup>
  95. ```streaming {{ title: 'Response' }}
  96. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  97. ```
  98. </CodeGroup>
  99. 流式块中根据 event 不同,结构也不同:
  100. - `event: message` LLM 返回文本块事件,即:完整的文本以分块的方式输出。
  101. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  102. - `message_id` (string) 消息唯一 ID
  103. - `conversation_id` (string) 会话 ID
  104. - `answer` (string) LLM 返回文本块内容
  105. - `created_at` (int) 创建时间戳,如:1705395332
  106. - `event: message_file` 文件事件,表示有新文件需要展示
  107. - `id` (string) 文件唯一ID
  108. - `type` (string) 文件类型,目前仅为image
  109. - `belongs_to` (string) 文件归属,user或assistant,该接口返回仅为 `assistant`
  110. - `url` (string) 文件访问地址
  111. - `conversation_id` (string) 会话ID
  112. - `event: message_end` 消息结束事件,收到此事件则代表流式返回结束。
  113. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  114. - `message_id` (string) 消息唯一 ID
  115. - `conversation_id` (string) 会话 ID
  116. - `metadata` (object) 元数据
  117. - `usage` (Usage) 模型用量信息
  118. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  119. - `event: tts_message` TTS 音频流事件,即:语音合成输出。内容是Mp3格式的音频块,使用 base64 编码后的字符串,播放的时候直接解码即可。(开启自动播放才有此消息)
  120. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  121. - `message_id` (string) 消息唯一 ID
  122. - `audio` (string) 语音合成之后的音频块使用 Base64 编码之后的文本内容,播放的时候直接 base64 解码送入播放器即可
  123. - `created_at` (int) 创建时间戳,如:1705395332
  124. - `event: tts_message_end` TTS 音频流结束事件,收到这个事件表示音频流返回结束。
  125. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  126. - `message_id` (string) 消息唯一 ID
  127. - `audio` (string) 结束事件是没有音频的,所以这里是空字符串
  128. - `created_at` (int) 创建时间戳,如:1705395332
  129. - `event: message_replace` 消息内容替换事件。
  130. 开启内容审查和审查输出内容时,若命中了审查条件,则会通过此事件替换消息内容为预设回复。
  131. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  132. - `message_id` (string) 消息唯一 ID
  133. - `conversation_id` (string) 会话 ID
  134. - `answer` (string) 替换内容(直接替换 LLM 所有回复文本)
  135. - `created_at` (int) 创建时间戳,如:1705395332
  136. - `event: workflow_started` workflow 开始执行
  137. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  138. - `workflow_run_id` (string) workflow 执行 ID
  139. - `event` (string) 固定为 `workflow_started`
  140. - `data` (object) 详细内容
  141. - `id` (string) workflow 执行 ID
  142. - `workflow_id` (string) 关联 Workflow ID
  143. - `created_at` (timestamp) 开始时间
  144. - `event: node_started` node 开始执行
  145. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  146. - `workflow_run_id` (string) workflow 执行 ID
  147. - `event` (string) 固定为 `node_started`
  148. - `data` (object) 详细内容
  149. - `id` (string) workflow 执行 ID
  150. - `node_id` (string) 节点 ID
  151. - `node_type` (string) 节点类型
  152. - `title` (string) 节点名称
  153. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  154. - `predecessor_node_id` (string) 前置节点 ID,用于画布展示执行路径
  155. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  156. - `created_at` (timestamp) 开始时间
  157. - `event: node_finished` node 执行结束,成功失败同一事件中不同状态
  158. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  159. - `workflow_run_id` (string) workflow 执行 ID
  160. - `event` (string) 固定为 `node_finished`
  161. - `data` (object) 详细内容
  162. - `id` (string) node 执行 ID
  163. - `node_id` (string) 节点 ID
  164. - `index` (int) 执行序号,用于展示 Tracing Node 顺序
  165. - `predecessor_node_id` (string) optional 前置节点 ID,用于画布展示执行路径
  166. - `inputs` (object) 节点中所有使用到的前置节点变量内容
  167. - `process_data` (json) Optional 节点过程数据
  168. - `outputs` (json) Optional 输出内容
  169. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  170. - `error` (string) Optional 错误原因
  171. - `elapsed_time` (float) Optional 耗时(s)
  172. - `execution_metadata` (json) 元数据
  173. - `total_tokens` (int) optional 总使用 tokens
  174. - `total_price` (decimal) optional 总费用
  175. - `currency` (string) optional 货币,如 `USD` / `RMB`
  176. - `created_at` (timestamp) 开始时间
  177. - `event: workflow_finished` workflow 执行结束,成功失败同一事件中不同状态
  178. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  179. - `workflow_run_id` (string) workflow 执行 ID
  180. - `event` (string) 固定为 `workflow_finished`
  181. - `data` (object) 详细内容
  182. - `id` (string) workflow 执行 ID
  183. - `workflow_id` (string) 关联 Workflow ID
  184. - `status` (string) 执行状态 `running` / `succeeded` / `failed` / `stopped`
  185. - `outputs` (json) Optional 输出内容
  186. - `error` (string) Optional 错误原因
  187. - `elapsed_time` (float) Optional 耗时(s)
  188. - `total_tokens` (int) Optional 总使用 tokens
  189. - `total_steps` (int) 总步数(冗余),默认 0
  190. - `created_at` (timestamp) 开始时间
  191. - `finished_at` (timestamp) 结束时间
  192. - `event: error`
  193. 流式输出过程中出现的异常会以 stream event 形式输出,收到异常事件后即结束。
  194. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  195. - `message_id` (string) 消息唯一 ID
  196. - `status` (int) HTTP 状态码
  197. - `code` (string) 错误码
  198. - `message` (string) 错误消息
  199. - `event: ping` 每 10s 一次的 ping 事件,保持连接存活。
  200. ### Errors
  201. - 404,对话不存在
  202. - 400,`invalid_param`,传入参数异常
  203. - 400,`app_unavailable`,App 配置不可用
  204. - 400,`provider_not_initialize`,无可用模型凭据配置
  205. - 400,`provider_quota_exceeded`,模型调用额度不足
  206. - 400,`model_currently_not_support`,当前模型不可用
  207. - 400,`workflow_not_found`,指定的工作流版本未找到
  208. - 400,`draft_workflow_error`,无法使用草稿工作流版本
  209. - 400,`workflow_id_format_error`,工作流ID格式错误,需要UUID格式
  210. - 400,`completion_request_error`,文本生成失败
  211. - 500,服务内部异常
  212. </Properties>
  213. </Col>
  214. <Col sticky>
  215. <CodeGroup
  216. title="Request"
  217. tag="POST"
  218. label="/chat-messages"
  219. targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages' \\
  220. --header 'Authorization: Bearer {api_key}' \\
  221. --header 'Content-Type: application/json' \\
  222. --data-raw '{
  223. "inputs": ${JSON.stringify(props.inputs)},
  224. "query": "What are the specs of the iPhone 13 Pro Max?",
  225. "response_mode": "streaming",
  226. "conversation_id": "",
  227. "user": "abc-123",
  228. "files": [
  229. {
  230. "type": "image",
  231. "transfer_method": "remote_url",
  232. "url": "https://cloud.dify.ai/logo/logo-site.png"
  233. }
  234. ]
  235. }'`}
  236. />
  237. ### 阻塞模式
  238. <CodeGroup title="Response">
  239. ```json {{ title: 'Response' }}
  240. {
  241. "event": "message",
  242. "task_id": "c3800678-a077-43df-a102-53f23ed20b88",
  243. "id": "9da23599-e713-473b-982c-4328d4f5c78a",
  244. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  245. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  246. "mode": "chat",
  247. "answer": "iPhone 13 Pro Max specs are listed here:...",
  248. "metadata": {
  249. "usage": {
  250. "prompt_tokens": 1033,
  251. "prompt_unit_price": "0.001",
  252. "prompt_price_unit": "0.001",
  253. "prompt_price": "0.0010330",
  254. "completion_tokens": 128,
  255. "completion_unit_price": "0.002",
  256. "completion_price_unit": "0.001",
  257. "completion_price": "0.0002560",
  258. "total_tokens": 1161,
  259. "total_price": "0.0012890",
  260. "currency": "USD",
  261. "latency": 0.7682376249867957
  262. },
  263. "retriever_resources": [
  264. {
  265. "position": 1,
  266. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  267. "dataset_name": "iPhone",
  268. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  269. "document_name": "iPhone List",
  270. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  271. "score": 0.98457545,
  272. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  273. }
  274. ]
  275. },
  276. "created_at": 1705407629
  277. }
  278. ```
  279. </CodeGroup>
  280. ### 流式模式
  281. <CodeGroup title="Response">
  282. ```streaming {{ title: 'Response' }}
  283. data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
  284. data: {"event": "node_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "created_at": 1679586595}}
  285. data: {"event": "node_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "execution_metadata": {"total_tokens": 63127864, "total_price": 2.378, "currency": "USD"}, "created_at": 1679586595}}
  286. data: {"event": "workflow_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "total_tokens": 63127864, "total_steps": "1", "created_at": 1679586595, "finished_at": 1679976595}}
  287. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  288. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  289. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  290. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  291. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  292. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  293. data: {"event": "message_end", "id": "5e52ce04-874b-4d27-9045-b3bc80def685", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "metadata": {"usage": {"prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 135, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002700", "total_tokens": 1168, "total_price": "0.0013030", "currency": "USD", "latency": 1.381760165997548}, "retriever_resources": [{"position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""}]}}
  294. 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"}
  295. 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": ""}
  296. ```
  297. </CodeGroup>
  298. </Col>
  299. </Row>
  300. ---
  301. <Heading
  302. url='/files/upload'
  303. method='POST'
  304. title='上传文件'
  305. name='#files-upload'
  306. />
  307. <Row>
  308. <Col>
  309. 上传文件并在发送消息时使用,可实现图文多模态理解。
  310. 支持您的应用程序所支持的所有格式。
  311. <i>上传的文件仅供当前终端用户使用。</i>
  312. ### Request Body
  313. 该接口需使用 `multipart/form-data` 进行请求。
  314. <Properties>
  315. <Property name='file' type='file' key='file'>
  316. 要上传的文件。
  317. </Property>
  318. <Property name='user' type='string' key='user'>
  319. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。
  320. </Property>
  321. </Properties>
  322. ### Response
  323. 成功上传后,服务器会返回文件的 ID 和相关信息。
  324. - `id` (uuid) ID
  325. - `name` (string) 文件名
  326. - `size` (int) 文件大小(byte)
  327. - `extension` (string) 文件后缀
  328. - `mime_type` (string) 文件 mime-type
  329. - `created_by` (uuid) 上传人 ID
  330. - `created_at` (timestamp) 上传时间
  331. ### Errors
  332. - 400,`no_file_uploaded`,必须提供文件
  333. - 400,`too_many_files`,目前只接受一个文件
  334. - 400,`unsupported_preview`,该文件不支持预览
  335. - 400,`unsupported_estimate`,该文件不支持估算
  336. - 413,`file_too_large`,文件太大
  337. - 415,`unsupported_file_type`,不支持的扩展名,当前只接受文档类文件
  338. - 503,`s3_connection_failed`,无法连接到 S3 服务
  339. - 503,`s3_permission_denied`,无权限上传文件到 S3
  340. - 503,`s3_file_too_large`,文件超出 S3 大小限制
  341. </Col>
  342. <Col sticky>
  343. <CodeGroup
  344. title="Request"
  345. tag="POST"
  346. label="/files/upload"
  347. targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\
  348. --header 'Authorization: Bearer {api_key}' \\
  349. --form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\
  350. --form 'user=abc-123'`}
  351. />
  352. <CodeGroup title="Response">
  353. ```json {{ title: 'Response' }}
  354. {
  355. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  356. "name": "example.png",
  357. "size": 1024,
  358. "extension": "png",
  359. "mime_type": "image/png",
  360. "created_by": 123,
  361. "created_at": 1577836800,
  362. }
  363. ```
  364. </CodeGroup>
  365. </Col>
  366. </Row>
  367. ---
  368. <Heading
  369. url='/files/:file_id/preview'
  370. method='GET'
  371. title='文件预览'
  372. name='#file-preview'
  373. />
  374. <Row>
  375. <Col>
  376. 预览或下载已上传的文件。此端点允许您访问先前通过文件上传 API 上传的文件。
  377. <i>文件只能在属于请求应用程序的消息范围内访问。</i>
  378. ### 路径参数
  379. - `file_id` (string) 必需
  380. 要预览的文件的唯一标识符,从文件上传 API 响应中获得。
  381. ### 查询参数
  382. - `as_attachment` (boolean) 可选
  383. 是否强制将文件作为附件下载。默认为 `false`(在浏览器中预览)。
  384. ### 响应
  385. 返回带有适当浏览器显示或下载标头的文件内容。
  386. - `Content-Type` 根据文件 MIME 类型设置
  387. - `Content-Length` 文件大小(以字节为单位,如果可用)
  388. - `Content-Disposition` 如果 `as_attachment=true` 则设置为 "attachment"
  389. - `Cache-Control` 用于性能的缓存标头
  390. - `Accept-Ranges` 对于音频/视频文件设置为 "bytes"
  391. ### 错误
  392. - 400, `invalid_param`, 参数输入异常
  393. - 403, `file_access_denied`, 文件访问被拒绝或文件不属于当前应用程序
  394. - 404, `file_not_found`, 文件未找到或已被删除
  395. - 500, 服务内部错误
  396. </Col>
  397. <Col sticky>
  398. ### 请求示例
  399. <CodeGroup
  400. title="Request"
  401. tag="GET"
  402. label="/files/:file_id/preview"
  403. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview' \\
  404. --header 'Authorization: Bearer {api_key}'`}
  405. />
  406. ### 作为附件下载
  407. <CodeGroup
  408. title="Download Request"
  409. tag="GET"
  410. label="/files/:file_id/preview?as_attachment=true"
  411. targetCode={`curl -X GET '${props.appDetail.api_base_url}/files/72fa9618-8f89-4a37-9b33-7e1178a24a67/preview?as_attachment=true' \\
  412. --header 'Authorization: Bearer {api_key}' \\
  413. --output downloaded_file.png`}
  414. />
  415. ### 响应标头示例
  416. <CodeGroup title="Response Headers">
  417. ```http {{ title: 'Headers - 图片预览' }}
  418. Content-Type: image/png
  419. Content-Length: 1024
  420. Cache-Control: public, max-age=3600
  421. ```
  422. </CodeGroup>
  423. ### 文件下载响应标头
  424. <CodeGroup title="Download Response Headers">
  425. ```http {{ title: 'Headers - 文件下载' }}
  426. Content-Type: image/png
  427. Content-Length: 1024
  428. Content-Disposition: attachment; filename*=UTF-8''example.png
  429. Cache-Control: public, max-age=3600
  430. ```
  431. </CodeGroup>
  432. </Col>
  433. </Row>
  434. ---
  435. <Heading
  436. url='/chat-messages/:task_id/stop'
  437. method='POST'
  438. title='停止响应'
  439. name='#Stop'
  440. />
  441. <Row>
  442. <Col>
  443. 仅支持流式模式。
  444. ### Path
  445. - `task_id` (string) 任务 ID,可在流式返回 Chunk 中获取
  446. ### Request Body
  447. - `user` (string) Required
  448. 用户标识,用于定义终端用户的身份,必须和发送消息接口传入 user 保持一致。API 无法访问 WebApp 创建的会话。
  449. ### Response
  450. - `result` (string) 固定返回 success
  451. </Col>
  452. <Col sticky>
  453. <CodeGroup
  454. title="Request"
  455. tag="POST"
  456. label="/chat-messages/:task_id/stop"
  457. targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \\
  458. -H 'Authorization: Bearer {api_key}' \\
  459. -H 'Content-Type: application/json' \\
  460. --data-raw '{
  461. "user": "abc-123"
  462. }'`}
  463. />
  464. <CodeGroup title="Response">
  465. ```json {{ title: 'Response' }}
  466. {
  467. "result": "success"
  468. }
  469. ```
  470. </CodeGroup>
  471. </Col>
  472. </Row>
  473. ---
  474. <Heading
  475. url='/messages/:message_id/feedbacks'
  476. method='POST'
  477. title='消息反馈(点赞)'
  478. name='#feedbacks'
  479. />
  480. <Row>
  481. <Col>
  482. 消息终端用户反馈、点赞,方便应用开发者优化输出预期。
  483. ### Path Params
  484. <Properties>
  485. <Property name='message_id' type='string' key='message_id'>
  486. 消息 ID
  487. </Property>
  488. </Properties>
  489. ### Request Body
  490. <Properties>
  491. <Property name='rating' type='string' key='rating'>
  492. 点赞 like, 点踩 dislike, 撤销点赞 null
  493. </Property>
  494. <Property name='user' type='string' key='user'>
  495. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  496. </Property>
  497. <Property name='content' type='string' key='content'>
  498. 消息反馈的具体信息。
  499. </Property>
  500. </Properties>
  501. ### Response
  502. - `result` (string) 固定返回 success
  503. </Col>
  504. <Col sticky>
  505. <CodeGroup
  506. title="Request"
  507. tag="POST"
  508. label="/messages/:message_id/feedbacks"
  509. targetCode={`curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \\
  510. --header 'Authorization: Bearer {api_key}' \\
  511. --header 'Content-Type: application/json' \\
  512. --data-raw '{
  513. "rating": "like",
  514. "user": "abc-123",
  515. "content": "message feedback information"
  516. }'`}
  517. />
  518. <CodeGroup title="Response">
  519. ```json {{ title: 'Response' }}
  520. {
  521. "result": "success"
  522. }
  523. ```
  524. </CodeGroup>
  525. </Col>
  526. </Row>
  527. ---
  528. <Heading
  529. url='/app/feedbacks'
  530. method='GET'
  531. title='获取APP的消息点赞和反馈'
  532. name='#app-feedbacks'
  533. />
  534. <Row>
  535. <Col>
  536. 获取应用的终端用户反馈、点赞。
  537. ### Query
  538. <Properties>
  539. <Property name='page' type='string' key='page'>
  540. (选填)分页,默认值:1
  541. </Property>
  542. </Properties>
  543. <Properties>
  544. <Property name='limit' type='string' key='limit'>
  545. (选填)每页数量,默认值:20
  546. </Property>
  547. </Properties>
  548. ### Response
  549. - `data` (List) 返回该APP的点赞、反馈列表。
  550. </Col>
  551. <Col sticky>
  552. <CodeGroup
  553. title="Request"
  554. tag="GET"
  555. label="/app/feedbacks"
  556. targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \\
  557. --header 'Authorization: Bearer {api_key}' \\
  558. --header 'Content-Type: application/json'`}
  559. />
  560. <CodeGroup title="Response">
  561. ```json {{ title: 'Response' }}
  562. {
  563. "data": [
  564. {
  565. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  566. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  567. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  568. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  569. "rating": "like",
  570. "content": "message feedback information-3",
  571. "from_source": "user",
  572. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  573. "from_account_id": null,
  574. "created_at": "2025-04-24T09:24:38",
  575. "updated_at": "2025-04-24T09:24:38"
  576. }
  577. ]
  578. }
  579. ```
  580. </CodeGroup>
  581. </Col>
  582. </Row>
  583. ---
  584. <Heading
  585. url='/messages/{message_id}/suggested'
  586. method='GET'
  587. title='获取下一轮建议问题列表'
  588. name='#suggested'
  589. />
  590. <Row>
  591. <Col>
  592. 获取下一轮建议问题列表。
  593. ### Path Params
  594. <Properties>
  595. <Property name='message_id' type='string' key='message_id'>
  596. Message ID
  597. </Property>
  598. </Properties>
  599. ### Query
  600. <Properties>
  601. <Property name='user' type='string' key='user'>
  602. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  603. </Property>
  604. </Properties>
  605. </Col>
  606. <Col sticky>
  607. <CodeGroup
  608. title="Request"
  609. tag="GET"
  610. label="/messages/{message_id}/suggested"
  611. targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123' \\
  612. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\
  613. --header 'Content-Type: application/json'`}
  614. />
  615. <CodeGroup title="Response">
  616. ```json {{ title: 'Response' }}
  617. {
  618. "result": "success",
  619. "data": [
  620. "a",
  621. "b",
  622. "c"
  623. ]
  624. }
  625. ```
  626. </CodeGroup>
  627. </Col>
  628. </Row>
  629. ---
  630. ---
  631. <Heading
  632. url='/messages'
  633. method='GET'
  634. title='获取会话历史消息'
  635. name='#messages'
  636. />
  637. <Row>
  638. <Col>
  639. 滚动加载形式返回历史聊天记录,第一页返回最新 `limit` 条,即:倒序返回。
  640. ### Query
  641. <Properties>
  642. <Property name='conversation_id' type='string' key='conversation_id'>
  643. 会话 ID
  644. </Property>
  645. <Property name='user' type='string' key='user'>
  646. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  647. </Property>
  648. <Property name='first_id' type='string' key='first_id'>
  649. 当前页第一条聊天记录的 ID,默认 null
  650. </Property>
  651. <Property name='limit' type='int' key='limit'>
  652. 一次请求返回多少条聊天记录,默认 20 条。
  653. </Property>
  654. </Properties>
  655. ### Response
  656. - `data` (array[object]) 消息列表
  657. - `id` (string) 消息 ID
  658. - `conversation_id` (string) 会话 ID
  659. - `inputs` (object) 用户输入参数。
  660. - `query` (string) 用户输入 / 提问内容。
  661. - `message_files` (array[object]) 消息文件
  662. - `id` (string) ID
  663. - `type` (string) 文件类型,image 图片
  664. - `url` (string) 文件预览地址,使用文件预览 API (`/files/{file_id}/preview`) 访问文件
  665. - `belongs_to` (string) 文件归属方,user 或 assistant
  666. - `answer` (string) 回答消息内容
  667. - `created_at` (timestamp) 创建时间
  668. - `feedback` (object) 反馈信息
  669. - `rating` (string) 点赞 like / 点踩 dislike
  670. - `retriever_resources` (array[RetrieverResource]) 引用和归属分段列表
  671. - `has_more` (bool) 是否存在下一页
  672. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  673. </Col>
  674. <Col sticky>
  675. ### Request Example
  676. <CodeGroup
  677. title="Request"
  678. tag="GET"
  679. label="/messages"
  680. targetCode={`curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id={conversation_id}'
  681. --header 'Authorization: Bearer {api_key}'`}
  682. />
  683. ### Response Example
  684. <CodeGroup title="Response">
  685. ```json {{ title: 'Response' }}
  686. {
  687. "limit": 20,
  688. "has_more": false,
  689. "data": [
  690. {
  691. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  692. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  693. "inputs": {
  694. "name": "dify"
  695. },
  696. "query": "iphone 13 pro",
  697. "answer": "The iPhone 13 Pro, released on September 24, 2021, features a 6.1-inch display with a resolution of 1170 x 2532. It is equipped with a Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard) processor, 6 GB of RAM, and offers storage options of 128 GB, 256 GB, 512 GB, and 1 TB. The camera is 12 MP, the battery capacity is 3095 mAh, and it runs on iOS 15.",
  698. "message_files": [],
  699. "feedback": null,
  700. "retriever_resources": [
  701. {
  702. "position": 1,
  703. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  704. "dataset_name": "iPhone",
  705. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  706. "document_name": "iPhone List",
  707. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  708. "score": 0.98457545,
  709. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  710. }
  711. ],
  712. "created_at": 1705569239
  713. }
  714. ]
  715. }
  716. ```
  717. </CodeGroup>
  718. ### Response Example(智能助手)
  719. <CodeGroup title="Response">
  720. ```json {{ title: 'Response' }}
  721. {
  722. "limit": 20,
  723. "has_more": false,
  724. "data": [
  725. {
  726. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  727. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  728. "inputs": {},
  729. "query": "draw a cat",
  730. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  731. "message_files": [
  732. {
  733. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  734. "type": "image",
  735. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  736. "belongs_to": "assistant"
  737. }
  738. ],
  739. "feedback": null,
  740. "retriever_resources": [],
  741. "created_at": 1705988187
  742. }
  743. ]
  744. }
  745. ```
  746. </CodeGroup>
  747. </Col>
  748. </Row>
  749. ---
  750. <Heading
  751. url='/conversations'
  752. method='GET'
  753. title='获取会话列表'
  754. name='#conversations'
  755. />
  756. <Row>
  757. <Col>
  758. 获取当前用户的会话列表,默认返回最近的 20 条。
  759. ### Query
  760. <Properties>
  761. <Property name='user' type='string' key='user'>
  762. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  763. </Property>
  764. <Property name='last_id' type='string' key='last_id'>
  765. (选填)当前页最后面一条记录的 ID,默认 null
  766. </Property>
  767. <Property name='limit' type='int' key='limit'>
  768. (选填)一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。
  769. </Property>
  770. <Property name='sort_by' type='string' key='sort_by'>
  771. (选填)排序字段,默认 -updated_at(按更新时间倒序排列)
  772. - 可选值:created_at, -created_at, updated_at, -updated_at
  773. - 字段前面的符号代表顺序或倒序,-代表倒序
  774. </Property>
  775. </Properties>
  776. ### Response
  777. - `data` (array[object]) 会话列表
  778. - `id` (string) 会话 ID
  779. - `name` (string) 会话名称,默认由大语言模型生成。
  780. - `inputs` (object) 用户输入参数。
  781. - `status` (string) 会话状态
  782. - `introduction` (string) 开场白
  783. - `created_at` (timestamp) 创建时间
  784. - `updated_at` (timestamp) 更新时间
  785. - `has_more` (bool)
  786. - `limit` (int) 返回条数,若传入超过系统限制,返回系统限制数量
  787. </Col>
  788. <Col sticky>
  789. <CodeGroup
  790. title="Request"
  791. tag="GET"
  792. label="/conversations"
  793. targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \\
  794. --header 'Authorization: Bearer {api_key}'`}
  795. />
  796. <CodeGroup title="Response">
  797. ```json {{ title: 'Response' }}
  798. {
  799. "limit": 20,
  800. "has_more": false,
  801. "data": [
  802. {
  803. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  804. "name": "New chat",
  805. "inputs": {
  806. "book": "book",
  807. "myName": "Lucy"
  808. },
  809. "status": "normal",
  810. "created_at": 1679667915,
  811. "updated_at": 1679667915
  812. },
  813. {
  814. "id": "hSIhXBhNe8X1d8Et"
  815. // ...
  816. }
  817. ]
  818. }
  819. ```
  820. </CodeGroup>
  821. </Col>
  822. </Row>
  823. ---
  824. <Heading
  825. url='/conversations/:conversation_id'
  826. method='DELETE'
  827. title='删除会话'
  828. name='#delete'
  829. />
  830. <Row>
  831. <Col>
  832. 删除会话。
  833. ### Path
  834. - `conversation_id` (string) 会话 ID
  835. ### Request Body
  836. <Properties>
  837. <Property name='user' type='string' key='user'>
  838. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  839. </Property>
  840. </Properties>
  841. ### Response
  842. - `result` (string) 固定返回 success
  843. </Col>
  844. <Col sticky>
  845. <CodeGroup
  846. title="Request"
  847. tag="DELETE"
  848. label="/conversations/:conversation_id"
  849. targetCode={`curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \\
  850. --header 'Content-Type: application/json' \\
  851. --header 'Accept: application/json' \\
  852. --header 'Authorization: Bearer {api_key}' \\
  853. --data '{
  854. "user": "abc-123"
  855. }'`}
  856. />
  857. <CodeGroup title="Response">
  858. ```text {{ title: 'Response' }}
  859. 204 No Content
  860. ```
  861. </CodeGroup>
  862. </Col>
  863. </Row>
  864. ---
  865. <Heading
  866. url='/conversations/:conversation_id/name'
  867. method='POST'
  868. title='会话重命名'
  869. name='#rename'
  870. />
  871. <Row>
  872. <Col>
  873. 对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
  874. ### Path
  875. - `conversation_id` (string) 会话 ID
  876. ### Request Body
  877. <Properties>
  878. <Property name='name' type='string' key='name'>
  879. (选填)名称,若 `auto_generate` 为 `true` 时,该参数可不传。
  880. </Property>
  881. <Property name='auto_generate' type='bool' key='auto_generate'>
  882. (选填)自动生成标题,默认 false。
  883. </Property>
  884. <Property name='user' type='string' key='user'>
  885. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  886. </Property>
  887. </Properties>
  888. ### Response
  889. - `id` (string) 会话 ID
  890. - `name` (string) 会话名称
  891. - `inputs` (object) 用户输入参数
  892. - `status` (string) 会话状态
  893. - `introduction` (string) 开场白
  894. - `created_at` (timestamp) 创建时间
  895. - `updated_at` (timestamp) 更新时间
  896. </Col>
  897. <Col sticky>
  898. <CodeGroup
  899. title="Request"
  900. tag="POST"
  901. label="/conversations/:conversation_id/name"
  902. targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \\
  903. --header 'Content-Type: application/json' \\
  904. --header 'Authorization: Bearer {api_key}' \\
  905. --data-raw '{
  906. "name": "",
  907. "auto_generate": true,
  908. "user": "abc-123"
  909. }'`}
  910. />
  911. <CodeGroup title="Response">
  912. ```json {{ title: 'Response' }}
  913. {
  914. "id": "34d511d5-56de-4f16-a997-57b379508443",
  915. "name": "hello",
  916. "inputs": {},
  917. "status": "normal",
  918. "introduction": "",
  919. "created_at": 1732731141,
  920. "updated_at": 1732734510
  921. }
  922. ```
  923. </CodeGroup>
  924. </Col>
  925. </Row>
  926. ---
  927. <Heading
  928. url='/conversations/:conversation_id/variables'
  929. method='GET'
  930. title='获取对话变量'
  931. name='#conversation-variables'
  932. />
  933. <Row>
  934. <Col>
  935. 从特定对话中检索变量。此端点对于提取对话过程中捕获的结构化数据非常有用。
  936. ### 路径参数
  937. <Properties>
  938. <Property name='conversation_id' type='string' key='conversation_id'>
  939. 要从中检索变量的对话ID。
  940. </Property>
  941. </Properties>
  942. ### 查询参数
  943. <Properties>
  944. <Property name='user' type='string' key='user'>
  945. 用户标识符,由开发人员定义的规则,在应用程序内必须唯一。
  946. </Property>
  947. <Property name='last_id' type='string' key='last_id'>
  948. (选填)当前页最后面一条记录的 ID,默认 null
  949. </Property>
  950. <Property name='limit' type='int' key='limit'>
  951. (选填)一次请求返回多少条记录,默认 20 条,最大 100 条,最小 1 条。
  952. </Property>
  953. </Properties>
  954. ### 响应
  955. - `limit` (int) 每页项目数
  956. - `has_more` (bool) 是否有更多项目
  957. - `data` (array[object]) 变量列表
  958. - `id` (string) 变量 ID
  959. - `name` (string) 变量名称
  960. - `value_type` (string) 变量类型(字符串、数字、布尔等)
  961. - `value` (string) 变量值
  962. - `description` (string) 变量描述
  963. - `created_at` (int) 创建时间戳
  964. - `updated_at` (int) 最后更新时间戳
  965. ### 错误
  966. - 404, `conversation_not_exists`, 对话不存在
  967. </Col>
  968. <Col sticky>
  969. <CodeGroup
  970. title="Request"
  971. tag="GET"
  972. label="/conversations/:conversation_id/variables"
  973. debug="true"
  974. targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \\
  975. --header 'Authorization: Bearer {api_key}'`} />
  976. <CodeGroup
  977. title="带变量名过滤的请求"
  978. language="bash"
  979. targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123&variable_name=customer_name' \\
  980. --header 'Authorization: Bearer {api_key}'`}
  981. />
  982. <CodeGroup title="Response">
  983. ```json {{ title: 'Response' }}
  984. {
  985. "limit": 100,
  986. "has_more": false,
  987. "data": [
  988. {
  989. "id": "variable-uuid-1",
  990. "name": "customer_name",
  991. "value_type": "string",
  992. "value": "John Doe",
  993. "description": "客户名称(从对话中提取)",
  994. "created_at": 1650000000000,
  995. "updated_at": 1650000000000
  996. },
  997. {
  998. "id": "variable-uuid-2",
  999. "name": "order_details",
  1000. "value_type": "json",
  1001. "value": "{\"product\":\"Widget\",\"quantity\":5,\"price\":19.99}",
  1002. "description": "客户的订单详情",
  1003. "created_at": 1650000000000,
  1004. "updated_at": 1650000000000
  1005. }
  1006. ]
  1007. }
  1008. ```
  1009. </CodeGroup>
  1010. </Col>
  1011. </Row>
  1012. ---
  1013. <Heading
  1014. url='/conversations/:conversation_id/variables/:variable_id'
  1015. method='PUT'
  1016. title='更新对话变量'
  1017. name='#update-conversation-variable'
  1018. />
  1019. <Row>
  1020. <Col>
  1021. 更新特定对话变量的值。此端点允许您修改在对话过程中捕获的变量值,同时保留其名称、类型和描述。
  1022. ### 路径参数
  1023. <Properties>
  1024. <Property name='conversation_id' type='string' key='conversation_id'>
  1025. 包含要更新变量的对话ID。
  1026. </Property>
  1027. <Property name='variable_id' type='string' key='variable_id'>
  1028. 要更新的变量ID。
  1029. </Property>
  1030. </Properties>
  1031. ### 请求体
  1032. <Properties>
  1033. <Property name='value' type='any' key='value'>
  1034. 变量的新值。必须匹配变量的预期类型(字符串、数字、对象等)。
  1035. </Property>
  1036. <Property name='user' type='string' key='user'>
  1037. 用户标识符,由开发人员定义的规则,在应用程序内必须唯一。
  1038. </Property>
  1039. </Properties>
  1040. ### 响应
  1041. 返回包含以下内容的更新变量对象:
  1042. - `id` (string) 变量ID
  1043. - `name` (string) 变量名称
  1044. - `value_type` (string) 变量类型(字符串、数字、对象等)
  1045. - `value` (any) 更新后的变量值
  1046. - `description` (string) 变量描述
  1047. - `created_at` (int) 创建时间戳
  1048. - `updated_at` (int) 最后更新时间戳
  1049. ### 错误
  1050. - 400, `Type mismatch: variable expects {expected_type}, but got {actual_type} type`, 值类型与变量的预期类型不匹配
  1051. - 404, `conversation_not_exists`, 对话不存在
  1052. - 404, `conversation_variable_not_exists`, 变量不存在
  1053. </Col>
  1054. <Col sticky>
  1055. <CodeGroup
  1056. title="Request"
  1057. tag="PUT"
  1058. label="/conversations/:conversation_id/variables/:variable_id"
  1059. targetCode={`curl -X PUT '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables/{variable_id}' \\
  1060. --header 'Content-Type: application/json' \\
  1061. --header 'Authorization: Bearer {api_key}' \\
  1062. --data-raw '{
  1063. "value": "Updated Value",
  1064. "user": "abc-123"
  1065. }'`}
  1066. />
  1067. <CodeGroup
  1068. title="使用不同值类型更新"
  1069. targetCode={[
  1070. {
  1071. title: '字符串值',
  1072. code: `curl -X PUT '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables/{variable_id}' \\
  1073. --header 'Content-Type: application/json' \\
  1074. --header 'Authorization: Bearer {api_key}' \\
  1075. --data-raw '{
  1076. "value": "新的字符串值",
  1077. "user": "abc-123"
  1078. }'`,
  1079. }, {
  1080. title: '数字值',
  1081. code: `curl -X PUT '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables/{variable_id}' \\
  1082. --header 'Content-Type: application/json' \\
  1083. --header 'Authorization: Bearer {api_key}' \\
  1084. --data-raw '{
  1085. "value": 42,
  1086. "user": "abc-123"
  1087. }'`,
  1088. }, {
  1089. title: '对象值',
  1090. code: `curl -X PUT '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables/{variable_id}' \\
  1091. --header 'Content-Type: application/json' \\
  1092. --header 'Authorization: Bearer {api_key}' \\
  1093. --data-raw '{
  1094. "value": {"product": "Widget", "quantity": 10, "price": 29.99},
  1095. "user": "abc-123"
  1096. }'`,
  1097. },
  1098. ]}
  1099. />
  1100. <CodeGroup title="Response">
  1101. ```json {{ title: 'Response' }}
  1102. {
  1103. "id": "variable-uuid-1",
  1104. "name": "customer_name",
  1105. "value_type": "string",
  1106. "value": "Updated Value",
  1107. "description": "客户名称(从对话中提取)",
  1108. "created_at": 1650000000000,
  1109. "updated_at": 1650000001000
  1110. }
  1111. ```
  1112. </CodeGroup>
  1113. </Col>
  1114. </Row>
  1115. ---
  1116. <Heading
  1117. url='/audio-to-text'
  1118. method='POST'
  1119. title='语音转文字'
  1120. name='#audio-to-text'
  1121. />
  1122. <Row>
  1123. <Col>
  1124. ### Request Body
  1125. 该接口需使用 `multipart/form-data` 进行请求。
  1126. <Properties>
  1127. <Property name='file' type='file' key='file'>
  1128. 语音文件。
  1129. 支持格式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  1130. 文件大小限制:15MB
  1131. </Property>
  1132. <Property name='user' type='string' key='user'>
  1133. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  1134. </Property>
  1135. </Properties>
  1136. ### Response
  1137. - `text` (string) 输出文字
  1138. </Col>
  1139. <Col sticky>
  1140. <CodeGroup
  1141. title="Request"
  1142. tag="POST"
  1143. label="/audio-to-text"
  1144. targetCode={`curl -X POST '${props.appDetail.api_base_url}/audio-to-text' \\
  1145. --header 'Authorization: Bearer {api_key}' \\
  1146. --form 'file=@localfile;type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]'`}
  1147. />
  1148. <CodeGroup title="Response">
  1149. ```json {{ title: 'Response' }}
  1150. {
  1151. "text": "hello"
  1152. }
  1153. ```
  1154. </CodeGroup>
  1155. </Col>
  1156. </Row>
  1157. ---
  1158. <Heading
  1159. url='/text-to-audio'
  1160. method='POST'
  1161. title='文字转语音'
  1162. name='#text-to-audio'
  1163. />
  1164. <Row>
  1165. <Col>
  1166. 文字转语音。
  1167. ### Request Body
  1168. <Properties>
  1169. <Property name='message_id' type='str' key='message_id'>
  1170. Dify 生成的文本消息,那么直接传递生成的message-id 即可,后台会通过 message_id 查找相应的内容直接合成语音信息。如果同时传 message_id 和 text,优先使用 message_id。
  1171. </Property>
  1172. <Property name='text' type='str' key='text'>
  1173. 语音生成内容。如果没有传 message-id的话,则会使用这个字段的内容
  1174. </Property>
  1175. <Property name='user' type='string' key='user'>
  1176. 用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
  1177. </Property>
  1178. </Properties>
  1179. </Col>
  1180. <Col sticky>
  1181. <CodeGroup
  1182. title="Request"
  1183. tag="POST"
  1184. label="/text-to-audio"
  1185. targetCode={`curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \\
  1186. --header 'Authorization: Bearer {api_key}' \\
  1187. --header 'Content-Type: application/json' \\
  1188. --data-raw '{
  1189. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  1190. "text": "Hello Dify",
  1191. "user": "abc-123",
  1192. }'`}
  1193. />
  1194. <CodeGroup title="headers">
  1195. ```json {{ title: 'headers' }}
  1196. {
  1197. "Content-Type": "audio/wav"
  1198. }
  1199. ```
  1200. </CodeGroup>
  1201. </Col>
  1202. </Row>
  1203. ---
  1204. <Heading
  1205. url='/info'
  1206. method='GET'
  1207. title='获取应用基本信息'
  1208. name='#info'
  1209. />
  1210. <Row>
  1211. <Col>
  1212. 用于获取应用的基本信息
  1213. ### Response
  1214. - `name` (string) 应用名称
  1215. - `description` (string) 应用描述
  1216. - `tags` (array[string]) 应用标签
  1217. </Col>
  1218. <Col>
  1219. <CodeGroup
  1220. title="Request"
  1221. tag="GET"
  1222. label="/info"
  1223. targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\
  1224. -H 'Authorization: Bearer {api_key}'`}
  1225. />
  1226. <CodeGroup title="Response">
  1227. ```json {{ title: 'Response' }}
  1228. {
  1229. "name": "My App",
  1230. "description": "This is my app.",
  1231. "tags": [
  1232. "tag1",
  1233. "tag2"
  1234. ],
  1235. "mode": "advanced-chat",
  1236. "author_name": "Dify"
  1237. }
  1238. ```
  1239. </CodeGroup>
  1240. </Col>
  1241. </Row>
  1242. ---
  1243. <Heading
  1244. url='/parameters'
  1245. method='GET'
  1246. title='获取应用参数'
  1247. name='#parameters'
  1248. />
  1249. <Row>
  1250. <Col>
  1251. 用于进入页面一开始,获取功能开关、输入参数名称、类型及默认值等使用。
  1252. ### Response
  1253. - `opening_statement` (string) 开场白
  1254. - `suggested_questions` (array[string]) 开场推荐问题列表
  1255. - `suggested_questions_after_answer` (object) 启用回答后给出推荐问题。
  1256. - `enabled` (bool) 是否开启
  1257. - `speech_to_text` (object) 语音转文本
  1258. - `enabled` (bool) 是否开启
  1259. - `text_to_speech` (object) 文本转语音
  1260. - `enabled` (bool) 是否开启
  1261. - `voice` (string) 语音类型
  1262. - `language` (string) 语言
  1263. - `autoPlay` (string) 自动播放
  1264. - `enabled` 开启
  1265. - `disabled` 关闭
  1266. - `retriever_resource` (object) 引用和归属
  1267. - `enabled` (bool) 是否开启
  1268. - `annotation_reply` (object) 标记回复
  1269. - `enabled` (bool) 是否开启
  1270. - `user_input_form` (array[object]) 用户输入表单配置
  1271. - `text-input` (object) 文本输入控件
  1272. - `label` (string) 控件展示标签名
  1273. - `variable` (string) 控件 ID
  1274. - `required` (bool) 是否必填
  1275. - `default` (string) 默认值
  1276. - `paragraph` (object) 段落文本输入控件
  1277. - `label` (string) 控件展示标签名
  1278. - `variable` (string) 控件 ID
  1279. - `required` (bool) 是否必填
  1280. - `default` (string) 默认值
  1281. - `select` (object) 下拉控件
  1282. - `label` (string) 控件展示标签名
  1283. - `variable` (string) 控件 ID
  1284. - `required` (bool) 是否必填
  1285. - `default` (string) 默认值
  1286. - `options` (array[string]) 选项值
  1287. - `file_upload` (object) 文件上传配置
  1288. - `document` (object) 文档设置
  1289. 当前仅支持文档类型:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  1290. - `enabled` (bool) 是否启用
  1291. - `number_limits` (int) 文档数量限制,默认为 3
  1292. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  1293. - `image` (object) 图片设置
  1294. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  1295. - `enabled` (bool) 是否启用
  1296. - `number_limits` (int) 图片数量限制,默认为 3
  1297. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  1298. - `audio` (object) 音频设置
  1299. 当前仅支持音频类型:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  1300. - `enabled` (bool) 是否启用
  1301. - `number_limits` (int) 音频数量限制,默认为 3
  1302. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  1303. - `video` (object) 视频设置
  1304. 当前仅支持视频类型:`mp4`, `mov`, `mpeg`, `mpga`。
  1305. - `enabled` (bool) 是否启用
  1306. - `number_limits` (int) 视频数量限制,默认为 3
  1307. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  1308. - `custom` (object) 自定义设置
  1309. - `enabled` (bool) 是否启用
  1310. - `number_limits` (int) 自定义数量限制,默认为 3
  1311. - `transfer_methods` (array[string]) 传输方式列表:`remote_url`, `local_file`,必须选择一个。
  1312. - `system_parameters` (object) 系统参数
  1313. - `file_size_limit` (int) Document upload size limit (MB)
  1314. - `image_file_size_limit` (int) Image file upload size limit (MB)
  1315. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  1316. - `video_file_size_limit` (int) Video file upload size limit (MB)
  1317. </Col>
  1318. <Col sticky>
  1319. <CodeGroup
  1320. title="Request"
  1321. tag="GET"
  1322. label="/parameters"
  1323. targetCode={`curl -X GET '${props.appDetail.api_base_url}/parameters'`}
  1324. />
  1325. <CodeGroup title="Response">
  1326. ```json {{ title: 'Response' }}
  1327. {
  1328. "introduction": "nice to meet you",
  1329. "user_input_form": [
  1330. {
  1331. "text-input": {
  1332. "label": "a",
  1333. "variable": "a",
  1334. "required": true,
  1335. "max_length": 48,
  1336. "default": ""
  1337. }
  1338. },
  1339. {
  1340. // ...
  1341. }
  1342. ],
  1343. "file_upload": {
  1344. "image": {
  1345. "enabled": true,
  1346. "number_limits": 3,
  1347. "transfer_methods": [
  1348. "remote_url",
  1349. "local_file"
  1350. ]
  1351. }
  1352. },
  1353. "system_parameters": {
  1354. "file_size_limit": 15,
  1355. "image_file_size_limit": 10,
  1356. "audio_file_size_limit": 50,
  1357. "video_file_size_limit": 100
  1358. }
  1359. }
  1360. ```
  1361. </CodeGroup>
  1362. </Col>
  1363. </Row>
  1364. ---
  1365. <Heading
  1366. url='/meta'
  1367. method='GET'
  1368. title='获取应用Meta信息'
  1369. name='#meta'
  1370. />
  1371. <Row>
  1372. <Col>
  1373. 用于获取工具 icon
  1374. ### Response
  1375. - `tool_icons`(object[string]) 工具图标
  1376. - `工具名称` (string)
  1377. - `icon` (object|string)
  1378. - (object) 图标
  1379. - `background` (string) hex 格式的背景色
  1380. - `content`(string) emoji
  1381. - (string) 图标 URL
  1382. </Col>
  1383. <Col>
  1384. <CodeGroup
  1385. title="Request"
  1386. tag="GET"
  1387. label="/meta"
  1388. targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\
  1389. -H 'Authorization: Bearer {api_key}'`}
  1390. />
  1391. <CodeGroup title="Response">
  1392. ```json {{ title: 'Response' }}
  1393. {
  1394. "tool_icons": {
  1395. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1396. "api_tool": {
  1397. "background": "#252525",
  1398. "content": "\ud83d\ude01"
  1399. }
  1400. }
  1401. }
  1402. ```
  1403. </CodeGroup>
  1404. </Col>
  1405. </Row>
  1406. ---
  1407. <Heading
  1408. url='/site'
  1409. method='GET'
  1410. title='获取应用 WebApp 设置'
  1411. name='#site'
  1412. />
  1413. <Row>
  1414. <Col>
  1415. 用于获取应用的 WebApp 设置
  1416. ### Response
  1417. - `title` (string) WebApp 名称
  1418. - `chat_color_theme` (string) 聊天颜色主题,hex 格式
  1419. - `chat_color_theme_inverted` (bool) 聊天颜色主题是否反转
  1420. - `icon_type` (string) 图标类型,`emoji`-表情,`image`-图片
  1421. - `icon` (string) 图标,如果是 `emoji` 类型,则是 emoji 表情符号,如果是 `image` 类型,则是图片 URL
  1422. - `icon_background` (string) hex 格式的背景色
  1423. - `icon_url` (string) 图标 URL
  1424. - `description` (string) 描述
  1425. - `copyright` (string) 版权信息
  1426. - `privacy_policy` (string) 隐私政策链接
  1427. - `custom_disclaimer` (string) 自定义免责声明
  1428. - `default_language` (string) 默认语言
  1429. - `show_workflow_steps` (bool) 是否显示工作流详情
  1430. - `use_icon_as_answer_icon` (bool) 是否使用 WebApp 图标替换聊天中的 🤖
  1431. </Col>
  1432. <Col>
  1433. <CodeGroup
  1434. title="Request"
  1435. tag="GET"
  1436. label="/site"
  1437. targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\
  1438. -H 'Authorization: Bearer {api_key}'`}
  1439. />
  1440. <CodeGroup title="Response">
  1441. ```json {{ title: 'Response' }}
  1442. {
  1443. "title": "My App",
  1444. "chat_color_theme": "#ff4a4a",
  1445. "chat_color_theme_inverted": false,
  1446. "icon_type": "emoji",
  1447. "icon": "😄",
  1448. "icon_background": "#FFEAD5",
  1449. "icon_url": null,
  1450. "description": "This is my app.",
  1451. "copyright": "all rights reserved",
  1452. "privacy_policy": "",
  1453. "custom_disclaimer": "All generated by AI",
  1454. "default_language": "en-US",
  1455. "show_workflow_steps": false,
  1456. "use_icon_as_answer_icon": false,
  1457. }
  1458. ```
  1459. </CodeGroup>
  1460. </Col>
  1461. </Row>
  1462. ___
  1463. <Heading
  1464. url='/apps/annotations'
  1465. method='GET'
  1466. title='获取标注列表'
  1467. name='#annotation_list'
  1468. />
  1469. <Row>
  1470. <Col>
  1471. ### Query
  1472. <Properties>
  1473. <Property name='page' type='string' key='page'>
  1474. 页码
  1475. </Property>
  1476. <Property name='limit' type='string' key='limit'>
  1477. 每页数量
  1478. </Property>
  1479. </Properties>
  1480. </Col>
  1481. <Col sticky>
  1482. <CodeGroup
  1483. title="Request"
  1484. tag="GET"
  1485. label="/apps/annotations"
  1486. targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/apps/annotations?page=1&limit=20' \\
  1487. --header 'Authorization: Bearer {api_key}'`}
  1488. />
  1489. <CodeGroup title="Response">
  1490. ```json {{ title: 'Response' }}
  1491. {
  1492. "data": [
  1493. {
  1494. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1495. "question": "What is your name?",
  1496. "answer": "I am Dify.",
  1497. "hit_count": 0,
  1498. "created_at": 1735625869
  1499. }
  1500. ],
  1501. "has_more": false,
  1502. "limit": 20,
  1503. "total": 1,
  1504. "page": 1
  1505. }
  1506. ```
  1507. </CodeGroup>
  1508. </Col>
  1509. </Row>
  1510. ---
  1511. <Heading
  1512. url='/apps/annotations'
  1513. method='POST'
  1514. title='创建标注'
  1515. name='#create_annotation'
  1516. />
  1517. <Row>
  1518. <Col>
  1519. ### Query
  1520. <Properties>
  1521. <Property name='question' type='string' key='question'>
  1522. 问题
  1523. </Property>
  1524. <Property name='answer' type='string' key='answer'>
  1525. 答案内容
  1526. </Property>
  1527. </Properties>
  1528. </Col>
  1529. <Col sticky>
  1530. <CodeGroup
  1531. title="Request"
  1532. tag="POST"
  1533. label="/apps/annotations"
  1534. targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/apps/annotations' \\
  1535. --header 'Authorization: Bearer {api_key}' \\
  1536. --header 'Content-Type: application/json' \\
  1537. --data-raw '{
  1538. "question": "What is your name?",
  1539. "answer": "I am Dify."
  1540. }'`}
  1541. />
  1542. <CodeGroup title="Response">
  1543. ```json {{ title: 'Response' }}
  1544. {
  1545. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1546. "question": "What is your name?",
  1547. "answer": "I am Dify.",
  1548. "hit_count": 0,
  1549. "created_at": 1735625869
  1550. }
  1551. ```
  1552. </CodeGroup>
  1553. </Col>
  1554. </Row>
  1555. ---
  1556. <Heading
  1557. url='/apps/annotations/{annotation_id}'
  1558. method='PUT'
  1559. title='更新标注'
  1560. name='#update_annotation'
  1561. />
  1562. <Row>
  1563. <Col>
  1564. ### Query
  1565. <Properties>
  1566. <Property name='annotation_id' type='string' key='annotation_id'>
  1567. 标注 ID
  1568. </Property>
  1569. <Property name='question' type='string' key='question'>
  1570. 问题
  1571. </Property>
  1572. <Property name='answer' type='string' key='answer'>
  1573. 答案内容
  1574. </Property>
  1575. </Properties>
  1576. </Col>
  1577. <Col sticky>
  1578. <CodeGroup
  1579. title="Request"
  1580. tag="PUT"
  1581. label="/apps/annotations/{annotation_id}"
  1582. targetCode={`curl --location --request PUT '${props.appDetail.api_base_url}/apps/annotations/{annotation_id}' \\
  1583. --header 'Authorization: Bearer {api_key}' \\
  1584. --header 'Content-Type: application/json' \\
  1585. --data-raw '{
  1586. "question": "What is your name?",
  1587. "answer": "I am Dify."
  1588. }'`}
  1589. />
  1590. <CodeGroup title="Response">
  1591. ```json {{ title: 'Response' }}
  1592. {
  1593. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1594. "question": "What is your name?",
  1595. "answer": "I am Dify.",
  1596. "hit_count": 0,
  1597. "created_at": 1735625869
  1598. }
  1599. ```
  1600. </CodeGroup>
  1601. </Col>
  1602. </Row>
  1603. ---
  1604. <Heading
  1605. url='/apps/annotations/{annotation_id}'
  1606. method='DELETE'
  1607. title='删除标注'
  1608. name='#delete_annotation'
  1609. />
  1610. <Row>
  1611. <Col>
  1612. ### Query
  1613. <Properties>
  1614. <Property name='annotation_id' type='string' key='annotation_id'>
  1615. 标注 ID
  1616. </Property>
  1617. </Properties>
  1618. </Col>
  1619. <Col sticky>
  1620. <CodeGroup
  1621. title="Request"
  1622. tag="DELETE"
  1623. label="/apps/annotations/{annotation_id}"
  1624. targetCode={`curl --location --request DELETE '${props.appDetail.api_base_url}/apps/annotations/{annotation_id}' \\
  1625. --header 'Authorization: Bearer {api_key}' \\
  1626. --header 'Content-Type: application/json'`}
  1627. />
  1628. <CodeGroup title="Response">
  1629. ```text {{ title: 'Response' }}
  1630. 204 No Content
  1631. ```
  1632. </CodeGroup>
  1633. </Col>
  1634. </Row>
  1635. ---
  1636. <Heading
  1637. url='/apps/annotation-reply/{action}'
  1638. method='POST'
  1639. title='标注回复初始设置'
  1640. name='#initial_annotation_reply_settings'
  1641. />
  1642. <Row>
  1643. <Col>
  1644. ### Query
  1645. <Properties>
  1646. <Property name='action' type='string' key='action'>
  1647. 动作,只能是 'enable' 或 'disable'
  1648. </Property>
  1649. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  1650. 指定的嵌入模型提供商,必须先在系统内设定好接入的模型,对应的是 provider 字段
  1651. </Property>
  1652. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  1653. 指定的嵌入模型,对应的是 model 字段
  1654. </Property>
  1655. <Property name='score_threshold' type='number' key='score_threshold'>
  1656. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  1657. </Property>
  1658. </Properties>
  1659. </Col>
  1660. <Col sticky>
  1661. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding,具体见:通过 API 维护知识库。使用的 Authorization 是 Dataset 的 API Token。
  1662. <CodeGroup
  1663. title="Request"
  1664. tag="POST"
  1665. label="/apps/annotation-reply/{action}"
  1666. targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/apps/annotation-reply/{action}' \\
  1667. --header 'Authorization: Bearer {api_key}' \\
  1668. --header 'Content-Type: application/json' \\
  1669. --data-raw '{
  1670. "score_threshold": 0.9,
  1671. "embedding_provider_name": "zhipu",
  1672. "embedding_model_name": "embedding_3"
  1673. }'`}
  1674. />
  1675. <CodeGroup title="Response">
  1676. ```json {{ title: 'Response' }}
  1677. {
  1678. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1679. "job_status": "waiting"
  1680. }
  1681. ```
  1682. </CodeGroup>
  1683. 该接口是异步执行,所以会返回一个job_id,通过查询job状态接口可以获取到最终的执行结果。
  1684. </Col>
  1685. </Row>
  1686. ---
  1687. <Heading
  1688. url='/apps/annotation-reply/{action}/status/{job_id}'
  1689. method='GET'
  1690. title='查询标注回复初始设置任务状态'
  1691. name='#initial_annotation_reply_settings_task_status'
  1692. />
  1693. <Row>
  1694. <Col>
  1695. ### Query
  1696. <Properties>
  1697. <Property name='action' type='string' key='action'>
  1698. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  1699. </Property>
  1700. <Property name='job_id' type='string' key='job_id'>
  1701. 任务 ID,从标注回复初始设置接口返回的 job_id
  1702. </Property>
  1703. </Properties>
  1704. </Col>
  1705. <Col sticky>
  1706. <CodeGroup
  1707. title="Request"
  1708. tag="GET"
  1709. label="/apps/annotations"
  1710. targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/apps/annotation-reply/{action}/status/{job_id}' \\
  1711. --header 'Authorization: Bearer {api_key}'`}
  1712. />
  1713. <CodeGroup title="Response">
  1714. ```json {{ title: 'Response' }}
  1715. {
  1716. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1717. "job_status": "waiting",
  1718. "error_msg": ""
  1719. }
  1720. ```
  1721. </CodeGroup>
  1722. </Col>
  1723. </Row>