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

template_advanced_chat.zh.mdx 61KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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. - `text_to_speech` (object) 文本转语音
  1071. - `enabled` (bool) 是否开启
  1072. - `voice` (string) 语音类型
  1073. - `language` (string) 语言
  1074. - `autoPlay` (string) 自动播放
  1075. - `enabled` 开启
  1076. - `disabled` 关闭
  1077. - `retriever_resource` (object) 引用和归属
  1078. - `enabled` (bool) 是否开启
  1079. - `annotation_reply` (object) 标记回复
  1080. - `enabled` (bool) 是否开启
  1081. - `user_input_form` (array[object]) 用户输入表单配置
  1082. - `text-input` (object) 文本输入控件
  1083. - `label` (string) 控件展示标签名
  1084. - `variable` (string) 控件 ID
  1085. - `required` (bool) 是否必填
  1086. - `default` (string) 默认值
  1087. - `paragraph` (object) 段落文本输入控件
  1088. - `label` (string) 控件展示标签名
  1089. - `variable` (string) 控件 ID
  1090. - `required` (bool) 是否必填
  1091. - `default` (string) 默认值
  1092. - `select` (object) 下拉控件
  1093. - `label` (string) 控件展示标签名
  1094. - `variable` (string) 控件 ID
  1095. - `required` (bool) 是否必填
  1096. - `default` (string) 默认值
  1097. - `options` (array[string]) 选项值
  1098. - `file_upload` (object) 文件上传配置
  1099. - `image` (object) 图片设置
  1100. 当前仅支持图片类型:`png`, `jpg`, `jpeg`, `webp`, `gif`
  1101. - `enabled` (bool) 是否开启
  1102. - `number_limits` (int) 图片数量限制,默认 3
  1103. - `transfer_methods` (array[string]) 传递方式列表,remote_url , local_file,必选一个
  1104. - `system_parameters` (object) 系统参数
  1105. - `file_size_limit` (int) Document upload size limit (MB)
  1106. - `image_file_size_limit` (int) Image file upload size limit (MB)
  1107. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  1108. - `video_file_size_limit` (int) Video file upload size limit (MB)
  1109. </Col>
  1110. <Col sticky>
  1111. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer {api_key}'`}>
  1112. ```bash {{ title: 'cURL' }}
  1113. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  1114. --header 'Authorization: Bearer {api_key}'
  1115. ```
  1116. </CodeGroup>
  1117. <CodeGroup title="Response">
  1118. ```json {{ title: 'Response' }}
  1119. {
  1120. "introduction": "nice to meet you",
  1121. "user_input_form": [
  1122. {
  1123. "text-input": {
  1124. "label": "a",
  1125. "variable": "a",
  1126. "required": true,
  1127. "max_length": 48,
  1128. "default": ""
  1129. }
  1130. },
  1131. {
  1132. // ...
  1133. }
  1134. ],
  1135. "file_upload": {
  1136. "image": {
  1137. "enabled": true,
  1138. "number_limits": 3,
  1139. "transfer_methods": [
  1140. "remote_url",
  1141. "local_file"
  1142. ]
  1143. }
  1144. },
  1145. "system_parameters": {
  1146. "file_size_limit": 15,
  1147. "image_file_size_limit": 10,
  1148. "audio_file_size_limit": 50,
  1149. "video_file_size_limit": 100
  1150. }
  1151. }
  1152. ```
  1153. </CodeGroup>
  1154. </Col>
  1155. </Row>
  1156. ---
  1157. <Heading
  1158. url='/meta'
  1159. method='GET'
  1160. title='获取应用Meta信息'
  1161. name='#meta'
  1162. />
  1163. <Row>
  1164. <Col>
  1165. 用于获取工具icon
  1166. ### Response
  1167. - `tool_icons`(object[string]) 工具图标
  1168. - `工具名称` (string)
  1169. - `icon` (object|string)
  1170. - (object) 图标
  1171. - `background` (string) hex格式的背景色
  1172. - `content`(string) emoji
  1173. - (string) 图标URL
  1174. </Col>
  1175. <Col>
  1176. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1177. ```bash {{ title: 'cURL' }}
  1178. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1179. -H 'Authorization: Bearer {api_key}'
  1180. ```
  1181. </CodeGroup>
  1182. <CodeGroup title="Response">
  1183. ```json {{ title: 'Response' }}
  1184. {
  1185. "tool_icons": {
  1186. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1187. "api_tool": {
  1188. "background": "#252525",
  1189. "content": "\ud83d\ude01"
  1190. }
  1191. }
  1192. }
  1193. ```
  1194. </CodeGroup>
  1195. </Col>
  1196. </Row>
  1197. ---
  1198. <Heading
  1199. url='/site'
  1200. method='GET'
  1201. title='获取应用 WebApp 设置'
  1202. name='#site'
  1203. />
  1204. <Row>
  1205. <Col>
  1206. 用于获取应用的 WebApp 设置
  1207. ### Response
  1208. - `title` (string) WebApp 名称
  1209. - `chat_color_theme` (string) 聊天颜色主题, hex 格式
  1210. - `chat_color_theme_inverted` (bool) 聊天颜色主题是否反转
  1211. - `icon_type` (string) 图标类型, `emoji`-表情, `image`-图片
  1212. - `icon` (string) 图标, 如果是 `emoji` 类型, 则是 emoji 表情符号, 如果是 `image` 类型, 则是图片 URL
  1213. - `icon_background` (string) hex 格式的背景色
  1214. - `icon_url` (string) 图标 URL
  1215. - `description` (string) 描述
  1216. - `copyright` (string) 版权信息
  1217. - `privacy_policy` (string) 隐私政策链接
  1218. - `custom_disclaimer` (string) 自定义免责声明
  1219. - `default_language` (string) 默认语言
  1220. - `show_workflow_steps` (bool) 是否显示工作流详情
  1221. - `use_icon_as_answer_icon` (bool) 是否使用 WebApp 图标替换聊天中的 🤖
  1222. </Col>
  1223. <Col>
  1224. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1225. ```bash {{ title: 'cURL' }}
  1226. curl -X GET '${props.appDetail.api_base_url}/site' \
  1227. -H 'Authorization: Bearer {api_key}'
  1228. ```
  1229. </CodeGroup>
  1230. <CodeGroup title="Response">
  1231. ```json {{ title: 'Response' }}
  1232. {
  1233. "title": "My App",
  1234. "chat_color_theme": "#ff4a4a",
  1235. "chat_color_theme_inverted": false,
  1236. "icon_type": "emoji",
  1237. "icon": "😄",
  1238. "icon_background": "#FFEAD5",
  1239. "icon_url": null,
  1240. "description": "This is my app.",
  1241. "copyright": "all rights reserved",
  1242. "privacy_policy": "",
  1243. "custom_disclaimer": "All generated by AI",
  1244. "default_language": "en-US",
  1245. "show_workflow_steps": false,
  1246. "use_icon_as_answer_icon": false,
  1247. }
  1248. ```
  1249. </CodeGroup>
  1250. </Col>
  1251. </Row>
  1252. ___
  1253. <Heading
  1254. url='/apps/annotations'
  1255. method='GET'
  1256. title='获取标注列表'
  1257. name='#annotation_list'
  1258. />
  1259. <Row>
  1260. <Col>
  1261. ### Query
  1262. <Properties>
  1263. <Property name='page' type='string' key='page'>
  1264. 页码
  1265. </Property>
  1266. <Property name='limit' type='string' key='limit'>
  1267. 每页数量
  1268. </Property>
  1269. </Properties>
  1270. </Col>
  1271. <Col sticky>
  1272. <CodeGroup
  1273. title="Request"
  1274. tag="GET"
  1275. label="/apps/annotations"
  1276. targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1277. >
  1278. ```bash {{ title: 'cURL' }}
  1279. curl --location --request GET '${props.appDetail.api_base_url}/apps/annotations?page=1&limit=20' \
  1280. --header 'Authorization: Bearer {api_key}'
  1281. ```
  1282. </CodeGroup>
  1283. <CodeGroup title="Response">
  1284. ```json {{ title: 'Response' }}
  1285. {
  1286. "data": [
  1287. {
  1288. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1289. "question": "What is your name?",
  1290. "answer": "I am Dify.",
  1291. "hit_count": 0,
  1292. "created_at": 1735625869
  1293. }
  1294. ],
  1295. "has_more": false,
  1296. "limit": 20,
  1297. "total": 1,
  1298. "page": 1
  1299. }
  1300. ```
  1301. </CodeGroup>
  1302. </Col>
  1303. </Row>
  1304. ---
  1305. <Heading
  1306. url='/apps/annotations'
  1307. method='POST'
  1308. title='创建标注'
  1309. name='#create_annotation'
  1310. />
  1311. <Row>
  1312. <Col>
  1313. ### Query
  1314. <Properties>
  1315. <Property name='question' type='string' key='question'>
  1316. 问题
  1317. </Property>
  1318. <Property name='answer' type='string' key='answer'>
  1319. 答案内容
  1320. </Property>
  1321. </Properties>
  1322. </Col>
  1323. <Col sticky>
  1324. <CodeGroup
  1325. title="Request"
  1326. tag="POST"
  1327. label="/apps/annotations"
  1328. 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."}'`}
  1329. >
  1330. ```bash {{ title: 'cURL' }}
  1331. curl --location --request POST '${props.appDetail.api_base_url}/apps/annotations' \
  1332. --header 'Authorization: Bearer {api_key}' \
  1333. --header 'Content-Type: application/json' \
  1334. --data-raw '{
  1335. "question": "What is your name?",
  1336. "answer": "I am Dify."
  1337. }'
  1338. ```
  1339. </CodeGroup>
  1340. <CodeGroup title="Response">
  1341. ```json {{ title: 'Response' }}
  1342. {
  1343. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1344. "question": "What is your name?",
  1345. "answer": "I am Dify.",
  1346. "hit_count": 0,
  1347. "created_at": 1735625869
  1348. }
  1349. ```
  1350. </CodeGroup>
  1351. </Col>
  1352. </Row>
  1353. ---
  1354. <Heading
  1355. url='/apps/annotations/{annotation_id}'
  1356. method='PUT'
  1357. title='更新标注'
  1358. name='#update_annotation'
  1359. />
  1360. <Row>
  1361. <Col>
  1362. ### Query
  1363. <Properties>
  1364. <Property name='annotation_id' type='string' key='annotation_id'>
  1365. 标注 ID
  1366. </Property>
  1367. <Property name='question' type='string' key='question'>
  1368. 问题
  1369. </Property>
  1370. <Property name='answer' type='string' key='answer'>
  1371. 答案内容
  1372. </Property>
  1373. </Properties>
  1374. </Col>
  1375. <Col sticky>
  1376. <CodeGroup
  1377. title="Request"
  1378. tag="PUT"
  1379. label="/apps/annotations/{annotation_id}"
  1380. 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."}'`}
  1381. >
  1382. ```bash {{ title: 'cURL' }}
  1383. curl --location --request PUT '${props.appDetail.api_base_url}/apps/annotations/{annotation_id}' \
  1384. --header 'Authorization: Bearer {api_key}' \
  1385. --header 'Content-Type: application/json' \
  1386. --data-raw '{
  1387. "question": "What is your name?",
  1388. "answer": "I am Dify."
  1389. }'
  1390. ```
  1391. </CodeGroup>
  1392. <CodeGroup title="Response">
  1393. ```json {{ title: 'Response' }}
  1394. {
  1395. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1396. "question": "What is your name?",
  1397. "answer": "I am Dify.",
  1398. "hit_count": 0,
  1399. "created_at": 1735625869
  1400. }
  1401. ```
  1402. </CodeGroup>
  1403. </Col>
  1404. </Row>
  1405. ---
  1406. <Heading
  1407. url='/apps/annotations/{annotation_id}'
  1408. method='DELETE'
  1409. title='删除标注'
  1410. name='#delete_annotation'
  1411. />
  1412. <Row>
  1413. <Col>
  1414. ### Query
  1415. <Properties>
  1416. <Property name='annotation_id' type='string' key='annotation_id'>
  1417. 标注 ID
  1418. </Property>
  1419. </Properties>
  1420. </Col>
  1421. <Col sticky>
  1422. <CodeGroup
  1423. title="Request"
  1424. tag="PUT"
  1425. label="/apps/annotations/{annotation_id}"
  1426. 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'`}
  1427. >
  1428. ```bash {{ title: 'cURL' }}
  1429. curl --location --request DELETE '${props.appDetail.api_base_url}/apps/annotations/{annotation_id}' \
  1430. --header 'Authorization: Bearer {api_key}'
  1431. ```
  1432. </CodeGroup>
  1433. <CodeGroup title="Response">
  1434. ```text {{ title: 'Response' }}
  1435. 204 No Content
  1436. ```
  1437. </CodeGroup>
  1438. </Col>
  1439. </Row>
  1440. ---
  1441. <Heading
  1442. url='/apps/annotation-reply/{action}'
  1443. method='POST'
  1444. title='标注回复初始设置'
  1445. name='#initial_annotation_reply_settings'
  1446. />
  1447. <Row>
  1448. <Col>
  1449. ### Query
  1450. <Properties>
  1451. <Property name='action' type='string' key='action'>
  1452. 动作,只能是 'enable' 或 'disable'
  1453. </Property>
  1454. <Property name='embedding_provider_name' type='string' key='embedding_provider_name'>
  1455. 指定的嵌入模型提供商, 必须先在系统内设定好接入的模型,对应的是provider字段
  1456. </Property>
  1457. <Property name='embedding_model_name' type='string' key='embedding_model_name'>
  1458. 指定的嵌入模型,对应的是model字段
  1459. </Property>
  1460. <Property name='score_threshold' type='number' key='score_threshold'>
  1461. 相似度阈值,当相似度大于该阈值时,系统会自动回复,否则不回复
  1462. </Property>
  1463. </Properties>
  1464. </Col>
  1465. <Col sticky>
  1466. 嵌入模型的提供商和模型名称可以通过以下接口获取:v1/workspaces/current/models/model-types/text-embedding, 具体见:通过 API 维护知识库。 使用的Authorization是Dataset的API Token。
  1467. <CodeGroup
  1468. title="Request"
  1469. tag="POST"
  1470. label="/apps/annotation-reply/{action}"
  1471. 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"}'`}
  1472. >
  1473. ```bash {{ title: 'cURL' }}
  1474. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  1475. --header 'Authorization: Bearer {api_key}' \
  1476. --header 'Content-Type: application/json' \
  1477. --data-raw '{
  1478. "score_threshold": 0.9,
  1479. "embedding_provider_name": "zhipu",
  1480. "embedding_model_name": "embedding_3"
  1481. }'
  1482. ```
  1483. </CodeGroup>
  1484. <CodeGroup title="Response">
  1485. ```json {{ title: 'Response' }}
  1486. {
  1487. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1488. "job_status": "waiting"
  1489. }
  1490. ```
  1491. </CodeGroup>
  1492. 该接口是异步执行,所以会返回一个job_id,通过查询job状态接口可以获取到最终的执行结果。
  1493. </Col>
  1494. </Row>
  1495. ---
  1496. <Heading
  1497. url='/apps/annotation-reply/{action}/status/{job_id}'
  1498. method='GET'
  1499. title='查询标注回复初始设置任务状态'
  1500. name='#initial_annotation_reply_settings_task_status'
  1501. />
  1502. <Row>
  1503. <Col>
  1504. ### Query
  1505. <Properties>
  1506. <Property name='action' type='string' key='action'>
  1507. 动作,只能是 'enable' 或 'disable',并且必须和标注回复初始设置接口的动作一致
  1508. </Property>
  1509. <Property name='job_id' type='string' key='job_id'>
  1510. 任务 ID,从标注回复初始设置接口返回的 job_id
  1511. </Property>
  1512. </Properties>
  1513. </Col>
  1514. <Col sticky>
  1515. <CodeGroup
  1516. title="Request"
  1517. tag="GET"
  1518. label="/apps/annotations"
  1519. targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1520. >
  1521. ```bash {{ title: 'cURL' }}
  1522. curl --location --request GET '${props.appDetail.api_base_url}/apps/annotation-reply/{action}/status/{job_id}' \
  1523. --header 'Authorization: Bearer {api_key}'
  1524. ```
  1525. </CodeGroup>
  1526. <CodeGroup title="Response">
  1527. ```json {{ title: 'Response' }}
  1528. {
  1529. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1530. "job_status": "waiting",
  1531. "error_msg": ""
  1532. }
  1533. ```
  1534. </CodeGroup>
  1535. </Col>
  1536. </Row>