You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_advanced_chat.zh.mdx 61KB

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