Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

template_advanced_chat.zh.mdx 68KB

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