You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_chat.en.mdx 58KB

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  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='/messages/{message_id}/suggested'
  412. method='GET'
  413. title='Next Suggested Questions'
  414. name='#suggested'
  415. />
  416. <Row>
  417. <Col>
  418. Get next questions suggestions for the current message
  419. ### Path Params
  420. <Properties>
  421. <Property name='message_id' type='string' key='message_id'>
  422. Message ID
  423. </Property>
  424. </Properties>
  425. ### Query
  426. <Properties>
  427. <Property name='user' type='string' key='user'>
  428. User identifier, used to define the identity of the end-user for retrieval and statistics.
  429. Should be uniquely defined by the developer within the application.
  430. </Property>
  431. </Properties>
  432. </Col>
  433. <Col sticky>
  434. <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'`}>
  435. ```bash {{ title: 'cURL' }}
  436. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  437. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  438. --header 'Content-Type: application/json' \
  439. ```
  440. </CodeGroup>
  441. <CodeGroup title="Response">
  442. ```json {{ title: 'Response' }}
  443. {
  444. "result": "success",
  445. "data": [
  446. "a",
  447. "b",
  448. "c"
  449. ]
  450. }
  451. ```
  452. </CodeGroup>
  453. </Col>
  454. </Row>
  455. ---
  456. <Heading
  457. url='/messages'
  458. method='GET'
  459. title='Get Conversation History Messages'
  460. name='#messages'
  461. />
  462. <Row>
  463. <Col>
  464. Returns historical chat records in a scrolling load format, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  465. ### Query
  466. <Properties>
  467. <Property name='conversation_id' type='string' key='conversation_id'>
  468. Conversation ID
  469. </Property>
  470. <Property name='user' type='string' key='user'>
  471. User identifier, used to define the identity of the end-user for retrieval and statistics.
  472. Should be uniquely defined by the developer within the application.
  473. </Property>
  474. <Property name='first_id' type='string' key='first_id'>
  475. The ID of the first chat record on the current page, default is null.
  476. </Property>
  477. <Property name='limit' type='int' key='limit'>
  478. How many chat history messages to return in one request, default is 20.
  479. </Property>
  480. </Properties>
  481. ### Response
  482. - `data` (array[object]) Message list
  483. - `id` (string) Message ID
  484. - `conversation_id` (string) Conversation ID
  485. - `inputs` (object) User input parameters.
  486. - `query` (string) User input / question content.
  487. - `message_files` (array[object]) Message files
  488. - `id` (string) ID
  489. - `type` (string) File type, image for images
  490. - `url` (string) Preview image URL
  491. - `belongs_to` (string) belongs to,user or assistant
  492. - `agent_thoughts` (array[object]) Agent thought(Empty if it's a Basic Assistant)
  493. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  494. - `message_id` (string) Unique message ID
  495. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  496. - `thought` (string) What LLM is thinking about
  497. - `observation` (string) Response from tool calls
  498. - `tool` (string) A list of tools represents which tools are called,split by ;
  499. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  500. - `created_at` (int) Creation timestamp, e.g., 1705395332
  501. - `message_files` (array[string]) Refer to message_file event
  502. - `file_id` (string) File ID
  503. - `answer` (string) Response message content
  504. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  505. - `feedback` (object) Feedback information
  506. - `rating` (string) Upvote as `like` / Downvote as `dislike`
  507. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  508. - `has_more` (bool) Whether there is a next page
  509. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  510. </Col>
  511. <Col sticky>
  512. <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}'`}>
  513. ```bash {{ title: 'cURL' }}
  514. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  515. --header 'Authorization: Bearer {api_key}'
  516. ```
  517. </CodeGroup>
  518. ### Response Example (Basic Assistant)
  519. <CodeGroup title="Response">
  520. ```json {{ title: 'Response' }}
  521. {
  522. "limit": 20,
  523. "has_more": false,
  524. "data": [
  525. {
  526. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  527. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  528. "inputs": {
  529. "name": "dify"
  530. },
  531. "query": "iphone 13 pro",
  532. "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.",
  533. "message_files": [],
  534. "feedback": null,
  535. "retriever_resources": [
  536. {
  537. "position": 1,
  538. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  539. "dataset_name": "iPhone",
  540. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  541. "document_name": "iPhone List",
  542. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  543. "score": 0.98457545,
  544. "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\""
  545. }
  546. ],
  547. "agent_thoughts": [],
  548. "created_at": 1705569239,
  549. }
  550. ]
  551. }
  552. ```
  553. </CodeGroup>
  554. ### Response Example (Agent Assistant)
  555. <CodeGroup title="Response">
  556. ```json {{ title: 'Response' }}
  557. {
  558. "limit": 20,
  559. "has_more": false,
  560. "data": [
  561. {
  562. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  563. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  564. "inputs": {},
  565. "query": "draw a cat",
  566. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  567. "message_files": [
  568. {
  569. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  570. "type": "image",
  571. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  572. "belongs_to": "assistant"
  573. }
  574. ],
  575. "feedback": null,
  576. "retriever_resources": [],
  577. "created_at": 1705988187,
  578. "agent_thoughts": [
  579. {
  580. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  581. "chain_id": null,
  582. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  583. "position": 1,
  584. "thought": "",
  585. "tool": "dalle2",
  586. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  587. "created_at": 1705988186,
  588. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  589. "files": [
  590. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  591. ]
  592. },
  593. {
  594. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  595. "chain_id": null,
  596. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  597. "position": 2,
  598. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  599. "tool": "",
  600. "tool_input": "",
  601. "created_at": 1705988199,
  602. "observation": "",
  603. "files": []
  604. }
  605. ]
  606. }
  607. ]
  608. }
  609. ```
  610. </CodeGroup>
  611. </Col>
  612. </Row>
  613. ---
  614. <Heading
  615. url='/conversations'
  616. method='GET'
  617. title='Get Conversations'
  618. name='#conversations'
  619. />
  620. <Row>
  621. <Col>
  622. Retrieve the conversation list for the current user, defaulting to the most recent 20 entries.
  623. ### Query
  624. <Properties>
  625. <Property name='user' type='string' key='user'>
  626. User identifier, used to define the identity of the end-user for retrieval and statistics.
  627. Should be uniquely defined by the developer within the application.
  628. </Property>
  629. <Property name='last_id' type='string' key='last_id'>
  630. (Optional) The ID of the last record on the current page, default is null.
  631. </Property>
  632. <Property name='limit' type='int' key='limit'>
  633. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  634. </Property>
  635. <Property name='sort_by' type='string' key='sort_by'>
  636. (Optional) Sorting Field, Default: -updated_at (sorted in descending order by update time)
  637. - Available Values: created_at, -created_at, updated_at, -updated_at
  638. - The symbol before the field represents the order or reverse, "-" represents reverse order.
  639. </Property>
  640. </Properties>
  641. ### Response
  642. - `data` (array[object]) List of conversations
  643. - `id` (string) Conversation ID
  644. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  645. - `inputs` (object) User input parameters.
  646. - `status` (string) Conversation status
  647. - `introduction` (string) Introduction
  648. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  649. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  650. - `has_more` (bool)
  651. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  652. </Col>
  653. <Col sticky>
  654. <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}'`}>
  655. ```bash {{ title: 'cURL' }}
  656. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  657. --header 'Authorization: Bearer {api_key}'
  658. ```
  659. </CodeGroup>
  660. <CodeGroup title="Response">
  661. ```json {{ title: 'Response' }}
  662. {
  663. "limit": 20,
  664. "has_more": false,
  665. "data": [
  666. {
  667. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  668. "name": "New chat",
  669. "inputs": {
  670. "book": "book",
  671. "myName": "Lucy"
  672. },
  673. "status": "normal",
  674. "created_at": 1679667915,
  675. "updated_at": 1679667915
  676. },
  677. {
  678. "id": "hSIhXBhNe8X1d8Et"
  679. // ...
  680. }
  681. ]
  682. }
  683. ```
  684. </CodeGroup>
  685. </Col>
  686. </Row>
  687. ---
  688. <Heading
  689. url='/conversations/:conversation_id'
  690. method='DELETE'
  691. title='Delete Conversation'
  692. name='#delete'
  693. />
  694. <Row>
  695. <Col>
  696. Delete a conversation.
  697. ### Path
  698. - `conversation_id` (string) Conversation ID
  699. ### Request Body
  700. <Properties>
  701. <Property name='user' type='string' key='user'>
  702. The user identifier, defined by the developer, must ensure uniqueness within the application.
  703. </Property>
  704. </Properties>
  705. ### Response
  706. - `result` (string) Always returns "success"
  707. </Col>
  708. <Col sticky>
  709. <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}'`}>
  710. ```bash {{ title: 'cURL' }}
  711. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  712. --header 'Content-Type: application/json' \
  713. --header 'Accept: application/json' \
  714. --header 'Authorization: Bearer {api_key}' \
  715. --data '{
  716. "user": "abc-123"
  717. }'
  718. ```
  719. </CodeGroup>
  720. <CodeGroup title="Response">
  721. ```json {{ title: 'Response' }}
  722. {
  723. "result": "success"
  724. }
  725. ```
  726. </CodeGroup>
  727. </Col>
  728. </Row>
  729. ---
  730. <Heading
  731. url='/conversations/:conversation_id/name'
  732. method='POST'
  733. title='Conversation Rename'
  734. name='#rename'
  735. />
  736. <Row>
  737. <Col>
  738. ### Request Body
  739. Rename the session, the session name is used for display on clients that support multiple sessions.
  740. ### Path
  741. - `conversation_id` (string) Conversation ID
  742. <Properties>
  743. <Property name='name' type='string' key='name'>
  744. (Optional) The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  745. </Property>
  746. <Property name='auto_generate' type='bool' key='auto_generate'>
  747. (Optional) Automatically generate the title, default is `false`
  748. </Property>
  749. <Property name='user' type='string' key='user'>
  750. The user identifier, defined by the developer, must ensure uniqueness within the application.
  751. </Property>
  752. </Properties>
  753. ### Response
  754. - `id` (string) Conversation ID
  755. - `name` (string) Conversation name
  756. - `inputs` (object) User input parameters
  757. - `status` (string) Conversation status
  758. - `introduction` (string) Introduction
  759. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  760. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  761. </Col>
  762. <Col sticky>
  763. <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}'`}>
  764. ```bash {{ title: 'cURL' }}
  765. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  766. --header 'Content-Type: application/json' \
  767. --header 'Authorization: Bearer {api_key}' \
  768. --data-raw '{
  769. "name": "",
  770. "auto_generate": true,
  771. "user": "abc-123"
  772. }'
  773. ```
  774. </CodeGroup>
  775. <CodeGroup title="Response">
  776. ```json {{ title: 'Response' }}
  777. {
  778. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  779. "name": "Chat vs AI",
  780. "inputs": {},
  781. "status": "normal",
  782. "introduction": "",
  783. "created_at": 1705569238,
  784. "updated_at": 1705569238
  785. }
  786. ```
  787. </CodeGroup>
  788. </Col>
  789. </Row>
  790. ---
  791. <Heading
  792. url='/audio-to-text'
  793. method='POST'
  794. title='Speech to Text'
  795. name='#audio'
  796. />
  797. <Row>
  798. <Col>
  799. This endpoint requires a multipart/form-data request.
  800. ### Request Body
  801. <Properties>
  802. <Property name='file' type='file' key='file'>
  803. Audio file.
  804. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  805. File size limit: 15MB
  806. </Property>
  807. <Property name='user' type='string' key='user'>
  808. User identifier, defined by the developer's rules, must be unique within the application.
  809. </Property>
  810. </Properties>
  811. ### Response
  812. - `text` (string) Output text
  813. </Col>
  814. <Col sticky>
  815. <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]'`}>
  816. ```bash {{ title: 'cURL' }}
  817. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  818. --header 'Authorization: Bearer {api_key}' \
  819. --form 'file=@localfile;type=audio/mp3'
  820. ```
  821. </CodeGroup>
  822. <CodeGroup title="Response">
  823. ```json {{ title: 'Response' }}
  824. {
  825. "text": ""
  826. }
  827. ```
  828. </CodeGroup>
  829. </Col>
  830. </Row>
  831. ---
  832. <Heading
  833. url='/text-to-audio'
  834. method='POST'
  835. title='Text to Audio'
  836. name='#audio'
  837. />
  838. <Row>
  839. <Col>
  840. Text to speech.
  841. ### Request Body
  842. <Properties>
  843. <Property name='message_id' type='str' key='message_id'>
  844. 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.
  845. </Property>
  846. <Property name='text' type='str' key='text'>
  847. Speech generated content。
  848. </Property>
  849. <Property name='user' type='string' key='user'>
  850. The user identifier, defined by the developer, must ensure uniqueness within the app.
  851. </Property>
  852. </Properties>
  853. </Col>
  854. <Col sticky>
  855. <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`}>
  856. ```bash {{ title: 'cURL' }}
  857. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  858. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  859. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  860. ```
  861. </CodeGroup>
  862. <CodeGroup title="headers">
  863. ```json {{ title: 'headers' }}
  864. {
  865. "Content-Type": "audio/wav"
  866. }
  867. ```
  868. </CodeGroup>
  869. </Col>
  870. </Row>
  871. ---
  872. <Heading
  873. url='/info'
  874. method='GET'
  875. title='Get Application Basic Information'
  876. name='#info'
  877. />
  878. <Row>
  879. <Col>
  880. Used to get basic information about this application
  881. ### Response
  882. - `name` (string) application name
  883. - `description` (string) application description
  884. - `tags` (array[string]) application tags
  885. </Col>
  886. <Col>
  887. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  888. ```bash {{ title: 'cURL' }}
  889. curl -X GET '${props.appDetail.api_base_url}/info' \
  890. -H 'Authorization: Bearer {api_key}'
  891. ```
  892. </CodeGroup>
  893. <CodeGroup title="Response">
  894. ```json {{ title: 'Response' }}
  895. {
  896. "name": "My App",
  897. "description": "This is my app.",
  898. "tags": [
  899. "tag1",
  900. "tag2"
  901. ]
  902. }
  903. ```
  904. </CodeGroup>
  905. </Col>
  906. </Row>
  907. ---
  908. <Heading
  909. url='/parameters'
  910. method='GET'
  911. title='Get Application Parameters Information'
  912. name='#parameters'
  913. />
  914. <Row>
  915. <Col>
  916. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  917. ### Query
  918. <Properties>
  919. <Property name='user' type='string' key='user'>
  920. User identifier, defined by the developer's rules, must be unique within the application.
  921. </Property>
  922. </Properties>
  923. ### Response
  924. - `opening_statement` (string) Opening statement
  925. - `suggested_questions` (array[string]) List of suggested questions for the opening
  926. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  927. - `enabled` (bool) Whether it is enabled
  928. - `speech_to_text` (object) Speech to text
  929. - `enabled` (bool) Whether it is enabled
  930. - `retriever_resource` (object) Citation and Attribution
  931. - `enabled` (bool) Whether it is enabled
  932. - `annotation_reply` (object) Annotation reply
  933. - `enabled` (bool) Whether it is enabled
  934. - `user_input_form` (array[object]) User input form configuration
  935. - `text-input` (object) Text input control
  936. - `label` (string) Variable display label name
  937. - `variable` (string) Variable ID
  938. - `required` (bool) Whether it is required
  939. - `default` (string) Default value
  940. - `paragraph` (object) Paragraph text input control
  941. - `label` (string) Variable display label name
  942. - `variable` (string) Variable ID
  943. - `required` (bool) Whether it is required
  944. - `default` (string) Default value
  945. - `select` (object) Dropdown control
  946. - `label` (string) Variable display label name
  947. - `variable` (string) Variable ID
  948. - `required` (bool) Whether it is required
  949. - `default` (string) Default value
  950. - `options` (array[string]) Option values
  951. - `file_upload` (object) File upload configuration
  952. - `image` (object) Image settings
  953. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  954. - `enabled` (bool) Whether it is enabled
  955. - `number_limits` (int) Image number limit, default is 3
  956. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  957. - `system_parameters` (object) System parameters
  958. - `file_size_limit` (int) Document upload size limit (MB)
  959. - `image_file_size_limit` (int) Image file upload size limit (MB)
  960. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  961. - `video_file_size_limit` (int) Video file upload size limit (MB)
  962. </Col>
  963. <Col sticky>
  964. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  965. ```bash {{ title: 'cURL' }}
  966. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  967. --header 'Authorization: Bearer {api_key}'
  968. ```
  969. </CodeGroup>
  970. <CodeGroup title="Response">
  971. ```json {{ title: 'Response' }}
  972. {
  973. "opening_statement": "Hello!",
  974. "suggested_questions_after_answer": {
  975. "enabled": true
  976. },
  977. "speech_to_text": {
  978. "enabled": true
  979. },
  980. "retriever_resource": {
  981. "enabled": true
  982. },
  983. "annotation_reply": {
  984. "enabled": true
  985. },
  986. "user_input_form": [
  987. {
  988. "paragraph": {
  989. "label": "Query",
  990. "variable": "query",
  991. "required": true,
  992. "default": ""
  993. }
  994. }
  995. ],
  996. "file_upload": {
  997. "image": {
  998. "enabled": false,
  999. "number_limits": 3,
  1000. "detail": "high",
  1001. "transfer_methods": [
  1002. "remote_url",
  1003. "local_file"
  1004. ]
  1005. }
  1006. },
  1007. "system_parameters": {
  1008. "file_size_limit": 15,
  1009. "image_file_size_limit": 10,
  1010. "audio_file_size_limit": 50,
  1011. "video_file_size_limit": 100
  1012. }
  1013. }
  1014. ```
  1015. </CodeGroup>
  1016. </Col>
  1017. </Row>
  1018. ---
  1019. <Heading
  1020. url='/meta'
  1021. method='GET'
  1022. title='Get Application Meta Information'
  1023. name='#meta'
  1024. />
  1025. <Row>
  1026. <Col>
  1027. Used to get icons of tools in this application
  1028. ### Response
  1029. - `tool_icons`(object[string]) tool icons
  1030. - `tool_name` (string)
  1031. - `icon` (object|string)
  1032. - (object) icon object
  1033. - `background` (string) background color in hex format
  1034. - `content`(string) emoji
  1035. - (string) url of icon
  1036. </Col>
  1037. <Col>
  1038. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1039. ```bash {{ title: 'cURL' }}
  1040. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1041. -H 'Authorization: Bearer {api_key}'
  1042. ```
  1043. </CodeGroup>
  1044. <CodeGroup title="Response">
  1045. ```json {{ title: 'Response' }}
  1046. {
  1047. "tool_icons": {
  1048. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1049. "api_tool": {
  1050. "background": "#252525",
  1051. "content": "\ud83d\ude01"
  1052. }
  1053. }
  1054. }
  1055. ```
  1056. </CodeGroup>
  1057. </Col>
  1058. </Row>
  1059. ---
  1060. <Heading
  1061. url='/apps/annotations'
  1062. method='GET'
  1063. title='Get Annotation List'
  1064. name='#annotation_list'
  1065. />
  1066. <Row>
  1067. <Col>
  1068. ### Query
  1069. <Properties>
  1070. <Property name='page' type='string' key='page'>
  1071. Page number
  1072. </Property>
  1073. <Property name='limit' type='string' key='limit'>
  1074. Number of items returned, default 20, range 1-100
  1075. </Property>
  1076. </Properties>
  1077. </Col>
  1078. <Col sticky>
  1079. <CodeGroup
  1080. title="Request"
  1081. tag="GET"
  1082. label="/apps/annotations"
  1083. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \\\n--header 'Authorization: Bearer {api_key}'`}
  1084. >
  1085. ```bash {{ title: 'cURL' }}
  1086. curl --location --request GET '${props.apiBaseUrl}/apps/annotations?page=1&limit=20' \
  1087. --header 'Authorization: Bearer {api_key}'
  1088. ```
  1089. </CodeGroup>
  1090. <CodeGroup title="Response">
  1091. ```json {{ title: 'Response' }}
  1092. {
  1093. "data": [
  1094. {
  1095. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1096. "question": "What is your name?",
  1097. "answer": "I am Dify.",
  1098. "hit_count": 0,
  1099. "created_at": 1735625869
  1100. }
  1101. ],
  1102. "has_more": false,
  1103. "limit": 20,
  1104. "total": 1,
  1105. "page": 1
  1106. }
  1107. ```
  1108. </CodeGroup>
  1109. </Col>
  1110. </Row>
  1111. ---
  1112. <Heading
  1113. url='/apps/annotations'
  1114. method='POST'
  1115. title='Create Annotation'
  1116. name='#create_annotation'
  1117. />
  1118. <Row>
  1119. <Col>
  1120. ### Query
  1121. <Properties>
  1122. <Property name='question' type='string' key='question'>
  1123. Question
  1124. </Property>
  1125. <Property name='answer' type='string' key='answer'>
  1126. Answer
  1127. </Property>
  1128. </Properties>
  1129. </Col>
  1130. <Col sticky>
  1131. <CodeGroup
  1132. title="Request"
  1133. tag="POST"
  1134. label="/apps/annotations"
  1135. 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."}'`}
  1136. >
  1137. ```bash {{ title: 'cURL' }}
  1138. curl --location --request POST '${props.apiBaseUrl}/apps/annotations' \
  1139. --header 'Authorization: Bearer {api_key}' \
  1140. --header 'Content-Type: application/json' \
  1141. --data-raw '{
  1142. "question": "What is your name?",
  1143. "answer": "I am Dify."
  1144. }'
  1145. ```
  1146. </CodeGroup>
  1147. <CodeGroup title="Response">
  1148. ```json {{ title: 'Response' }}
  1149. {
  1150. {
  1151. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1152. "question": "What is your name?",
  1153. "answer": "I am Dify.",
  1154. "hit_count": 0,
  1155. "created_at": 1735625869
  1156. }
  1157. }
  1158. ```
  1159. </CodeGroup>
  1160. </Col>
  1161. </Row>
  1162. ---
  1163. <Heading
  1164. url='/apps/annotations/{annotation_id}'
  1165. method='PUT'
  1166. title='Update Annotation'
  1167. name='#update_annotation'
  1168. />
  1169. <Row>
  1170. <Col>
  1171. ### Query
  1172. <Properties>
  1173. <Property name='annotation_id' type='string' key='annotation_id'>
  1174. Annotation ID
  1175. </Property>
  1176. <Property name='question' type='string' key='question'>
  1177. Question
  1178. </Property>
  1179. <Property name='answer' type='string' key='answer'>
  1180. Answer
  1181. </Property>
  1182. </Properties>
  1183. </Col>
  1184. <Col sticky>
  1185. <CodeGroup
  1186. title="Request"
  1187. tag="PUT"
  1188. label="/apps/annotations/{annotation_id}"
  1189. 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."}'`}
  1190. >
  1191. ```bash {{ title: 'cURL' }}
  1192. curl --location --request POST '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1193. --header 'Authorization: Bearer {api_key}' \
  1194. --header 'Content-Type: application/json' \
  1195. --data-raw '{
  1196. "question": "What is your name?",
  1197. "answer": "I am Dify."
  1198. }'
  1199. ```
  1200. </CodeGroup>
  1201. <CodeGroup title="Response">
  1202. ```json {{ title: 'Response' }}
  1203. {
  1204. {
  1205. "id": "69d48372-ad81-4c75-9c46-2ce197b4d402",
  1206. "question": "What is your name?",
  1207. "answer": "I am Dify.",
  1208. "hit_count": 0,
  1209. "created_at": 1735625869
  1210. }
  1211. }
  1212. ```
  1213. </CodeGroup>
  1214. </Col>
  1215. </Row>
  1216. ---
  1217. <Heading
  1218. url='/apps/annotations/{annotation_id}'
  1219. method='DELETE'
  1220. title='Delete Annotation'
  1221. name='#delete_annotation'
  1222. />
  1223. <Row>
  1224. <Col>
  1225. ### Query
  1226. <Properties>
  1227. <Property name='annotation_id' type='string' key='annotation_id'>
  1228. Annotation ID
  1229. </Property>
  1230. </Properties>
  1231. </Col>
  1232. <Col sticky>
  1233. <CodeGroup
  1234. title="Request"
  1235. tag="PUT"
  1236. label="/apps/annotations/{annotation_id}"
  1237. targetCode={`curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json'`}
  1238. >
  1239. ```bash {{ title: 'cURL' }}
  1240. curl --location --request DELETE '${props.apiBaseUrl}/apps/annotations/{annotation_id}' \
  1241. --header 'Authorization: Bearer {api_key}'
  1242. ```
  1243. </CodeGroup>
  1244. <CodeGroup title="Response">
  1245. ```json {{ title: 'Response' }}
  1246. {"result": "success"}
  1247. ```
  1248. </CodeGroup>
  1249. </Col>
  1250. </Row>
  1251. ---
  1252. <Heading
  1253. url='/apps/annotation-reply/{action}'
  1254. method='POST'
  1255. title='Initial Annotation Reply Settings'
  1256. name='#initial_annotation_reply_settings'
  1257. />
  1258. <Row>
  1259. <Col>
  1260. ### Query
  1261. <Properties>
  1262. <Property name='action' type='string' key='action'>
  1263. Action, can only be 'enable' or 'disable'
  1264. </Property>
  1265. <Property name='embedding_model_provider' type='string' key='embedding_model_provider'>
  1266. Specified embedding model provider, must be set up in the system first, corresponding to the provider field(Optional)
  1267. </Property>
  1268. <Property name='embedding_model' type='string' key='embedding_model'>
  1269. Specified embedding model, corresponding to the model field(Optional)
  1270. </Property>
  1271. <Property name='score_threshold' type='number' key='score_threshold'>
  1272. The similarity threshold for matching annotated replies. Only annotations with scores above this threshold will be recalled.
  1273. </Property>
  1274. </Properties>
  1275. </Col>
  1276. <Col sticky>
  1277. 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.
  1278. <CodeGroup
  1279. title="Request"
  1280. tag="POST"
  1281. label="/apps/annotation-reply/{action}"
  1282. 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"}'`}
  1283. >
  1284. ```bash {{ title: 'cURL' }}
  1285. curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \
  1286. --header 'Authorization: Bearer {api_key}' \
  1287. --header 'Content-Type: application/json' \
  1288. --data-raw '{
  1289. "score_threshold": 0.9,
  1290. "embedding_provider_name": "zhipu",
  1291. "embedding_model_name": "embedding_3"
  1292. }'
  1293. ```
  1294. </CodeGroup>
  1295. <CodeGroup title="Response">
  1296. ```json {{ title: 'Response' }}
  1297. {
  1298. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1299. "job_status": "waiting"
  1300. }
  1301. ```
  1302. </CodeGroup>
  1303. 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.
  1304. </Col>
  1305. </Row>
  1306. ---
  1307. <Heading
  1308. url='/apps/annotation-reply/{action}/status/{job_id}'
  1309. method='GET'
  1310. title='Query Initial Annotation Reply Settings Task Status'
  1311. name='#initial_annotation_reply_settings_task_status'
  1312. />
  1313. <Row>
  1314. <Col>
  1315. ### Query
  1316. <Properties>
  1317. <Property name='action' type='string' key='action'>
  1318. Action, can only be 'enable' or 'disable', must be the same as the action in the initial annotation reply settings interface
  1319. </Property>
  1320. <Property name='job_id' type='string' key='job_id'>
  1321. Job ID,
  1322. </Property>
  1323. </Properties>
  1324. </Col>
  1325. <Col sticky>
  1326. <CodeGroup
  1327. title="Request"
  1328. tag="GET"
  1329. label="/apps/annotations"
  1330. targetCode={`curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \\\n--header 'Authorization: Bearer {api_key}'`}
  1331. >
  1332. ```bash {{ title: 'cURL' }}
  1333. curl --location --request GET '${props.apiBaseUrl}/apps/annotation-reply/{action}/status/{job_id}' \
  1334. --header 'Authorization: Bearer {api_key}'
  1335. ```
  1336. </CodeGroup>
  1337. <CodeGroup title="Response">
  1338. ```json {{ title: 'Response' }}
  1339. {
  1340. "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802",
  1341. "job_status": "waiting",
  1342. "error_msg": ""
  1343. }
  1344. ```
  1345. </CodeGroup>
  1346. </Col>
  1347. </Row>