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.

http_api_reference.md 86KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097
  1. ---
  2. sidebar_position: 1
  3. slug: /http_api_reference
  4. ---
  5. # HTTP API
  6. A complete reference for RAGFlow's RESTful API. Before proceeding, please ensure you [have your RAGFlow API key ready for authentication](../guides/models/llm_api_key_setup.md).
  7. ---
  8. ## OpenAI-Compatible API
  9. ---
  10. ### Create chat completion
  11. **POST** `/api/v1/chats_openai/{chat_id}/chat/completions`
  12. Creates a model response for a given chat conversation.
  13. This API follows the same request and response format as OpenAI's API. It allows you to interact with the model in a manner similar to how you would with [OpenAI's API](https://platform.openai.com/docs/api-reference/chat/create).
  14. #### Request
  15. - Method: POST
  16. - URL: `/api/v1/chats_openai/{chat_id}/chat/completions`
  17. - Headers:
  18. - `'content-Type: application/json'`
  19. - `'Authorization: Bearer <YOUR_API_KEY>'`
  20. - Body:
  21. - `"model"`: `string`
  22. - `"messages"`: `object list`
  23. - `"stream"`: `boolean`
  24. ##### Request example
  25. ```bash
  26. curl --request POST \
  27. --url http://{address}/api/v1/chats_openai/{chat_id}/chat/completions \
  28. --header 'Content-Type: application/json' \
  29. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  30. --data '{
  31. "model": "model",
  32. "messages": [{"role": "user", "content": "Say this is a test!"}],
  33. "stream": true
  34. }'
  35. ```
  36. ##### Request Parameters
  37. - `model` (*Body parameter*) `string`, *Required*
  38. The model used to generate the response. The server will parse this automatically, so you can set it to any value for now.
  39. - `messages` (*Body parameter*) `list[object]`, *Required*
  40. A list of historical chat messages used to generate the response. This must contain at least one message with the `user` role.
  41. - `stream` (*Body parameter*) `boolean`
  42. Whether to receive the response as a stream. Set this to `false` explicitly if you prefer to receive the entire response in one go instead of as a stream.
  43. #### Response
  44. Stream:
  45. ```json
  46. {
  47. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  48. "choices": [
  49. {
  50. "delta": {
  51. "content": "This is a test. If you have any specific questions or need information, feel",
  52. "role": "assistant",
  53. "function_call": null,
  54. "tool_calls": null
  55. },
  56. "finish_reason": null,
  57. "index": 0,
  58. "logprobs": null
  59. }
  60. ],
  61. "created": 1740543996,
  62. "model": "model",
  63. "object": "chat.completion.chunk",
  64. "system_fingerprint": "",
  65. "usage": null
  66. }
  67. // omit duplicated information
  68. {"choices":[{"delta":{"content":" free to ask, and I will do my best to provide an answer based on","role":"assistant"}}]}
  69. {"choices":[{"delta":{"content":" the knowledge I have. If your question is unrelated to the provided knowledge base,","role":"assistant"}}]}
  70. {"choices":[{"delta":{"content":" I will let you know.","role":"assistant"}}]}
  71. // the last chunk
  72. {
  73. "id": "chatcmpl-3a9c3572f29311efa69751e139332ced",
  74. "choices": [
  75. {
  76. "delta": {
  77. "content": null,
  78. "role": "assistant",
  79. "function_call": null,
  80. "tool_calls": null
  81. },
  82. "finish_reason": "stop",
  83. "index": 0,
  84. "logprobs": null
  85. }
  86. ],
  87. "created": 1740543996,
  88. "model": "model",
  89. "object": "chat.completion.chunk",
  90. "system_fingerprint": "",
  91. "usage": {
  92. "prompt_tokens": 18,
  93. "completion_tokens": 225,
  94. "total_tokens": 243
  95. }
  96. }
  97. ```
  98. Non-stream:
  99. ```json
  100. {
  101. "choices":[
  102. {
  103. "finish_reason":"stop",
  104. "index":0,
  105. "logprobs":null,
  106. "message":{
  107. "content":"This is a test. If you have any specific questions or need information, feel free to ask, and I will do my best to provide an answer based on the knowledge I have. If your question is unrelated to the provided knowledge base, I will let you know.",
  108. "role":"assistant"
  109. }
  110. }
  111. ],
  112. "created":1740543499,
  113. "id":"chatcmpl-3a9c3572f29311efa69751e139332ced",
  114. "model":"model",
  115. "object":"chat.completion",
  116. "usage":{
  117. "completion_tokens":246,
  118. "completion_tokens_details":{
  119. "accepted_prediction_tokens":246,
  120. "reasoning_tokens":18,
  121. "rejected_prediction_tokens":0
  122. },
  123. "prompt_tokens":18,
  124. "total_tokens":264
  125. }
  126. }
  127. ```
  128. Failure:
  129. ```json
  130. {
  131. "code": 102,
  132. "message": "The last content of this conversation is not from user."
  133. }
  134. ```
  135. ## DATASET MANAGEMENT
  136. ---
  137. ### Create dataset
  138. **POST** `/api/v1/datasets`
  139. Creates a dataset.
  140. #### Request
  141. - Method: POST
  142. - URL: `/api/v1/datasets`
  143. - Headers:
  144. - `'content-Type: application/json'`
  145. - `'Authorization: Bearer <YOUR_API_KEY>'`
  146. - Body:
  147. - `"name"`: `string`
  148. - `"avatar"`: `string`
  149. - `"description"`: `string`
  150. - `"embedding_model"`: `string`
  151. - `"permission"`: `string`
  152. - `"chunk_method"`: `string`
  153. - `"parser_config"`: `object`
  154. ##### Request example
  155. ```bash
  156. curl --request POST \
  157. --url http://{address}/api/v1/datasets \
  158. --header 'Content-Type: application/json' \
  159. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  160. --data '{
  161. "name": "test_1"
  162. }'
  163. ```
  164. ##### Request parameters
  165. - `"name"`: (*Body parameter*), `string`, *Required*
  166. The unique name of the dataset to create. It must adhere to the following requirements:
  167. - Permitted characters include:
  168. - English letters (a-z, A-Z)
  169. - Digits (0-9)
  170. - "_" (underscore)
  171. - Must begin with an English letter or underscore.
  172. - Maximum 65,535 characters.
  173. - Case-insensitive.
  174. - `"avatar"`: (*Body parameter*), `string`
  175. Base64 encoding of the avatar.
  176. - `"description"`: (*Body parameter*), `string`
  177. A brief description of the dataset to create.
  178. - `"embedding_model"`: (*Body parameter*), `string`
  179. The name of the embedding model to use. For example: `"BAAI/bge-zh-v1.5"`
  180. - `"permission"`: (*Body parameter*), `string`
  181. Specifies who can access the dataset to create. Available options:
  182. - `"me"`: (Default) Only you can manage the dataset.
  183. - `"team"`: All team members can manage the dataset.
  184. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  185. The chunking method of the dataset to create. Available options:
  186. - `"naive"`: General (default)
  187. - `"manual"`: Manual
  188. - `"qa"`: Q&A
  189. - `"table"`: Table
  190. - `"paper"`: Paper
  191. - `"book"`: Book
  192. - `"laws"`: Laws
  193. - `"presentation"`: Presentation
  194. - `"picture"`: Picture
  195. - `"one"`: One
  196. - `"knowledge_graph"`: Knowledge Graph
  197. Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
  198. - `"email"`: Email
  199. - `"parser_config"`: (*Body parameter*), `object`
  200. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  201. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  202. - `"chunk_token_count"`: Defaults to `128`.
  203. - `"layout_recognize"`: Defaults to `true`.
  204. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  205. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  206. - `"task_page_size"`: Defaults to `12`. For PDF only.
  207. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  208. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  209. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  210. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  211. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  212. - `"chunk_token_count"`: Defaults to `128`.
  213. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  214. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  215. #### Response
  216. Success:
  217. ```json
  218. {
  219. "code": 0,
  220. "data": {
  221. "avatar": null,
  222. "chunk_count": 0,
  223. "chunk_method": "naive",
  224. "create_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  225. "create_time": 1729761247434,
  226. "created_by": "69736c5e723611efb51b0242ac120007",
  227. "description": null,
  228. "document_count": 0,
  229. "embedding_model": "BAAI/bge-large-zh-v1.5",
  230. "id": "527fa74891e811ef9c650242ac120006",
  231. "language": "English",
  232. "name": "test_1",
  233. "parser_config": {
  234. "chunk_token_num": 128,
  235. "delimiter": "\\n!?;。;!?",
  236. "html4excel": false,
  237. "layout_recognize": true,
  238. "raptor": {
  239. "user_raptor": false
  240. }
  241. },
  242. "permission": "me",
  243. "similarity_threshold": 0.2,
  244. "status": "1",
  245. "tenant_id": "69736c5e723611efb51b0242ac120007",
  246. "token_num": 0,
  247. "update_date": "Thu, 24 Oct 2024 09:14:07 GMT",
  248. "update_time": 1729761247434,
  249. "vector_similarity_weight": 0.3
  250. }
  251. }
  252. ```
  253. Failure:
  254. ```json
  255. {
  256. "code": 102,
  257. "message": "Duplicated knowledgebase name in creating dataset."
  258. }
  259. ```
  260. ---
  261. ### Delete datasets
  262. **DELETE** `/api/v1/datasets`
  263. Deletes datasets by ID.
  264. #### Request
  265. - Method: DELETE
  266. - URL: `/api/v1/datasets`
  267. - Headers:
  268. - `'content-Type: application/json'`
  269. - `'Authorization: Bearer <YOUR_API_KEY>'`
  270. - Body:
  271. - `"ids"`: `list[string]`
  272. ##### Request example
  273. ```bash
  274. curl --request DELETE \
  275. --url http://{address}/api/v1/datasets \
  276. --header 'Content-Type: application/json' \
  277. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  278. --data '{
  279. "ids": ["test_1", "test_2"]
  280. }'
  281. ```
  282. ##### Request parameters
  283. - `"ids"`: (*Body parameter*), `list[string]`
  284. The IDs of the datasets to delete. If it is not specified, all datasets will be deleted.
  285. #### Response
  286. Success:
  287. ```json
  288. {
  289. "code": 0
  290. }
  291. ```
  292. Failure:
  293. ```json
  294. {
  295. "code": 102,
  296. "message": "You don't own the dataset."
  297. }
  298. ```
  299. ---
  300. ### Update dataset
  301. **PUT** `/api/v1/datasets/{dataset_id}`
  302. Updates configurations for a specified dataset.
  303. #### Request
  304. - Method: PUT
  305. - URL: `/api/v1/datasets/{dataset_id}`
  306. - Headers:
  307. - `'content-Type: application/json'`
  308. - `'Authorization: Bearer <YOUR_API_KEY>'`
  309. - Body:
  310. - `"name"`: `string`
  311. - `"embedding_model"`: `string`
  312. - `"chunk_method"`: `enum<string>`
  313. ##### Request example
  314. ```bash
  315. curl --request PUT \
  316. --url http://{address}/api/v1/datasets/{dataset_id} \
  317. --header 'Content-Type: application/json' \
  318. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  319. --data '
  320. {
  321. "name": "updated_dataset"
  322. }'
  323. ```
  324. ##### Request parameters
  325. - `dataset_id`: (*Path parameter*)
  326. The ID of the dataset to update.
  327. - `"name"`: (*Body parameter*), `string`
  328. The revised name of the dataset.
  329. - `"embedding_model"`: (*Body parameter*), `string`
  330. The updated embedding model name.
  331. - Ensure that `"chunk_count"` is `0` before updating `"embedding_model"`.
  332. - `"chunk_method"`: (*Body parameter*), `enum<string>`
  333. The chunking method for the dataset. Available options:
  334. - `"naive"`: General
  335. - `"manual`: Manual
  336. - `"qa"`: Q&A
  337. - `"table"`: Table
  338. - `"paper"`: Paper
  339. - `"book"`: Book
  340. - `"laws"`: Laws
  341. - `"presentation"`: Presentation
  342. - `"picture"`: Picture
  343. - `"one"`:One
  344. - `"email"`: Email
  345. - `"knowledge_graph"`: Knowledge Graph
  346. Ensure your LLM is properly configured on the **Settings** page before selecting this. Please also note that Knowledge Graph consumes a large number of Tokens!
  347. #### Response
  348. Success:
  349. ```json
  350. {
  351. "code": 0
  352. }
  353. ```
  354. Failure:
  355. ```json
  356. {
  357. "code": 102,
  358. "message": "Can't change tenant_id."
  359. }
  360. ```
  361. ---
  362. ### List datasets
  363. **GET** `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  364. Lists datasets.
  365. #### Request
  366. - Method: GET
  367. - URL: `/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  368. - Headers:
  369. - `'Authorization: Bearer <YOUR_API_KEY>'`
  370. ##### Request example
  371. ```bash
  372. curl --request GET \
  373. --url http://{address}/api/v1/datasets?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  374. --header 'Authorization: Bearer <YOUR_API_KEY>'
  375. ```
  376. ##### Request parameters
  377. - `page`: (*Filter parameter*)
  378. Specifies the page on which the datasets will be displayed. Defaults to `1`.
  379. - `page_size`: (*Filter parameter*)
  380. The number of datasets on each page. Defaults to `30`.
  381. - `orderby`: (*Filter parameter*)
  382. The field by which datasets should be sorted. Available options:
  383. - `create_time` (default)
  384. - `update_time`
  385. - `desc`: (*Filter parameter*)
  386. Indicates whether the retrieved datasets should be sorted in descending order. Defaults to `true`.
  387. - `name`: (*Filter parameter*)
  388. The name of the dataset to retrieve.
  389. - `id`: (*Filter parameter*)
  390. The ID of the dataset to retrieve.
  391. #### Response
  392. Success:
  393. ```json
  394. {
  395. "code": 0,
  396. "data": [
  397. {
  398. "avatar": "",
  399. "chunk_count": 59,
  400. "create_date": "Sat, 14 Sep 2024 01:12:37 GMT",
  401. "create_time": 1726276357324,
  402. "created_by": "69736c5e723611efb51b0242ac120007",
  403. "description": null,
  404. "document_count": 1,
  405. "embedding_model": "BAAI/bge-large-zh-v1.5",
  406. "id": "6e211ee0723611efa10a0242ac120007",
  407. "language": "English",
  408. "name": "mysql",
  409. "chunk_method": "knowledge_graph",
  410. "parser_config": {
  411. "chunk_token_num": 8192,
  412. "delimiter": "\\n!?;。;!?",
  413. "entity_types": [
  414. "organization",
  415. "person",
  416. "location",
  417. "event",
  418. "time"
  419. ]
  420. },
  421. "permission": "me",
  422. "similarity_threshold": 0.2,
  423. "status": "1",
  424. "tenant_id": "69736c5e723611efb51b0242ac120007",
  425. "token_num": 12744,
  426. "update_date": "Thu, 10 Oct 2024 04:07:23 GMT",
  427. "update_time": 1728533243536,
  428. "vector_similarity_weight": 0.3
  429. }
  430. ]
  431. }
  432. ```
  433. Failure:
  434. ```json
  435. {
  436. "code": 102,
  437. "message": "The dataset doesn't exist"
  438. }
  439. ```
  440. ---
  441. ## Error Codes
  442. ---
  443. | Code | Message | Description |
  444. |------|---------|-------------|
  445. | 400 | Bad Request | Invalid request parameters |
  446. | 401 | Unauthorized | Unauthorized access |
  447. | 403 | Forbidden | Access denied |
  448. | 404 | Not Found | Resource not found |
  449. | 500 | Internal Server Error | Server internal error |
  450. | 1001 | Invalid Chunk ID | Invalid Chunk ID |
  451. | 1002 | Chunk Update Failed | Chunk update failed |
  452. ---
  453. ---
  454. ## FILE MANAGEMENT WITHIN DATASET
  455. ---
  456. ### Upload documents
  457. **POST** `/api/v1/datasets/{dataset_id}/documents`
  458. Uploads documents to a specified dataset.
  459. #### Request
  460. - Method: POST
  461. - URL: `/api/v1/datasets/{dataset_id}/documents`
  462. - Headers:
  463. - `'Content-Type: multipart/form-data'`
  464. - `'Authorization: Bearer <YOUR_API_KEY>'`
  465. - Form:
  466. - `'file=@{FILE_PATH}'`
  467. ##### Request example
  468. ```bash
  469. curl --request POST \
  470. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  471. --header 'Content-Type: multipart/form-data' \
  472. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  473. --form 'file=@./test1.txt' \
  474. --form 'file=@./test2.pdf'
  475. ```
  476. ##### Request parameters
  477. - `dataset_id`: (*Path parameter*)
  478. The ID of the dataset to which the documents will be uploaded.
  479. - `'file'`: (*Body parameter*)
  480. A document to upload.
  481. #### Response
  482. Success:
  483. ```json
  484. {
  485. "code": 0,
  486. "data": [
  487. {
  488. "chunk_method": "naive",
  489. "created_by": "69736c5e723611efb51b0242ac120007",
  490. "dataset_id": "527fa74891e811ef9c650242ac120006",
  491. "id": "b330ec2e91ec11efbc510242ac120004",
  492. "location": "1.txt",
  493. "name": "1.txt",
  494. "parser_config": {
  495. "chunk_token_num": 128,
  496. "delimiter": "\\n!?;。;!?",
  497. "html4excel": false,
  498. "layout_recognize": true,
  499. "raptor": {
  500. "user_raptor": false
  501. }
  502. },
  503. "run": "UNSTART",
  504. "size": 17966,
  505. "thumbnail": "",
  506. "type": "doc"
  507. }
  508. ]
  509. }
  510. ```
  511. Failure:
  512. ```json
  513. {
  514. "code": 101,
  515. "message": "No file part!"
  516. }
  517. ```
  518. ---
  519. ### Update document
  520. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  521. Updates configurations for a specified document.
  522. #### Request
  523. - Method: PUT
  524. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  525. - Headers:
  526. - `'content-Type: application/json'`
  527. - `'Authorization: Bearer <YOUR_API_KEY>'`
  528. - Body:
  529. - `"name"`:`string`
  530. - `"meta_fields"`:`object`
  531. - `"chunk_method"`:`string`
  532. - `"parser_config"`:`object`
  533. ##### Request example
  534. ```bash
  535. curl --request PUT \
  536. --url http://{address}/api/v1/datasets/{dataset_id}/info/{document_id} \
  537. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  538. --header 'Content-Type: application/json' \
  539. --data '
  540. {
  541. "name": "manual.txt",
  542. "chunk_method": "manual",
  543. "parser_config": {"chunk_token_count": 128}
  544. }'
  545. ```
  546. ##### Request parameters
  547. - `dataset_id`: (*Path parameter*)
  548. The ID of the associated dataset.
  549. - `document_id`: (*Path parameter*)
  550. The ID of the document to update.
  551. - `"name"`: (*Body parameter*), `string`
  552. - `"meta_fields"`: (*Body parameter*), `dict[str, Any]` The meta fields of the document.
  553. - `"chunk_method"`: (*Body parameter*), `string`
  554. The parsing method to apply to the document:
  555. - `"naive"`: General
  556. - `"manual`: Manual
  557. - `"qa"`: Q&A
  558. - `"table"`: Table
  559. - `"paper"`: Paper
  560. - `"book"`: Book
  561. - `"laws"`: Laws
  562. - `"presentation"`: Presentation
  563. - `"picture"`: Picture
  564. - `"one"`: One
  565. - `"email"`: Email
  566. - `"parser_config"`: (*Body parameter*), `object`
  567. The configuration settings for the dataset parser. The attributes in this JSON object vary with the selected `"chunk_method"`:
  568. - If `"chunk_method"` is `"naive"`, the `"parser_config"` object contains the following attributes:
  569. - `"chunk_token_count"`: Defaults to `128`.
  570. - `"layout_recognize"`: Defaults to `true`.
  571. - `"html4excel"`: Indicates whether to convert Excel documents into HTML format. Defaults to `false`.
  572. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  573. - `"task_page_size"`: Defaults to `12`. For PDF only.
  574. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  575. - If `"chunk_method"` is `"qa"`, `"manuel"`, `"paper"`, `"book"`, `"laws"`, or `"presentation"`, the `"parser_config"` object contains the following attribute:
  576. - `"raptor"`: Raptor-specific settings. Defaults to: `{"use_raptor": false}`.
  577. - If `"chunk_method"` is `"table"`, `"picture"`, `"one"`, or `"email"`, `"parser_config"` is an empty JSON object.
  578. - If `"chunk_method"` is `"knowledge_graph"`, the `"parser_config"` object contains the following attributes:
  579. - `"chunk_token_count"`: Defaults to `128`.
  580. - `"delimiter"`: Defaults to `"\n!?。;!?"`.
  581. - `"entity_types"`: Defaults to `["organization","person","location","event","time"]`
  582. #### Response
  583. Success:
  584. ```json
  585. {
  586. "code": 0
  587. }
  588. ```
  589. Failure:
  590. ```json
  591. {
  592. "code": 102,
  593. "message": "The dataset does not have the document."
  594. }
  595. ```
  596. ---
  597. ### Download document
  598. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  599. Downloads a document from a specified dataset.
  600. #### Request
  601. - Method: GET
  602. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}`
  603. - Headers:
  604. - `'Authorization: Bearer <YOUR_API_KEY>'`
  605. - Output:
  606. - `'{PATH_TO_THE_FILE}'`
  607. ##### Request example
  608. ```bash
  609. curl --request GET \
  610. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id} \
  611. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  612. --output ./ragflow.txt
  613. ```
  614. ##### Request parameters
  615. - `dataset_id`: (*Path parameter*)
  616. The associated dataset ID.
  617. - `documents_id`: (*Path parameter*)
  618. The ID of the document to download.
  619. #### Response
  620. Success:
  621. ```json
  622. This is a test to verify the file download feature.
  623. ```
  624. Failure:
  625. ```json
  626. {
  627. "code": 102,
  628. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  629. }
  630. ```
  631. ---
  632. ### List documents
  633. **GET** `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
  634. Lists documents in a specified dataset.
  635. #### Request
  636. - Method: GET
  637. - URL: `/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name}`
  638. - Headers:
  639. - `'content-Type: application/json'`
  640. - `'Authorization: Bearer <YOUR_API_KEY>'`
  641. ##### Request example
  642. ```bash
  643. curl --request GET \
  644. --url http://{address}/api/v1/datasets/{dataset_id}/documents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}&name={document_name} \
  645. --header 'Authorization: Bearer <YOUR_API_KEY>'
  646. ```
  647. ##### Request parameters
  648. - `dataset_id`: (*Path parameter*)
  649. The associated dataset ID.
  650. - `keywords`: (*Filter parameter*), `string`
  651. The keywords used to match document titles.
  652. - `page`: (*Filter parameter*), `integer`
  653. Specifies the page on which the documents will be displayed. Defaults to `1`.
  654. - `page_size`: (*Filter parameter*), `integer`
  655. The maximum number of documents on each page. Defaults to `30`.
  656. - `orderby`: (*Filter parameter*), `string`
  657. The field by which documents should be sorted. Available options:
  658. - `create_time` (default)
  659. - `update_time`
  660. - `desc`: (*Filter parameter*), `boolean`
  661. Indicates whether the retrieved documents should be sorted in descending order. Defaults to `true`.
  662. - `id`: (*Filter parameter*), `string`
  663. The ID of the document to retrieve.
  664. #### Response
  665. Success:
  666. ```json
  667. {
  668. "code": 0,
  669. "data": {
  670. "docs": [
  671. {
  672. "chunk_count": 0,
  673. "create_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  674. "create_time": 1728897061948,
  675. "created_by": "69736c5e723611efb51b0242ac120007",
  676. "id": "3bcfbf8a8a0c11ef8aba0242ac120006",
  677. "knowledgebase_id": "7898da028a0511efbf750242ac120005",
  678. "location": "Test_2.txt",
  679. "name": "Test_2.txt",
  680. "parser_config": {
  681. "chunk_token_count": 128,
  682. "delimiter": "\n!?。;!?",
  683. "layout_recognize": true,
  684. "task_page_size": 12
  685. },
  686. "chunk_method": "naive",
  687. "process_begin_at": null,
  688. "process_duation": 0.0,
  689. "progress": 0.0,
  690. "progress_msg": "",
  691. "run": "0",
  692. "size": 7,
  693. "source_type": "local",
  694. "status": "1",
  695. "thumbnail": null,
  696. "token_count": 0,
  697. "type": "doc",
  698. "update_date": "Mon, 14 Oct 2024 09:11:01 GMT",
  699. "update_time": 1728897061948
  700. }
  701. ],
  702. "total": 1
  703. }
  704. }
  705. ```
  706. Failure:
  707. ```json
  708. {
  709. "code": 102,
  710. "message": "You don't own the dataset 7898da028a0511efbf750242ac1220005. "
  711. }
  712. ```
  713. ---
  714. ### Delete documents
  715. **DELETE** `/api/v1/datasets/{dataset_id}/documents`
  716. Deletes documents by ID.
  717. #### Request
  718. - Method: DELETE
  719. - URL: `/api/v1/datasets/{dataset_id}/documents`
  720. - Headers:
  721. - `'Content-Type: application/json'`
  722. - `'Authorization: Bearer <YOUR_API_KEY>'`
  723. - Body:
  724. - `"ids"`: `list[string]`
  725. ##### Request example
  726. ```bash
  727. curl --request DELETE \
  728. --url http://{address}/api/v1/datasets/{dataset_id}/documents \
  729. --header 'Content-Type: application/json' \
  730. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  731. --data '
  732. {
  733. "ids": ["id_1","id_2"]
  734. }'
  735. ```
  736. ##### Request parameters
  737. - `dataset_id`: (*Path parameter*)
  738. The associated dataset ID.
  739. - `"ids"`: (*Body parameter*), `list[string]`
  740. The IDs of the documents to delete. If it is not specified, all documents in the specified dataset will be deleted.
  741. #### Response
  742. Success:
  743. ```json
  744. {
  745. "code": 0
  746. }.
  747. ```
  748. Failure:
  749. ```json
  750. {
  751. "code": 102,
  752. "message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
  753. }
  754. ```
  755. ---
  756. ### Parse documents
  757. **POST** `/api/v1/datasets/{dataset_id}/chunks`
  758. Parses documents in a specified dataset.
  759. #### Request
  760. - Method: POST
  761. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  762. - Headers:
  763. - `'content-Type: application/json'`
  764. - `'Authorization: Bearer <YOUR_API_KEY>'`
  765. - Body:
  766. - `"document_ids"`: `list[string]`
  767. ##### Request example
  768. ```bash
  769. curl --request POST \
  770. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  771. --header 'Content-Type: application/json' \
  772. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  773. --data '
  774. {
  775. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  776. }'
  777. ```
  778. ##### Request parameters
  779. - `dataset_id`: (*Path parameter*)
  780. The dataset ID.
  781. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  782. The IDs of the documents to parse.
  783. #### Response
  784. Success:
  785. ```json
  786. {
  787. "code": 0
  788. }
  789. ```
  790. Failure:
  791. ```json
  792. {
  793. "code": 102,
  794. "message": "`document_ids` is required"
  795. }
  796. ```
  797. ---
  798. ### Stop parsing documents
  799. **DELETE** `/api/v1/datasets/{dataset_id}/chunks`
  800. Stops parsing specified documents.
  801. #### Request
  802. - Method: DELETE
  803. - URL: `/api/v1/datasets/{dataset_id}/chunks`
  804. - Headers:
  805. - `'content-Type: application/json'`
  806. - `'Authorization: Bearer <YOUR_API_KEY>'`
  807. - Body:
  808. - `"document_ids"`: `list[string]`
  809. ##### Request example
  810. ```bash
  811. curl --request DELETE \
  812. --url http://{address}/api/v1/datasets/{dataset_id}/chunks \
  813. --header 'Content-Type: application/json' \
  814. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  815. --data '
  816. {
  817. "document_ids": ["97a5f1c2759811efaa500242ac120004","97ad64b6759811ef9fc30242ac120004"]
  818. }'
  819. ```
  820. ##### Request parameters
  821. - `dataset_id`: (*Path parameter*)
  822. The associated dataset ID.
  823. - `"document_ids"`: (*Body parameter*), `list[string]`, *Required*
  824. The IDs of the documents for which the parsing should be stopped.
  825. #### Response
  826. Success:
  827. ```json
  828. {
  829. "code": 0
  830. }
  831. ```
  832. Failure:
  833. ```json
  834. {
  835. "code": 102,
  836. "message": "`document_ids` is required"
  837. }
  838. ```
  839. ---
  840. ## CHUNK MANAGEMENT WITHIN DATASET
  841. ---
  842. ### Add chunk
  843. **POST** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  844. Adds a chunk to a specified document in a specified dataset.
  845. #### Request
  846. - Method: POST
  847. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  848. - Headers:
  849. - `'content-Type: application/json'`
  850. - `'Authorization: Bearer <YOUR_API_KEY>'`
  851. - Body:
  852. - `"content"`: `string`
  853. - `"important_keywords"`: `list[string]`
  854. ##### Request example
  855. ```bash
  856. curl --request POST \
  857. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  858. --header 'Content-Type: application/json' \
  859. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  860. --data '
  861. {
  862. "content": "<CHUNK_CONTENT_HERE>"
  863. }'
  864. ```
  865. ##### Request parameters
  866. - `dataset_id`: (*Path parameter*)
  867. The associated dataset ID.
  868. - `document_ids`: (*Path parameter*)
  869. The associated document ID.
  870. - `"content"`: (*Body parameter*), `string`, *Required*
  871. The text content of the chunk.
  872. - `"important_keywords`(*Body parameter*), `list[string]`
  873. The key terms or phrases to tag with the chunk.
  874. - `"questions"`(*Body parameter*), `list[string]`
  875. If there is a given question, the embedded chunks will be based on them
  876. #### Response
  877. Success:
  878. ```json
  879. {
  880. "code": 0,
  881. "data": {
  882. "chunk": {
  883. "content": "who are you",
  884. "create_time": "2024-12-30 16:59:55",
  885. "create_timestamp": 1735549195.969164,
  886. "dataset_id": "72f36e1ebdf411efb7250242ac120006",
  887. "document_id": "61d68474be0111ef98dd0242ac120006",
  888. "id": "12ccdc56e59837e5",
  889. "important_keywords": [],
  890. "questions": []
  891. }
  892. }
  893. }
  894. ```
  895. Failure:
  896. ```json
  897. {
  898. "code": 102,
  899. "message": "`content` is required"
  900. }
  901. ```
  902. ---
  903. ### List chunks
  904. **GET** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={id}`
  905. Lists chunks in a specified document.
  906. #### Request
  907. - Method: GET
  908. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id}`
  909. - Headers:
  910. - `'Authorization: Bearer <YOUR_API_KEY>'`
  911. ##### Request example
  912. ```bash
  913. curl --request GET \
  914. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks?keywords={keywords}&page={page}&page_size={page_size}&id={chunk_id} \
  915. --header 'Authorization: Bearer <YOUR_API_KEY>'
  916. ```
  917. ##### Request parameters
  918. - `dataset_id`: (*Path parameter*)
  919. The associated dataset ID.
  920. - `document_ids`: (*Path parameter*)
  921. The associated document ID.
  922. - `keywords`(*Filter parameter*), `string`
  923. The keywords used to match chunk content.
  924. - `page`(*Filter parameter*), `integer`
  925. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  926. - `page_size`(*Filter parameter*), `integer`
  927. The maximum number of chunks on each page. Defaults to `1024`.
  928. - `id`(*Filter parameter*), `string`
  929. The ID of the chunk to retrieve.
  930. #### Response
  931. Success:
  932. ```json
  933. {
  934. "code": 0,
  935. "data": {
  936. "chunks": [
  937. {
  938. "available_int": 1,
  939. "content": "This is a test content.",
  940. "docnm_kwd": "1.txt",
  941. "document_id": "b330ec2e91ec11efbc510242ac120004",
  942. "id": "b48c170e90f70af998485c1065490726",
  943. "image_id": "",
  944. "important_keywords": "",
  945. "positions": [
  946. ""
  947. ]
  948. }
  949. ],
  950. "doc": {
  951. "chunk_count": 1,
  952. "chunk_method": "naive",
  953. "create_date": "Thu, 24 Oct 2024 09:45:27 GMT",
  954. "create_time": 1729763127646,
  955. "created_by": "69736c5e723611efb51b0242ac120007",
  956. "dataset_id": "527fa74891e811ef9c650242ac120006",
  957. "id": "b330ec2e91ec11efbc510242ac120004",
  958. "location": "1.txt",
  959. "name": "1.txt",
  960. "parser_config": {
  961. "chunk_token_num": 128,
  962. "delimiter": "\\n!?;。;!?",
  963. "html4excel": false,
  964. "layout_recognize": true,
  965. "raptor": {
  966. "user_raptor": false
  967. }
  968. },
  969. "process_begin_at": "Thu, 24 Oct 2024 09:56:44 GMT",
  970. "process_duation": 0.54213,
  971. "progress": 0.0,
  972. "progress_msg": "Task dispatched...",
  973. "run": "2",
  974. "size": 17966,
  975. "source_type": "local",
  976. "status": "1",
  977. "thumbnail": "",
  978. "token_count": 8,
  979. "type": "doc",
  980. "update_date": "Thu, 24 Oct 2024 11:03:15 GMT",
  981. "update_time": 1729767795721
  982. },
  983. "total": 1
  984. }
  985. }
  986. ```
  987. Failure:
  988. ```json
  989. {
  990. "code": 102,
  991. "message": "You don't own the document 5c5999ec7be811ef9cab0242ac12000e5."
  992. }
  993. ```
  994. ---
  995. ### Delete chunks
  996. **DELETE** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  997. Deletes chunks by ID.
  998. #### Request
  999. - Method: DELETE
  1000. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks`
  1001. - Headers:
  1002. - `'content-Type: application/json'`
  1003. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1004. - Body:
  1005. - `"chunk_ids"`: `list[string]`
  1006. ##### Request example
  1007. ```bash
  1008. curl --request DELETE \
  1009. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks \
  1010. --header 'Content-Type: application/json' \
  1011. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1012. --data '
  1013. {
  1014. "chunk_ids": ["test_1", "test_2"]
  1015. }'
  1016. ```
  1017. ##### Request parameters
  1018. - `dataset_id`: (*Path parameter*)
  1019. The associated dataset ID.
  1020. - `document_ids`: (*Path parameter*)
  1021. The associated document ID.
  1022. - `"chunk_ids"`: (*Body parameter*), `list[string]`
  1023. The IDs of the chunks to delete. If it is not specified, all chunks of the specified document will be deleted.
  1024. #### Response
  1025. Success:
  1026. ```json
  1027. {
  1028. "code": 0
  1029. }
  1030. ```
  1031. Failure:
  1032. ```json
  1033. {
  1034. "code": 102,
  1035. "message": "`chunk_ids` is required"
  1036. }
  1037. ```
  1038. ---
  1039. ### Update chunk
  1040. **PUT** `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  1041. Updates content or configurations for a specified chunk.
  1042. #### Request
  1043. - Method: PUT
  1044. - URL: `/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id}`
  1045. - Headers:
  1046. - `'content-Type: application/json'`
  1047. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1048. - Body:
  1049. - `"content"`: `string`
  1050. - `"important_keywords"`: `list[string]`
  1051. - `"available"`: `boolean`
  1052. ##### Request example
  1053. ```bash
  1054. curl --request PUT \
  1055. --url http://{address}/api/v1/datasets/{dataset_id}/documents/{document_id}/chunks/{chunk_id} \
  1056. --header 'Content-Type: application/json' \
  1057. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1058. --data '
  1059. {
  1060. "content": "ragflow123",
  1061. "important_keywords": []
  1062. }'
  1063. ```
  1064. ##### Request parameters
  1065. - `dataset_id`: (*Path parameter*)
  1066. The associated dataset ID.
  1067. - `document_ids`: (*Path parameter*)
  1068. The associated document ID.
  1069. - `chunk_id`: (*Path parameter*)
  1070. The ID of the chunk to update.
  1071. - `"content"`: (*Body parameter*), `string`
  1072. The text content of the chunk.
  1073. - `"important_keywords"`: (*Body parameter*), `list[string]`
  1074. A list of key terms or phrases to tag with the chunk.
  1075. - `"available"`: (*Body parameter*) `boolean`
  1076. The chunk's availability status in the dataset. Value options:
  1077. - `true`: Available (default)
  1078. - `false`: Unavailable
  1079. #### Response
  1080. Success:
  1081. ```json
  1082. {
  1083. "code": 0
  1084. }
  1085. ```
  1086. Failure:
  1087. ```json
  1088. {
  1089. "code": 102,
  1090. "message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
  1091. }
  1092. ```
  1093. ---
  1094. ### Retrieve chunks
  1095. **POST** `/api/v1/retrieval`
  1096. Retrieves chunks from specified datasets.
  1097. #### Request
  1098. - Method: POST
  1099. - URL: `/api/v1/retrieval`
  1100. - Headers:
  1101. - `'content-Type: application/json'`
  1102. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1103. - Body:
  1104. - `"question"`: `string`
  1105. - `"dataset_ids"`: `list[string]`
  1106. - `"document_ids"`: `list[string]`
  1107. - `"page"`: `integer`
  1108. - `"page_size"`: `integer`
  1109. - `"similarity_threshold"`: `float`
  1110. - `"vector_similarity_weight"`: `float`
  1111. - `"top_k"`: `integer`
  1112. - `"rerank_id"`: `string`
  1113. - `"keyword"`: `boolean`
  1114. - `"highlight"`: `boolean`
  1115. ##### Request example
  1116. ```bash
  1117. curl --request POST \
  1118. --url http://{address}/api/v1/retrieval \
  1119. --header 'Content-Type: application/json' \
  1120. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1121. --data '
  1122. {
  1123. "question": "What is advantage of ragflow?",
  1124. "dataset_ids": ["b2a62730759d11ef987d0242ac120004"],
  1125. "document_ids": ["77df9ef4759a11ef8bdd0242ac120004"]
  1126. }'
  1127. ```
  1128. ##### Request parameter
  1129. - `"question"`: (*Body parameter*), `string`, *Required*
  1130. The user query or query keywords.
  1131. - `"dataset_ids"`: (*Body parameter*) `list[string]`
  1132. The IDs of the datasets to search. If you do not set this argument, ensure that you set `"document_ids"`.
  1133. - `"document_ids"`: (*Body parameter*), `list[string]`
  1134. The IDs of the documents to search. Ensure that all selected documents use the same embedding model. Otherwise, an error will occur. If you do not set this argument, ensure that you set `"dataset_ids"`.
  1135. - `"page"`: (*Body parameter*), `integer`
  1136. Specifies the page on which the chunks will be displayed. Defaults to `1`.
  1137. - `"page_size"`: (*Body parameter*)
  1138. The maximum number of chunks on each page. Defaults to `30`.
  1139. - `"similarity_threshold"`: (*Body parameter*)
  1140. The minimum similarity score. Defaults to `0.2`.
  1141. - `"vector_similarity_weight"`: (*Body parameter*), `float`
  1142. The weight of vector cosine similarity. Defaults to `0.3`. If x represents the weight of vector cosine similarity, then (1 - x) is the term similarity weight.
  1143. - `"top_k"`: (*Body parameter*), `integer`
  1144. The number of chunks engaged in vector cosine computation. Defaults to `1024`.
  1145. - `"rerank_id"`: (*Body parameter*), `integer`
  1146. The ID of the rerank model.
  1147. - `"keyword"`: (*Body parameter*), `boolean`
  1148. Indicates whether to enable keyword-based matching:
  1149. - `true`: Enable keyword-based matching.
  1150. - `false`: Disable keyword-based matching (default).
  1151. - `"highlight"`: (*Body parameter*), `boolean`
  1152. Specifies whether to enable highlighting of matched terms in the results:
  1153. - `true`: Enable highlighting of matched terms.
  1154. - `false`: Disable highlighting of matched terms (default).
  1155. #### Response
  1156. Success:
  1157. ```json
  1158. {
  1159. "code": 0,
  1160. "data": {
  1161. "chunks": [
  1162. {
  1163. "content": "ragflow content",
  1164. "content_ltks": "ragflow content",
  1165. "document_id": "5c5999ec7be811ef9cab0242ac120005",
  1166. "document_keyword": "1.txt",
  1167. "highlight": "<em>ragflow</em> content",
  1168. "id": "d78435d142bd5cf6704da62c778795c5",
  1169. "image_id": "",
  1170. "important_keywords": [
  1171. ""
  1172. ],
  1173. "kb_id": "c7ee74067a2c11efb21c0242ac120006",
  1174. "positions": [
  1175. ""
  1176. ],
  1177. "similarity": 0.9669436601210759,
  1178. "term_similarity": 1.0,
  1179. "vector_similarity": 0.8898122004035864
  1180. }
  1181. ],
  1182. "doc_aggs": [
  1183. {
  1184. "count": 1,
  1185. "doc_id": "5c5999ec7be811ef9cab0242ac120005",
  1186. "doc_name": "1.txt"
  1187. }
  1188. ],
  1189. "total": 1
  1190. }
  1191. }
  1192. ```
  1193. Failure:
  1194. ```json
  1195. {
  1196. "code": 102,
  1197. "message": "`datasets` is required."
  1198. }
  1199. ```
  1200. ---
  1201. ## CHAT ASSISTANT MANAGEMENT
  1202. ---
  1203. ### Create chat assistant
  1204. **POST** `/api/v1/chats`
  1205. Creates a chat assistant.
  1206. #### Request
  1207. - Method: POST
  1208. - URL: `/api/v1/chats`
  1209. - Headers:
  1210. - `'content-Type: application/json'`
  1211. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1212. - Body:
  1213. - `"name"`: `string`
  1214. - `"avatar"`: `string`
  1215. - `"dataset_ids"`: `list[string]`
  1216. - `"llm"`: `object`
  1217. - `"prompt"`: `object`
  1218. ##### Request example
  1219. ```shell
  1220. curl --request POST \
  1221. --url http://{address}/api/v1/chats \
  1222. --header 'Content-Type: application/json' \
  1223. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1224. --data '{
  1225. "dataset_ids": ["0b2cbc8c877f11ef89070242ac120005"],
  1226. "name":"new_chat_1"
  1227. }'
  1228. ```
  1229. ##### Request parameters
  1230. - `"name"`: (*Body parameter*), `string`, *Required*
  1231. The name of the chat assistant.
  1232. - `"avatar"`: (*Body parameter*), `string`
  1233. Base64 encoding of the avatar.
  1234. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1235. The IDs of the associated datasets.
  1236. - `"llm"`: (*Body parameter*), `object`
  1237. The LLM settings for the chat assistant to create. If it is not explicitly set, a JSON object with the following values will be generated as the default. An `llm` JSON object contains the following attributes:
  1238. - `"model_name"`, `string`
  1239. The chat model name. If not set, the user's default chat model will be used.
  1240. - `"temperature"`: `float`
  1241. Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1`.
  1242. - `"top_p"`: `float`
  1243. Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
  1244. - `"presence_penalty"`: `float`
  1245. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1246. - `"frequency penalty"`: `float`
  1247. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1248. - `"prompt"`: (*Body parameter*), `object`
  1249. Instructions for the LLM to follow. If it is not explicitly set, a JSON object with the following values will be generated as the default. A `prompt` JSON object contains the following attributes:
  1250. - `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
  1251. - `"keywords_similarity_weight"`: `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7`.
  1252. - `"top_n"`: `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8`.
  1253. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1254. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1255. - All the variables in 'System' should be curly bracketed.
  1256. - The default value is `[{"key": "knowledge", "optional": true}]`.
  1257. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1258. - `top_k`: `int` Refers to the process of reordering or selecting the top-k items from a list or set based on a specific ranking criterion. Default to 1024.
  1259. - `"empty_response"`: `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
  1260. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1261. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1262. - `"prompt"`: `string` The prompt content.
  1263. #### Response
  1264. Success:
  1265. ```json
  1266. {
  1267. "code": 0,
  1268. "data": {
  1269. "avatar": "",
  1270. "create_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1271. "create_time": 1729768709023,
  1272. "dataset_ids": [
  1273. "527fa74891e811ef9c650242ac120006"
  1274. ],
  1275. "description": "A helpful Assistant",
  1276. "do_refer": "1",
  1277. "id": "b1f2f15691f911ef81180242ac120003",
  1278. "language": "English",
  1279. "llm": {
  1280. "frequency_penalty": 0.7,
  1281. "model_name": "qwen-plus@Tongyi-Qianwen",
  1282. "presence_penalty": 0.4,
  1283. "temperature": 0.1,
  1284. "top_p": 0.3
  1285. },
  1286. "name": "12234",
  1287. "prompt": {
  1288. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1289. "keywords_similarity_weight": 0.3,
  1290. "opener": "Hi! I'm your assistant, what can I do for you?",
  1291. "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n ",
  1292. "rerank_model": "",
  1293. "similarity_threshold": 0.2,
  1294. "top_n": 6,
  1295. "variables": [
  1296. {
  1297. "key": "knowledge",
  1298. "optional": false
  1299. }
  1300. ]
  1301. },
  1302. "prompt_type": "simple",
  1303. "status": "1",
  1304. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1305. "top_k": 1024,
  1306. "update_date": "Thu, 24 Oct 2024 11:18:29 GMT",
  1307. "update_time": 1729768709023
  1308. }
  1309. }
  1310. ```
  1311. Failure:
  1312. ```json
  1313. {
  1314. "code": 102,
  1315. "message": "Duplicated chat name in creating dataset."
  1316. }
  1317. ```
  1318. ---
  1319. ### Update chat assistant
  1320. **PUT** `/api/v1/chats/{chat_id}`
  1321. Updates configurations for a specified chat assistant.
  1322. #### Request
  1323. - Method: PUT
  1324. - URL: `/api/v1/chats/{chat_id}`
  1325. - Headers:
  1326. - `'content-Type: application/json'`
  1327. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1328. - Body:
  1329. - `"name"`: `string`
  1330. - `"avatar"`: `string`
  1331. - `"dataset_ids"`: `list[string]`
  1332. - `"llm"`: `object`
  1333. - `"prompt"`: `object`
  1334. ##### Request example
  1335. ```bash
  1336. curl --request PUT \
  1337. --url http://{address}/api/v1/chats/{chat_id} \
  1338. --header 'Content-Type: application/json' \
  1339. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1340. --data '
  1341. {
  1342. "name":"Test"
  1343. }'
  1344. ```
  1345. #### Parameters
  1346. - `chat_id`: (*Path parameter*)
  1347. The ID of the chat assistant to update.
  1348. - `"name"`: (*Body parameter*), `string`, *Required*
  1349. The revised name of the chat assistant.
  1350. - `"avatar"`: (*Body parameter*), `string`
  1351. Base64 encoding of the avatar.
  1352. - `"dataset_ids"`: (*Body parameter*), `list[string]`
  1353. The IDs of the associated datasets.
  1354. - `"llm"`: (*Body parameter*), `object`
  1355. The LLM settings for the chat assistant to create. If it is not explicitly set, a dictionary with the following values will be generated as the default. An `llm` object contains the following attributes:
  1356. - `"model_name"`, `string`
  1357. The chat model name. If not set, the user's default chat model will be used.
  1358. - `"temperature"`: `float`
  1359. Controls the randomness of the model's predictions. A lower temperature results in more conservative responses, while a higher temperature yields more creative and diverse responses. Defaults to `0.1`.
  1360. - `"top_p"`: `float`
  1361. Also known as “nucleus sampling”, this parameter sets a threshold to select a smaller set of words to sample from. It focuses on the most likely words, cutting off the less probable ones. Defaults to `0.3`
  1362. - `"presence_penalty"`: `float`
  1363. This discourages the model from repeating the same information by penalizing words that have already appeared in the conversation. Defaults to `0.2`.
  1364. - `"frequency penalty"`: `float`
  1365. Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
  1366. - `"prompt"`: (*Body parameter*), `object`
  1367. Instructions for the LLM to follow. A `prompt` object contains the following attributes:
  1368. - `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted rerank score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
  1369. - `"keywords_similarity_weight"`: `float` This argument sets the weight of keyword similarity in the hybrid similarity score with vector cosine similarity or reranking model similarity. By adjusting this weight, you can control the influence of keyword similarity in relation to other similarity measures. The default value is `0.7`.
  1370. - `"top_n"`: `int` This argument specifies the number of top chunks with similarity scores above the `similarity_threshold` that are fed to the LLM. The LLM will *only* access these 'top N' chunks. The default value is `8`.
  1371. - `"variables"`: `object[]` This argument lists the variables to use in the 'System' field of **Chat Configurations**. Note that:
  1372. - `"knowledge"` is a reserved variable, which represents the retrieved chunks.
  1373. - All the variables in 'System' should be curly bracketed.
  1374. - The default value is `[{"key": "knowledge", "optional": true}]`
  1375. - `"rerank_model"`: `string` If it is not specified, vector cosine similarity will be used; otherwise, reranking score will be used.
  1376. - `"empty_response"`: `string` If nothing is retrieved in the dataset for the user's question, this will be used as the response. To allow the LLM to improvise when nothing is found, leave this blank.
  1377. - `"opener"`: `string` The opening greeting for the user. Defaults to `"Hi! I am your assistant, can I help you?"`.
  1378. - `"show_quote`: `boolean` Indicates whether the source of text should be displayed. Defaults to `true`.
  1379. - `"prompt"`: `string` The prompt content.
  1380. #### Response
  1381. Success:
  1382. ```json
  1383. {
  1384. "code": 0
  1385. }
  1386. ```
  1387. Failure:
  1388. ```json
  1389. {
  1390. "code": 102,
  1391. "message": "Duplicated chat name in updating dataset."
  1392. }
  1393. ```
  1394. ---
  1395. ### Delete chat assistants
  1396. **DELETE** `/api/v1/chats`
  1397. Deletes chat assistants by ID.
  1398. #### Request
  1399. - Method: DELETE
  1400. - URL: `/api/v1/chats`
  1401. - Headers:
  1402. - `'content-Type: application/json'`
  1403. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1404. - Body:
  1405. - `"ids"`: `list[string]`
  1406. ##### Request example
  1407. ```bash
  1408. curl --request DELETE \
  1409. --url http://{address}/api/v1/chats \
  1410. --header 'Content-Type: application/json' \
  1411. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1412. --data '
  1413. {
  1414. "ids": ["test_1", "test_2"]
  1415. }'
  1416. ```
  1417. ##### Request parameters
  1418. - `"ids"`: (*Body parameter*), `list[string]`
  1419. The IDs of the chat assistants to delete. If it is not specified, all chat assistants in the system will be deleted.
  1420. #### Response
  1421. Success:
  1422. ```json
  1423. {
  1424. "code": 0
  1425. }
  1426. ```
  1427. Failure:
  1428. ```json
  1429. {
  1430. "code": 102,
  1431. "message": "ids are required"
  1432. }
  1433. ```
  1434. ---
  1435. ### List chat assistants
  1436. **GET** `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={chat_name}&id={chat_id}`
  1437. Lists chat assistants.
  1438. #### Request
  1439. - Method: GET
  1440. - URL: `/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
  1441. - Headers:
  1442. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1443. ##### Request example
  1444. ```bash
  1445. curl --request GET \
  1446. --url http://{address}/api/v1/chats?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
  1447. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1448. ```
  1449. ##### Request parameters
  1450. - `page`: (*Filter parameter*), `integer`
  1451. Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
  1452. - `page_size`: (*Filter parameter*), `integer`
  1453. The number of chat assistants on each page. Defaults to `30`.
  1454. - `orderby`: (*Filter parameter*), `string`
  1455. The attribute by which the results are sorted. Available options:
  1456. - `create_time` (default)
  1457. - `update_time`
  1458. - `desc`: (*Filter parameter*), `boolean`
  1459. Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `true`.
  1460. - `id`: (*Filter parameter*), `string`
  1461. The ID of the chat assistant to retrieve.
  1462. - `name`: (*Filter parameter*), `string`
  1463. The name of the chat assistant to retrieve.
  1464. #### Response
  1465. Success:
  1466. ```json
  1467. {
  1468. "code": 0,
  1469. "data": [
  1470. {
  1471. "avatar": "",
  1472. "create_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1473. "create_time": 1729232406637,
  1474. "description": "A helpful Assistant",
  1475. "do_refer": "1",
  1476. "id": "04d0d8e28d1911efa3630242ac120006",
  1477. "dataset_ids": ["527fa74891e811ef9c650242ac120006"],
  1478. "language": "English",
  1479. "llm": {
  1480. "frequency_penalty": 0.7,
  1481. "model_name": "qwen-plus@Tongyi-Qianwen",
  1482. "presence_penalty": 0.4,
  1483. "temperature": 0.1,
  1484. "top_p": 0.3
  1485. },
  1486. "name": "13243",
  1487. "prompt": {
  1488. "empty_response": "Sorry! No relevant content was found in the knowledge base!",
  1489. "keywords_similarity_weight": 0.3,
  1490. "opener": "Hi! I'm your assistant, what can I do for you?",
  1491. "prompt": "You are an intelligent assistant. Please summarize the content of the knowledge base to answer the question. Please list the data in the knowledge base and answer in detail. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\" Answers need to consider chat history.\n",
  1492. "rerank_model": "",
  1493. "similarity_threshold": 0.2,
  1494. "top_n": 6,
  1495. "variables": [
  1496. {
  1497. "key": "knowledge",
  1498. "optional": false
  1499. }
  1500. ]
  1501. },
  1502. "prompt_type": "simple",
  1503. "status": "1",
  1504. "tenant_id": "69736c5e723611efb51b0242ac120007",
  1505. "top_k": 1024,
  1506. "update_date": "Fri, 18 Oct 2024 06:20:06 GMT",
  1507. "update_time": 1729232406638
  1508. }
  1509. ]
  1510. }
  1511. ```
  1512. Failure:
  1513. ```json
  1514. {
  1515. "code": 102,
  1516. "message": "The chat doesn't exist"
  1517. }
  1518. ```
  1519. ---
  1520. ## SESSION MANAGEMENT
  1521. ---
  1522. ### Create session with chat assistant
  1523. **POST** `/api/v1/chats/{chat_id}/sessions`
  1524. Creates a session with a chat assistant.
  1525. #### Request
  1526. - Method: POST
  1527. - URL: `/api/v1/chats/{chat_id}/sessions`
  1528. - Headers:
  1529. - `'content-Type: application/json'`
  1530. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1531. - Body:
  1532. - `"name"`: `string`
  1533. - `"user_id"`: `string` (optional)
  1534. ##### Request example
  1535. ```bash
  1536. curl --request POST \
  1537. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1538. --header 'Content-Type: application/json' \
  1539. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1540. --data '
  1541. {
  1542. "name": "new session"
  1543. }'
  1544. ```
  1545. ##### Request parameters
  1546. - `chat_id`: (*Path parameter*)
  1547. The ID of the associated chat assistant.
  1548. - `"name"`: (*Body parameter*), `string`
  1549. The name of the chat session to create.
  1550. - `"user_id"`: (*Body parameter*), `string`
  1551. Optional user-defined ID.
  1552. #### Response
  1553. Success:
  1554. ```json
  1555. {
  1556. "code": 0,
  1557. "data": {
  1558. "chat_id": "2ca4b22e878011ef88fe0242ac120005",
  1559. "create_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1560. "create_time": 1728636374571,
  1561. "id": "4606b4ec87ad11efbc4f0242ac120006",
  1562. "messages": [
  1563. {
  1564. "content": "Hi! I am your assistant,can I help you?",
  1565. "role": "assistant"
  1566. }
  1567. ],
  1568. "name": "new session",
  1569. "update_date": "Fri, 11 Oct 2024 08:46:14 GMT",
  1570. "update_time": 1728636374571
  1571. }
  1572. }
  1573. ```
  1574. Failure:
  1575. ```json
  1576. {
  1577. "code": 102,
  1578. "message": "Name cannot be empty."
  1579. }
  1580. ```
  1581. ---
  1582. ### Update chat assistant's session
  1583. **PUT** `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1584. Updates a session of a specified chat assistant.
  1585. #### Request
  1586. - Method: PUT
  1587. - URL: `/api/v1/chats/{chat_id}/sessions/{session_id}`
  1588. - Headers:
  1589. - `'content-Type: application/json'`
  1590. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1591. - Body:
  1592. - `"name`: `string`
  1593. - `"user_id`: `string` (optional)
  1594. ##### Request example
  1595. ```bash
  1596. curl --request PUT \
  1597. --url http://{address}/api/v1/chats/{chat_id}/sessions/{session_id} \
  1598. --header 'Content-Type: application/json' \
  1599. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1600. --data '
  1601. {
  1602. "name": "<REVISED_SESSION_NAME_HERE>"
  1603. }'
  1604. ```
  1605. ##### Request Parameter
  1606. - `chat_id`: (*Path parameter*)
  1607. The ID of the associated chat assistant.
  1608. - `session_id`: (*Path parameter*)
  1609. The ID of the session to update.
  1610. - `"name"`: (*Body Parameter*), `string`
  1611. The revised name of the session.
  1612. - `"user_id"`: (*Body parameter*), `string`
  1613. Optional user-defined ID.
  1614. #### Response
  1615. Success:
  1616. ```json
  1617. {
  1618. "code": 0
  1619. }
  1620. ```
  1621. Failure:
  1622. ```json
  1623. {
  1624. "code": 102,
  1625. "message": "Name cannot be empty."
  1626. }
  1627. ```
  1628. ---
  1629. ### List chat assistant's sessions
  1630. **GET** `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}`
  1631. Lists sessions associated with a specified chat assistant.
  1632. #### Request
  1633. - Method: GET
  1634. - URL: `/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id}&user_id={user_id}`
  1635. - Headers:
  1636. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1637. ##### Request example
  1638. ```bash
  1639. curl --request GET \
  1640. --url http://{address}/api/v1/chats/{chat_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={session_name}&id={session_id} \
  1641. --header 'Authorization: Bearer <YOUR_API_KEY>'
  1642. ```
  1643. ##### Request Parameters
  1644. - `chat_id`: (*Path parameter*)
  1645. The ID of the associated chat assistant.
  1646. - `page`: (*Filter parameter*), `integer`
  1647. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  1648. - `page_size`: (*Filter parameter*), `integer`
  1649. The number of sessions on each page. Defaults to `30`.
  1650. - `orderby`: (*Filter parameter*), `string`
  1651. The field by which sessions should be sorted. Available options:
  1652. - `create_time` (default)
  1653. - `update_time`
  1654. - `desc`: (*Filter parameter*), `boolean`
  1655. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  1656. - `name`: (*Filter parameter*) `string`
  1657. The name of the chat session to retrieve.
  1658. - `id`: (*Filter parameter*), `string`
  1659. The ID of the chat session to retrieve.
  1660. - `user_id`: (*Filter parameter*), `string`
  1661. The optional user-defined ID passed in when creating session.
  1662. #### Response
  1663. Success:
  1664. ```json
  1665. {
  1666. "code": 0,
  1667. "data": [
  1668. {
  1669. "chat": "2ca4b22e878011ef88fe0242ac120005",
  1670. "create_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1671. "create_time": 1728636403974,
  1672. "id": "578d541e87ad11ef96b90242ac120006",
  1673. "messages": [
  1674. {
  1675. "content": "Hi! I am your assistant,can I help you?",
  1676. "role": "assistant"
  1677. }
  1678. ],
  1679. "name": "new session",
  1680. "update_date": "Fri, 11 Oct 2024 08:46:43 GMT",
  1681. "update_time": 1728636403974
  1682. }
  1683. ]
  1684. }
  1685. ```
  1686. Failure:
  1687. ```json
  1688. {
  1689. "code": 102,
  1690. "message": "The session doesn't exist"
  1691. }
  1692. ```
  1693. ---
  1694. ### Delete chat assistant's sessions
  1695. **DELETE** `/api/v1/chats/{chat_id}/sessions`
  1696. Deletes sessions of a chat assistant by ID.
  1697. #### Request
  1698. - Method: DELETE
  1699. - URL: `/api/v1/chats/{chat_id}/sessions`
  1700. - Headers:
  1701. - `'content-Type: application/json'`
  1702. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1703. - Body:
  1704. - `"ids"`: `list[string]`
  1705. ##### Request example
  1706. ```bash
  1707. curl --request DELETE \
  1708. --url http://{address}/api/v1/chats/{chat_id}/sessions \
  1709. --header 'Content-Type: application/json' \
  1710. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1711. --data '
  1712. {
  1713. "ids": ["test_1", "test_2"]
  1714. }'
  1715. ```
  1716. ##### Request Parameters
  1717. - `chat_id`: (*Path parameter*)
  1718. The ID of the associated chat assistant.
  1719. - `"ids"`: (*Body Parameter*), `list[string]`
  1720. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified chat assistant will be deleted.
  1721. #### Response
  1722. Success:
  1723. ```json
  1724. {
  1725. "code": 0
  1726. }
  1727. ```
  1728. Failure:
  1729. ```json
  1730. {
  1731. "code": 102,
  1732. "message": "The chat doesn't own the session"
  1733. }
  1734. ```
  1735. ---
  1736. ### Converse with chat assistant
  1737. **POST** `/api/v1/chats/{chat_id}/completions`
  1738. Asks a specified chat assistant a question to start an AI-powered conversation.
  1739. :::tip NOTE
  1740. - In streaming mode, not all responses include a reference, as this depends on the system's judgement.
  1741. - In streaming mode, the last message is an empty message:
  1742. ```json
  1743. data:
  1744. {
  1745. "code": 0,
  1746. "data": true
  1747. }
  1748. ```
  1749. :::
  1750. #### Request
  1751. - Method: POST
  1752. - URL: `/api/v1/chats/{chat_id}/completions`
  1753. - Headers:
  1754. - `'content-Type: application/json'`
  1755. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1756. - Body:
  1757. - `"question"`: `string`
  1758. - `"stream"`: `boolean`
  1759. - `"session_id"`: `string` (optional)
  1760. - `"user_id`: `string` (optional)
  1761. ##### Request example
  1762. ```bash
  1763. curl --request POST \
  1764. --url http://{address}/api/v1/chats/{chat_id}/completions \
  1765. --header 'Content-Type: application/json' \
  1766. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1767. --data-binary '
  1768. {
  1769. }'
  1770. ```
  1771. ```bash
  1772. curl --request POST \
  1773. --url http://{address}/api/v1/chats/{chat_id}/completions \
  1774. --header 'Content-Type: application/json' \
  1775. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1776. --data-binary '
  1777. {
  1778. "question": "Who are you",
  1779. "stream": true,
  1780. "session_id":"9fa7691cb85c11ef9c5f0242ac120005"
  1781. }'
  1782. ```
  1783. ##### Request Parameters
  1784. - `chat_id`: (*Path parameter*)
  1785. The ID of the associated chat assistant.
  1786. - `"question"`: (*Body Parameter*), `string`, *Required*
  1787. The question to start an AI-powered conversation.
  1788. - `"stream"`: (*Body Parameter*), `boolean`
  1789. Indicates whether to output responses in a streaming way:
  1790. - `true`: Enable streaming (default).
  1791. - `false`: Disable streaming.
  1792. - `"session_id"`: (*Body Parameter*)
  1793. The ID of session. If it is not provided, a new session will be generated.
  1794. - `"user_id"`: (*Body parameter*), `string`
  1795. The optional user-defined ID. Valid *only* when no `session_id` is provided.
  1796. #### Response
  1797. Success without `session_id`:
  1798. ```json
  1799. data:{
  1800. "code": 0,
  1801. "message": "",
  1802. "data": {
  1803. "answer": "Hi! I'm your assistant, what can I do for you?",
  1804. "reference": {},
  1805. "audio_binary": null,
  1806. "id": null,
  1807. "session_id": "b01eed84b85611efa0e90242ac120005"
  1808. }
  1809. }
  1810. data:{
  1811. "code": 0,
  1812. "message": "",
  1813. "data": true
  1814. }
  1815. ```
  1816. Success with `session_id`:
  1817. ```json
  1818. data:{
  1819. "code": 0,
  1820. "data": {
  1821. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a",
  1822. "reference": {},
  1823. "audio_binary": null,
  1824. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1825. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1826. }
  1827. }
  1828. data:{
  1829. "code": 0,
  1830. "data": {
  1831. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and",
  1832. "reference": {},
  1833. "audio_binary": null,
  1834. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1835. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1836. }
  1837. }
  1838. data:{
  1839. "code": 0,
  1840. "data": {
  1841. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base. My responses are based on the information available in the knowledge base and any relevant chat history.",
  1842. "reference": {},
  1843. "audio_binary": null,
  1844. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1845. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1846. }
  1847. }
  1848. data:{
  1849. "code": 0,
  1850. "data": {
  1851. "answer": "I am an intelligent assistant designed to help answer questions by summarizing content from a knowledge base ##0$$. My responses are based on the information available in the knowledge base and any relevant chat history.",
  1852. "reference": {
  1853. "total": 1,
  1854. "chunks": [
  1855. {
  1856. "id": "faf26c791128f2d5e821f822671063bd",
  1857. "content": "xxxxxxxx",
  1858. "document_id": "dd58f58e888511ef89c90242ac120006",
  1859. "document_name": "1.txt",
  1860. "dataset_id": "8e83e57a884611ef9d760242ac120006",
  1861. "image_id": "",
  1862. "similarity": 0.7,
  1863. "vector_similarity": 0.0,
  1864. "term_similarity": 1.0,
  1865. "positions": [
  1866. ""
  1867. ]
  1868. }
  1869. ],
  1870. "doc_aggs": [
  1871. {
  1872. "doc_name": "1.txt",
  1873. "doc_id": "dd58f58e888511ef89c90242ac120006",
  1874. "count": 1
  1875. }
  1876. ]
  1877. },
  1878. "prompt": "xxxxxxxxxxx",
  1879. "id": "a84c5dd4-97b4-4624-8c3b-974012c8000d",
  1880. "session_id": "82b0ab2a9c1911ef9d870242ac120006"
  1881. }
  1882. }
  1883. data:{
  1884. "code": 0,
  1885. "data": true
  1886. }
  1887. ```
  1888. Failure:
  1889. ```json
  1890. {
  1891. "code": 102,
  1892. "message": "Please input your question."
  1893. }
  1894. ```
  1895. ---
  1896. ### Create session with agent
  1897. **POST** `/api/v1/agents/{agent_id}/sessions`
  1898. Creates a session with an agent.
  1899. #### Request
  1900. - Method: POST
  1901. - URL: `/api/v1/agents/{agent_id}/sessions?user_id={user_id}`
  1902. - Headers:
  1903. - `'content-Type: application/json' or 'multipart/form-data'`
  1904. - `'Authorization: Bearer <YOUR_API_KEY>'`
  1905. - Body:
  1906. - the required parameters:`str`
  1907. - other parameters:
  1908. The parameters specified in the **Begin** component.
  1909. ##### Request example
  1910. If the **Begin** component in your agent does not take required parameters:
  1911. ```bash
  1912. curl --request POST \
  1913. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  1914. --header 'Content-Type: application/json' \
  1915. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1916. --data '{
  1917. }'
  1918. ```
  1919. If the **Begin** component in your agent takes required parameters:
  1920. ```bash
  1921. curl --request POST \
  1922. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  1923. --header 'Content-Type: application/json' \
  1924. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1925. --data '{
  1926. "lang":"Japanese",
  1927. "file":"Who are you"
  1928. }'
  1929. ```
  1930. If the **Begin** component in your agent takes required file parameters:
  1931. ```bash
  1932. curl --request POST \
  1933. --url http://{address}/api/v1/agents/{agent_id}/sessions?user_id={user_id} \
  1934. --header 'Content-Type: multipart/form-data' \
  1935. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  1936. --form '<FILE_KEY>=@./test1.png'
  1937. ```
  1938. ##### Request parameters
  1939. - `agent_id`: (*Path parameter*)
  1940. The ID of the associated agent.
  1941. - `user_id`: (*Filter parameter*)
  1942. The optional user-defined ID for parsing docs (especially images) when creating a session while uploading files.
  1943. #### Response
  1944. Success:
  1945. ```json
  1946. {
  1947. "code": 0,
  1948. "data": {
  1949. "agent_id": "b4a39922b76611efaa1a0242ac120006",
  1950. "dsl": {
  1951. "answer": [],
  1952. "components": {
  1953. "Answer:GreenReadersDrum": {
  1954. "downstream": [],
  1955. "obj": {
  1956. "component_name": "Answer",
  1957. "inputs": [],
  1958. "output": null,
  1959. "params": {}
  1960. },
  1961. "upstream": []
  1962. },
  1963. "begin": {
  1964. "downstream": [],
  1965. "obj": {
  1966. "component_name": "Begin",
  1967. "inputs": [],
  1968. "output": {},
  1969. "params": {}
  1970. },
  1971. "upstream": []
  1972. }
  1973. },
  1974. "embed_id": "",
  1975. "graph": {
  1976. "edges": [],
  1977. "nodes": [
  1978. {
  1979. "data": {
  1980. "label": "Begin",
  1981. "name": "begin"
  1982. },
  1983. "dragging": false,
  1984. "height": 44,
  1985. "id": "begin",
  1986. "position": {
  1987. "x": 53.25688640427177,
  1988. "y": 198.37155679786412
  1989. },
  1990. "positionAbsolute": {
  1991. "x": 53.25688640427177,
  1992. "y": 198.37155679786412
  1993. },
  1994. "selected": false,
  1995. "sourcePosition": "left",
  1996. "targetPosition": "right",
  1997. "type": "beginNode",
  1998. "width": 200
  1999. },
  2000. {
  2001. "data": {
  2002. "form": {},
  2003. "label": "Answer",
  2004. "name": "dialog_0"
  2005. },
  2006. "dragging": false,
  2007. "height": 44,
  2008. "id": "Answer:GreenReadersDrum",
  2009. "position": {
  2010. "x": 360.43473114516974,
  2011. "y": 207.29298425089348
  2012. },
  2013. "positionAbsolute": {
  2014. "x": 360.43473114516974,
  2015. "y": 207.29298425089348
  2016. },
  2017. "selected": false,
  2018. "sourcePosition": "right",
  2019. "targetPosition": "left",
  2020. "type": "logicNode",
  2021. "width": 200
  2022. }
  2023. ]
  2024. },
  2025. "history": [],
  2026. "messages": [],
  2027. "path": [
  2028. [
  2029. "begin"
  2030. ],
  2031. []
  2032. ],
  2033. "reference": []
  2034. },
  2035. "id": "2581031eb7a311efb5200242ac120005",
  2036. "message": [
  2037. {
  2038. "content": "Hi! I'm your smart assistant. What can I do for you?",
  2039. "role": "assistant"
  2040. }
  2041. ],
  2042. "source": "agent",
  2043. "user_id": "69736c5e723611efb51b0242ac120007"
  2044. }
  2045. }
  2046. ```
  2047. Failure:
  2048. ```json
  2049. {
  2050. "code": 102,
  2051. "message": "Agent not found."
  2052. }
  2053. ```
  2054. ---
  2055. ### Converse with agent
  2056. **POST** `/api/v1/agents/{agent_id}/completions`
  2057. Asks a specified agent a question to start an AI-powered conversation.
  2058. :::tip NOTE
  2059. - In streaming mode, not all responses include a reference, as this depends on the system's judgement.
  2060. - In streaming mode, the last message is an empty message:
  2061. ```json
  2062. data:
  2063. {
  2064. "code": 0,
  2065. "data": true
  2066. }
  2067. ```
  2068. :::
  2069. #### Request
  2070. - Method: POST
  2071. - URL: `/api/v1/agents/{agent_id}/completions`
  2072. - Headers:
  2073. - `'content-Type: application/json'`
  2074. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2075. - Body:
  2076. - `"question"`: `string`
  2077. - `"stream"`: `boolean`
  2078. - `"session_id"`: `string`
  2079. - `"user_id"`: `string`(optional)
  2080. - `"sync_dsl"`: `boolean` (optional)
  2081. - other parameters: `string`
  2082. ##### Request example
  2083. If the **Begin** component does not take parameters, the following code will create a session.
  2084. ```bash
  2085. curl --request POST \
  2086. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2087. --header 'Content-Type: application/json' \
  2088. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2089. --data-binary '
  2090. {
  2091. }'
  2092. ```
  2093. If the **Begin** component takes parameters, the following code will create a session.
  2094. ```bash
  2095. curl --request POST \
  2096. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2097. --header 'Content-Type: application/json' \
  2098. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2099. --data-binary '
  2100. {
  2101. "lang":"English",
  2102. "file":"How is the weather tomorrow?"
  2103. }'
  2104. ```
  2105. The following code will execute the completion process
  2106. ```bash
  2107. curl --request POST \
  2108. --url http://{address}/api/v1/agents/{agent_id}/completions \
  2109. --header 'Content-Type: application/json' \
  2110. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2111. --data-binary '
  2112. {
  2113. "question": "Hello",
  2114. "stream": true,
  2115. "session_id": "cb2f385cb86211efa36e0242ac120005"
  2116. }'
  2117. ```
  2118. ##### Request Parameters
  2119. - `agent_id`: (*Path parameter*), `string`
  2120. The ID of the associated agent.
  2121. - `"question"`: (*Body Parameter*), `string`, *Required*
  2122. The question to start an AI-powered conversation.
  2123. - `"stream"`: (*Body Parameter*), `boolean`
  2124. Indicates whether to output responses in a streaming way:
  2125. - `true`: Enable streaming (default).
  2126. - `false`: Disable streaming.
  2127. - `"session_id"`: (*Body Parameter*)
  2128. The ID of the session. If it is not provided, a new session will be generated.
  2129. - `"user_id"`: (*Body parameter*), `string`
  2130. The optional user-defined ID. Valid *only* when no `session_id` is provided.
  2131. - `"sync_dsl"`: (*Body parameter*), `boolean`
  2132. Whether to synchronize the changes to existing sessions when an agent is modified, defaults to `false`.
  2133. - Other parameters: (*Body Parameter*)
  2134. Parameters specified in the **Begin** component.
  2135. #### Response
  2136. success without `session_id` provided and with no parameters specified in the **Begin** component:
  2137. ```json
  2138. data:{
  2139. "code": 0,
  2140. "message": "",
  2141. "data": {
  2142. "answer": "Hi! I'm your smart assistant. What can I do for you?",
  2143. "reference": {},
  2144. "id": "31e6091d-88d4-441b-ac65-eae1c055be7b",
  2145. "session_id": "2987ad3eb85f11efb2a70242ac120005"
  2146. }
  2147. }
  2148. data:{
  2149. "code": 0,
  2150. "message": "",
  2151. "data": true
  2152. }
  2153. ```
  2154. Success without `session_id` provided and with parameters specified in the **Begin** component:
  2155. ```json
  2156. data:{
  2157. "code": 0,
  2158. "message": "",
  2159. "data": {
  2160. "session_id": "eacb36a0bdff11ef97120242ac120006",
  2161. "answer": "",
  2162. "reference": [],
  2163. "param": [
  2164. {
  2165. "key": "lang",
  2166. "name": "Target Language",
  2167. "optional": false,
  2168. "type": "line",
  2169. "value": "English"
  2170. },
  2171. {
  2172. "key": "file",
  2173. "name": "Files",
  2174. "optional": false,
  2175. "type": "file",
  2176. "value": "How is the weather tomorrow?"
  2177. },
  2178. {
  2179. "key": "hhyt",
  2180. "name": "hhty",
  2181. "optional": true,
  2182. "type": "line"
  2183. }
  2184. ]
  2185. }
  2186. }
  2187. data:
  2188. ```
  2189. Success with parameters specified in the **Begin** component:
  2190. ```json
  2191. data:{
  2192. "code": 0,
  2193. "message": "",
  2194. "data": {
  2195. "answer": "How",
  2196. "reference": {},
  2197. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2198. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2199. }
  2200. }
  2201. data:{
  2202. "code": 0,
  2203. "message": "",
  2204. "data": {
  2205. "answer": "How is",
  2206. "reference": {},
  2207. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2208. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2209. }
  2210. }
  2211. data:{
  2212. "code": 0,
  2213. "message": "",
  2214. "data": {
  2215. "answer": "How is the",
  2216. "reference": {},
  2217. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2218. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2219. }
  2220. }
  2221. data:{
  2222. "code": 0,
  2223. "message": "",
  2224. "data": {
  2225. "answer": "How is the weather",
  2226. "reference": {},
  2227. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2228. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2229. }
  2230. }
  2231. data:{
  2232. "code": 0,
  2233. "message": "",
  2234. "data": {
  2235. "answer": "How is the weather tomorrow",
  2236. "reference": {},
  2237. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2238. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2239. }
  2240. }
  2241. data:{
  2242. "code": 0,
  2243. "message": "",
  2244. "data": {
  2245. "answer": "How is the weather tomorrow?",
  2246. "reference": {},
  2247. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2248. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2249. }
  2250. }
  2251. data:{
  2252. "code": 0,
  2253. "message": "",
  2254. "data": {
  2255. "answer": "How is the weather tomorrow?",
  2256. "reference": {},
  2257. "id": "0379ac4c-b26b-4a44-8b77-99cebf313fdf",
  2258. "session_id": "4399c7d0b86311efac5b0242ac120005"
  2259. }
  2260. }
  2261. data:{
  2262. "code": 0,
  2263. "message": "",
  2264. "data": true
  2265. }
  2266. ```
  2267. Failure:
  2268. ```json
  2269. {
  2270. "code": 102,
  2271. "message": "`question` is required."
  2272. }
  2273. ```
  2274. ---
  2275. ### List agent sessions
  2276. **GET** `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id}&dsl={dsl}`
  2277. Lists sessions associated with a specified agent.
  2278. #### Request
  2279. - Method: GET
  2280. - URL: `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}`
  2281. - Headers:
  2282. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2283. ##### Request example
  2284. ```bash
  2285. curl --request GET \
  2286. --url http://{address}/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id} \
  2287. --header 'Authorization: Bearer <YOUR_API_KEY>'
  2288. ```
  2289. ##### Request Parameters
  2290. - `agent_id`: (*Path parameter*)
  2291. The ID of the associated agent.
  2292. - `page`: (*Filter parameter*), `integer`
  2293. Specifies the page on which the sessions will be displayed. Defaults to `1`.
  2294. - `page_size`: (*Filter parameter*), `integer`
  2295. The number of sessions on each page. Defaults to `30`.
  2296. - `orderby`: (*Filter parameter*), `string`
  2297. The field by which sessions should be sorted. Available options:
  2298. - `create_time` (default)
  2299. - `update_time`
  2300. - `desc`: (*Filter parameter*), `boolean`
  2301. Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `true`.
  2302. - `id`: (*Filter parameter*), `string`
  2303. The ID of the agent session to retrieve.
  2304. - `user_id`: (*Filter parameter*), `string`
  2305. The optional user-defined ID passed in when creating session.
  2306. - `dsl`: (*Filter parameter*), `boolean`
  2307. Indicates whether to include the dsl field of the sessions in the response. Defaults to `true`.
  2308. #### Response
  2309. Success:
  2310. ```json
  2311. {
  2312. "code": 0,
  2313. "data": [{
  2314. "agent_id": "e9e2b9c2b2f911ef801d0242ac120006",
  2315. "dsl": {
  2316. "answer": [],
  2317. "components": {
  2318. "Answer:OrangeTermsBurn": {
  2319. "downstream": [],
  2320. "obj": {
  2321. "component_name": "Answer",
  2322. "params": {}
  2323. },
  2324. "upstream": []
  2325. },
  2326. "Generate:SocialYearsRemain": {
  2327. "downstream": [],
  2328. "obj": {
  2329. "component_name": "Generate",
  2330. "params": {
  2331. "cite": true,
  2332. "frequency_penalty": 0.7,
  2333. "llm_id": "gpt-4o___OpenAI-API@OpenAI-API-Compatible",
  2334. "message_history_window_size": 12,
  2335. "parameters": [],
  2336. "presence_penalty": 0.4,
  2337. "prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
  2338. "temperature": 0.1,
  2339. "top_p": 0.3
  2340. }
  2341. },
  2342. "upstream": []
  2343. },
  2344. "begin": {
  2345. "downstream": [],
  2346. "obj": {
  2347. "component_name": "Begin",
  2348. "params": {}
  2349. },
  2350. "upstream": []
  2351. }
  2352. },
  2353. "graph": {
  2354. "edges": [],
  2355. "nodes": [
  2356. {
  2357. "data": {
  2358. "label": "Begin",
  2359. "name": "begin"
  2360. },
  2361. "height": 44,
  2362. "id": "begin",
  2363. "position": {
  2364. "x": 50,
  2365. "y": 200
  2366. },
  2367. "sourcePosition": "left",
  2368. "targetPosition": "right",
  2369. "type": "beginNode",
  2370. "width": 200
  2371. },
  2372. {
  2373. "data": {
  2374. "form": {
  2375. "cite": true,
  2376. "frequencyPenaltyEnabled": true,
  2377. "frequency_penalty": 0.7,
  2378. "llm_id": "gpt-4o___OpenAI-API@OpenAI-API-Compatible",
  2379. "maxTokensEnabled": true,
  2380. "message_history_window_size": 12,
  2381. "parameters": [],
  2382. "presencePenaltyEnabled": true,
  2383. "presence_penalty": 0.4,
  2384. "prompt": "Please summarize the following paragraph. Pay attention to the numbers and do not make things up. The paragraph is as follows:\n{input}\nThis is what you need to summarize.",
  2385. "temperature": 0.1,
  2386. "temperatureEnabled": true,
  2387. "topPEnabled": true,
  2388. "top_p": 0.3
  2389. },
  2390. "label": "Generate",
  2391. "name": "Generate Answer_0"
  2392. },
  2393. "dragging": false,
  2394. "height": 105,
  2395. "id": "Generate:SocialYearsRemain",
  2396. "position": {
  2397. "x": 561.3457829707513,
  2398. "y": 178.7211182312641
  2399. },
  2400. "positionAbsolute": {
  2401. "x": 561.3457829707513,
  2402. "y": 178.7211182312641
  2403. },
  2404. "selected": true,
  2405. "sourcePosition": "right",
  2406. "targetPosition": "left",
  2407. "type": "generateNode",
  2408. "width": 200
  2409. },
  2410. {
  2411. "data": {
  2412. "form": {},
  2413. "label": "Answer",
  2414. "name": "Dialogue_0"
  2415. },
  2416. "height": 44,
  2417. "id": "Answer:OrangeTermsBurn",
  2418. "position": {
  2419. "x": 317.2368194777658,
  2420. "y": 218.30635555445093
  2421. },
  2422. "sourcePosition": "right",
  2423. "targetPosition": "left",
  2424. "type": "logicNode",
  2425. "width": 200
  2426. }
  2427. ]
  2428. },
  2429. "history": [],
  2430. "messages": [],
  2431. "path": [],
  2432. "reference": []
  2433. },
  2434. "id": "792dde22b2fa11ef97550242ac120006",
  2435. "message": [
  2436. {
  2437. "content": "Hi! I'm your smart assistant. What can I do for you?",
  2438. "role": "assistant"
  2439. }
  2440. ],
  2441. "source": "agent",
  2442. "user_id": ""
  2443. }]
  2444. }
  2445. ```
  2446. Failure:
  2447. ```json
  2448. {
  2449. "code": 102,
  2450. "message": "You don't own the agent ccd2f856b12311ef94ca0242ac1200052."
  2451. }
  2452. ```
  2453. ---
  2454. ### Delete agent's sessions
  2455. **DELETE** `/api/v1/agents/{agent_id}/sessions`
  2456. Deletes sessions of a agent by ID.
  2457. #### Request
  2458. - Method: DELETE
  2459. - URL: `/api/v1/agents/{agent_id}/sessions`
  2460. - Headers:
  2461. - `'content-Type: application/json'`
  2462. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2463. - Body:
  2464. - `"ids"`: `list[string]`
  2465. ##### Request example
  2466. ```bash
  2467. curl --request DELETE \
  2468. --url http://{address}/api/v1/agents/{agent_id}/sessions \
  2469. --header 'Content-Type: application/json' \
  2470. --header 'Authorization: Bearer <YOUR_API_KEY>' \
  2471. --data '
  2472. {
  2473. "ids": ["test_1", "test_2"]
  2474. }'
  2475. ```
  2476. ##### Request Parameters
  2477. - `agent_id`: (*Path parameter*)
  2478. The ID of the associated agent.
  2479. - `"ids"`: (*Body Parameter*), `list[string]`
  2480. The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified agent will be deleted.
  2481. #### Response
  2482. Success:
  2483. ```json
  2484. {
  2485. "code": 0
  2486. }
  2487. ```
  2488. Failure:
  2489. ```json
  2490. {
  2491. "code": 102,
  2492. "message": "The agent doesn't own the session cbd31e52f73911ef93b232903b842af6"
  2493. }
  2494. ```
  2495. ---
  2496. ## AGENT MANAGEMENT
  2497. ---
  2498. ### List agents
  2499. **GET** `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
  2500. Lists agents.
  2501. #### Request
  2502. - Method: GET
  2503. - URL: `/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id}`
  2504. - Headers:
  2505. - `'Authorization: Bearer <YOUR_API_KEY>'`
  2506. ##### Request example
  2507. ```bash
  2508. curl --request GET \
  2509. --url http://{address}/api/v1/agents?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={agent_name}&id={agent_id} \
  2510. --header 'Authorization: Bearer <YOUR_API_KEY>'
  2511. ```
  2512. ##### Request parameters
  2513. - `page`: (*Filter parameter*), `integer`
  2514. Specifies the page on which the agents will be displayed. Defaults to `1`.
  2515. - `page_size`: (*Filter parameter*), `integer`
  2516. The number of agents on each page. Defaults to `30`.
  2517. - `orderby`: (*Filter parameter*), `string`
  2518. The attribute by which the results are sorted. Available options:
  2519. - `create_time` (default)
  2520. - `update_time`
  2521. - `desc`: (*Filter parameter*), `boolean`
  2522. Indicates whether the retrieved agents should be sorted in descending order. Defaults to `true`.
  2523. - `id`: (*Filter parameter*), `string`
  2524. The ID of the agent to retrieve.
  2525. - `name`: (*Filter parameter*), `string`
  2526. The name of the agent to retrieve.
  2527. #### Response
  2528. Success:
  2529. ```json
  2530. {
  2531. "code": 0,
  2532. "data": [
  2533. {
  2534. "avatar": null,
  2535. "canvas_type": null,
  2536. "create_date": "Thu, 05 Dec 2024 19:10:36 GMT",
  2537. "create_time": 1733397036424,
  2538. "description": null,
  2539. "dsl": {
  2540. "answer": [],
  2541. "components": {
  2542. "begin": {
  2543. "downstream": [],
  2544. "obj": {
  2545. "component_name": "Begin",
  2546. "params": {}
  2547. },
  2548. "upstream": []
  2549. }
  2550. },
  2551. "graph": {
  2552. "edges": [],
  2553. "nodes": [
  2554. {
  2555. "data": {
  2556. "label": "Begin",
  2557. "name": "begin"
  2558. },
  2559. "height": 44,
  2560. "id": "begin",
  2561. "position": {
  2562. "x": 50,
  2563. "y": 200
  2564. },
  2565. "sourcePosition": "left",
  2566. "targetPosition": "right",
  2567. "type": "beginNode",
  2568. "width": 200
  2569. }
  2570. ]
  2571. },
  2572. "history": [],
  2573. "messages": [],
  2574. "path": [],
  2575. "reference": []
  2576. },
  2577. "id": "8d9ca0e2b2f911ef9ca20242ac120006",
  2578. "title": "123465",
  2579. "update_date": "Thu, 05 Dec 2024 19:10:56 GMT",
  2580. "update_time": 1733397056801,
  2581. "user_id": "69736c5e723611efb51b0242ac120007"
  2582. }
  2583. ]
  2584. }
  2585. ```
  2586. Failure:
  2587. ```json
  2588. {
  2589. "code": 102,
  2590. "message": "The agent doesn't exist."
  2591. }
  2592. ```
  2593. ---