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

http_api_reference.md 85KB

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