Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

template_chat.zh.mdx 63KB

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