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

http_api_reference.md 80KB

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