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_chat.zh.mdx 62KB

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