Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

template_advanced_chat.zh.mdx 63KB

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