Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

http_api_reference.md 98KB

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