Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

http_api_reference.md 87KB

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