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 61KB

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