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

http_api_reference.md 98KB

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