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

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