您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

template_chat.en.mdx 65KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Chat App API
  4. Chat applications support session persistence, allowing previous chat history to be used as context for responses. This can be applicable for chatbot, customer service AI, etc.
  5. <div>
  6. ### Base URL
  7. <CodeGroup title="Code" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### Authentication
  12. The Service API uses `API-Key` authentication.
  13. <i>**Strongly recommend storing your API Key on the server-side, not shared or stored on the client-side, to avoid possible API-Key leakage that can lead to serious consequences.**</i>
  14. For all API requests, include your API Key in the `Authorization`HTTP Header, as shown below:
  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='Send Chat Message'
  26. name='#Send-Chat-Message'
  27. />
  28. <Row>
  29. <Col>
  30. Send a request to the chat application.
  31. ### Request Body
  32. <Properties>
  33. <Property name='query' type='string' key='query'>
  34. User Input/Question content
  35. </Property>
  36. <Property name='inputs' type='object' key='inputs'>
  37. Allows the entry of various variable values defined by the App.
  38. The `inputs` parameter contains multiple key/value pairs, with each key corresponding to a specific variable and each value being the specific value for that variable. Default `{}`
  39. </Property>
  40. <Property name='response_mode' type='string' key='response_mode'>
  41. The mode of response return, supporting:
  42. - `streaming` Streaming mode (recommended), implements a typewriter-like output through SSE ([Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)).
  43. - `blocking` Blocking mode, returns result after execution is complete. (Requests may be interrupted if the process is long)
  44. Due to Cloudflare restrictions, the request will be interrupted without a return after 100 seconds.
  45. <i>Note: blocking mode is not supported in Agent Assistant mode</i>
  46. </Property>
  47. <Property name='user' type='string' key='user'>
  48. User identifier, used to define the identity of the end-user for retrieval and statistics.
  49. Should be uniquely defined by the developer within the application.
  50. </Property>
  51. <Property name='conversation_id' type='string' key='conversation_id'>
  52. Conversation ID, to continue the conversation based on previous chat records, it is necessary to pass the previous message's conversation_id.
  53. </Property>
  54. <Property name='files' type='array[object]' key='files'>
  55. File list, suitable for inputting files (images) combined with text understanding and answering questions, available only when the model supports Vision capability.
  56. - `type` (string) Supported type: `image` (currently only supports image type)
  57. - `transfer_method` (string) Transfer method, `remote_url` for image URL / `local_file` for file upload
  58. - `url` (string) Image URL (when the transfer method is `remote_url`)
  59. - `upload_file_id` (string) Uploaded file ID, which must be obtained by uploading through the File Upload API in advance (when the transfer method is `local_file`)
  60. </Property>
  61. <Property name='auto_generate_name' type='bool' key='auto_generate_name'>
  62. Auto-generate title, default is `true`.
  63. If set to `false`, can achieve async title generation by calling the conversation rename API and setting `auto_generate` to `true`.
  64. </Property>
  65. </Properties>
  66. ### Response
  67. When response_mode is blocking, return a CompletionResponse object.
  68. When response_mode is streaming, return a ChunkCompletionResponse stream.
  69. ### ChatCompletionResponse
  70. Returns the complete App result, `Content-Type` is `application/json`.
  71. - `event` (string) 事件类型,固定为 `message`
  72. - `task_id` (string) 任务 ID,用于请求跟踪和下方的停止响应接口
  73. - `id` (string) 唯一ID
  74. - `message_id` (string) Unique message ID
  75. - `conversation_id` (string) Conversation ID
  76. - `mode` (string) App mode, fixed as `chat`
  77. - `answer` (string) Complete response content
  78. - `metadata` (object) Metadata
  79. - `usage` (Usage) Model usage information
  80. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  81. - `created_at` (int) Message creation timestamp, e.g., 1705395332
  82. ### ChunkChatCompletionResponse
  83. Returns the stream chunks outputted by the App, `Content-Type` is `text/event-stream`.
  84. Each streaming chunk starts with `data:`, separated by two newline characters `\n\n`, as shown below:
  85. <CodeGroup>
  86. ```streaming {{ title: 'Response' }}
  87. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  88. ```
  89. </CodeGroup>
  90. The structure of the streaming chunks varies depending on the `event`:
  91. - `event: message` LLM returns text chunk event, i.e., the complete text is output in a chunked fashion.
  92. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  93. - `message_id` (string) Unique message ID
  94. - `conversation_id` (string) Conversation ID
  95. - `answer` (string) LLM returned text chunk content
  96. - `created_at` (int) Creation timestamp, e.g., 1705395332
  97. - `event: agent_message` LLM returns text chunk event, i.e., with Agent Assistant enabled, the complete text is output in a chunked fashion (Only supported in Agent mode)
  98. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  99. - `message_id` (string) Unique message ID
  100. - `conversation_id` (string) Conversation ID
  101. - `answer` (string) LLM returned text chunk content
  102. - `created_at` (int) Creation timestamp, e.g., 1705395332
  103. - `event: tts_message` TTS audio stream event, that is, speech synthesis output. The content is an audio block in Mp3 format, encoded as a base64 string. When playing, simply decode the base64 and feed it into the player. (This message is available only when auto-play is enabled)
  104. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  105. - `message_id` (string) Unique message ID
  106. - `audio` (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player
  107. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  108. - `event: tts_message_end` TTS audio stream end event, receiving this event indicates the end of the audio stream.
  109. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  110. - `message_id` (string) Unique message ID
  111. - `audio` (string) The end event has no audio, so this is an empty string
  112. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  113. - `event: agent_thought` thought of Agent, contains the thought of LLM, input and output of tool calls (Only supported in Agent mode)
  114. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  115. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  116. - `message_id` (string) Unique message ID
  117. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  118. - `thought` (string) What LLM is thinking about
  119. - `observation` (string) Response from tool calls
  120. - `tool` (string) A list of tools represents which tools are called,split by ;
  121. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  122. - `created_at` (int) Creation timestamp, e.g., 1705395332
  123. - `message_files` (array[string]) Refer to message_file event
  124. - `file_id` (string) File ID
  125. - `conversation_id` (string) Conversation ID
  126. - `event: message_file` Message file event, a new file has created by tool
  127. - `id` (string) File unique ID
  128. - `type` (string) File type,only allow "image" currently
  129. - `belongs_to` (string) Belongs to, it will only be an 'assistant' here
  130. - `url` (string) Remote url of file
  131. - `conversation_id` (string) Conversation ID
  132. - `event: message_end` Message end event, receiving this event means streaming has ended.
  133. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  134. - `message_id` (string) Unique message ID
  135. - `conversation_id` (string) Conversation ID
  136. - `metadata` (object) Metadata
  137. - `usage` (Usage) Model usage information
  138. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  139. - `event: message_replace` Message content replacement event.
  140. When output content moderation is enabled, if the content is flagged, then the message content will be replaced with a preset reply through this event.
  141. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  142. - `message_id` (string) Unique message ID
  143. - `conversation_id` (string) Conversation ID
  144. - `answer` (string) Replacement content (directly replaces all LLM reply text)
  145. - `created_at` (int) Creation timestamp, e.g., 1705395332
  146. - `event: error`
  147. Exceptions that occur during the streaming process will be output in the form of stream events, and reception of an error event will end the stream.
  148. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  149. - `message_id` (string) Unique message ID
  150. - `status` (int) HTTP status code
  151. - `code` (string) Error code
  152. - `message` (string) Error message
  153. - `event: ping` Ping event every 10 seconds to keep the connection alive.
  154. ### Errors
  155. - 404, Conversation does not exists
  156. - 400, `invalid_param`, abnormal parameter input
  157. - 400, `app_unavailable`, App configuration unavailable
  158. - 400, `provider_not_initialize`, no available model credential configuration
  159. - 400, `provider_quota_exceeded`, model invocation quota insufficient
  160. - 400, `model_currently_not_support`, current model unavailable
  161. - 400, `completion_request_error`, text generation failed
  162. - 500, internal server error
  163. </Col>
  164. <Col sticky>
  165. <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}'`}>
  166. ```bash {{ title: 'cURL' }}
  167. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  168. --header 'Authorization: Bearer {api_key}' \
  169. --header 'Content-Type: application/json' \
  170. --data-raw '{
  171. "inputs": {},
  172. "query": "eh",
  173. "response_mode": "streaming",
  174. "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  175. "user": "abc-123"
  176. }'
  177. ```
  178. </CodeGroup>
  179. ### Blocking Mode
  180. <CodeGroup title="Response">
  181. ```json {{ title: 'Response' }}
  182. {
  183. "event": "message",
  184. "task_id": "c3800678-a077-43df-a102-53f23ed20b88",
  185. "id": "9da23599-e713-473b-982c-4328d4f5c78a",
  186. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  187. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  188. "mode": "chat",
  189. "answer": "iPhone 13 Pro Max specs are listed here:...",
  190. "metadata": {
  191. "usage": {
  192. "prompt_tokens": 1033,
  193. "prompt_unit_price": "0.001",
  194. "prompt_price_unit": "0.001",
  195. "prompt_price": "0.0010330",
  196. "completion_tokens": 128,
  197. "completion_unit_price": "0.002",
  198. "completion_price_unit": "0.001",
  199. "completion_price": "0.0002560",
  200. "total_tokens": 1161,
  201. "total_price": "0.0012890",
  202. "currency": "USD",
  203. "latency": 0.7682376249867957
  204. },
  205. "retriever_resources": [
  206. {
  207. "position": 1,
  208. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  209. "dataset_name": "iPhone",
  210. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  211. "document_name": "iPhone List",
  212. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  213. "score": 0.98457545,
  214. "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\""
  215. }
  216. ]
  217. },
  218. "created_at": 1705407629
  219. }
  220. ```
  221. </CodeGroup>
  222. ### Streaming Mode ( Basic Assistant )
  223. <CodeGroup title="Response">
  224. ```streaming {{ title: 'Response' }}
  225. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  226. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  227. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  228. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  229. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  230. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  231. 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\""}]}}
  232. 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"}
  233. 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": ""}
  234. ```
  235. </CodeGroup>
  236. ### Response Example(Agent Assistant)
  237. <CodeGroup title="Response">
  238. ```streaming {{ title: 'Response' }}
  239. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  240. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  241. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  242. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  243. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  244. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  245. 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\""}]}}
  246. 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"}
  247. 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": ""}
  248. ```
  249. </CodeGroup>
  250. </Col>
  251. </Row>
  252. ---
  253. <Heading
  254. url='/files/upload'
  255. method='POST'
  256. title='File Upload'
  257. name='#file-upload'
  258. />
  259. <Row>
  260. <Col>
  261. Upload a file (currently only images are supported) for use when sending messages, enabling multimodal understanding of images and text.
  262. Supports png, jpg, jpeg, webp, gif formats.
  263. Uploaded files are for use by the current end-user only.
  264. ### Request Body
  265. This interface requires a `multipart/form-data` request.
  266. - `file` (File) Required
  267. The file to be uploaded.
  268. - `user` (string) Required
  269. User identifier, defined by the developer's rules, must be unique within the application.
  270. ### Response
  271. After a successful upload, the server will return the file's ID and related information.
  272. - `id` (uuid) ID
  273. - `name` (string) File name
  274. - `size` (int) File size (bytes)
  275. - `extension` (string) File extension
  276. - `mime_type` (string) File mime-type
  277. - `created_by` (uuid) End-user ID
  278. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  279. ### Errors
  280. - 400, `no_file_uploaded`, a file must be provided
  281. - 400, `too_many_files`, currently only one file is accepted
  282. - 400, `unsupported_preview`, the file does not support preview
  283. - 400, `unsupported_estimate`, the file does not support estimation
  284. - 413, `file_too_large`, the file is too large
  285. - 415, `unsupported_file_type`, unsupported extension, currently only document files are accepted
  286. - 503, `s3_connection_failed`, unable to connect to S3 service
  287. - 503, `s3_permission_denied`, no permission to upload files to S3
  288. - 503, `s3_file_too_large`, file exceeds S3 size limit
  289. - 500, internal server error
  290. </Col>
  291. <Col sticky>
  292. ### Request Example
  293. <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'`}>
  294. ```bash {{ title: 'cURL' }}
  295. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  296. --header 'Authorization: Bearer {api_key}' \
  297. --form 'file=@"/path/to/file"'
  298. ```
  299. </CodeGroup>
  300. ### Response Example
  301. <CodeGroup title="Response">
  302. ```json {{ title: 'Response' }}
  303. {
  304. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  305. "name": "example.png",
  306. "size": 1024,
  307. "extension": "png",
  308. "mime_type": "image/png",
  309. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  310. "created_at": 1577836800,
  311. }
  312. ```
  313. </CodeGroup>
  314. </Col>
  315. </Row>
  316. ---
  317. <Heading
  318. url='/chat-messages/:task_id/stop'
  319. method='POST'
  320. title='Stop Generate'
  321. name='#stop-generatebacks'
  322. />
  323. <Row>
  324. <Col>
  325. Only supported in streaming mode.
  326. ### Path
  327. - `task_id` (string) Task ID, can be obtained from the streaming chunk return
  328. ### Request Body
  329. - `user` (string) Required
  330. User identifier, used to define the identity of the end-user, must be consistent with the user passed in the send message interface.
  331. ### Response
  332. - `result` (string) Always returns "success"
  333. </Col>
  334. <Col sticky>
  335. ### Request Example
  336. <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"}'`}>
  337. ```bash {{ title: 'cURL' }}
  338. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  339. -H 'Authorization: Bearer {api_key}' \
  340. -H 'Content-Type: application/json' \
  341. --data-raw '{
  342. "user": "abc-123"
  343. }'
  344. ```
  345. </CodeGroup>
  346. ### Response Example
  347. <CodeGroup title="Response">
  348. ```json {{ title: 'Response' }}
  349. {
  350. "result": "success"
  351. }
  352. ```
  353. </CodeGroup>
  354. </Col>
  355. </Row>
  356. ---
  357. <Heading
  358. url='/messages/:message_id/feedbacks'
  359. method='POST'
  360. title='Message Feedback'
  361. name='#feedbacks'
  362. />
  363. <Row>
  364. <Col>
  365. End-users can provide feedback messages, facilitating application developers to optimize expected outputs.
  366. ### Path
  367. <Properties>
  368. <Property name='message_id' type='string' key='message_id'>
  369. Message ID
  370. </Property>
  371. </Properties>
  372. ### Request Body
  373. <Properties>
  374. <Property name='rating' type='string' key='rating'>
  375. Upvote as `like`, downvote as `dislike`, revoke upvote as `null`
  376. </Property>
  377. <Property name='user' type='string' key='user'>
  378. User identifier, defined by the developer's rules, must be unique within the application.
  379. </Property>
  380. <Property name='content' type='string' key='content'>
  381. The specific content of message feedback.
  382. </Property>
  383. </Properties>
  384. ### Response
  385. - `result` (string) Always returns "success"
  386. </Col>
  387. <Col sticky>
  388. <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}'`}>
  389. ```bash {{ title: 'cURL' }}
  390. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  391. --header 'Authorization: Bearer {api_key}' \
  392. --header 'Content-Type: application/json' \
  393. --data-raw '{
  394. "rating": "like",
  395. "user": "abc-123",
  396. "content": "message feedback information"
  397. }'
  398. ```
  399. </CodeGroup>
  400. <CodeGroup title="Response">
  401. ```json {{ title: 'Response' }}
  402. {
  403. "result": "success"
  404. }
  405. ```
  406. </CodeGroup>
  407. </Col>
  408. </Row>
  409. ---
  410. <Heading
  411. url='/app/feedbacks'
  412. method='GET'
  413. title='Get feedbacks of application'
  414. name='#app-feedbacks'
  415. />
  416. <Row>
  417. <Col>
  418. Get application's feedbacks.
  419. ### Query
  420. <Properties>
  421. <Property name='page' type='string' key='page'>
  422. (optional)pagination,default:1
  423. </Property>
  424. </Properties>
  425. <Properties>
  426. <Property name='limit' type='string' key='limit'>
  427. (optional) records per page default:20
  428. </Property>
  429. </Properties>
  430. ### Response
  431. - `data` (List) return apps feedback list.
  432. </Col>
  433. <Col sticky>
  434. <CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
  435. ```bash {{ title: 'cURL' }}
  436. curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
  437. --header 'Authorization: Bearer {api_key}' \
  438. --header 'Content-Type: application/json'
  439. ```
  440. </CodeGroup>
  441. <CodeGroup title="Response">
  442. ```json {{ title: 'Response' }}
  443. {
  444. "data": [
  445. {
  446. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  447. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  448. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  449. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  450. "rating": "like",
  451. "content": "message feedback information-3",
  452. "from_source": "user",
  453. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  454. "from_account_id": null,
  455. "created_at": "2025-04-24T09:24:38",
  456. "updated_at": "2025-04-24T09:24:38"
  457. }
  458. ]
  459. }
  460. ```
  461. </CodeGroup>
  462. </Col>
  463. </Row>
  464. ---
  465. <Heading
  466. url='/messages/{message_id}/suggested'
  467. method='GET'
  468. title='Next Suggested Questions'
  469. name='#suggested'
  470. />
  471. <Row>
  472. <Col>
  473. Get next questions suggestions for the current message
  474. ### Path Params
  475. <Properties>
  476. <Property name='message_id' type='string' key='message_id'>
  477. Message ID
  478. </Property>
  479. </Properties>
  480. ### Query
  481. <Properties>
  482. <Property name='user' type='string' key='user'>
  483. User identifier, used to define the identity of the end-user for retrieval and statistics.
  484. Should be uniquely defined by the developer within the application.
  485. </Property>
  486. </Properties>
  487. </Col>
  488. <Col sticky>
  489. <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'`}>
  490. ```bash {{ title: 'cURL' }}
  491. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  492. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  493. --header 'Content-Type: application/json' \
  494. ```
  495. </CodeGroup>
  496. <CodeGroup title="Response">
  497. ```json {{ title: 'Response' }}
  498. {
  499. "result": "success",
  500. "data": [
  501. "a",
  502. "b",
  503. "c"
  504. ]
  505. }
  506. ```
  507. </CodeGroup>
  508. </Col>
  509. </Row>
  510. ---
  511. <Heading
  512. url='/messages'
  513. method='GET'
  514. title='Get Conversation History Messages'
  515. name='#messages'
  516. />
  517. <Row>
  518. <Col>
  519. Returns historical chat records in a scrolling load format, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  520. ### Query
  521. <Properties>
  522. <Property name='conversation_id' type='string' key='conversation_id'>
  523. Conversation ID
  524. </Property>
  525. <Property name='user' type='string' key='user'>
  526. User identifier, used to define the identity of the end-user for retrieval and statistics.
  527. Should be uniquely defined by the developer within the application.
  528. </Property>
  529. <Property name='first_id' type='string' key='first_id'>
  530. The ID of the first chat record on the current page, default is null.
  531. </Property>
  532. <Property name='limit' type='int' key='limit'>
  533. How many chat history messages to return in one request, default is 20.
  534. </Property>
  535. </Properties>
  536. ### Response
  537. - `data` (array[object]) Message list
  538. - `id` (string) Message ID
  539. - `conversation_id` (string) Conversation ID
  540. - `inputs` (object) User input parameters.
  541. - `query` (string) User input / question content.
  542. - `message_files` (array[object]) Message files
  543. - `id` (string) ID
  544. - `type` (string) File type, image for images
  545. - `url` (string) Preview image URL
  546. - `belongs_to` (string) belongs to,user or assistant
  547. - `agent_thoughts` (array[object]) Agent thought(Empty if it's a Basic Assistant)
  548. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  549. - `message_id` (string) Unique message ID
  550. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  551. - `thought` (string) What LLM is thinking about
  552. - `observation` (string) Response from tool calls
  553. - `tool` (string) A list of tools represents which tools are called,split by ;
  554. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  555. - `created_at` (int) Creation timestamp, e.g., 1705395332
  556. - `message_files` (array[string]) Refer to message_file event
  557. - `file_id` (string) File ID
  558. - `answer` (string) Response message content
  559. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  560. - `feedback` (object) Feedback information
  561. - `rating` (string) Upvote as `like` / Downvote as `dislike`
  562. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  563. - `has_more` (bool) Whether there is a next page
  564. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  565. </Col>
  566. <Col sticky>
  567. <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}'`}>
  568. ```bash {{ title: 'cURL' }}
  569. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  570. --header 'Authorization: Bearer {api_key}'
  571. ```
  572. </CodeGroup>
  573. ### Response Example (Basic Assistant)
  574. <CodeGroup title="Response">
  575. ```json {{ title: 'Response' }}
  576. {
  577. "limit": 20,
  578. "has_more": false,
  579. "data": [
  580. {
  581. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  582. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  583. "inputs": {
  584. "name": "dify"
  585. },
  586. "query": "iphone 13 pro",
  587. "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.",
  588. "message_files": [],
  589. "feedback": null,
  590. "retriever_resources": [
  591. {
  592. "position": 1,
  593. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  594. "dataset_name": "iPhone",
  595. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  596. "document_name": "iPhone List",
  597. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  598. "score": 0.98457545,
  599. "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\""
  600. }
  601. ],
  602. "agent_thoughts": [],
  603. "created_at": 1705569239,
  604. }
  605. ]
  606. }
  607. ```
  608. </CodeGroup>
  609. ### Response Example (Agent Assistant)
  610. <CodeGroup title="Response">
  611. ```json {{ title: 'Response' }}
  612. {
  613. "limit": 20,
  614. "has_more": false,
  615. "data": [
  616. {
  617. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  618. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  619. "inputs": {},
  620. "query": "draw a cat",
  621. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  622. "message_files": [
  623. {
  624. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  625. "type": "image",
  626. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  627. "belongs_to": "assistant"
  628. }
  629. ],
  630. "feedback": null,
  631. "retriever_resources": [],
  632. "created_at": 1705988187,
  633. "agent_thoughts": [
  634. {
  635. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  636. "chain_id": null,
  637. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  638. "position": 1,
  639. "thought": "",
  640. "tool": "dalle2",
  641. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  642. "created_at": 1705988186,
  643. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  644. "files": [
  645. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  646. ]
  647. },
  648. {
  649. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  650. "chain_id": null,
  651. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  652. "position": 2,
  653. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  654. "tool": "",
  655. "tool_input": "",
  656. "created_at": 1705988199,
  657. "observation": "",
  658. "files": []
  659. }
  660. ]
  661. }
  662. ]
  663. }
  664. ```
  665. </CodeGroup>
  666. </Col>
  667. </Row>
  668. ---
  669. <Heading
  670. url='/conversations'
  671. method='GET'
  672. title='Get Conversations'
  673. name='#conversations'
  674. />
  675. <Row>
  676. <Col>
  677. Retrieve the conversation list for the current user, defaulting to the most recent 20 entries.
  678. ### Query
  679. <Properties>
  680. <Property name='user' type='string' key='user'>
  681. User identifier, used to define the identity of the end-user for retrieval and statistics.
  682. Should be uniquely defined by the developer within the application.
  683. </Property>
  684. <Property name='last_id' type='string' key='last_id'>
  685. (Optional) The ID of the last record on the current page, default is null.
  686. </Property>
  687. <Property name='limit' type='int' key='limit'>
  688. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  689. </Property>
  690. <Property name='sort_by' type='string' key='sort_by'>
  691. (Optional) Sorting Field, Default: -updated_at (sorted in descending order by update time)
  692. - Available Values: created_at, -created_at, updated_at, -updated_at
  693. - The symbol before the field represents the order or reverse, "-" represents reverse order.
  694. </Property>
  695. </Properties>
  696. ### Response
  697. - `data` (array[object]) List of conversations
  698. - `id` (string) Conversation ID
  699. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  700. - `inputs` (object) User input parameters.
  701. - `status` (string) Conversation status
  702. - `introduction` (string) Introduction
  703. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  704. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  705. - `has_more` (bool)
  706. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  707. </Col>
  708. <Col sticky>
  709. <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}'`}>
  710. ```bash {{ title: 'cURL' }}
  711. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  712. --header 'Authorization: Bearer {api_key}'
  713. ```
  714. </CodeGroup>
  715. <CodeGroup title="Response">
  716. ```json {{ title: 'Response' }}
  717. {
  718. "limit": 20,
  719. "has_more": false,
  720. "data": [
  721. {
  722. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  723. "name": "New chat",
  724. "inputs": {
  725. "book": "book",
  726. "myName": "Lucy"
  727. },
  728. "status": "normal",
  729. "created_at": 1679667915,
  730. "updated_at": 1679667915
  731. },
  732. {
  733. "id": "hSIhXBhNe8X1d8Et"
  734. // ...
  735. }
  736. ]
  737. }
  738. ```
  739. </CodeGroup>
  740. </Col>
  741. </Row>
  742. ---
  743. <Heading
  744. url='/conversations/:conversation_id'
  745. method='DELETE'
  746. title='Delete Conversation'
  747. name='#delete'
  748. />
  749. <Row>
  750. <Col>
  751. Delete a conversation.
  752. ### Path
  753. - `conversation_id` (string) Conversation ID
  754. ### Request Body
  755. <Properties>
  756. <Property name='user' type='string' key='user'>
  757. The user identifier, defined by the developer, must ensure uniqueness within the application.
  758. </Property>
  759. </Properties>
  760. ### Response
  761. - `result` (string) Always returns "success"
  762. </Col>
  763. <Col sticky>
  764. <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}'`}>
  765. ```bash {{ title: 'cURL' }}
  766. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  767. --header 'Content-Type: application/json' \
  768. --header 'Accept: application/json' \
  769. --header 'Authorization: Bearer {api_key}' \
  770. --data '{
  771. "user": "abc-123"
  772. }'
  773. ```
  774. </CodeGroup>
  775. <CodeGroup title="Response">
  776. ```text {{ title: 'Response' }}
  777. 204 No Content
  778. ```
  779. </CodeGroup>
  780. </Col>
  781. </Row>
  782. ---
  783. <Heading
  784. url='/conversations/:conversation_id/name'
  785. method='POST'
  786. title='Conversation Rename'
  787. name='#rename'
  788. />
  789. <Row>
  790. <Col>
  791. ### Request Body
  792. Rename the session, the session name is used for display on clients that support multiple sessions.
  793. ### Path
  794. - `conversation_id` (string) Conversation ID
  795. <Properties>
  796. <Property name='name' type='string' key='name'>
  797. (Optional) The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  798. </Property>
  799. <Property name='auto_generate' type='bool' key='auto_generate'>
  800. (Optional) Automatically generate the title, default is `false`
  801. </Property>
  802. <Property name='user' type='string' key='user'>
  803. The user identifier, defined by the developer, must ensure uniqueness within the application.
  804. </Property>
  805. </Properties>
  806. ### Response
  807. - `id` (string) Conversation ID
  808. - `name` (string) Conversation name
  809. - `inputs` (object) User input parameters
  810. - `status` (string) Conversation status
  811. - `introduction` (string) Introduction
  812. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  813. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  814. </Col>
  815. <Col sticky>
  816. <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}'`}>
  817. ```bash {{ title: 'cURL' }}
  818. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  819. --header 'Content-Type: application/json' \
  820. --header 'Authorization: Bearer {api_key}' \
  821. --data-raw '{
  822. "name": "",
  823. "auto_generate": true,
  824. "user": "abc-123"
  825. }'
  826. ```
  827. </CodeGroup>
  828. <CodeGroup title="Response">
  829. ```json {{ title: 'Response' }}
  830. {
  831. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  832. "name": "Chat vs AI",
  833. "inputs": {},
  834. "status": "normal",
  835. "introduction": "",
  836. "created_at": 1705569238,
  837. "updated_at": 1705569238
  838. }
  839. ```
  840. </CodeGroup>
  841. </Col>
  842. </Row>
  843. ---
  844. <Heading
  845. url='/conversations/:conversation_id/variables'
  846. method='GET'
  847. title='Get Conversation Variables'
  848. name='#conversation-variables'
  849. />
  850. <Row>
  851. <Col>
  852. Retrieve variables from a specific conversation. This endpoint is useful for extracting structured data that was captured during the conversation.
  853. ### Path Parameters
  854. <Properties>
  855. <Property name='conversation_id' type='string' key='conversation_id'>
  856. The ID of the conversation to retrieve variables from.
  857. </Property>
  858. </Properties>
  859. ### Query Parameters
  860. <Properties>
  861. <Property name='user' type='string' key='user'>
  862. The user identifier, defined by the developer, must ensure uniqueness within the application
  863. </Property>
  864. <Property name='last_id' type='string' key='last_id'>
  865. (Optional) The ID of the last record on the current page, default is null.
  866. </Property>
  867. <Property name='limit' type='int' key='limit'>
  868. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  869. </Property>
  870. </Properties>
  871. ### Response
  872. - `limit` (int) Number of items per page
  873. - `has_more` (bool) Whether there is a next page
  874. - `data` (array[object]) List of variables
  875. - `id` (string) Variable ID
  876. - `name` (string) Variable name
  877. - `value_type` (string) Variable type (string, number, object, etc.)
  878. - `value` (string) Variable value
  879. - `description` (string) Variable description
  880. - `created_at` (int) Creation timestamp
  881. - `updated_at` (int) Last update timestamp
  882. ### Errors
  883. - 404, `conversation_not_exists`, Conversation not found
  884. </Col>
  885. <Col sticky>
  886. <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}'`}>
  887. ```bash {{ title: 'cURL' }}
  888. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \
  889. --header 'Authorization: Bearer {api_key}'
  890. ```
  891. </CodeGroup>
  892. <CodeGroup title="Request with variable name filter">
  893. ```bash {{ title: 'cURL' }}
  894. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123&variable_name=customer_name' \
  895. --header 'Authorization: Bearer {api_key}'
  896. ```
  897. </CodeGroup>
  898. <CodeGroup title="Response">
  899. ```json {{ title: 'Response' }}
  900. {
  901. "limit": 100,
  902. "has_more": false,
  903. "data": [
  904. {
  905. "id": "variable-uuid-1",
  906. "name": "customer_name",
  907. "value_type": "string",
  908. "value": "John Doe",
  909. "description": "Customer name extracted from the conversation",
  910. "created_at": 1650000000000,
  911. "updated_at": 1650000000000
  912. },
  913. {
  914. "id": "variable-uuid-2",
  915. "name": "order_details",
  916. "value_type": "json",
  917. "value": "{\"product\":\"Widget\",\"quantity\":5,\"price\":19.99}",
  918. "description": "Order details from the customer",
  919. "created_at": 1650000000000,
  920. "updated_at": 1650000000000
  921. }
  922. ]
  923. }
  924. ```
  925. </CodeGroup>
  926. </Col>
  927. </Row>
  928. ---
  929. <Heading
  930. url='/audio-to-text'
  931. method='POST'
  932. title='Speech to Text'
  933. name='#audio'
  934. />
  935. <Row>
  936. <Col>
  937. This endpoint requires a multipart/form-data request.
  938. ### Request Body
  939. <Properties>
  940. <Property name='file' type='file' key='file'>
  941. Audio file.
  942. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  943. File size limit: 15MB
  944. </Property>
  945. <Property name='user' type='string' key='user'>
  946. User identifier, defined by the developer's rules, must be unique within the application.
  947. </Property>
  948. </Properties>
  949. ### Response
  950. - `text` (string) Output text
  951. </Col>
  952. <Col sticky>
  953. <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]'`}>
  954. ```bash {{ title: 'cURL' }}
  955. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  956. --header 'Authorization: Bearer {api_key}' \
  957. --form 'file=@localfile;type=audio/mp3'
  958. ```
  959. </CodeGroup>
  960. <CodeGroup title="Response">
  961. ```json {{ title: 'Response' }}
  962. {
  963. "text": ""
  964. }
  965. ```
  966. </CodeGroup>
  967. </Col>
  968. </Row>
  969. ---
  970. <Heading
  971. url='/text-to-audio'
  972. method='POST'
  973. title='Text to Audio'
  974. name='#audio'
  975. />
  976. <Row>
  977. <Col>
  978. Text to speech.
  979. ### Request Body
  980. <Properties>
  981. <Property name='message_id' type='str' key='message_id'>
  982. For text messages generated by Dify, simply pass the generated message-id directly. The backend will use the message-id to look up the corresponding content and synthesize the voice information directly. If both message_id and text are provided simultaneously, the message_id is given priority.
  983. </Property>
  984. <Property name='text' type='str' key='text'>
  985. Speech generated content。
  986. </Property>
  987. <Property name='user' type='string' key='user'>
  988. The user identifier, defined by the developer, must ensure uniqueness within the app.
  989. </Property>
  990. </Properties>
  991. </Col>
  992. <Col sticky>
  993. <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=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290`}>
  994. ```bash {{ title: 'cURL' }}
  995. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  996. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  997. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  998. ```
  999. </CodeGroup>
  1000. <CodeGroup title="headers">
  1001. ```json {{ title: 'headers' }}
  1002. {
  1003. "Content-Type": "audio/wav"
  1004. }
  1005. ```
  1006. </CodeGroup>
  1007. </Col>
  1008. </Row>
  1009. ---
  1010. <Heading
  1011. url='/info'
  1012. method='GET'
  1013. title='Get Application Basic Information'
  1014. name='#info'
  1015. />
  1016. <Row>
  1017. <Col>
  1018. Used to get basic information about this application
  1019. ### Response
  1020. - `name` (string) application name
  1021. - `description` (string) application description
  1022. - `tags` (array[string]) application tags
  1023. </Col>
  1024. <Col>
  1025. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1026. ```bash {{ title: 'cURL' }}
  1027. curl -X GET '${props.appDetail.api_base_url}/info' \
  1028. -H 'Authorization: Bearer {api_key}'
  1029. ```
  1030. </CodeGroup>
  1031. <CodeGroup title="Response">
  1032. ```json {{ title: 'Response' }}
  1033. {
  1034. "name": "My App",
  1035. "description": "This is my app.",
  1036. "tags": [
  1037. "tag1",
  1038. "tag2"
  1039. ]
  1040. }
  1041. ```
  1042. </CodeGroup>
  1043. </Col>
  1044. </Row>
  1045. ---
  1046. <Heading
  1047. url='/parameters'
  1048. method='GET'
  1049. title='Get Application Parameters Information'
  1050. name='#parameters'
  1051. />
  1052. <Row>
  1053. <Col>
  1054. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  1055. ### Query
  1056. <Properties>
  1057. <Property name='user' type='string' key='user'>
  1058. User identifier, defined by the developer's rules, must be unique within the application.
  1059. </Property>
  1060. </Properties>
  1061. ### Response
  1062. - `opening_statement` (string) Opening statement
  1063. - `suggested_questions` (array[string]) List of suggested questions for the opening
  1064. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  1065. - `enabled` (bool) Whether it is enabled
  1066. - `speech_to_text` (object) Speech to text
  1067. - `enabled` (bool) Whether it is enabled
  1068. - `retriever_resource` (object) Citation and Attribution
  1069. - `enabled` (bool) Whether it is enabled
  1070. - `annotation_reply` (object) Annotation reply
  1071. - `enabled` (bool) Whether it is enabled
  1072. - `user_input_form` (array[object]) User input form configuration
  1073. - `text-input` (object) Text input control
  1074. - `label` (string) Variable display label name
  1075. - `variable` (string) Variable ID
  1076. - `required` (bool) Whether it is required
  1077. - `default` (string) Default value
  1078. - `paragraph` (object) Paragraph text input control
  1079. - `label` (string) Variable display label name
  1080. - `variable` (string) Variable ID
  1081. - `required` (bool) Whether it is required
  1082. - `default` (string) Default value
  1083. - `select` (object) Dropdown control
  1084. - `label` (string) Variable display label name
  1085. - `variable` (string) Variable ID
  1086. - `required` (bool) Whether it is required
  1087. - `default` (string) Default value
  1088. - `options` (array[string]) Option values
  1089. - `file_upload` (object) File upload configuration
  1090. - `image` (object) Image settings
  1091. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  1092. - `enabled` (bool) Whether it is enabled
  1093. - `number_limits` (int) Image number limit, default is 3
  1094. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  1095. - `system_parameters` (object) System parameters
  1096. - `file_size_limit` (int) Document upload size limit (MB)
  1097. - `image_file_size_limit` (int) Image file upload size limit (MB)
  1098. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  1099. - `video_file_size_limit` (int) Video file upload size limit (MB)
  1100. </Col>
  1101. <Col sticky>
  1102. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  1103. ```bash {{ title: 'cURL' }}
  1104. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  1105. --header 'Authorization: Bearer {api_key}'
  1106. ```
  1107. </CodeGroup>
  1108. <CodeGroup title="Response">
  1109. ```json {{ title: 'Response' }}
  1110. {
  1111. "opening_statement": "Hello!",
  1112. "suggested_questions_after_answer": {
  1113. "enabled": true
  1114. },
  1115. "speech_to_text": {
  1116. "enabled": true
  1117. },
  1118. "retriever_resource": {
  1119. "enabled": true
  1120. },
  1121. "annotation_reply": {
  1122. "enabled": true
  1123. },
  1124. "user_input_form": [
  1125. {
  1126. "paragraph": {
  1127. "label": "Query",
  1128. "variable": "query",
  1129. "required": true,
  1130. "default": ""
  1131. }
  1132. }
  1133. ],
  1134. "file_upload": {
  1135. "image": {
  1136. "enabled": false,
  1137. "number_limits": 3,
  1138. "detail": "high",
  1139. "transfer_methods": [
  1140. "remote_url",
  1141. "local_file"
  1142. ]
  1143. }
  1144. },
  1145. "system_parameters": {
  1146. "file_size_limit": 15,
  1147. "image_file_size_limit": 10,
  1148. "audio_file_size_limit": 50,
  1149. "video_file_size_limit": 100
  1150. }
  1151. }
  1152. ```
  1153. </CodeGroup>
  1154. </Col>
  1155. </Row>
  1156. ---
  1157. <Heading
  1158. url='/meta'
  1159. method='GET'
  1160. title='Get Application Meta Information'
  1161. name='#meta'
  1162. />
  1163. <Row>
  1164. <Col>
  1165. Used to get icons of tools in this application
  1166. ### Response
  1167. - `tool_icons`(object[string]) tool icons
  1168. - `tool_name` (string)
  1169. - `icon` (object|string)
  1170. - (object) icon object
  1171. - `background` (string) background color in hex format
  1172. - `content`(string) emoji
  1173. - (string) url of icon
  1174. </Col>
  1175. <Col>
  1176. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1177. ```bash {{ title: 'cURL' }}
  1178. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1179. -H 'Authorization: Bearer {api_key}'
  1180. ```
  1181. </CodeGroup>
  1182. <CodeGroup title="Response">
  1183. ```json {{ title: 'Response' }}
  1184. {
  1185. "tool_icons": {
  1186. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1187. "api_tool": {
  1188. "background": "#252525",
  1189. "content": "\ud83d\ude01"
  1190. }
  1191. }
  1192. }
  1193. ```
  1194. </CodeGroup>
  1195. </Col>
  1196. </Row>
  1197. ---
  1198. <Heading
  1199. url='/site'
  1200. method='GET'
  1201. title='Get Application WebApp Settings'
  1202. name='#site'
  1203. />
  1204. <Row>
  1205. <Col>
  1206. Used to get the WebApp settings of the application.
  1207. ### Response
  1208. - `title` (string) WebApp name
  1209. - `chat_color_theme` (string) Chat color theme, in hex format
  1210. - `chat_color_theme_inverted` (bool) Whether the chat color theme is inverted
  1211. - `icon_type` (string) Icon type, `emoji` - emoji, `image` - picture
  1212. - `icon` (string) Icon. If it's `emoji` type, it's an emoji symbol; if it's `image` type, it's an image URL
  1213. - `icon_background` (string) Background color in hex format
  1214. - `icon_url` (string) Icon URL
  1215. - `description` (string) Description
  1216. - `copyright` (string) Copyright information
  1217. - `privacy_policy` (string) Privacy policy link
  1218. - `custom_disclaimer` (string) Custom disclaimer
  1219. - `default_language` (string) Default language
  1220. - `show_workflow_steps` (bool) Whether to show workflow details
  1221. - `use_icon_as_answer_icon` (bool) Whether to replace 🤖 in chat with the WebApp icon
  1222. </Col>
  1223. <Col>
  1224. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1225. ```bash {{ title: 'cURL' }}
  1226. curl -X GET '${props.appDetail.api_base_url}/site' \
  1227. -H 'Authorization: Bearer {api_key}'
  1228. ```
  1229. </CodeGroup>
  1230. <CodeGroup title="Response">
  1231. ```json {{ title: 'Response' }}
  1232. {
  1233. "title": "My App",
  1234. "chat_color_theme": "#ff4a4a",
  1235. "chat_color_theme_inverted": false,
  1236. "icon_type": "emoji",
  1237. "icon": "😄",
  1238. "icon_background": "#FFEAD5",
  1239. "icon_url": null,
  1240. "description": "This is my app.",
  1241. "copyright": "all rights reserved",
  1242. "privacy_policy": "",
  1243. "custom_disclaimer": "All generated by AI",
  1244. "default_language": "en-US",
  1245. "show_workflow_steps": false,
  1246. "use_icon_as_answer_icon": false,
  1247. }
  1248. ```
  1249. </CodeGroup>
  1250. </Col>
  1251. </Row>
  1252. ___
  1253. <Heading
  1254. url='/apps/annotations'
  1255. method='GET'
  1256. title='Get Annotation List'
  1257. name='#annotation_list'
  1258. />
  1259. <Row>
  1260. <Col>
  1261. ### Query
  1262. <Properties>
  1263. <Property name='page' type='string' key='page'>
  1264. Page number
  1265. </Property>
  1266. <Property name='limit' type='string' key='limit'>
  1267. Number of items returned, default 20, range 1-100
  1268. </Property>
  1269. </Properties>
  1270. </Col>
  1271. <Col sticky>
  1272. <CodeGroup
  1273. title="Request"
  1274. tag="GET"
  1275. label="/apps/annotations"
  1276. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1277. >
  1278. ```bash {{ title: 'cURL' }}
  1279. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  1280. --header 'Authorization: Bearer {api_key}'
  1281. ```
  1282. </CodeGroup>
  1283. <CodeGroup title="Response">
  1284. ```json {{ title: 'Response' }}
  1285. {
  1286. "data": [
  1287. {
  1288. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1289. "question": "What is your name?",
  1290. "answer": "I am Dify.",
  1291. "hit_count": 0,
  1292. "created_at": 1735625869
  1293. }
  1294. ],
  1295. "has_more": false,
  1296. "limit": 20,
  1297. "total": 1,
  1298. "page": 1
  1299. }
  1300. ```
  1301. </CodeGroup>
  1302. </Col>
  1303. </Row>
  1304. ---
  1305. <Heading
  1306. url='/apps/annotations'
  1307. method='POST'
  1308. title='Create Annotation'
  1309. name='#create_annotation'
  1310. />
  1311. <Row>
  1312. <Col>
  1313. ### Query
  1314. <Properties>
  1315. <Property name='question' type='string' key='question'>
  1316. Question
  1317. </Property>
  1318. <Property name='answer' type='string' key='answer'>
  1319. Answer
  1320. </Property>
  1321. </Properties>
  1322. </Col>
  1323. <Col sticky>
  1324. <CodeGroup
  1325. title="Request"
  1326. tag="POST"
  1327. label="/apps/annotations"
  1328. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  1329. >
  1330. ```bash {{ title: 'cURL' }}
  1331. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  1332. --header 'Authorization: Bearer {api_key}' \
  1333. --header 'Content-Type: application/json' \
  1334. --data-raw '{
  1335. "question": "What is your name?",
  1336. "answer": "I am Dify."
  1337. }'
  1338. ```
  1339. </CodeGroup>
  1340. <CodeGroup title="Response">
  1341. ```json {{ title: 'Response' }}
  1342. {
  1343. {
  1344. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1345. "question": "What is your name?",
  1346. "answer": "I am Dify.",
  1347. "hit_count": 0,
  1348. "created_at": 1735625869
  1349. }
  1350. }
  1351. ```
  1352. </CodeGroup>
  1353. </Col>
  1354. </Row>
  1355. ---
  1356. <Heading
  1357. url='/apps/annotations/{annotation_id}'
  1358. method='PUT'
  1359. title='Update Annotation'
  1360. name='#update_annotation'
  1361. />
  1362. <Row>
  1363. <Col>
  1364. ### Query
  1365. <Properties>
  1366. <Property name='annotation_id' type='string' key='annotation_id'>
  1367. Annotation ID
  1368. </Property>
  1369. <Property name='question' type='string' key='question'>
  1370. Question
  1371. </Property>
  1372. <Property name='answer' type='string' key='answer'>
  1373. Answer
  1374. </Property>
  1375. </Properties>
  1376. </Col>
  1377. <Col sticky>
  1378. <CodeGroup
  1379. title="Request"
  1380. tag="PUT"
  1381. label="/apps/annotations/{annotation_id}"
  1382. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"question": "What is your name?","answer": "I am Dify."}'`}
  1383. >
  1384. ```bash {{ title: 'cURL' }}
  1385. curl --location --request POST '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1386. --header 'Authorization: Bearer {api_key}' \
  1387. --header 'Content-Type: application/json' \
  1388. --data-raw '{
  1389. "question": "What is your name?",
  1390. "answer": "I am Dify."
  1391. }'
  1392. ```
  1393. </CodeGroup>
  1394. <CodeGroup title="Response">
  1395. ```json {{ title: 'Response' }}
  1396. {
  1397. {
  1398. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1399. "question": "What is your name?",
  1400. "answer": "I am Dify.",
  1401. "hit_count": 0,
  1402. "created_at": 1735625869
  1403. }
  1404. }
  1405. ```
  1406. </CodeGroup>
  1407. </Col>
  1408. </Row>
  1409. ---
  1410. <Heading
  1411. url='/apps/annotations/{annotation_id}'
  1412. method='DELETE'
  1413. title='Delete Annotation'
  1414. name='#delete_annotation'
  1415. />
  1416. <Row>
  1417. <Col>
  1418. ### Query
  1419. <Properties>
  1420. <Property name='annotation_id' type='string' key='annotation_id'>
  1421. Annotation ID
  1422. </Property>
  1423. </Properties>
  1424. </Col>
  1425. <Col sticky>
  1426. <CodeGroup
  1427. title="Request"
  1428. tag="PUT"
  1429. label="/apps/annotations/{annotation_id}"
  1430. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  1431. >
  1432. ```bash {{ title: 'cURL' }}
  1433. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1434. --header 'Authorization: Bearer {api_key}'
  1435. ```
  1436. </CodeGroup>
  1437. <CodeGroup title="Response">
  1438. ```text {{ title: 'Response' }}
  1439. 204 No Content
  1440. ```
  1441. </CodeGroup>
  1442. </Col>
  1443. </Row>
  1444. ---
  1445. <Heading
  1446. url='/apps/annotation-reply/{action}'
  1447. method='POST'
  1448. title='Initial Annotation Reply Settings'
  1449. name='#initial_annotation_reply_settings'
  1450. />
  1451. <Row>
  1452. <Col>
  1453. ### Query
  1454. <Properties>
  1455. <Property name='action' type='string' key='action'>
  1456. Action, can only be 'enable' or 'disable'
  1457. </Property>
  1458. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  1459. Specified embedding model provider, must be set up in the system first, corresponding to the provider field(Optional)
  1460. </Property>
  1461. <Property name='embedding_model' type='string' key='embedding_model'>
  1462. Specified embedding model, corresponding to the model field(Optional)
  1463. </Property>
  1464. <Property name='score_threshold' type='number' key='score_threshold'>
  1465. The similarity threshold for matching annotated replies. Only annotations with scores above this threshold will be recalled.
  1466. </Property>
  1467. </Properties>
  1468. </Col>
  1469. <Col sticky>
  1470. The provider and model name of the embedding model can be obtained through the following interface: v1/workspaces/current/models/model-types/text-embedding. For specific instructions, see: Maintain Knowledge Base via API. The Authorization used is the Dataset API Token.
  1471. <CodeGroup
  1472. title="Request"
  1473. tag="POST"
  1474. label="/apps/annotation-reply/{action}"
  1475. targetCode={`curl --location --request POST '${props.apiBaseUrl}/apps/annotation-reply/{action}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{"score_threshold": 0.9, "embedding_provider_name": "zhipu", "embedding_model_name": "embedding_3"}'`}
  1476. >
  1477. ```bash {{ title: 'cURL' }}
  1478. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  1479. --header 'Authorization: Bearer {api_key}' \
  1480. --header 'Content-Type: application/json' \
  1481. --data-raw '{
  1482. "score_threshold": 0.9,
  1483. "embedding_provider_name": "zhipu",
  1484. "embedding_model_name": "embedding_3"
  1485. }'
  1486. ```
  1487. </CodeGroup>
  1488. <CodeGroup title="Response">
  1489. ```json {{ title: 'Response' }}
  1490. {
  1491. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1492. "job_status": "waiting"
  1493. }
  1494. ```
  1495. </CodeGroup>
  1496. This interface is executed asynchronously, so it will return a job_id. You can get the final execution result by querying the job status interface.
  1497. </Col>
  1498. </Row>
  1499. ---
  1500. <Heading
  1501. url='/apps/annotation-reply/{action}/status/{job_id}'
  1502. method='GET'
  1503. title='Query Initial Annotation Reply Settings Task Status'
  1504. name='#initial_annotation_reply_settings_task_status'
  1505. />
  1506. <Row>
  1507. <Col>
  1508. ### Query
  1509. <Properties>
  1510. <Property name='action' type='string' key='action'>
  1511. Action, can only be 'enable' or 'disable', must be the same as the action in the initial annotation reply settings interface
  1512. </Property>
  1513. <Property name='job_id' type='string' key='job_id'>
  1514. Job ID,
  1515. </Property>
  1516. </Properties>
  1517. </Col>
  1518. <Col sticky>
  1519. <CodeGroup
  1520. title="Request"
  1521. tag="GET"
  1522. label="/apps/annotations"
  1523. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1524. >
  1525. ```bash {{ title: 'cURL' }}
  1526. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  1527. --header 'Authorization: Bearer {api_key}'
  1528. ```
  1529. </CodeGroup>
  1530. <CodeGroup title="Response">
  1531. ```json {{ title: 'Response' }}
  1532. {
  1533. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1534. "job_status": "waiting",
  1535. "error_msg": ""
  1536. }
  1537. ```
  1538. </CodeGroup>
  1539. </Col>
  1540. </Row>