您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

template_advanced_chat.zh.mdx 61KB

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