template_chat.en.mdx 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. - `message_id` (string) Unique message ID
  72. - `conversation_id` (string) Conversation ID
  73. - `mode` (string) App mode, fixed as `chat`
  74. - `answer` (string) Complete response content
  75. - `metadata` (object) Metadata
  76. - `usage` (Usage) Model usage information
  77. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  78. - `created_at` (int) Message creation timestamp, e.g., 1705395332
  79. ### ChunkChatCompletionResponse
  80. Returns the stream chunks outputted by the App, `Content-Type` is `text/event-stream`.
  81. Each streaming chunk starts with `data:`, separated by two newline characters `\n\n`, as shown below:
  82. <CodeGroup>
  83. ```streaming {{ title: 'Response' }}
  84. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  85. ```
  86. </CodeGroup>
  87. The structure of the streaming chunks varies depending on the `event`:
  88. - `event: message` LLM returns text chunk event, i.e., the complete text is output in a chunked fashion.
  89. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  90. - `message_id` (string) Unique message ID
  91. - `conversation_id` (string) Conversation ID
  92. - `answer` (string) LLM returned text chunk content
  93. - `created_at` (int) Creation timestamp, e.g., 1705395332
  94. - `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)
  95. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  96. - `message_id` (string) Unique message ID
  97. - `conversation_id` (string) Conversation ID
  98. - `answer` (string) LLM returned text chunk content
  99. - `created_at` (int) Creation timestamp, e.g., 1705395332
  100. - `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)
  101. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  102. - `message_id` (string) Unique message ID
  103. - `audio` (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player
  104. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  105. - `event: tts_message_end` TTS audio stream end event, receiving this event indicates the end of the audio stream.
  106. - `task_id` (string) Task ID, used for request tracking and the stop response interface below
  107. - `message_id` (string) Unique message ID
  108. - `audio` (string) The end event has no audio, so this is an empty string
  109. - `created_at` (int) Creation timestamp, e.g.: 1705395332
  110. - `event: agent_thought` thought of Agent, contains the thought of LLM, input and output of tool calls (Only supported in Agent mode)
  111. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  112. - `task_id` (string) (string) Task ID, used for request tracking and the below Stop Generate API
  113. - `message_id` (string) Unique message ID
  114. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  115. - `thought` (string) What LLM is thinking about
  116. - `observation` (string) Response from tool calls
  117. - `tool` (string) A list of tools represents which tools are called,split by ;
  118. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  119. - `created_at` (int) Creation timestamp, e.g., 1705395332
  120. - `message_files` (array[string]) Refer to message_file event
  121. - `file_id` (string) File ID
  122. - `conversation_id` (string) Conversation ID
  123. - `event: message_file` Message file event, a new file has created by tool
  124. - `id` (string) File unique ID
  125. - `type` (string) File type,only allow "image" currently
  126. - `belongs_to` (string) Belongs to, it will only be an 'assistant' here
  127. - `url` (string) Remote url of file
  128. - `conversation_id` (string) Conversation ID
  129. - `event: message_end` Message end event, receiving this event means streaming has ended.
  130. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  131. - `message_id` (string) Unique message ID
  132. - `conversation_id` (string) Conversation ID
  133. - `metadata` (object) Metadata
  134. - `usage` (Usage) Model usage information
  135. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  136. - `event: message_replace` Message content replacement event.
  137. 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.
  138. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  139. - `message_id` (string) Unique message ID
  140. - `conversation_id` (string) Conversation ID
  141. - `answer` (string) Replacement content (directly replaces all LLM reply text)
  142. - `created_at` (int) Creation timestamp, e.g., 1705395332
  143. - `event: error`
  144. 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.
  145. - `task_id` (string) Task ID, used for request tracking and the below Stop Generate API
  146. - `message_id` (string) Unique message ID
  147. - `status` (int) HTTP status code
  148. - `code` (string) Error code
  149. - `message` (string) Error message
  150. - `event: ping` Ping event every 10 seconds to keep the connection alive.
  151. ### Errors
  152. - 404, Conversation does not exists
  153. - 400, `invalid_param`, abnormal parameter input
  154. - 400, `app_unavailable`, App configuration unavailable
  155. - 400, `provider_not_initialize`, no available model credential configuration
  156. - 400, `provider_quota_exceeded`, model invocation quota insufficient
  157. - 400, `model_currently_not_support`, current model unavailable
  158. - 400, `completion_request_error`, text generation failed
  159. - 500, internal server error
  160. </Col>
  161. <Col sticky>
  162. <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}'`}>
  163. ```bash {{ title: 'cURL' }}
  164. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  165. --header 'Authorization: Bearer {api_key}' \
  166. --header 'Content-Type: application/json' \
  167. --data-raw '{
  168. "inputs": {},
  169. "query": "eh",
  170. "response_mode": "streaming",
  171. "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  172. "user": "abc-123"
  173. }'
  174. ```
  175. </CodeGroup>
  176. ### Blocking Mode
  177. <CodeGroup title="Response">
  178. ```json {{ title: 'Response' }}
  179. {
  180. "event": "message",
  181. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  182. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  183. "mode": "chat",
  184. "answer": "iPhone 13 Pro Max specs are listed here:...",
  185. "metadata": {
  186. "usage": {
  187. "prompt_tokens": 1033,
  188. "prompt_unit_price": "0.001",
  189. "prompt_price_unit": "0.001",
  190. "prompt_price": "0.0010330",
  191. "completion_tokens": 128,
  192. "completion_unit_price": "0.002",
  193. "completion_price_unit": "0.001",
  194. "completion_price": "0.0002560",
  195. "total_tokens": 1161,
  196. "total_price": "0.0012890",
  197. "currency": "USD",
  198. "latency": 0.7682376249867957
  199. },
  200. "retriever_resources": [
  201. {
  202. "position": 1,
  203. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  204. "dataset_name": "iPhone",
  205. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  206. "document_name": "iPhone List",
  207. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  208. "score": 0.98457545,
  209. "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\""
  210. }
  211. ]
  212. },
  213. "created_at": 1705407629
  214. }
  215. ```
  216. </CodeGroup>
  217. ### Streaming Mode ( Basic Assistant )
  218. <CodeGroup title="Response">
  219. ```streaming {{ title: 'Response' }}
  220. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  221. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  222. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  223. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  224. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  225. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  226. 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\""}]}}
  227. 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"}
  228. 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": ""}
  229. ```
  230. </CodeGroup>
  231. ### Response Example(Agent Assistant)
  232. <CodeGroup title="Response">
  233. ```streaming {{ title: 'Response' }}
  234. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  235. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  236. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  237. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  238. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  239. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  240. 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\""}]}}
  241. 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"}
  242. 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": ""}
  243. ```
  244. </CodeGroup>
  245. </Col>
  246. </Row>
  247. ---
  248. <Heading
  249. url='/files/upload'
  250. method='POST'
  251. title='File Upload'
  252. name='#file-upload'
  253. />
  254. <Row>
  255. <Col>
  256. Upload a file (currently only images are supported) for use when sending messages, enabling multimodal understanding of images and text.
  257. Supports png, jpg, jpeg, webp, gif formats.
  258. Uploaded files are for use by the current end-user only.
  259. ### Request Body
  260. This interface requires a `multipart/form-data` request.
  261. - `file` (File) Required
  262. The file to be uploaded.
  263. - `user` (string) Required
  264. User identifier, defined by the developer's rules, must be unique within the application.
  265. ### Response
  266. After a successful upload, the server will return the file's ID and related information.
  267. - `id` (uuid) ID
  268. - `name` (string) File name
  269. - `size` (int) File size (bytes)
  270. - `extension` (string) File extension
  271. - `mime_type` (string) File mime-type
  272. - `created_by` (uuid) End-user ID
  273. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  274. ### Errors
  275. - 400, `no_file_uploaded`, a file must be provided
  276. - 400, `too_many_files`, currently only one file is accepted
  277. - 400, `unsupported_preview`, the file does not support preview
  278. - 400, `unsupported_estimate`, the file does not support estimation
  279. - 413, `file_too_large`, the file is too large
  280. - 415, `unsupported_file_type`, unsupported extension, currently only document files are accepted
  281. - 503, `s3_connection_failed`, unable to connect to S3 service
  282. - 503, `s3_permission_denied`, no permission to upload files to S3
  283. - 503, `s3_file_too_large`, file exceeds S3 size limit
  284. - 500, internal server error
  285. </Col>
  286. <Col sticky>
  287. ### Request Example
  288. <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'`}>
  289. ```bash {{ title: 'cURL' }}
  290. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  291. --header 'Authorization: Bearer {api_key}' \
  292. --form 'file=@"/path/to/file"'
  293. ```
  294. </CodeGroup>
  295. ### Response Example
  296. <CodeGroup title="Response">
  297. ```json {{ title: 'Response' }}
  298. {
  299. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  300. "name": "example.png",
  301. "size": 1024,
  302. "extension": "png",
  303. "mime_type": "image/png",
  304. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  305. "created_at": 1577836800,
  306. }
  307. ```
  308. </CodeGroup>
  309. </Col>
  310. </Row>
  311. ---
  312. <Heading
  313. url='/chat-messages/:task_id/stop'
  314. method='POST'
  315. title='Stop Generate'
  316. name='#stop-generatebacks'
  317. />
  318. <Row>
  319. <Col>
  320. Only supported in streaming mode.
  321. ### Path
  322. - `task_id` (string) Task ID, can be obtained from the streaming chunk return
  323. ### Request Body
  324. - `user` (string) Required
  325. User identifier, used to define the identity of the end-user, must be consistent with the user passed in the send message interface.
  326. ### Response
  327. - `result` (string) Always returns "success"
  328. </Col>
  329. <Col sticky>
  330. ### Request Example
  331. <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"}'`}>
  332. ```bash {{ title: 'cURL' }}
  333. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  334. -H 'Authorization: Bearer {api_key}' \
  335. -H 'Content-Type: application/json' \
  336. --data-raw '{
  337. "user": "abc-123"
  338. }'
  339. ```
  340. </CodeGroup>
  341. ### Response Example
  342. <CodeGroup title="Response">
  343. ```json {{ title: 'Response' }}
  344. {
  345. "result": "success"
  346. }
  347. ```
  348. </CodeGroup>
  349. </Col>
  350. </Row>
  351. ---
  352. <Heading
  353. url='/messages/:message_id/feedbacks'
  354. method='POST'
  355. title='Message Feedback'
  356. name='#feedbacks'
  357. />
  358. <Row>
  359. <Col>
  360. End-users can provide feedback messages, facilitating application developers to optimize expected outputs.
  361. ### Path
  362. <Properties>
  363. <Property name='message_id' type='string' key='message_id'>
  364. Message ID
  365. </Property>
  366. </Properties>
  367. ### Request Body
  368. <Properties>
  369. <Property name='rating' type='string' key='rating'>
  370. Upvote as `like`, downvote as `dislike`, revoke upvote as `null`
  371. </Property>
  372. <Property name='user' type='string' key='user'>
  373. User identifier, defined by the developer's rules, must be unique within the application.
  374. </Property>
  375. <Property name='content' type='string' key='content'>
  376. The specific content of message feedback.
  377. </Property>
  378. </Properties>
  379. ### Response
  380. - `result` (string) Always returns "success"
  381. </Col>
  382. <Col sticky>
  383. <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}'`}>
  384. ```bash {{ title: 'cURL' }}
  385. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  386. --header 'Authorization: Bearer {api_key}' \
  387. --header 'Content-Type: application/json' \
  388. --data-raw '{
  389. "rating": "like",
  390. "user": "abc-123",
  391. "content": "message feedback information"
  392. }'
  393. ```
  394. </CodeGroup>
  395. <CodeGroup title="Response">
  396. ```json {{ title: 'Response' }}
  397. {
  398. "result": "success"
  399. }
  400. ```
  401. </CodeGroup>
  402. </Col>
  403. </Row>
  404. ---
  405. <Heading
  406. url='/messages/{message_id}/suggested'
  407. method='GET'
  408. title='Next Suggested Questions'
  409. name='#suggested'
  410. />
  411. <Row>
  412. <Col>
  413. Get next questions suggestions for the current message
  414. ### Path Params
  415. <Properties>
  416. <Property name='message_id' type='string' key='message_id'>
  417. Message ID
  418. </Property>
  419. </Properties>
  420. ### Query
  421. <Properties>
  422. <Property name='user' type='string' key='user'>
  423. User identifier, used to define the identity of the end-user for retrieval and statistics.
  424. Should be uniquely defined by the developer within the application.
  425. </Property>
  426. </Properties>
  427. </Col>
  428. <Col sticky>
  429. <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'`}>
  430. ```bash {{ title: 'cURL' }}
  431. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
  432. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  433. --header 'Content-Type: application/json' \
  434. ```
  435. </CodeGroup>
  436. <CodeGroup title="Response">
  437. ```json {{ title: 'Response' }}
  438. {
  439. "result": "success",
  440. "data": [
  441. "a",
  442. "b",
  443. "c"
  444. ]
  445. }
  446. ```
  447. </CodeGroup>
  448. </Col>
  449. </Row>
  450. ---
  451. <Heading
  452. url='/messages'
  453. method='GET'
  454. title='Get Conversation History Messages'
  455. name='#messages'
  456. />
  457. <Row>
  458. <Col>
  459. Returns historical chat records in a scrolling load format, with the first page returning the latest `{limit}` messages, i.e., in reverse order.
  460. ### Query
  461. <Properties>
  462. <Property name='conversation_id' type='string' key='conversation_id'>
  463. Conversation ID
  464. </Property>
  465. <Property name='user' type='string' key='user'>
  466. User identifier, used to define the identity of the end-user for retrieval and statistics.
  467. Should be uniquely defined by the developer within the application.
  468. </Property>
  469. <Property name='first_id' type='string' key='first_id'>
  470. The ID of the first chat record on the current page, default is null.
  471. </Property>
  472. <Property name='limit' type='int' key='limit'>
  473. How many chat history messages to return in one request, default is 20.
  474. </Property>
  475. </Properties>
  476. ### Response
  477. - `data` (array[object]) Message list
  478. - `id` (string) Message ID
  479. - `conversation_id` (string) Conversation ID
  480. - `inputs` (object) User input parameters.
  481. - `query` (string) User input / question content.
  482. - `message_files` (array[object]) Message files
  483. - `id` (string) ID
  484. - `type` (string) File type, image for images
  485. - `url` (string) Preview image URL
  486. - `belongs_to` (string) belongs to,user or assistant
  487. - `agent_thoughts` (array[object]) Agent thought(Empty if it's a Basic Assistant)
  488. - `id` (string) Agent thought ID, every iteration has a unique agent thought ID
  489. - `message_id` (string) Unique message ID
  490. - `position` (int) Position of current agent thought, each message may have multiple thoughts in order.
  491. - `thought` (string) What LLM is thinking about
  492. - `observation` (string) Response from tool calls
  493. - `tool` (string) A list of tools represents which tools are called,split by ;
  494. - `tool_input` (string) Input of tools in JSON format. Like: `{"dalle3": {"prompt": "a cute cat"}}`.
  495. - `created_at` (int) Creation timestamp, e.g., 1705395332
  496. - `message_files` (array[string]) Refer to message_file event
  497. - `file_id` (string) File ID
  498. - `answer` (string) Response message content
  499. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  500. - `feedback` (object) Feedback information
  501. - `rating` (string) Upvote as `like` / Downvote as `dislike`
  502. - `retriever_resources` (array[RetrieverResource]) Citation and Attribution List
  503. - `has_more` (bool) Whether there is a next page
  504. - `limit` (int) Number of returned items, if input exceeds system limit, returns system limit amount
  505. </Col>
  506. <Col sticky>
  507. <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}'`}>
  508. ```bash {{ title: 'cURL' }}
  509. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  510. --header 'Authorization: Bearer {api_key}'
  511. ```
  512. </CodeGroup>
  513. ### Response Example (Basic Assistant)
  514. <CodeGroup title="Response">
  515. ```json {{ title: 'Response' }}
  516. {
  517. "limit": 20,
  518. "has_more": false,
  519. "data": [
  520. {
  521. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  522. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  523. "inputs": {
  524. "name": "dify"
  525. },
  526. "query": "iphone 13 pro",
  527. "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.",
  528. "message_files": [],
  529. "feedback": null,
  530. "retriever_resources": [
  531. {
  532. "position": 1,
  533. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  534. "dataset_name": "iPhone",
  535. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  536. "document_name": "iPhone List",
  537. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  538. "score": 0.98457545,
  539. "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\""
  540. }
  541. ],
  542. "agent_thoughts": [],
  543. "created_at": 1705569239,
  544. }
  545. ]
  546. }
  547. ```
  548. </CodeGroup>
  549. ### Response Example (Agent Assistant)
  550. <CodeGroup title="Response">
  551. ```json {{ title: 'Response' }}
  552. {
  553. "limit": 20,
  554. "has_more": false,
  555. "data": [
  556. {
  557. "id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  558. "conversation_id": "957c068b-f258-4f89-ba10-6e8a0361c457",
  559. "inputs": {},
  560. "query": "draw a cat",
  561. "answer": "I have generated an image of a cat for you. Please check your messages to view the image.",
  562. "message_files": [
  563. {
  564. "id": "976990d2-5294-47e6-8f14-7356ba9d2d76",
  565. "type": "image",
  566. "url": "http://127.0.0.1:5001/files/tools/976990d2-5294-47e6-8f14-7356ba9d2d76.png?timestamp=1705988524&nonce=55df3f9f7311a9acd91bf074cd524092&sign=z43nMSO1L2HBvoqADLkRxr7Biz0fkjeDstnJiCK1zh8=",
  567. "belongs_to": "assistant"
  568. }
  569. ],
  570. "feedback": null,
  571. "retriever_resources": [],
  572. "created_at": 1705988187,
  573. "agent_thoughts": [
  574. {
  575. "id": "592c84cf-07ee-441c-9dcc-ffc66c033469",
  576. "chain_id": null,
  577. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  578. "position": 1,
  579. "thought": "",
  580. "tool": "dalle2",
  581. "tool_input": "{\"dalle2\": {\"prompt\": \"cat\"}}",
  582. "created_at": 1705988186,
  583. "observation": "image has been created and sent to user already, you should tell user to check it now.",
  584. "files": [
  585. "976990d2-5294-47e6-8f14-7356ba9d2d76"
  586. ]
  587. },
  588. {
  589. "id": "73ead60d-2370-4780-b5ed-532d2762b0e5",
  590. "chain_id": null,
  591. "message_id": "d35e006c-7c4d-458f-9142-be4930abdf94",
  592. "position": 2,
  593. "thought": "I have generated an image of a cat for you. Please check your messages to view the image.",
  594. "tool": "",
  595. "tool_input": "",
  596. "created_at": 1705988199,
  597. "observation": "",
  598. "files": []
  599. }
  600. ]
  601. }
  602. ]
  603. }
  604. ```
  605. </CodeGroup>
  606. </Col>
  607. </Row>
  608. ---
  609. <Heading
  610. url='/conversations'
  611. method='GET'
  612. title='Get Conversations'
  613. name='#conversations'
  614. />
  615. <Row>
  616. <Col>
  617. Retrieve the conversation list for the current user, defaulting to the most recent 20 entries.
  618. ### Query
  619. <Properties>
  620. <Property name='user' type='string' key='user'>
  621. User identifier, used to define the identity of the end-user for retrieval and statistics.
  622. Should be uniquely defined by the developer within the application.
  623. </Property>
  624. <Property name='last_id' type='string' key='last_id'>
  625. (Optional) The ID of the last record on the current page, default is null.
  626. </Property>
  627. <Property name='limit' type='int' key='limit'>
  628. (Optional) How many records to return in one request, default is the most recent 20 entries. Maximum 100, minimum 1.
  629. </Property>
  630. <Property name='sort_by' type='string' key='sort_by'>
  631. (Optional) Sorting Field, Default: -updated_at (sorted in descending order by update time)
  632. - Available Values: created_at, -created_at, updated_at, -updated_at
  633. - The symbol before the field represents the order or reverse, "-" represents reverse order.
  634. </Property>
  635. </Properties>
  636. ### Response
  637. - `data` (array[object]) List of conversations
  638. - `id` (string) Conversation ID
  639. - `name` (string) Conversation name, by default, is a snippet of the first question asked by the user in the conversation.
  640. - `inputs` (object) User input parameters.
  641. - `status` (string) Conversation status
  642. - `introduction` (string) Introduction
  643. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  644. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  645. - `has_more` (bool)
  646. - `limit` (int) Number of entries returned, if input exceeds system limit, system limit number is returned
  647. </Col>
  648. <Col sticky>
  649. <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}'`}>
  650. ```bash {{ title: 'cURL' }}
  651. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  652. --header 'Authorization: Bearer {api_key}'
  653. ```
  654. </CodeGroup>
  655. <CodeGroup title="Response">
  656. ```json {{ title: 'Response' }}
  657. {
  658. "limit": 20,
  659. "has_more": false,
  660. "data": [
  661. {
  662. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  663. "name": "New chat",
  664. "inputs": {
  665. "book": "book",
  666. "myName": "Lucy"
  667. },
  668. "status": "normal",
  669. "created_at": 1679667915,
  670. "updated_at": 1679667915
  671. },
  672. {
  673. "id": "hSIhXBhNe8X1d8Et"
  674. // ...
  675. }
  676. ]
  677. }
  678. ```
  679. </CodeGroup>
  680. </Col>
  681. </Row>
  682. ---
  683. <Heading
  684. url='/conversations/:conversation_id'
  685. method='DELETE'
  686. title='Delete Conversation'
  687. name='#delete'
  688. />
  689. <Row>
  690. <Col>
  691. Delete a conversation.
  692. ### Path
  693. - `conversation_id` (string) Conversation ID
  694. ### Request Body
  695. <Properties>
  696. <Property name='user' type='string' key='user'>
  697. The user identifier, defined by the developer, must ensure uniqueness within the application.
  698. </Property>
  699. </Properties>
  700. ### Response
  701. - `result` (string) Always returns "success"
  702. </Col>
  703. <Col sticky>
  704. <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}'`}>
  705. ```bash {{ title: 'cURL' }}
  706. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  707. --header 'Content-Type: application/json' \
  708. --header 'Accept: application/json' \
  709. --header 'Authorization: Bearer {api_key}' \
  710. --data '{
  711. "user": "abc-123"
  712. }'
  713. ```
  714. </CodeGroup>
  715. <CodeGroup title="Response">
  716. ```json {{ title: 'Response' }}
  717. {
  718. "result": "success"
  719. }
  720. ```
  721. </CodeGroup>
  722. </Col>
  723. </Row>
  724. ---
  725. <Heading
  726. url='/conversations/:conversation_id/name'
  727. method='POST'
  728. title='Conversation Rename'
  729. name='#rename'
  730. />
  731. <Row>
  732. <Col>
  733. ### Request Body
  734. Rename the session, the session name is used for display on clients that support multiple sessions.
  735. ### Path
  736. - `conversation_id` (string) Conversation ID
  737. <Properties>
  738. <Property name='name' type='string' key='name'>
  739. (Optional) The name of the conversation. This parameter can be omitted if `auto_generate` is set to `true`.
  740. </Property>
  741. <Property name='auto_generate' type='bool' key='auto_generate'>
  742. (Optional) Automatically generate the title, default is `false`
  743. </Property>
  744. <Property name='user' type='string' key='user'>
  745. The user identifier, defined by the developer, must ensure uniqueness within the application.
  746. </Property>
  747. </Properties>
  748. ### Response
  749. - `id` (string) Conversation ID
  750. - `name` (string) Conversation name
  751. - `inputs` (object) User input parameters
  752. - `status` (string) Conversation status
  753. - `introduction` (string) Introduction
  754. - `created_at` (timestamp) Creation timestamp, e.g., 1705395332
  755. - `updated_at` (timestamp) Update timestamp, e.g., 1705395332
  756. </Col>
  757. <Col sticky>
  758. <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}'`}>
  759. ```bash {{ title: 'cURL' }}
  760. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  761. --header 'Content-Type: application/json' \
  762. --header 'Authorization: Bearer {api_key}' \
  763. --data-raw '{
  764. "name": "",
  765. "auto_generate": true,
  766. "user": "abc-123"
  767. }'
  768. ```
  769. </CodeGroup>
  770. <CodeGroup title="Response">
  771. ```json {{ title: 'Response' }}
  772. {
  773. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  774. "name": "Chat vs AI",
  775. "inputs": {},
  776. "status": "normal",
  777. "introduction": "",
  778. "created_at": 1705569238,
  779. "updated_at": 1705569238
  780. }
  781. ```
  782. </CodeGroup>
  783. </Col>
  784. </Row>
  785. ---
  786. <Heading
  787. url='/audio-to-text'
  788. method='POST'
  789. title='Speech to Text'
  790. name='#audio'
  791. />
  792. <Row>
  793. <Col>
  794. This endpoint requires a multipart/form-data request.
  795. ### Request Body
  796. <Properties>
  797. <Property name='file' type='file' key='file'>
  798. Audio file.
  799. Supported formats: `['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  800. File size limit: 15MB
  801. </Property>
  802. <Property name='user' type='string' key='user'>
  803. User identifier, defined by the developer's rules, must be unique within the application.
  804. </Property>
  805. </Properties>
  806. ### Response
  807. - `text` (string) Output text
  808. </Col>
  809. <Col sticky>
  810. <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]'`}>
  811. ```bash {{ title: 'cURL' }}
  812. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  813. --header 'Authorization: Bearer {api_key}' \
  814. --form 'file=@localfile;type=audio/mp3'
  815. ```
  816. </CodeGroup>
  817. <CodeGroup title="Response">
  818. ```json {{ title: 'Response' }}
  819. {
  820. "text": ""
  821. }
  822. ```
  823. </CodeGroup>
  824. </Col>
  825. </Row>
  826. ---
  827. <Heading
  828. url='/text-to-audio'
  829. method='POST'
  830. title='Text to Audio'
  831. name='#audio'
  832. />
  833. <Row>
  834. <Col>
  835. Text to speech.
  836. ### Request Body
  837. <Properties>
  838. <Property name='message_id' type='str' key='message_id'>
  839. 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.
  840. </Property>
  841. <Property name='text' type='str' key='text'>
  842. Speech generated content。
  843. </Property>
  844. <Property name='user' type='string' key='user'>
  845. The user identifier, defined by the developer, must ensure uniqueness within the app.
  846. </Property>
  847. </Properties>
  848. </Col>
  849. <Col sticky>
  850. <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`}>
  851. ```bash {{ title: 'cURL' }}
  852. curl --location --request POST '${props.appDetail.api_base_url}/text-to-audio' \
  853. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  854. --form 'file=Hello Dify;user=abc-123;message_id=5ad4cb98-f0c7-4085-b384-88c403be6290'
  855. ```
  856. </CodeGroup>
  857. <CodeGroup title="headers">
  858. ```json {{ title: 'headers' }}
  859. {
  860. "Content-Type": "audio/wav"
  861. }
  862. ```
  863. </CodeGroup>
  864. </Col>
  865. </Row>
  866. ---
  867. <Heading
  868. url='/info'
  869. method='GET'
  870. title='Get Application Basic Information'
  871. name='#info'
  872. />
  873. <Row>
  874. <Col>
  875. Used to get basic information about this application
  876. ### Response
  877. - `name` (string) application name
  878. - `description` (string) application description
  879. - `tags` (array[string]) application tags
  880. </Col>
  881. <Col>
  882. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  883. ```bash {{ title: 'cURL' }}
  884. curl -X GET '${props.appDetail.api_base_url}/info' \
  885. -H 'Authorization: Bearer {api_key}'
  886. ```
  887. </CodeGroup>
  888. <CodeGroup title="Response">
  889. ```json {{ title: 'Response' }}
  890. {
  891. "name": "My App",
  892. "description": "This is my app.",
  893. "tags": [
  894. "tag1",
  895. "tag2"
  896. ]
  897. }
  898. ```
  899. </CodeGroup>
  900. </Col>
  901. </Row>
  902. ---
  903. <Heading
  904. url='/parameters'
  905. method='GET'
  906. title='Get Application Parameters Information'
  907. name='#parameters'
  908. />
  909. <Row>
  910. <Col>
  911. Used at the start of entering the page to obtain information such as features, input parameter names, types, and default values.
  912. ### Query
  913. <Properties>
  914. <Property name='user' type='string' key='user'>
  915. User identifier, defined by the developer's rules, must be unique within the application.
  916. </Property>
  917. </Properties>
  918. ### Response
  919. - `opening_statement` (string) Opening statement
  920. - `suggested_questions` (array[string]) List of suggested questions for the opening
  921. - `suggested_questions_after_answer` (object) Suggest questions after enabling the answer.
  922. - `enabled` (bool) Whether it is enabled
  923. - `speech_to_text` (object) Speech to text
  924. - `enabled` (bool) Whether it is enabled
  925. - `retriever_resource` (object) Citation and Attribution
  926. - `enabled` (bool) Whether it is enabled
  927. - `annotation_reply` (object) Annotation reply
  928. - `enabled` (bool) Whether it is enabled
  929. - `user_input_form` (array[object]) User input form configuration
  930. - `text-input` (object) Text input control
  931. - `label` (string) Variable display label name
  932. - `variable` (string) Variable ID
  933. - `required` (bool) Whether it is required
  934. - `default` (string) Default value
  935. - `paragraph` (object) Paragraph 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. - `select` (object) Dropdown 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. - `options` (array[string]) Option values
  946. - `file_upload` (object) File upload configuration
  947. - `image` (object) Image settings
  948. Currently only supports image types: `png`, `jpg`, `jpeg`, `webp`, `gif`
  949. - `enabled` (bool) Whether it is enabled
  950. - `number_limits` (int) Image number limit, default is 3
  951. - `transfer_methods` (array[string]) List of transfer methods, remote_url, local_file, must choose one
  952. - `system_parameters` (object) System parameters
  953. - `file_size_limit` (int) Document upload size limit (MB)
  954. - `image_file_size_limit` (int) Image file upload size limit (MB)
  955. - `audio_file_size_limit` (int) Audio file upload size limit (MB)
  956. - `video_file_size_limit` (int) Video file upload size limit (MB)
  957. </Col>
  958. <Col sticky>
  959. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  960. ```bash {{ title: 'cURL' }}
  961. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  962. --header 'Authorization: Bearer {api_key}'
  963. ```
  964. </CodeGroup>
  965. <CodeGroup title="Response">
  966. ```json {{ title: 'Response' }}
  967. {
  968. "opening_statement": "Hello!",
  969. "suggested_questions_after_answer": {
  970. "enabled": true
  971. },
  972. "speech_to_text": {
  973. "enabled": true
  974. },
  975. "retriever_resource": {
  976. "enabled": true
  977. },
  978. "annotation_reply": {
  979. "enabled": true
  980. },
  981. "user_input_form": [
  982. {
  983. "paragraph": {
  984. "label": "Query",
  985. "variable": "query",
  986. "required": true,
  987. "default": ""
  988. }
  989. }
  990. ],
  991. "file_upload": {
  992. "image": {
  993. "enabled": false,
  994. "number_limits": 3,
  995. "detail": "high",
  996. "transfer_methods": [
  997. "remote_url",
  998. "local_file"
  999. ]
  1000. }
  1001. },
  1002. "system_parameters": {
  1003. "file_size_limit": 15,
  1004. "image_file_size_limit": 10,
  1005. "audio_file_size_limit": 50,
  1006. "video_file_size_limit": 100
  1007. }
  1008. }
  1009. ```
  1010. </CodeGroup>
  1011. </Col>
  1012. </Row>
  1013. ---
  1014. <Heading
  1015. url='/meta'
  1016. method='GET'
  1017. title='Get Application Meta Information'
  1018. name='#meta'
  1019. />
  1020. <Row>
  1021. <Col>
  1022. Used to get icons of tools in this application
  1023. ### Response
  1024. - `tool_icons`(object[string]) tool icons
  1025. - `tool_name` (string)
  1026. - `icon` (object|string)
  1027. - (object) icon object
  1028. - `background` (string) background color in hex format
  1029. - `content`(string) emoji
  1030. - (string) url of icon
  1031. </Col>
  1032. <Col>
  1033. <CodeGroup title="Request" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1034. ```bash {{ title: 'cURL' }}
  1035. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1036. -H 'Authorization: Bearer {api_key}'
  1037. ```
  1038. </CodeGroup>
  1039. <CodeGroup title="Response">
  1040. ```json {{ title: 'Response' }}
  1041. {
  1042. "tool_icons": {
  1043. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1044. "api_tool": {
  1045. "background": "#252525",
  1046. "content": "\ud83d\ude01"
  1047. }
  1048. }
  1049. }
  1050. ```
  1051. </CodeGroup>
  1052. </Col>
  1053. </Row>