Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

http_api_reference.md 86KB

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