writinwaters
commited on
Commit
·
d36c193
1
Parent(s):
9aabebd
DRAFT: Miscellaneous updates to HTTP API. Tried to finish off Python API ref… (#2909)
Browse files…erence but failed.
### What problem does this PR solve?
### Type of change
- [x] Documentation Update
- api/http_api.md +328 -211
- api/python_api_reference.md +218 -187
api/http_api.md
CHANGED
@@ -3,6 +3,14 @@
|
|
3 |
|
4 |
**THE API REFERENCES BELOW ARE STILL UNDER DEVELOPMENT.**
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
## Create dataset
|
7 |
|
8 |
**POST** `/api/v1/dataset`
|
@@ -17,10 +25,8 @@ Creates a dataset.
|
|
17 |
- `content-Type: application/json`
|
18 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
19 |
- Body:
|
20 |
-
- `"id"`: `string`
|
21 |
- `"name"`: `string`
|
22 |
- `"avatar"`: `string`
|
23 |
-
- `"tenant_id"`: `string`
|
24 |
- `"description"`: `string`
|
25 |
- `"language"`: `string`
|
26 |
- `"embedding_model"`: `string`
|
@@ -33,9 +39,7 @@ Creates a dataset.
|
|
33 |
#### Request example
|
34 |
|
35 |
```bash
|
36 |
-
# "id": id must not be provided.
|
37 |
# "name": name is required and can't be duplicated.
|
38 |
-
# "tenant_id": tenant_id must not be provided.
|
39 |
# "embedding_model": embedding_model must not be provided.
|
40 |
# "naive" means general.
|
41 |
curl --request POST \
|
@@ -52,10 +56,6 @@ curl --request POST \
|
|
52 |
|
53 |
#### Request parameters
|
54 |
|
55 |
-
- `"id"`: (*Body parameter*)
|
56 |
-
The ID of the created dataset used to uniquely identify different datasets.
|
57 |
-
- If creating a dataset, `id` must not be provided.
|
58 |
-
|
59 |
- `"name"`: (*Body parameter*)
|
60 |
The name of the dataset, which must adhere to the following requirements:
|
61 |
- Required when creating a dataset and must be unique.
|
@@ -64,11 +64,6 @@ curl --request POST \
|
|
64 |
- `"avatar"`: (*Body parameter*)
|
65 |
Base64 encoding of the avatar.
|
66 |
|
67 |
-
- `"tenant_id"`: (*Body parameter*)
|
68 |
-
The ID of the tenant associated with the dataset, used to link it with specific users.
|
69 |
-
- If creating a dataset, `tenant_id` must not be provided.
|
70 |
-
- If updating a dataset, `tenant_id` cannot be changed.
|
71 |
-
|
72 |
- `"description"`: (*Body parameter*)
|
73 |
The description of the dataset.
|
74 |
|
@@ -81,7 +76,7 @@ curl --request POST \
|
|
81 |
- If updating a dataset, `embedding_model` cannot be changed.
|
82 |
|
83 |
- `"permission"`: (*Body parameter*)
|
84 |
-
Specifies who can
|
85 |
|
86 |
- `"document_count"`: (*Body parameter*)
|
87 |
Document count of the dataset.
|
@@ -151,11 +146,13 @@ The error response includes a JSON object like the following:
|
|
151 |
}
|
152 |
```
|
153 |
|
|
|
|
|
154 |
## Delete datasets
|
155 |
|
156 |
**DELETE** `/api/v1/dataset`
|
157 |
|
158 |
-
Deletes datasets by
|
159 |
|
160 |
### Request
|
161 |
|
@@ -184,8 +181,7 @@ curl --request DELETE \
|
|
184 |
#### Request parameters
|
185 |
|
186 |
- `"ids"`: (*Body parameter*)
|
187 |
-
|
188 |
-
|
189 |
|
190 |
### Response
|
191 |
|
@@ -210,11 +206,13 @@ The error response includes a JSON object like the following:
|
|
210 |
}
|
211 |
```
|
212 |
|
|
|
|
|
213 |
## Update dataset
|
214 |
|
215 |
**PUT** `/api/v1/dataset/{dataset_id}`
|
216 |
|
217 |
-
Updates
|
218 |
|
219 |
### Request
|
220 |
|
@@ -252,8 +250,8 @@ curl --request PUT \
|
|
252 |
```
|
253 |
|
254 |
#### Request parameters
|
255 |
-
(Refer to the "Create Dataset" for the complete structure of the request parameters.)
|
256 |
|
|
|
257 |
|
258 |
### Response
|
259 |
|
@@ -278,11 +276,15 @@ The error response includes a JSON object like the following:
|
|
278 |
}
|
279 |
```
|
280 |
|
|
|
|
|
281 |
## List datasets
|
282 |
|
283 |
**GET** `/api/v1/dataset?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
284 |
|
285 |
-
|
|
|
|
|
286 |
|
287 |
### Request
|
288 |
|
@@ -365,7 +367,6 @@ The successful response includes a JSON object like the following:
|
|
365 |
]
|
366 |
}
|
367 |
```
|
368 |
-
|
369 |
|
370 |
The error response includes a JSON object like the following:
|
371 |
|
@@ -376,11 +377,19 @@ The error response includes a JSON object like the following:
|
|
376 |
}
|
377 |
```
|
378 |
|
379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
|
381 |
**POST** `/api/v1/dataset/{dataset_id}/document`
|
382 |
|
383 |
-
Uploads
|
384 |
|
385 |
### Request
|
386 |
|
@@ -432,37 +441,54 @@ The error response includes a JSON object like the following:
|
|
432 |
}
|
433 |
```
|
434 |
|
435 |
-
|
436 |
|
437 |
-
|
|
|
|
|
438 |
|
439 |
-
|
440 |
|
441 |
### Request
|
442 |
|
443 |
-
- Method:
|
444 |
-
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document`
|
445 |
- Headers:
|
446 |
-
-
|
447 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
448 |
- Body:
|
449 |
-
- `
|
|
|
|
|
|
|
450 |
#### Request example
|
451 |
|
452 |
```bash
|
453 |
-
curl --request
|
454 |
-
--url http://{address}/api/v1/dataset/{dataset_id}/
|
|
|
455 |
--header 'Content-Type: application/json' \
|
456 |
-
--header 'Authorization: {YOUR ACCESS TOKEN}' \
|
457 |
--data '{
|
458 |
-
"
|
|
|
|
|
459 |
}'
|
|
|
460 |
```
|
461 |
|
462 |
#### Request parameters
|
463 |
|
464 |
-
- `"
|
465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
### Response
|
467 |
|
468 |
The successful response includes a JSON object like the following:
|
@@ -470,27 +496,25 @@ The successful response includes a JSON object like the following:
|
|
470 |
```json
|
471 |
{
|
472 |
"code": 0
|
473 |
-
}
|
474 |
```
|
475 |
-
|
476 |
-
- `"error_code"`: `integer`
|
477 |
-
`0`: The operation succeeds.
|
478 |
-
|
479 |
|
480 |
The error response includes a JSON object like the following:
|
481 |
|
482 |
```json
|
483 |
{
|
484 |
"code": 102,
|
485 |
-
"message": "
|
486 |
}
|
487 |
```
|
488 |
|
489 |
-
|
|
|
|
|
490 |
|
491 |
**GET** `/api/v1/dataset/{dataset_id}/document/{document_id}`
|
492 |
|
493 |
-
Downloads a
|
494 |
|
495 |
### Request
|
496 |
|
@@ -500,6 +524,7 @@ Downloads a file from a dataset.
|
|
500 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
501 |
- Output:
|
502 |
- '{FILE_NAME}'
|
|
|
503 |
#### Request example
|
504 |
|
505 |
```bash
|
@@ -537,12 +562,13 @@ The error response includes a JSON object like the following:
|
|
537 |
}
|
538 |
```
|
539 |
|
|
|
540 |
|
541 |
-
## List
|
542 |
|
543 |
**GET** `/api/v1/dataset/{dataset_id}/info?offset={offset}&limit={limit}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}`
|
544 |
|
545 |
-
|
546 |
|
547 |
### Request
|
548 |
|
@@ -635,53 +661,40 @@ The error response includes a JSON object like the following:
|
|
635 |
}
|
636 |
```
|
637 |
|
638 |
-
|
639 |
|
640 |
-
|
|
|
|
|
641 |
|
642 |
-
|
643 |
|
644 |
### Request
|
645 |
|
646 |
-
- Method:
|
647 |
-
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document
|
648 |
- Headers:
|
649 |
-
-
|
650 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
651 |
- Body:
|
652 |
-
- `
|
653 |
-
|
654 |
-
- `parser_config`:`dict`
|
655 |
#### Request example
|
656 |
|
657 |
```bash
|
658 |
-
curl --request
|
659 |
-
--url http://{address}/api/v1/dataset/{dataset_id}/
|
660 |
-
--header 'Authorization: Bearer {YOUR_ACCESS TOKEN}' \
|
661 |
--header 'Content-Type: application/json' \
|
|
|
662 |
--data '{
|
663 |
-
"
|
664 |
-
"parser_method": "manual",
|
665 |
-
"parser_config": {"chunk_token_count": 128, "delimiter": "\n!?。;!?", "layout_recognize": true, "task_page_size": 12}
|
666 |
}'
|
667 |
-
|
668 |
```
|
669 |
|
670 |
#### Request parameters
|
671 |
|
672 |
-
- `"
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
- `"parser_config"`: (*Body parameter*)
|
677 |
-
Configuration object for the parser.
|
678 |
-
- If the value is `None`, a dictionary with default values will be generated.
|
679 |
-
|
680 |
-
- `"name"`: (*Body parameter*)
|
681 |
-
Name or title of the document.
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
|
686 |
### Response
|
687 |
|
@@ -690,23 +703,29 @@ The successful response includes a JSON object like the following:
|
|
690 |
```json
|
691 |
{
|
692 |
"code": 0
|
693 |
-
}
|
694 |
```
|
|
|
|
|
|
|
|
|
695 |
|
696 |
The error response includes a JSON object like the following:
|
697 |
|
698 |
```json
|
699 |
{
|
700 |
"code": 102,
|
701 |
-
"message": "
|
702 |
}
|
703 |
```
|
704 |
|
705 |
-
|
|
|
|
|
706 |
|
707 |
**POST** `/api/v1/dataset/{dataset_id}/chunk`
|
708 |
|
709 |
-
|
710 |
|
711 |
### Request
|
712 |
|
@@ -753,11 +772,13 @@ The error response includes a JSON object like the following:
|
|
753 |
}
|
754 |
```
|
755 |
|
756 |
-
|
|
|
|
|
757 |
|
758 |
**DELETE** `/api/v1/dataset/{dataset_id}/chunk`
|
759 |
|
760 |
-
|
761 |
|
762 |
### Request
|
763 |
|
@@ -804,11 +825,81 @@ The error response includes a JSON object like the following:
|
|
804 |
}
|
805 |
```
|
806 |
|
807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
|
809 |
**GET** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
|
810 |
|
811 |
-
|
812 |
|
813 |
### Request
|
814 |
|
@@ -836,7 +927,8 @@ curl --request GET \
|
|
836 |
- `"limit"`(*Filter parameter*)
|
837 |
Records number to return
|
838 |
- `"id"`(*Filter parameter*)
|
839 |
-
The
|
|
|
840 |
### Response
|
841 |
|
842 |
The successful response includes a JSON object like the following:
|
@@ -853,8 +945,8 @@ The successful response includes a JSON object like the following:
|
|
853 |
"created_by": "69736c5e723611efb51b0242ac120007",
|
854 |
"id": "8cb781ec7e1511ef98ac0242ac120006",
|
855 |
"kb_id": "c7ee74067a2c11efb21c0242ac120006",
|
856 |
-
"location": "
|
857 |
-
"name": "
|
858 |
"parser_config": {
|
859 |
"pages": [
|
860 |
[
|
@@ -892,11 +984,13 @@ The error response includes a JSON object like the following:
|
|
892 |
}
|
893 |
```
|
894 |
|
895 |
-
|
|
|
|
|
896 |
|
897 |
**DELETE** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
898 |
|
899 |
-
|
900 |
|
901 |
### Request
|
902 |
|
@@ -906,7 +1000,7 @@ Delete document chunks
|
|
906 |
- `content-Type: application/json`
|
907 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
908 |
- Body:
|
909 |
-
- `chunk_ids`:
|
910 |
|
911 |
#### Request example
|
912 |
|
@@ -919,18 +1013,21 @@ curl --request DELETE \
|
|
919 |
"chunk_ids": ["test_1", "test_2"]
|
920 |
}'
|
921 |
```
|
|
|
922 |
#### Request parameters
|
923 |
|
924 |
- `"chunk_ids"`:(*Body parameter*)
|
925 |
The chunks of the document to be deleted
|
926 |
|
927 |
### Response
|
|
|
928 |
Success
|
929 |
```json
|
930 |
{
|
931 |
"code": 0
|
932 |
}
|
933 |
```
|
|
|
934 |
Error
|
935 |
```json
|
936 |
{
|
@@ -939,12 +1036,13 @@ Error
|
|
939 |
}
|
940 |
```
|
941 |
|
|
|
942 |
|
943 |
-
## Update
|
944 |
|
945 |
**PUT** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
|
946 |
|
947 |
-
|
948 |
|
949 |
### Request
|
950 |
|
@@ -957,6 +1055,7 @@ Update document chunk
|
|
957 |
- `content`:str
|
958 |
- `important_keywords`:str
|
959 |
- `available`:int
|
|
|
960 |
#### Request example
|
961 |
|
962 |
```bash
|
@@ -969,7 +1068,9 @@ curl --request PUT \
|
|
969 |
"important_keywords": [],
|
970 |
}'
|
971 |
```
|
|
|
972 |
#### Request parameters
|
|
|
973 |
- `"content"`:(*Body parameter*)
|
974 |
Contains the main text or information of the chunk.
|
975 |
- `"important_keywords"`:(*Body parameter*)
|
@@ -978,80 +1079,25 @@ curl --request PUT \
|
|
978 |
Indicating the availability status, 0 means unavailable and 1 means available.
|
979 |
|
980 |
### Response
|
|
|
981 |
Success
|
|
|
982 |
```json
|
983 |
{
|
984 |
"code": 0
|
985 |
}
|
986 |
```
|
987 |
Error
|
|
|
988 |
```json
|
989 |
{
|
990 |
"code": 102,
|
991 |
"message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
|
992 |
}
|
993 |
```
|
994 |
-
## Insert document chunks
|
995 |
-
|
996 |
-
**POST** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
997 |
-
|
998 |
-
Insert document chunks
|
999 |
-
|
1000 |
-
### Request
|
1001 |
-
|
1002 |
-
- Method: POST
|
1003 |
-
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
1004 |
-
- Headers:
|
1005 |
-
- `content-Type: application/json`
|
1006 |
-
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1007 |
-
- Body:
|
1008 |
-
- `content`: str
|
1009 |
-
- `important_keywords`:List[str]
|
1010 |
-
#### Request example
|
1011 |
-
|
1012 |
-
```bash
|
1013 |
-
curl --request POST \
|
1014 |
-
--url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
|
1015 |
-
--header 'Content-Type: application/json' \
|
1016 |
-
--header 'Authorization: Bearer {YOUR_ACCESS_TOKEN}' \
|
1017 |
-
--data '{
|
1018 |
-
"content": "ragflow content"
|
1019 |
-
}'
|
1020 |
-
```
|
1021 |
-
#### Request parameters
|
1022 |
-
- `content`:(*Body parameter*)
|
1023 |
-
Contains the main text or information of the chunk.
|
1024 |
-
- `important_keywords`(*Body parameter*)
|
1025 |
-
list the key terms or phrases that are significant or central to the chunk's content.
|
1026 |
|
1027 |
-
|
1028 |
-
Success
|
1029 |
-
```json
|
1030 |
-
{
|
1031 |
-
"code": 0,
|
1032 |
-
"data": {
|
1033 |
-
"chunk": {
|
1034 |
-
"content": "ragflow content",
|
1035 |
-
"create_time": "2024-10-16 08:05:04",
|
1036 |
-
"create_timestamp": 1729065904.581025,
|
1037 |
-
"dataset_id": [
|
1038 |
-
"c7ee74067a2c11efb21c0242ac120006"
|
1039 |
-
],
|
1040 |
-
"document_id": "5c5999ec7be811ef9cab0242ac120005",
|
1041 |
-
"id": "d78435d142bd5cf6704da62c778795c5",
|
1042 |
-
"important_keywords": []
|
1043 |
-
}
|
1044 |
-
}
|
1045 |
-
}
|
1046 |
-
```
|
1047 |
|
1048 |
-
Error
|
1049 |
-
```json
|
1050 |
-
{
|
1051 |
-
"code": 102,
|
1052 |
-
"message": "`content` is required"
|
1053 |
-
}
|
1054 |
-
```
|
1055 |
## Dataset retrieval test
|
1056 |
|
1057 |
**GET** `/api/v1/retrieval`
|
@@ -1077,6 +1123,7 @@ Retrieval test of a dataset
|
|
1077 |
- `rerank_id`: string
|
1078 |
- `keyword`: bool
|
1079 |
- `highlight`: bool
|
|
|
1080 |
#### Request example
|
1081 |
|
1082 |
```bash
|
@@ -1096,6 +1143,7 @@ curl --request POST \
|
|
1096 |
```
|
1097 |
|
1098 |
#### Request parameter
|
|
|
1099 |
- `"question"`: (*Body parameter*)
|
1100 |
User's question, search keywords
|
1101 |
`""`
|
@@ -1136,7 +1184,9 @@ curl --request POST \
|
|
1136 |
- `"highlight"`: (*Body parameter*)
|
1137 |
Whether to enable highlighting of matched terms in the results
|
1138 |
`False`
|
|
|
1139 |
### Response
|
|
|
1140 |
Success
|
1141 |
```json
|
1142 |
{
|
@@ -1174,6 +1224,7 @@ Success
|
|
1174 |
}
|
1175 |
}
|
1176 |
```
|
|
|
1177 |
Error
|
1178 |
```json
|
1179 |
{
|
@@ -1181,11 +1232,20 @@ Error
|
|
1181 |
"message": "`datasets` is required."
|
1182 |
}
|
1183 |
```
|
1184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1185 |
|
1186 |
**POST** `/api/v1/chat`
|
1187 |
|
1188 |
-
|
1189 |
|
1190 |
### Request
|
1191 |
|
@@ -1331,7 +1391,9 @@ curl --request POST \
|
|
1331 |
- `"prompt"`: (*Body parameter*)
|
1332 |
Instructions for LLM to follow when answering questions, such as character design or answer length.
|
1333 |
- `"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. Here is the knowledge base: {knowledge} The above is the knowledge base."`
|
|
|
1334 |
### Response
|
|
|
1335 |
Success:
|
1336 |
```json
|
1337 |
{
|
@@ -1400,7 +1462,9 @@ Success:
|
|
1400 |
}
|
1401 |
}
|
1402 |
```
|
|
|
1403 |
Error:
|
|
|
1404 |
```json
|
1405 |
{
|
1406 |
"code": 102,
|
@@ -1408,11 +1472,13 @@ Error:
|
|
1408 |
}
|
1409 |
```
|
1410 |
|
1411 |
-
|
|
|
|
|
1412 |
|
1413 |
**PUT** `/api/v1/chat/{chat_id}`
|
1414 |
|
1415 |
-
|
1416 |
|
1417 |
### Request
|
1418 |
|
@@ -1433,16 +1499,20 @@ curl --request PUT \
|
|
1433 |
"name":"Test"
|
1434 |
}'
|
1435 |
```
|
|
|
1436 |
#### Parameters
|
1437 |
-
|
|
|
1438 |
|
1439 |
### Response
|
|
|
1440 |
Success
|
1441 |
```json
|
1442 |
{
|
1443 |
"code": 0
|
1444 |
}
|
1445 |
```
|
|
|
1446 |
Error
|
1447 |
```json
|
1448 |
{
|
@@ -1451,11 +1521,13 @@ Error
|
|
1451 |
}
|
1452 |
```
|
1453 |
|
1454 |
-
|
|
|
|
|
1455 |
|
1456 |
**DELETE** `/api/v1/chat`
|
1457 |
|
1458 |
-
|
1459 |
|
1460 |
### Request
|
1461 |
|
@@ -1466,7 +1538,9 @@ Delete chats
|
|
1466 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1467 |
- Body:
|
1468 |
- `ids`: List[string]
|
|
|
1469 |
#### Request example
|
|
|
1470 |
```bash
|
1471 |
# Either id or name must be provided, but not both.
|
1472 |
curl --request DELETE \
|
@@ -1478,19 +1552,24 @@ curl --request DELETE \
|
|
1478 |
}'
|
1479 |
}'
|
1480 |
```
|
|
|
1481 |
#### Request parameters:
|
1482 |
|
1483 |
- `"ids"`: (*Body parameter*)
|
1484 |
IDs of the chats to be deleted.
|
1485 |
- `None`
|
|
|
1486 |
### Response
|
|
|
1487 |
Success
|
1488 |
```json
|
1489 |
{
|
1490 |
"code": 0
|
1491 |
}
|
1492 |
```
|
|
|
1493 |
Error
|
|
|
1494 |
```json
|
1495 |
{
|
1496 |
"code": 102,
|
@@ -1498,11 +1577,13 @@ Error
|
|
1498 |
}
|
1499 |
```
|
1500 |
|
1501 |
-
|
|
|
|
|
1502 |
|
1503 |
**GET** `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
1504 |
|
1505 |
-
|
1506 |
|
1507 |
### Request
|
1508 |
|
@@ -1520,6 +1601,7 @@ curl --request GET \
|
|
1520 |
```
|
1521 |
|
1522 |
#### Request parameters
|
|
|
1523 |
- `"page"`: (*Path parameter*)
|
1524 |
The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
|
1525 |
- `1`
|
@@ -1545,6 +1627,7 @@ curl --request GET \
|
|
1545 |
- `None`
|
1546 |
|
1547 |
### Response
|
|
|
1548 |
Success
|
1549 |
```json
|
1550 |
{
|
@@ -1622,7 +1705,9 @@ Success
|
|
1622 |
]
|
1623 |
}
|
1624 |
```
|
|
|
1625 |
Error
|
|
|
1626 |
```json
|
1627 |
{
|
1628 |
"code": 102,
|
@@ -1656,7 +1741,9 @@ curl --request POST \
|
|
1656 |
"name": "new session"
|
1657 |
}'
|
1658 |
```
|
|
|
1659 |
#### Request parameters
|
|
|
1660 |
- `"id"`: (*Body parameter*)
|
1661 |
The ID of the created session used to identify different sessions.
|
1662 |
- `None`
|
@@ -1676,7 +1763,9 @@ curl --request POST \
|
|
1676 |
- `""`
|
1677 |
- `chat_id` cannot be changed.
|
1678 |
|
|
|
1679 |
### Response
|
|
|
1680 |
Success
|
1681 |
```json
|
1682 |
{
|
@@ -1698,7 +1787,9 @@ Success
|
|
1698 |
}
|
1699 |
}
|
1700 |
```
|
|
|
1701 |
Error
|
|
|
1702 |
```json
|
1703 |
{
|
1704 |
"code": 102,
|
@@ -1706,11 +1797,72 @@ Error
|
|
1706 |
}
|
1707 |
```
|
1708 |
|
1709 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1710 |
|
1711 |
**GET** `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
1712 |
|
1713 |
-
|
1714 |
|
1715 |
### Request
|
1716 |
|
@@ -1720,6 +1872,7 @@ List all sessions under the chat based on the filtering criteria.
|
|
1720 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1721 |
|
1722 |
#### Request example
|
|
|
1723 |
```bash
|
1724 |
curl --request GET \
|
1725 |
--url http://{address}/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
|
@@ -1727,6 +1880,7 @@ curl --request GET \
|
|
1727 |
```
|
1728 |
|
1729 |
#### Request Parameters
|
|
|
1730 |
- `"page"`: (*Path parameter*)
|
1731 |
The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
|
1732 |
- `1`
|
@@ -1750,7 +1904,9 @@ curl --request GET \
|
|
1750 |
- `"name"`: (*Path parameter*)
|
1751 |
The name of the session to be retrieved.
|
1752 |
- `None`
|
|
|
1753 |
### Response
|
|
|
1754 |
Success
|
1755 |
```json
|
1756 |
{
|
@@ -1774,7 +1930,9 @@ Success
|
|
1774 |
]
|
1775 |
}
|
1776 |
```
|
|
|
1777 |
Error
|
|
|
1778 |
```json
|
1779 |
{
|
1780 |
"code": 102,
|
@@ -1782,12 +1940,13 @@ Error
|
|
1782 |
}
|
1783 |
```
|
1784 |
|
|
|
1785 |
|
1786 |
-
## Delete
|
1787 |
|
1788 |
**DELETE** `/api/v1/chat/{chat_id}/session`
|
1789 |
|
1790 |
-
|
1791 |
|
1792 |
### Request
|
1793 |
|
@@ -1800,6 +1959,7 @@ Delete chat sessions
|
|
1800 |
- `ids`: List[string]
|
1801 |
|
1802 |
#### Request example
|
|
|
1803 |
```bash
|
1804 |
# Either id or name must be provided, but not both.
|
1805 |
curl --request DELETE \
|
@@ -1829,59 +1989,14 @@ Error
|
|
1829 |
"message": "The chat doesn't own the session"
|
1830 |
}
|
1831 |
```
|
1832 |
-
## Update a chat session
|
1833 |
-
|
1834 |
-
**PUT** `/api/v1/chat/{chat_id}/session/{session_id}`
|
1835 |
-
|
1836 |
-
Update a chat session
|
1837 |
-
|
1838 |
-
### Request
|
1839 |
-
|
1840 |
-
- Method: PUT
|
1841 |
-
- URL: `http://{address}/api/v1/chat/{chat_id}/session/{session_id}`
|
1842 |
-
- Headers:
|
1843 |
-
- `content-Type: application/json`
|
1844 |
-
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1845 |
-
- Body:
|
1846 |
-
- `name`: string
|
1847 |
|
1848 |
-
|
1849 |
-
```bash
|
1850 |
-
curl --request PUT \
|
1851 |
-
--url http://{address}/api/v1/chat/{chat_id}/session/{session_id} \
|
1852 |
-
--header 'Content-Type: application/json' \
|
1853 |
-
--header 'Authorization: Bearer {YOUR_ACCESS_TOKEN}' \
|
1854 |
-
--data '{
|
1855 |
-
"name": "Updated session"
|
1856 |
-
}'
|
1857 |
-
|
1858 |
-
```
|
1859 |
-
|
1860 |
-
#### Request Parameter
|
1861 |
-
- `name`:(*Body Parameter)
|
1862 |
-
The name of the created session.
|
1863 |
-
- `None`
|
1864 |
-
|
1865 |
-
### Response
|
1866 |
-
Success
|
1867 |
-
```json
|
1868 |
-
{
|
1869 |
-
"code": 0
|
1870 |
-
}
|
1871 |
-
```
|
1872 |
-
Error
|
1873 |
-
```json
|
1874 |
-
{
|
1875 |
-
"code": 102,
|
1876 |
-
"message": "Name can not be empty."
|
1877 |
-
}
|
1878 |
-
```
|
1879 |
|
1880 |
-
## Chat with a chat session
|
1881 |
|
1882 |
**POST** `/api/v1/chat/{chat_id}/completion`
|
1883 |
|
1884 |
-
|
1885 |
|
1886 |
### Request
|
1887 |
|
@@ -1897,6 +2012,7 @@ Chat with a chat session
|
|
1897 |
|
1898 |
|
1899 |
#### Request example
|
|
|
1900 |
```bash
|
1901 |
curl --request POST \
|
1902 |
--url http://{address} /api/v1/chat/{chat_id}/completion \
|
@@ -1917,6 +2033,7 @@ curl --request POST \
|
|
1917 |
`False`
|
1918 |
- `session_id`: (*Body Parameter*)
|
1919 |
The id of session.If not provided, a new session will be generated.
|
|
|
1920 |
### Response
|
1921 |
Success
|
1922 |
```json
|
|
|
3 |
|
4 |
**THE API REFERENCES BELOW ARE STILL UNDER DEVELOPMENT.**
|
5 |
|
6 |
+
---
|
7 |
+
|
8 |
+
:::tip NOTE
|
9 |
+
Dataset Management
|
10 |
+
:::
|
11 |
+
|
12 |
+
---
|
13 |
+
|
14 |
## Create dataset
|
15 |
|
16 |
**POST** `/api/v1/dataset`
|
|
|
25 |
- `content-Type: application/json`
|
26 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
27 |
- Body:
|
|
|
28 |
- `"name"`: `string`
|
29 |
- `"avatar"`: `string`
|
|
|
30 |
- `"description"`: `string`
|
31 |
- `"language"`: `string`
|
32 |
- `"embedding_model"`: `string`
|
|
|
39 |
#### Request example
|
40 |
|
41 |
```bash
|
|
|
42 |
# "name": name is required and can't be duplicated.
|
|
|
43 |
# "embedding_model": embedding_model must not be provided.
|
44 |
# "naive" means general.
|
45 |
curl --request POST \
|
|
|
56 |
|
57 |
#### Request parameters
|
58 |
|
|
|
|
|
|
|
|
|
59 |
- `"name"`: (*Body parameter*)
|
60 |
The name of the dataset, which must adhere to the following requirements:
|
61 |
- Required when creating a dataset and must be unique.
|
|
|
64 |
- `"avatar"`: (*Body parameter*)
|
65 |
Base64 encoding of the avatar.
|
66 |
|
|
|
|
|
|
|
|
|
|
|
67 |
- `"description"`: (*Body parameter*)
|
68 |
The description of the dataset.
|
69 |
|
|
|
76 |
- If updating a dataset, `embedding_model` cannot be changed.
|
77 |
|
78 |
- `"permission"`: (*Body parameter*)
|
79 |
+
Specifies who can access the dataset.
|
80 |
|
81 |
- `"document_count"`: (*Body parameter*)
|
82 |
Document count of the dataset.
|
|
|
146 |
}
|
147 |
```
|
148 |
|
149 |
+
---
|
150 |
+
|
151 |
## Delete datasets
|
152 |
|
153 |
**DELETE** `/api/v1/dataset`
|
154 |
|
155 |
+
Deletes datasets by ID.
|
156 |
|
157 |
### Request
|
158 |
|
|
|
181 |
#### Request parameters
|
182 |
|
183 |
- `"ids"`: (*Body parameter*)
|
184 |
+
The IDs of the dataset to delete.
|
|
|
185 |
|
186 |
### Response
|
187 |
|
|
|
206 |
}
|
207 |
```
|
208 |
|
209 |
+
---
|
210 |
+
|
211 |
## Update dataset
|
212 |
|
213 |
**PUT** `/api/v1/dataset/{dataset_id}`
|
214 |
|
215 |
+
Updates configurations for a specified dataset.
|
216 |
|
217 |
### Request
|
218 |
|
|
|
250 |
```
|
251 |
|
252 |
#### Request parameters
|
|
|
253 |
|
254 |
+
Refer to the "Create Dataset" for the complete structure of the request parameters.
|
255 |
|
256 |
### Response
|
257 |
|
|
|
276 |
}
|
277 |
```
|
278 |
|
279 |
+
---
|
280 |
+
|
281 |
## List datasets
|
282 |
|
283 |
**GET** `/api/v1/dataset?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
284 |
|
285 |
+
Lists all datasets?????
|
286 |
+
|
287 |
+
Retrieves a list of datasets.
|
288 |
|
289 |
### Request
|
290 |
|
|
|
367 |
]
|
368 |
}
|
369 |
```
|
|
|
370 |
|
371 |
The error response includes a JSON object like the following:
|
372 |
|
|
|
377 |
}
|
378 |
```
|
379 |
|
380 |
+
---
|
381 |
+
|
382 |
+
:::tip API GROUPING
|
383 |
+
File Management within Dataset
|
384 |
+
:::
|
385 |
+
|
386 |
+
---
|
387 |
+
|
388 |
+
## Upload documents
|
389 |
|
390 |
**POST** `/api/v1/dataset/{dataset_id}/document`
|
391 |
|
392 |
+
Uploads documents to a specified dataset.
|
393 |
|
394 |
### Request
|
395 |
|
|
|
441 |
}
|
442 |
```
|
443 |
|
444 |
+
---
|
445 |
|
446 |
+
## Update document
|
447 |
+
|
448 |
+
**PUT** `/api/v1/dataset/{dataset_id}/info/{document_id}`
|
449 |
|
450 |
+
Updates configurations for a specified document.
|
451 |
|
452 |
### Request
|
453 |
|
454 |
+
- Method: PUT
|
455 |
+
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}`
|
456 |
- Headers:
|
457 |
+
- `content-Type: application/json`
|
458 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
459 |
- Body:
|
460 |
+
- `name`:`string`
|
461 |
+
- `parser_method`:`string`
|
462 |
+
- `parser_config`:`dict`
|
463 |
+
|
464 |
#### Request example
|
465 |
|
466 |
```bash
|
467 |
+
curl --request PUT \
|
468 |
+
--url http://{address}/api/v1/dataset/{dataset_id}/info/{document_id} \
|
469 |
+
--header 'Authorization: Bearer {YOUR_ACCESS TOKEN}' \
|
470 |
--header 'Content-Type: application/json' \
|
|
|
471 |
--data '{
|
472 |
+
"name": "manual.txt",
|
473 |
+
"parser_method": "manual",
|
474 |
+
"parser_config": {"chunk_token_count": 128, "delimiter": "\n!?。;!?", "layout_recognize": true, "task_page_size": 12}
|
475 |
}'
|
476 |
+
|
477 |
```
|
478 |
|
479 |
#### Request parameters
|
480 |
|
481 |
+
- `"parser_method"`: (*Body parameter*)
|
482 |
+
Method used to parse the document.
|
483 |
+
|
484 |
+
|
485 |
+
- `"parser_config"`: (*Body parameter*)
|
486 |
+
Configuration object for the parser.
|
487 |
+
- If the value is `None`, a dictionary with default values will be generated.
|
488 |
+
|
489 |
+
- `"name"`: (*Body parameter*)
|
490 |
+
Name or title of the document.
|
491 |
+
|
492 |
### Response
|
493 |
|
494 |
The successful response includes a JSON object like the following:
|
|
|
496 |
```json
|
497 |
{
|
498 |
"code": 0
|
499 |
+
}
|
500 |
```
|
|
|
|
|
|
|
|
|
501 |
|
502 |
The error response includes a JSON object like the following:
|
503 |
|
504 |
```json
|
505 |
{
|
506 |
"code": 102,
|
507 |
+
"message": "The dataset not own the document."
|
508 |
}
|
509 |
```
|
510 |
|
511 |
+
---
|
512 |
+
|
513 |
+
## Download document
|
514 |
|
515 |
**GET** `/api/v1/dataset/{dataset_id}/document/{document_id}`
|
516 |
|
517 |
+
Downloads a document from a specified dataset.
|
518 |
|
519 |
### Request
|
520 |
|
|
|
524 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
525 |
- Output:
|
526 |
- '{FILE_NAME}'
|
527 |
+
|
528 |
#### Request example
|
529 |
|
530 |
```bash
|
|
|
562 |
}
|
563 |
```
|
564 |
|
565 |
+
---
|
566 |
|
567 |
+
## List documents
|
568 |
|
569 |
**GET** `/api/v1/dataset/{dataset_id}/info?offset={offset}&limit={limit}&orderby={orderby}&desc={desc}&keywords={keywords}&id={document_id}`
|
570 |
|
571 |
+
Retrieves a list of documents from a specified dataset.
|
572 |
|
573 |
### Request
|
574 |
|
|
|
661 |
}
|
662 |
```
|
663 |
|
664 |
+
---
|
665 |
|
666 |
+
## Delete documents
|
667 |
+
|
668 |
+
**DELETE** `/api/v1/dataset/{dataset_id}/document `
|
669 |
|
670 |
+
Deletes documents by ID.
|
671 |
|
672 |
### Request
|
673 |
|
674 |
+
- Method: DELETE
|
675 |
+
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document`
|
676 |
- Headers:
|
677 |
+
- 'Content-Type: application/json'
|
678 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
679 |
- Body:
|
680 |
+
- `ids`:list[str]
|
681 |
+
|
|
|
682 |
#### Request example
|
683 |
|
684 |
```bash
|
685 |
+
curl --request DELETE \
|
686 |
+
--url http://{address}/api/v1/dataset/{dataset_id}/document \
|
|
|
687 |
--header 'Content-Type: application/json' \
|
688 |
+
--header 'Authorization: {YOUR ACCESS TOKEN}' \
|
689 |
--data '{
|
690 |
+
"ids": ["id_1","id_2"]
|
|
|
|
|
691 |
}'
|
|
|
692 |
```
|
693 |
|
694 |
#### Request parameters
|
695 |
|
696 |
+
- `"ids"`: (*Body parameter*)
|
697 |
+
The ids of teh documents to delete.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
|
699 |
### Response
|
700 |
|
|
|
703 |
```json
|
704 |
{
|
705 |
"code": 0
|
706 |
+
}.
|
707 |
```
|
708 |
+
|
709 |
+
- `"error_code"`: `integer`
|
710 |
+
`0`: The operation succeeds.
|
711 |
+
|
712 |
|
713 |
The error response includes a JSON object like the following:
|
714 |
|
715 |
```json
|
716 |
{
|
717 |
"code": 102,
|
718 |
+
"message": "You do not own the dataset 7898da028a0511efbf750242ac1220005."
|
719 |
}
|
720 |
```
|
721 |
|
722 |
+
---
|
723 |
+
|
724 |
+
## Parse documents
|
725 |
|
726 |
**POST** `/api/v1/dataset/{dataset_id}/chunk`
|
727 |
|
728 |
+
Parses documents in a specified dataset.
|
729 |
|
730 |
### Request
|
731 |
|
|
|
772 |
}
|
773 |
```
|
774 |
|
775 |
+
---
|
776 |
+
|
777 |
+
## Stop parsing documents
|
778 |
|
779 |
**DELETE** `/api/v1/dataset/{dataset_id}/chunk`
|
780 |
|
781 |
+
Stops parsing specified documents.
|
782 |
|
783 |
### Request
|
784 |
|
|
|
825 |
}
|
826 |
```
|
827 |
|
828 |
+
---
|
829 |
+
|
830 |
+
|
831 |
+
## Add chunks
|
832 |
+
|
833 |
+
**POST** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
834 |
+
|
835 |
+
Adds a chunk to a specified document in a specified dataset.
|
836 |
+
|
837 |
+
### Request
|
838 |
+
|
839 |
+
- Method: POST
|
840 |
+
- URL: `http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
841 |
+
- Headers:
|
842 |
+
- `content-Type: application/json`
|
843 |
+
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
844 |
+
- Body:
|
845 |
+
- `content`: string
|
846 |
+
- `important_keywords`: `list[string]`
|
847 |
+
|
848 |
+
#### Request example
|
849 |
+
|
850 |
+
```bash
|
851 |
+
curl --request POST \
|
852 |
+
--url http://{address}/api/v1/dataset/{dataset_id}/document/{document_id}/chunk \
|
853 |
+
--header 'Content-Type: application/json' \
|
854 |
+
--header 'Authorization: Bearer {YOUR_ACCESS_TOKEN}' \
|
855 |
+
--data '{
|
856 |
+
"content": "ragflow content"
|
857 |
+
}'
|
858 |
+
```
|
859 |
+
|
860 |
+
#### Request parameters
|
861 |
+
|
862 |
+
- `content`:(*Body parameter*)
|
863 |
+
Contains the main text or information of the chunk.
|
864 |
+
- `important_keywords`(*Body parameter*)
|
865 |
+
list the key terms or phrases that are significant or central to the chunk's content.
|
866 |
+
|
867 |
+
### Response
|
868 |
+
Success
|
869 |
+
```json
|
870 |
+
{
|
871 |
+
"code": 0,
|
872 |
+
"data": {
|
873 |
+
"chunk": {
|
874 |
+
"content": "ragflow content",
|
875 |
+
"create_time": "2024-10-16 08:05:04",
|
876 |
+
"create_timestamp": 1729065904.581025,
|
877 |
+
"dataset_id": [
|
878 |
+
"c7ee74067a2c11efb21c0242ac120006"
|
879 |
+
],
|
880 |
+
"document_id": "5c5999ec7be811ef9cab0242ac120005",
|
881 |
+
"id": "d78435d142bd5cf6704da62c778795c5",
|
882 |
+
"important_keywords": []
|
883 |
+
}
|
884 |
+
}
|
885 |
+
}
|
886 |
+
```
|
887 |
+
|
888 |
+
Error
|
889 |
+
```json
|
890 |
+
{
|
891 |
+
"code": 102,
|
892 |
+
"message": "`content` is required"
|
893 |
+
}
|
894 |
+
```
|
895 |
+
|
896 |
+
---
|
897 |
+
|
898 |
+
## List chunks
|
899 |
|
900 |
**GET** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk?keywords={keywords}&offset={offset}&limit={limit}&id={id}`
|
901 |
|
902 |
+
Retrieves a list of chunks from a specified document in a specified dataset.
|
903 |
|
904 |
### Request
|
905 |
|
|
|
927 |
- `"limit"`(*Filter parameter*)
|
928 |
Records number to return
|
929 |
- `"id"`(*Filter parameter*)
|
930 |
+
The ID of chunk to retrieve.
|
931 |
+
|
932 |
### Response
|
933 |
|
934 |
The successful response includes a JSON object like the following:
|
|
|
945 |
"created_by": "69736c5e723611efb51b0242ac120007",
|
946 |
"id": "8cb781ec7e1511ef98ac0242ac120006",
|
947 |
"kb_id": "c7ee74067a2c11efb21c0242ac120006",
|
948 |
+
"location": "sunny_tomorrow.txt",
|
949 |
+
"name": "sunny_tomorrow.txt",
|
950 |
"parser_config": {
|
951 |
"pages": [
|
952 |
[
|
|
|
984 |
}
|
985 |
```
|
986 |
|
987 |
+
---
|
988 |
+
|
989 |
+
## Delete chunks
|
990 |
|
991 |
**DELETE** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk`
|
992 |
|
993 |
+
Deletes chunks by ID.
|
994 |
|
995 |
### Request
|
996 |
|
|
|
1000 |
- `content-Type: application/json`
|
1001 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1002 |
- Body:
|
1003 |
+
- `chunk_ids`: `list[string]`
|
1004 |
|
1005 |
#### Request example
|
1006 |
|
|
|
1013 |
"chunk_ids": ["test_1", "test_2"]
|
1014 |
}'
|
1015 |
```
|
1016 |
+
|
1017 |
#### Request parameters
|
1018 |
|
1019 |
- `"chunk_ids"`:(*Body parameter*)
|
1020 |
The chunks of the document to be deleted
|
1021 |
|
1022 |
### Response
|
1023 |
+
|
1024 |
Success
|
1025 |
```json
|
1026 |
{
|
1027 |
"code": 0
|
1028 |
}
|
1029 |
```
|
1030 |
+
|
1031 |
Error
|
1032 |
```json
|
1033 |
{
|
|
|
1036 |
}
|
1037 |
```
|
1038 |
|
1039 |
+
---
|
1040 |
|
1041 |
+
## Update chunk
|
1042 |
|
1043 |
**PUT** `/api/v1/dataset/{dataset_id}/document/{document_id}/chunk/{chunk_id}`
|
1044 |
|
1045 |
+
Updates content or configurations for a specified chunk.
|
1046 |
|
1047 |
### Request
|
1048 |
|
|
|
1055 |
- `content`:str
|
1056 |
- `important_keywords`:str
|
1057 |
- `available`:int
|
1058 |
+
|
1059 |
#### Request example
|
1060 |
|
1061 |
```bash
|
|
|
1068 |
"important_keywords": [],
|
1069 |
}'
|
1070 |
```
|
1071 |
+
|
1072 |
#### Request parameters
|
1073 |
+
|
1074 |
- `"content"`:(*Body parameter*)
|
1075 |
Contains the main text or information of the chunk.
|
1076 |
- `"important_keywords"`:(*Body parameter*)
|
|
|
1079 |
Indicating the availability status, 0 means unavailable and 1 means available.
|
1080 |
|
1081 |
### Response
|
1082 |
+
|
1083 |
Success
|
1084 |
+
|
1085 |
```json
|
1086 |
{
|
1087 |
"code": 0
|
1088 |
}
|
1089 |
```
|
1090 |
Error
|
1091 |
+
|
1092 |
```json
|
1093 |
{
|
1094 |
"code": 102,
|
1095 |
"message": "Can't find this chunk 29a2d9987e16ba331fb4d7d30d99b71d2"
|
1096 |
}
|
1097 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1098 |
|
1099 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1101 |
## Dataset retrieval test
|
1102 |
|
1103 |
**GET** `/api/v1/retrieval`
|
|
|
1123 |
- `rerank_id`: string
|
1124 |
- `keyword`: bool
|
1125 |
- `highlight`: bool
|
1126 |
+
|
1127 |
#### Request example
|
1128 |
|
1129 |
```bash
|
|
|
1143 |
```
|
1144 |
|
1145 |
#### Request parameter
|
1146 |
+
|
1147 |
- `"question"`: (*Body parameter*)
|
1148 |
User's question, search keywords
|
1149 |
`""`
|
|
|
1184 |
- `"highlight"`: (*Body parameter*)
|
1185 |
Whether to enable highlighting of matched terms in the results
|
1186 |
`False`
|
1187 |
+
|
1188 |
### Response
|
1189 |
+
|
1190 |
Success
|
1191 |
```json
|
1192 |
{
|
|
|
1224 |
}
|
1225 |
}
|
1226 |
```
|
1227 |
+
|
1228 |
Error
|
1229 |
```json
|
1230 |
{
|
|
|
1232 |
"message": "`datasets` is required."
|
1233 |
}
|
1234 |
```
|
1235 |
+
|
1236 |
+
---
|
1237 |
+
|
1238 |
+
:::tip API GROUPING
|
1239 |
+
Chat Assistant Management
|
1240 |
+
:::
|
1241 |
+
|
1242 |
+
---
|
1243 |
+
|
1244 |
+
## Create chat assistant
|
1245 |
|
1246 |
**POST** `/api/v1/chat`
|
1247 |
|
1248 |
+
Creates a chat assistant.
|
1249 |
|
1250 |
### Request
|
1251 |
|
|
|
1391 |
- `"prompt"`: (*Body parameter*)
|
1392 |
Instructions for LLM to follow when answering questions, such as character design or answer length.
|
1393 |
- `"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. Here is the knowledge base: {knowledge} The above is the knowledge base."`
|
1394 |
+
|
1395 |
### Response
|
1396 |
+
|
1397 |
Success:
|
1398 |
```json
|
1399 |
{
|
|
|
1462 |
}
|
1463 |
}
|
1464 |
```
|
1465 |
+
|
1466 |
Error:
|
1467 |
+
|
1468 |
```json
|
1469 |
{
|
1470 |
"code": 102,
|
|
|
1472 |
}
|
1473 |
```
|
1474 |
|
1475 |
+
---
|
1476 |
+
|
1477 |
+
## Update chat assistant
|
1478 |
|
1479 |
**PUT** `/api/v1/chat/{chat_id}`
|
1480 |
|
1481 |
+
Updates configurations for a specified chat assistant.
|
1482 |
|
1483 |
### Request
|
1484 |
|
|
|
1499 |
"name":"Test"
|
1500 |
}'
|
1501 |
```
|
1502 |
+
|
1503 |
#### Parameters
|
1504 |
+
|
1505 |
+
Refer to the "Create chat" for the complete structure of the request parameters.
|
1506 |
|
1507 |
### Response
|
1508 |
+
|
1509 |
Success
|
1510 |
```json
|
1511 |
{
|
1512 |
"code": 0
|
1513 |
}
|
1514 |
```
|
1515 |
+
|
1516 |
Error
|
1517 |
```json
|
1518 |
{
|
|
|
1521 |
}
|
1522 |
```
|
1523 |
|
1524 |
+
---
|
1525 |
+
|
1526 |
+
## Delete chat assistants
|
1527 |
|
1528 |
**DELETE** `/api/v1/chat`
|
1529 |
|
1530 |
+
Deletes chat assistants by ID.
|
1531 |
|
1532 |
### Request
|
1533 |
|
|
|
1538 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1539 |
- Body:
|
1540 |
- `ids`: List[string]
|
1541 |
+
|
1542 |
#### Request example
|
1543 |
+
|
1544 |
```bash
|
1545 |
# Either id or name must be provided, but not both.
|
1546 |
curl --request DELETE \
|
|
|
1552 |
}'
|
1553 |
}'
|
1554 |
```
|
1555 |
+
|
1556 |
#### Request parameters:
|
1557 |
|
1558 |
- `"ids"`: (*Body parameter*)
|
1559 |
IDs of the chats to be deleted.
|
1560 |
- `None`
|
1561 |
+
|
1562 |
### Response
|
1563 |
+
|
1564 |
Success
|
1565 |
```json
|
1566 |
{
|
1567 |
"code": 0
|
1568 |
}
|
1569 |
```
|
1570 |
+
|
1571 |
Error
|
1572 |
+
|
1573 |
```json
|
1574 |
{
|
1575 |
"code": 102,
|
|
|
1577 |
}
|
1578 |
```
|
1579 |
|
1580 |
+
---
|
1581 |
+
|
1582 |
+
## List chats (INCONSISTENT WITH THE PYTHON API)
|
1583 |
|
1584 |
**GET** `/api/v1/chat?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
1585 |
|
1586 |
+
Retrieves a list of chat assistants.
|
1587 |
|
1588 |
### Request
|
1589 |
|
|
|
1601 |
```
|
1602 |
|
1603 |
#### Request parameters
|
1604 |
+
|
1605 |
- `"page"`: (*Path parameter*)
|
1606 |
The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
|
1607 |
- `1`
|
|
|
1627 |
- `None`
|
1628 |
|
1629 |
### Response
|
1630 |
+
|
1631 |
Success
|
1632 |
```json
|
1633 |
{
|
|
|
1705 |
]
|
1706 |
}
|
1707 |
```
|
1708 |
+
|
1709 |
Error
|
1710 |
+
|
1711 |
```json
|
1712 |
{
|
1713 |
"code": 102,
|
|
|
1741 |
"name": "new session"
|
1742 |
}'
|
1743 |
```
|
1744 |
+
|
1745 |
#### Request parameters
|
1746 |
+
|
1747 |
- `"id"`: (*Body parameter*)
|
1748 |
The ID of the created session used to identify different sessions.
|
1749 |
- `None`
|
|
|
1763 |
- `""`
|
1764 |
- `chat_id` cannot be changed.
|
1765 |
|
1766 |
+
|
1767 |
### Response
|
1768 |
+
|
1769 |
Success
|
1770 |
```json
|
1771 |
{
|
|
|
1787 |
}
|
1788 |
}
|
1789 |
```
|
1790 |
+
|
1791 |
Error
|
1792 |
+
|
1793 |
```json
|
1794 |
{
|
1795 |
"code": 102,
|
|
|
1797 |
}
|
1798 |
```
|
1799 |
|
1800 |
+
---
|
1801 |
+
|
1802 |
+
:::tip API GROUPING
|
1803 |
+
Chat Session APIs
|
1804 |
+
:::
|
1805 |
+
|
1806 |
+
---
|
1807 |
+
|
1808 |
+
=========MISSING CREATE SESSION API!==============
|
1809 |
+
|
1810 |
+
---
|
1811 |
+
## Update a chat session
|
1812 |
+
|
1813 |
+
**PUT** `/api/v1/chat/{chat_id}/session/{session_id}`
|
1814 |
+
|
1815 |
+
Update a chat session
|
1816 |
+
|
1817 |
+
### Request
|
1818 |
+
|
1819 |
+
- Method: PUT
|
1820 |
+
- URL: `http://{address}/api/v1/chat/{chat_id}/session/{session_id}`
|
1821 |
+
- Headers:
|
1822 |
+
- `content-Type: application/json`
|
1823 |
+
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1824 |
+
- Body:
|
1825 |
+
- `name`: string
|
1826 |
+
|
1827 |
+
#### Request example
|
1828 |
+
```bash
|
1829 |
+
curl --request PUT \
|
1830 |
+
--url http://{address}/api/v1/chat/{chat_id}/session/{session_id} \
|
1831 |
+
--header 'Content-Type: application/json' \
|
1832 |
+
--header 'Authorization: Bearer {YOUR_ACCESS_TOKEN}' \
|
1833 |
+
--data '{
|
1834 |
+
"name": "Updated session"
|
1835 |
+
}'
|
1836 |
+
|
1837 |
+
```
|
1838 |
+
|
1839 |
+
#### Request Parameter
|
1840 |
+
- `name`:(*Body Parameter)
|
1841 |
+
The name of the created session.
|
1842 |
+
- `None`
|
1843 |
+
|
1844 |
+
### Response
|
1845 |
+
Success
|
1846 |
+
```json
|
1847 |
+
{
|
1848 |
+
"code": 0
|
1849 |
+
}
|
1850 |
+
```
|
1851 |
+
Error
|
1852 |
+
```json
|
1853 |
+
{
|
1854 |
+
"code": 102,
|
1855 |
+
"message": "Name can not be empty."
|
1856 |
+
}
|
1857 |
+
```
|
1858 |
+
|
1859 |
+
---
|
1860 |
+
|
1861 |
+
## List sessions
|
1862 |
|
1863 |
**GET** `/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id}`
|
1864 |
|
1865 |
+
Lists sessions associated with a specified????????????? chat assistant.
|
1866 |
|
1867 |
### Request
|
1868 |
|
|
|
1872 |
- 'Authorization: Bearer {YOUR_ACCESS_TOKEN}'
|
1873 |
|
1874 |
#### Request example
|
1875 |
+
|
1876 |
```bash
|
1877 |
curl --request GET \
|
1878 |
--url http://{address}/api/v1/chat/{chat_id}/session?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&name={dataset_name}&id={dataset_id} \
|
|
|
1880 |
```
|
1881 |
|
1882 |
#### Request Parameters
|
1883 |
+
|
1884 |
- `"page"`: (*Path parameter*)
|
1885 |
The current page number to retrieve from the paginated data. This parameter determines which set of records will be fetched.
|
1886 |
- `1`
|
|
|
1904 |
- `"name"`: (*Path parameter*)
|
1905 |
The name of the session to be retrieved.
|
1906 |
- `None`
|
1907 |
+
|
1908 |
### Response
|
1909 |
+
|
1910 |
Success
|
1911 |
```json
|
1912 |
{
|
|
|
1930 |
]
|
1931 |
}
|
1932 |
```
|
1933 |
+
|
1934 |
Error
|
1935 |
+
|
1936 |
```json
|
1937 |
{
|
1938 |
"code": 102,
|
|
|
1940 |
}
|
1941 |
```
|
1942 |
|
1943 |
+
---
|
1944 |
|
1945 |
+
## Delete sessions
|
1946 |
|
1947 |
**DELETE** `/api/v1/chat/{chat_id}/session`
|
1948 |
|
1949 |
+
Deletes sessions by ID.
|
1950 |
|
1951 |
### Request
|
1952 |
|
|
|
1959 |
- `ids`: List[string]
|
1960 |
|
1961 |
#### Request example
|
1962 |
+
|
1963 |
```bash
|
1964 |
# Either id or name must be provided, but not both.
|
1965 |
curl --request DELETE \
|
|
|
1989 |
"message": "The chat doesn't own the session"
|
1990 |
}
|
1991 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1992 |
|
1993 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1994 |
|
1995 |
+
## Chat with a chat session???
|
1996 |
|
1997 |
**POST** `/api/v1/chat/{chat_id}/completion`
|
1998 |
|
1999 |
+
Asks a question to start a conversation.
|
2000 |
|
2001 |
### Request
|
2002 |
|
|
|
2012 |
|
2013 |
|
2014 |
#### Request example
|
2015 |
+
|
2016 |
```bash
|
2017 |
curl --request POST \
|
2018 |
--url http://{address} /api/v1/chat/{chat_id}/completion \
|
|
|
2033 |
`False`
|
2034 |
- `session_id`: (*Body Parameter*)
|
2035 |
The id of session.If not provided, a new session will be generated.
|
2036 |
+
|
2037 |
### Response
|
2038 |
Success
|
2039 |
```json
|
api/python_api_reference.md
CHANGED
@@ -380,7 +380,7 @@ The ID of the document to retrieve. Defaults to `None`.
|
|
380 |
|
381 |
#### keywords: `str`
|
382 |
|
383 |
-
The keywords to match document titles. Defaults to `None`.
|
384 |
|
385 |
#### offset: `int`
|
386 |
|
@@ -419,7 +419,7 @@ A `Document` object contains the following attributes:
|
|
419 |
- `created_by`: `str` The creator of the document. Defaults to `""`.
|
420 |
- `size`: `int` The document size in bytes. Defaults to `0`.
|
421 |
- `token_count`: `int` The number of tokens in the document. Defaults to `0`.
|
422 |
-
- `chunk_count`: `int` The number of chunks
|
423 |
- `progress`: `float` The current processing progress as a percentage. Defaults to `0.0`.
|
424 |
- `progress_msg`: `str` A message indicating the current progress status. Defaults to `""`.
|
425 |
- `process_begin_at`: `datetime` The start time of document processing. Defaults to `None`.
|
@@ -432,8 +432,8 @@ A `Document` object contains the following attributes:
|
|
432 |
```python
|
433 |
from ragflow import RAGFlow
|
434 |
|
435 |
-
|
436 |
-
dataset =
|
437 |
|
438 |
filename1 = "~/ragflow.txt"
|
439 |
blob = open(filename1 , "rb").read()
|
@@ -482,6 +482,8 @@ dataset.delete_documents(ids=["id_1","id_2"])
|
|
482 |
DataSet.async_parse_documents(document_ids:list[str]) -> None
|
483 |
```
|
484 |
|
|
|
|
|
485 |
### Parameters
|
486 |
|
487 |
#### document_ids: `list[str]`, *Required*
|
@@ -490,7 +492,7 @@ The IDs of the documents to parse.
|
|
490 |
|
491 |
### Returns
|
492 |
|
493 |
-
- Success: No value is returned
|
494 |
- Failure: `Exception`
|
495 |
|
496 |
### Examples
|
@@ -520,6 +522,8 @@ print("Async bulk parsing initiated.")
|
|
520 |
DataSet.async_cancel_parse_documents(document_ids:list[str])-> None
|
521 |
```
|
522 |
|
|
|
|
|
523 |
### Parameters
|
524 |
|
525 |
#### document_ids: `list[str]`, *Required*
|
@@ -554,86 +558,106 @@ print("Async bulk parsing cancelled.")
|
|
554 |
|
555 |
---
|
556 |
|
557 |
-
##
|
558 |
|
559 |
```python
|
560 |
-
Document.
|
561 |
```
|
562 |
|
563 |
-
|
564 |
|
565 |
### Parameters
|
566 |
|
567 |
-
####
|
568 |
-
|
569 |
-
List chunks whose name has the given keywords. Defaults to `None`
|
570 |
-
|
571 |
-
#### offset: `int`
|
572 |
-
|
573 |
-
The starting index for the chunks to retrieve. Defaults to `1`
|
574 |
|
575 |
-
|
576 |
|
577 |
-
|
578 |
|
579 |
-
|
580 |
-
|
581 |
-
The ID of the chunk to retrieve. Default: `None`
|
582 |
|
583 |
### Returns
|
584 |
|
585 |
-
- Success: A
|
586 |
- Failure: `Exception`.
|
587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
588 |
### Examples
|
589 |
|
590 |
```python
|
591 |
from ragflow import RAGFlow
|
592 |
|
593 |
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
594 |
-
dataset = rag_object.list_datasets("123")
|
595 |
-
|
596 |
-
dataset.
|
597 |
-
|
598 |
-
|
599 |
```
|
600 |
|
601 |
-
|
|
|
|
|
602 |
|
603 |
```python
|
604 |
-
Document.
|
605 |
```
|
606 |
|
|
|
|
|
607 |
### Parameters
|
608 |
|
609 |
-
####
|
|
|
|
|
610 |
|
611 |
-
|
|
|
|
|
|
|
|
|
612 |
|
613 |
-
|
614 |
|
615 |
-
|
|
|
|
|
616 |
|
617 |
### Returns
|
618 |
|
619 |
-
|
|
|
620 |
|
621 |
### Examples
|
622 |
|
623 |
```python
|
624 |
from ragflow import RAGFlow
|
625 |
|
626 |
-
|
627 |
-
dataset =
|
628 |
-
|
629 |
-
|
630 |
-
doc =
|
631 |
-
chunk
|
632 |
```
|
633 |
|
634 |
---
|
635 |
|
636 |
-
## Delete
|
637 |
|
638 |
```python
|
639 |
Document.delete_chunks(chunk_ids: list[str])
|
@@ -657,10 +681,10 @@ The IDs of the chunks to delete. Defaults to `None`. If not specified, all chunk
|
|
657 |
```python
|
658 |
from ragflow import RAGFlow
|
659 |
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
doc =
|
664 |
doc = doc[0]
|
665 |
chunk = doc.add_chunk(content="xxxxxxx")
|
666 |
doc.delete_chunks(["id_1","id_2"])
|
@@ -683,7 +707,7 @@ Updates content or configurations for the current chunk.
|
|
683 |
A dictionary representing the attributes to update, with the following keys:
|
684 |
|
685 |
- `"content"`: `str` Content of the chunk.
|
686 |
-
- `"important_keywords"`: `list[str]` A list of key terms
|
687 |
- `"available"`: `int` The chunk's availability status in the dataset. Value options:
|
688 |
- `0`: Unavailable
|
689 |
- `1`: Available
|
@@ -715,13 +739,15 @@ chunk.update({"content":"sdfx..."})
|
|
715 |
RAGFlow.retrieve(question:str="", datasets:list[str]=None, document=list[str]=None, offset:int=1, limit:int=30, similarity_threshold:float=0.2, vector_similarity_weight:float=0.3, top_k:int=1024,rerank_id:str=None,keyword:bool=False,higlight:bool=False) -> list[Chunk]
|
716 |
```
|
717 |
|
|
|
|
|
718 |
### Parameters
|
719 |
|
720 |
#### question: `str` *Required*
|
721 |
|
722 |
The user query or query keywords. Defaults to `""`.
|
723 |
|
724 |
-
#### datasets: `list[str]`, *Required
|
725 |
|
726 |
The datasets to search from.
|
727 |
|
@@ -735,7 +761,7 @@ The starting index for the documents to retrieve. Defaults to `0`??????.
|
|
735 |
|
736 |
#### limit: `int`
|
737 |
|
738 |
-
The maximum number of chunks to retrieve. Defaults to `6
|
739 |
|
740 |
#### Similarity_threshold: `float`
|
741 |
|
@@ -749,18 +775,18 @@ The weight of vector cosine similarity. Defaults to `0.3`. If x represents the v
|
|
749 |
|
750 |
The number of chunks engaged in vector cosine computaton. Defaults to `1024`.
|
751 |
|
752 |
-
#### rerank_id
|
753 |
|
754 |
-
The ID of the rerank model.
|
755 |
|
756 |
-
#### keyword
|
757 |
|
758 |
Indicates whether keyword-based matching is enabled:
|
759 |
|
760 |
- `True`: Enabled.
|
761 |
-
- `False`: Disabled.
|
762 |
|
763 |
-
#### highlight
|
764 |
|
765 |
Specifying whether to enable highlighting of matched terms in the results (True) or not (False).
|
766 |
|
@@ -775,16 +801,16 @@ Specifying whether to enable highlighting of matched terms in the results (True)
|
|
775 |
from ragflow import RAGFlow
|
776 |
|
777 |
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
778 |
-
|
779 |
-
|
780 |
name = 'ragflow_test.txt'
|
781 |
path = './test_data/ragflow_test.txt'
|
782 |
-
rag_object.create_document(
|
783 |
-
doc =
|
784 |
doc = doc[0]
|
785 |
-
|
786 |
for c in rag_object.retrieve(question="What's ragflow?",
|
787 |
-
datasets=[
|
788 |
offset=1, limit=30, similarity_threshold=0.2,
|
789 |
vector_similarity_weight=0.3,
|
790 |
top_k=1024
|
@@ -818,11 +844,11 @@ Creates a chat assistant.
|
|
818 |
|
819 |
The following shows the attributes of a `Chat` object:
|
820 |
|
821 |
-
#### name: *Required
|
822 |
|
823 |
The name of the chat assistant. Defaults to `"assistant"`.
|
824 |
|
825 |
-
#### avatar
|
826 |
|
827 |
Base64 encoding of the avatar. Defaults to `""`.
|
828 |
|
@@ -830,7 +856,7 @@ Base64 encoding of the avatar. Defaults to `""`.
|
|
830 |
|
831 |
The IDs of the associated datasets. Defaults to `[""]`.
|
832 |
|
833 |
-
#### llm
|
834 |
|
835 |
The llm of the created chat. Defaults to `None`. When the value is `None`, a dictionary with the following values will be generated as the default.
|
836 |
|
@@ -849,7 +875,7 @@ An `LLM` object contains the following attributes:
|
|
849 |
- `max_token`, `int`
|
850 |
This sets the maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
|
851 |
|
852 |
-
#### Prompt
|
853 |
|
854 |
Instructions for the LLM to follow. A `Prompt` object contains the following attributes:
|
855 |
|
@@ -876,17 +902,17 @@ Instructions for the LLM to follow. A `Prompt` object contains the following at
|
|
876 |
```python
|
877 |
from ragflow import RAGFlow
|
878 |
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
for
|
883 |
-
|
884 |
-
|
885 |
```
|
886 |
|
887 |
---
|
888 |
|
889 |
-
## Update chat
|
890 |
|
891 |
```python
|
892 |
Chat.update(update_message: dict)
|
@@ -934,15 +960,15 @@ A dictionary representing the attributes to update, with the following keys:
|
|
934 |
```python
|
935 |
from ragflow import RAGFlow
|
936 |
|
937 |
-
|
938 |
-
|
939 |
-
assistant =
|
940 |
assistant.update({"name": "Stefan", "llm": {"temperature": 0.8}, "prompt": {"top_n": 8}})
|
941 |
```
|
942 |
|
943 |
---
|
944 |
|
945 |
-
## Delete
|
946 |
|
947 |
```python
|
948 |
RAGFlow.delete_chats(ids: list[str] = None)
|
@@ -966,13 +992,13 @@ The IDs of the chat assistants to delete. Defaults to `None`. If not specified,
|
|
966 |
```python
|
967 |
from ragflow import RAGFlow
|
968 |
|
969 |
-
|
970 |
-
|
971 |
```
|
972 |
|
973 |
---
|
974 |
|
975 |
-
## List
|
976 |
|
977 |
```python
|
978 |
RAGFlow.list_chats(
|
@@ -989,29 +1015,32 @@ Retrieves a list of chat assistants.
|
|
989 |
|
990 |
### Parameters
|
991 |
|
992 |
-
#### page
|
993 |
|
994 |
Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
|
995 |
|
996 |
-
#### page_size
|
997 |
|
998 |
The number of chat assistants on each page. Defaults to `1024`.
|
999 |
|
1000 |
-
####
|
1001 |
|
1002 |
-
The attribute by which the results are sorted.
|
1003 |
|
1004 |
-
|
|
|
|
|
|
|
1005 |
|
1006 |
Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `True`.
|
1007 |
|
1008 |
-
#### id: `
|
1009 |
|
1010 |
-
The ID of the chat to retrieve. Defaults to `None`.
|
1011 |
|
1012 |
-
#### name: `
|
1013 |
|
1014 |
-
The name of the chat to retrieve. Defaults to `None`.
|
1015 |
|
1016 |
### Returns
|
1017 |
|
@@ -1031,7 +1060,7 @@ for assistant in rag_object.list_chats():
|
|
1031 |
---
|
1032 |
|
1033 |
:::tip API GROUPING
|
1034 |
-
Chat
|
1035 |
:::
|
1036 |
|
1037 |
---
|
@@ -1046,7 +1075,7 @@ Creates a chat session.
|
|
1046 |
|
1047 |
### Parameters
|
1048 |
|
1049 |
-
#### name
|
1050 |
|
1051 |
The name of the chat session to create.
|
1052 |
|
@@ -1064,12 +1093,14 @@ The name of the chat session to create.
|
|
1064 |
```python
|
1065 |
from ragflow import RAGFlow
|
1066 |
|
1067 |
-
|
1068 |
-
assistant =
|
1069 |
assistant = assistant[0]
|
1070 |
session = assistant.create_session()
|
1071 |
```
|
1072 |
|
|
|
|
|
1073 |
## Update session
|
1074 |
|
1075 |
```python
|
@@ -1096,8 +1127,8 @@ A dictionary representing the attributes to update, with only one key:
|
|
1096 |
```python
|
1097 |
from ragflow import RAGFlow
|
1098 |
|
1099 |
-
|
1100 |
-
assistant =
|
1101 |
assistant = assistant[0]
|
1102 |
session = assistant.create_session("session_name")
|
1103 |
session.update({"name": "updated_name"})
|
@@ -1105,93 +1136,6 @@ session.update({"name": "updated_name"})
|
|
1105 |
|
1106 |
---
|
1107 |
|
1108 |
-
## Chat
|
1109 |
-
|
1110 |
-
```python
|
1111 |
-
Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]]
|
1112 |
-
```
|
1113 |
-
|
1114 |
-
Asks a question to start a conversation.
|
1115 |
-
|
1116 |
-
### Parameters
|
1117 |
-
|
1118 |
-
#### question *Required*
|
1119 |
-
|
1120 |
-
The question to start an AI chat. Defaults to `None`.
|
1121 |
-
|
1122 |
-
#### stream
|
1123 |
-
|
1124 |
-
Indicates whether to output responses in a streaming way:
|
1125 |
-
|
1126 |
-
- `True`: Enable streaming.
|
1127 |
-
- `False`: (Default) Disable streaming.
|
1128 |
-
|
1129 |
-
### Returns
|
1130 |
-
|
1131 |
-
- A `Message` object containing the response to the question if `stream` is set to `False`
|
1132 |
-
- An iterator containing multiple `message` objects (`iter[Message]`) if `stream` is set to `True`
|
1133 |
-
|
1134 |
-
The following shows the attributes of a `Message` object:
|
1135 |
-
|
1136 |
-
#### id: `str`
|
1137 |
-
|
1138 |
-
The auto-generated message ID.
|
1139 |
-
|
1140 |
-
#### content: `str`
|
1141 |
-
|
1142 |
-
The content of the message. Defaults to `"Hi! I am your assistant, can I help you?"`.
|
1143 |
-
|
1144 |
-
#### reference: `list[Chunk]`
|
1145 |
-
|
1146 |
-
A list of `Chunk` objects representing references to the message, each containing the following attributes:
|
1147 |
-
|
1148 |
-
- `id` `str`
|
1149 |
-
The chunk ID.
|
1150 |
-
- `content` `str`
|
1151 |
-
The content of the chunk.
|
1152 |
-
- `image_id` `str`
|
1153 |
-
The ID of the snapshot of the chunk.
|
1154 |
-
- `document_id` `str`
|
1155 |
-
The ID of the referenced document.
|
1156 |
-
- `document_name` `str`
|
1157 |
-
The name of the referenced document.
|
1158 |
-
- `position` `list[str]`
|
1159 |
-
The location information of the chunk within the referenced document.
|
1160 |
-
- `knowledgebase_id` `str`
|
1161 |
-
The ID of the dataset to which the referenced document belongs.
|
1162 |
-
- `similarity` `float`
|
1163 |
-
A composite similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity.
|
1164 |
-
- `vector_similarity` `float`
|
1165 |
-
A vector similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity between vector embeddings.
|
1166 |
-
- `term_similarity` `float`
|
1167 |
-
A keyword similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity between keywords.
|
1168 |
-
|
1169 |
-
|
1170 |
-
### Examples
|
1171 |
-
|
1172 |
-
```python
|
1173 |
-
from ragflow import RAGFlow
|
1174 |
-
|
1175 |
-
rag = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
1176 |
-
assistant = rag.list_chats(name="Miss R")
|
1177 |
-
assistant = assistant[0]
|
1178 |
-
session = assistant.create_session()
|
1179 |
-
|
1180 |
-
print("\n==================== Miss R =====================\n")
|
1181 |
-
print(assistant.get_prologue())
|
1182 |
-
|
1183 |
-
while True:
|
1184 |
-
question = input("\n==================== User =====================\n> ")
|
1185 |
-
print("\n==================== Miss R =====================\n")
|
1186 |
-
|
1187 |
-
cont = ""
|
1188 |
-
for ans in session.ask(question, stream=True):
|
1189 |
-
print(answer.content[len(cont):], end='', flush=True)
|
1190 |
-
cont = answer.content
|
1191 |
-
```
|
1192 |
-
|
1193 |
-
---
|
1194 |
-
|
1195 |
## List sessions
|
1196 |
|
1197 |
```python
|
@@ -1209,32 +1153,32 @@ Lists sessions associated with the current chat assistant.
|
|
1209 |
|
1210 |
### Parameters
|
1211 |
|
1212 |
-
#### page
|
1213 |
|
1214 |
Specifies the page on which the sessions will be displayed. Defaults to `1`.
|
1215 |
|
1216 |
-
#### page_size
|
1217 |
|
1218 |
The number of sessions on each page. Defaults to `1024`.
|
1219 |
|
1220 |
-
#### orderby
|
1221 |
|
1222 |
The field by which sessions should be sorted. Available options:
|
1223 |
|
1224 |
- `"create_time"` (default)
|
1225 |
- `"update_time"`
|
1226 |
|
1227 |
-
#### desc
|
1228 |
|
1229 |
Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `True`.
|
1230 |
|
1231 |
-
#### id
|
1232 |
|
1233 |
The ID of the chat session to retrieve. Defaults to `None`.
|
1234 |
|
1235 |
-
#### name
|
1236 |
|
1237 |
-
The name of the chat to retrieve. Defaults to `None`.
|
1238 |
|
1239 |
### Returns
|
1240 |
|
@@ -1279,8 +1223,95 @@ The IDs of the sessions to delete. Defaults to `None`. If not specified, all ses
|
|
1279 |
```python
|
1280 |
from ragflow import RAGFlow
|
1281 |
|
1282 |
-
|
1283 |
-
assistant =
|
1284 |
assistant = assistant[0]
|
1285 |
assistant.delete_sessions(ids=["id_1","id_2"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1286 |
```
|
|
|
380 |
|
381 |
#### keywords: `str`
|
382 |
|
383 |
+
The keywords used to match document titles. Defaults to `None`.
|
384 |
|
385 |
#### offset: `int`
|
386 |
|
|
|
419 |
- `created_by`: `str` The creator of the document. Defaults to `""`.
|
420 |
- `size`: `int` The document size in bytes. Defaults to `0`.
|
421 |
- `token_count`: `int` The number of tokens in the document. Defaults to `0`.
|
422 |
+
- `chunk_count`: `int` The number of chunks in the document. Defaults to `0`.
|
423 |
- `progress`: `float` The current processing progress as a percentage. Defaults to `0.0`.
|
424 |
- `progress_msg`: `str` A message indicating the current progress status. Defaults to `""`.
|
425 |
- `process_begin_at`: `datetime` The start time of document processing. Defaults to `None`.
|
|
|
432 |
```python
|
433 |
from ragflow import RAGFlow
|
434 |
|
435 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
436 |
+
dataset = rag_object.create_dataset(name="kb_1")
|
437 |
|
438 |
filename1 = "~/ragflow.txt"
|
439 |
blob = open(filename1 , "rb").read()
|
|
|
482 |
DataSet.async_parse_documents(document_ids:list[str]) -> None
|
483 |
```
|
484 |
|
485 |
+
Parses documents in the current dataset.
|
486 |
+
|
487 |
### Parameters
|
488 |
|
489 |
#### document_ids: `list[str]`, *Required*
|
|
|
492 |
|
493 |
### Returns
|
494 |
|
495 |
+
- Success: No value is returned.????????????????????
|
496 |
- Failure: `Exception`
|
497 |
|
498 |
### Examples
|
|
|
522 |
DataSet.async_cancel_parse_documents(document_ids:list[str])-> None
|
523 |
```
|
524 |
|
525 |
+
Stops parsing specified documents.
|
526 |
+
|
527 |
### Parameters
|
528 |
|
529 |
#### document_ids: `list[str]`, *Required*
|
|
|
558 |
|
559 |
---
|
560 |
|
561 |
+
## Add chunk
|
562 |
|
563 |
```python
|
564 |
+
Document.add_chunk(content:str) -> Chunk ?????????????????????
|
565 |
```
|
566 |
|
567 |
+
Adds a chunk to the current document.
|
568 |
|
569 |
### Parameters
|
570 |
|
571 |
+
#### content: `str`, *Required*
|
|
|
|
|
|
|
|
|
|
|
|
|
572 |
|
573 |
+
The text content of the chunk.
|
574 |
|
575 |
+
#### important_keywords: `list[str]` ??????????????????????
|
576 |
|
577 |
+
The key terms or phrases to tag with the chunk.
|
|
|
|
|
578 |
|
579 |
### Returns
|
580 |
|
581 |
+
- Success: A `Chunk` object.
|
582 |
- Failure: `Exception`.
|
583 |
|
584 |
+
A `Chunk` object contains the following attributes:
|
585 |
+
|
586 |
+
- `id`: `str`
|
587 |
+
- `content`: `str` Content of the chunk.
|
588 |
+
- `important_keywords`: `list[str]` A list of key terms or phrases to tag with the chunk.
|
589 |
+
- `create_time`: `str` The time when the chunk was created (added to the document).
|
590 |
+
- `create_timestamp`: `float` The timestamp representing the creation time of the chunk, expressed in seconds since January 1, 1970.
|
591 |
+
- `knowledgebase_id`: `str` The ID of the associated dataset.
|
592 |
+
- `document_name`: `str` The name of the associated document.
|
593 |
+
- `document_id`: `str` The ID of the associated document.
|
594 |
+
- `available`: `int`???? The chunk's availability status in the dataset. Value options:
|
595 |
+
- `0`: Unavailable
|
596 |
+
- `1`: Available
|
597 |
+
|
598 |
+
|
599 |
### Examples
|
600 |
|
601 |
```python
|
602 |
from ragflow import RAGFlow
|
603 |
|
604 |
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
605 |
+
dataset = rag_object.list_datasets(id="123")
|
606 |
+
dtaset = dataset[0]
|
607 |
+
doc = dataset.list_documents(id="wdfxb5t547d")
|
608 |
+
doc = doc[0]
|
609 |
+
chunk = doc.add_chunk(content="xxxxxxx")
|
610 |
```
|
611 |
|
612 |
+
---
|
613 |
+
|
614 |
+
## List chunks
|
615 |
|
616 |
```python
|
617 |
+
Document.list_chunks(keywords: str = None, offset: int = 0, limit: int = -1, id : str = None) -> list[Chunk]
|
618 |
```
|
619 |
|
620 |
+
Retrieves a list of chunks from the current document.
|
621 |
+
|
622 |
### Parameters
|
623 |
|
624 |
+
#### keywords: `str`
|
625 |
+
|
626 |
+
The keywords used to match chunk content. Defaults to `None`
|
627 |
|
628 |
+
#### offset: `int`
|
629 |
+
|
630 |
+
The starting index for the chunks to retrieve. Defaults to `1`??????
|
631 |
+
|
632 |
+
#### limit
|
633 |
|
634 |
+
The maximum number of chunks to retrieve. Default: `30`?????????
|
635 |
|
636 |
+
#### id
|
637 |
+
|
638 |
+
The ID of the chunk to retrieve. Default: `None`
|
639 |
|
640 |
### Returns
|
641 |
|
642 |
+
- Success: A list of `Chunk` objects.
|
643 |
+
- Failure: `Exception`.
|
644 |
|
645 |
### Examples
|
646 |
|
647 |
```python
|
648 |
from ragflow import RAGFlow
|
649 |
|
650 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
651 |
+
dataset = rag_object.list_datasets("123")
|
652 |
+
dataset = dataset[0]
|
653 |
+
dataset.async_parse_documents(["wdfxb5t547d"])
|
654 |
+
for chunk in doc.list_chunks(keywords="rag", offset=0, limit=12):
|
655 |
+
print(chunk)
|
656 |
```
|
657 |
|
658 |
---
|
659 |
|
660 |
+
## Delete chunks
|
661 |
|
662 |
```python
|
663 |
Document.delete_chunks(chunk_ids: list[str])
|
|
|
681 |
```python
|
682 |
from ragflow import RAGFlow
|
683 |
|
684 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
685 |
+
dataset = rag_object.list_datasets(id="123")
|
686 |
+
dataset = dataset[0]
|
687 |
+
doc = dataset.list_documents(id="wdfxb5t547d")
|
688 |
doc = doc[0]
|
689 |
chunk = doc.add_chunk(content="xxxxxxx")
|
690 |
doc.delete_chunks(["id_1","id_2"])
|
|
|
707 |
A dictionary representing the attributes to update, with the following keys:
|
708 |
|
709 |
- `"content"`: `str` Content of the chunk.
|
710 |
+
- `"important_keywords"`: `list[str]` A list of key terms or phrases to tag with the chunk.
|
711 |
- `"available"`: `int` The chunk's availability status in the dataset. Value options:
|
712 |
- `0`: Unavailable
|
713 |
- `1`: Available
|
|
|
739 |
RAGFlow.retrieve(question:str="", datasets:list[str]=None, document=list[str]=None, offset:int=1, limit:int=30, similarity_threshold:float=0.2, vector_similarity_weight:float=0.3, top_k:int=1024,rerank_id:str=None,keyword:bool=False,higlight:bool=False) -> list[Chunk]
|
740 |
```
|
741 |
|
742 |
+
???????
|
743 |
+
|
744 |
### Parameters
|
745 |
|
746 |
#### question: `str` *Required*
|
747 |
|
748 |
The user query or query keywords. Defaults to `""`.
|
749 |
|
750 |
+
#### datasets: `list[str]`, *Required*?????
|
751 |
|
752 |
The datasets to search from.
|
753 |
|
|
|
761 |
|
762 |
#### limit: `int`
|
763 |
|
764 |
+
The maximum number of chunks to retrieve. Defaults to `6`.???????????????
|
765 |
|
766 |
#### Similarity_threshold: `float`
|
767 |
|
|
|
775 |
|
776 |
The number of chunks engaged in vector cosine computaton. Defaults to `1024`.
|
777 |
|
778 |
+
#### rerank_id: `str`
|
779 |
|
780 |
+
The ID of the rerank model. Defaults to `None`.
|
781 |
|
782 |
+
#### keyword: `bool`
|
783 |
|
784 |
Indicates whether keyword-based matching is enabled:
|
785 |
|
786 |
- `True`: Enabled.
|
787 |
+
- `False`: Disabled (default).
|
788 |
|
789 |
+
#### highlight: `bool`
|
790 |
|
791 |
Specifying whether to enable highlighting of matched terms in the results (True) or not (False).
|
792 |
|
|
|
801 |
from ragflow import RAGFlow
|
802 |
|
803 |
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
804 |
+
dataset = rag_object.list_datasets(name="ragflow")
|
805 |
+
dataset = dataset[0]
|
806 |
name = 'ragflow_test.txt'
|
807 |
path = './test_data/ragflow_test.txt'
|
808 |
+
rag_object.create_document(dataset, name=name, blob=open(path, "rb").read())
|
809 |
+
doc = dataset.list_documents(name=name)
|
810 |
doc = doc[0]
|
811 |
+
dataset.async_parse_documents([doc.id])
|
812 |
for c in rag_object.retrieve(question="What's ragflow?",
|
813 |
+
datasets=[dataset.id], documents=[doc.id],
|
814 |
offset=1, limit=30, similarity_threshold=0.2,
|
815 |
vector_similarity_weight=0.3,
|
816 |
top_k=1024
|
|
|
844 |
|
845 |
The following shows the attributes of a `Chat` object:
|
846 |
|
847 |
+
#### name: `str`, *Required*????????
|
848 |
|
849 |
The name of the chat assistant. Defaults to `"assistant"`.
|
850 |
|
851 |
+
#### avatar: `str`
|
852 |
|
853 |
Base64 encoding of the avatar. Defaults to `""`.
|
854 |
|
|
|
856 |
|
857 |
The IDs of the associated datasets. Defaults to `[""]`.
|
858 |
|
859 |
+
#### llm: `Chat.LLM`
|
860 |
|
861 |
The llm of the created chat. Defaults to `None`. When the value is `None`, a dictionary with the following values will be generated as the default.
|
862 |
|
|
|
875 |
- `max_token`, `int`
|
876 |
This sets the maximum length of the model’s output, measured in the number of tokens (words or pieces of words). Defaults to `512`.
|
877 |
|
878 |
+
#### prompt: `Chat.Prompt`
|
879 |
|
880 |
Instructions for the LLM to follow. A `Prompt` object contains the following attributes:
|
881 |
|
|
|
902 |
```python
|
903 |
from ragflow import RAGFlow
|
904 |
|
905 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
906 |
+
datasets = rag_object.list_datasets(name="kb_1")
|
907 |
+
dataset_ids = []
|
908 |
+
for dataset in datasets:
|
909 |
+
dataset_ids.append(dataset.id)
|
910 |
+
assistant = rag_object.create_chat("Miss R", knowledgebases=dataset_ids)
|
911 |
```
|
912 |
|
913 |
---
|
914 |
|
915 |
+
## Update chat assistant
|
916 |
|
917 |
```python
|
918 |
Chat.update(update_message: dict)
|
|
|
960 |
```python
|
961 |
from ragflow import RAGFlow
|
962 |
|
963 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
964 |
+
datasets = rag_object.list_datasets(name="kb_1")
|
965 |
+
assistant = rag_object.create_chat("Miss R", knowledgebases=datasets)
|
966 |
assistant.update({"name": "Stefan", "llm": {"temperature": 0.8}, "prompt": {"top_n": 8}})
|
967 |
```
|
968 |
|
969 |
---
|
970 |
|
971 |
+
## Delete chat assistants
|
972 |
|
973 |
```python
|
974 |
RAGFlow.delete_chats(ids: list[str] = None)
|
|
|
992 |
```python
|
993 |
from ragflow import RAGFlow
|
994 |
|
995 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
996 |
+
rag_object.delete_chats(ids=["id_1","id_2"])
|
997 |
```
|
998 |
|
999 |
---
|
1000 |
|
1001 |
+
## List chat assistants
|
1002 |
|
1003 |
```python
|
1004 |
RAGFlow.list_chats(
|
|
|
1015 |
|
1016 |
### Parameters
|
1017 |
|
1018 |
+
#### page: `int`
|
1019 |
|
1020 |
Specifies the page on which the chat assistants will be displayed. Defaults to `1`.
|
1021 |
|
1022 |
+
#### page_size: `int`
|
1023 |
|
1024 |
The number of chat assistants on each page. Defaults to `1024`.
|
1025 |
|
1026 |
+
#### orderby: `str`
|
1027 |
|
1028 |
+
The attribute by which the results are sorted. Available options:
|
1029 |
|
1030 |
+
- `"create_time"` (default)
|
1031 |
+
- `"update_time"`
|
1032 |
+
|
1033 |
+
#### desc: `bool`
|
1034 |
|
1035 |
Indicates whether the retrieved chat assistants should be sorted in descending order. Defaults to `True`.
|
1036 |
|
1037 |
+
#### id: `str`
|
1038 |
|
1039 |
+
The ID of the chat assistant to retrieve. Defaults to `None`.
|
1040 |
|
1041 |
+
#### name: `str`
|
1042 |
|
1043 |
+
The name of the chat assistant to retrieve. Defaults to `None`.
|
1044 |
|
1045 |
### Returns
|
1046 |
|
|
|
1060 |
---
|
1061 |
|
1062 |
:::tip API GROUPING
|
1063 |
+
Chat Session APIs
|
1064 |
:::
|
1065 |
|
1066 |
---
|
|
|
1075 |
|
1076 |
### Parameters
|
1077 |
|
1078 |
+
#### name: `str`
|
1079 |
|
1080 |
The name of the chat session to create.
|
1081 |
|
|
|
1093 |
```python
|
1094 |
from ragflow import RAGFlow
|
1095 |
|
1096 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
1097 |
+
assistant = rag_object.list_chats(name="Miss R")
|
1098 |
assistant = assistant[0]
|
1099 |
session = assistant.create_session()
|
1100 |
```
|
1101 |
|
1102 |
+
---
|
1103 |
+
|
1104 |
## Update session
|
1105 |
|
1106 |
```python
|
|
|
1127 |
```python
|
1128 |
from ragflow import RAGFlow
|
1129 |
|
1130 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
1131 |
+
assistant = rag_object.list_chats(name="Miss R")
|
1132 |
assistant = assistant[0]
|
1133 |
session = assistant.create_session("session_name")
|
1134 |
session.update({"name": "updated_name"})
|
|
|
1136 |
|
1137 |
---
|
1138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1139 |
## List sessions
|
1140 |
|
1141 |
```python
|
|
|
1153 |
|
1154 |
### Parameters
|
1155 |
|
1156 |
+
#### page: `int`
|
1157 |
|
1158 |
Specifies the page on which the sessions will be displayed. Defaults to `1`.
|
1159 |
|
1160 |
+
#### page_size: `int`
|
1161 |
|
1162 |
The number of sessions on each page. Defaults to `1024`.
|
1163 |
|
1164 |
+
#### orderby: `str`
|
1165 |
|
1166 |
The field by which sessions should be sorted. Available options:
|
1167 |
|
1168 |
- `"create_time"` (default)
|
1169 |
- `"update_time"`
|
1170 |
|
1171 |
+
#### desc: `bool`
|
1172 |
|
1173 |
Indicates whether the retrieved sessions should be sorted in descending order. Defaults to `True`.
|
1174 |
|
1175 |
+
#### id: `str`
|
1176 |
|
1177 |
The ID of the chat session to retrieve. Defaults to `None`.
|
1178 |
|
1179 |
+
#### name: `str`
|
1180 |
|
1181 |
+
The name of the chat session to retrieve. Defaults to `None`.
|
1182 |
|
1183 |
### Returns
|
1184 |
|
|
|
1223 |
```python
|
1224 |
from ragflow import RAGFlow
|
1225 |
|
1226 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
1227 |
+
assistant = rag_object.list_chats(name="Miss R")
|
1228 |
assistant = assistant[0]
|
1229 |
assistant.delete_sessions(ids=["id_1","id_2"])
|
1230 |
+
```
|
1231 |
+
|
1232 |
+
---
|
1233 |
+
|
1234 |
+
## Chat
|
1235 |
+
|
1236 |
+
```python
|
1237 |
+
Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]]
|
1238 |
+
```
|
1239 |
+
|
1240 |
+
Asks a question to start a conversation.
|
1241 |
+
|
1242 |
+
### Parameters
|
1243 |
+
|
1244 |
+
#### question: `str` *Required*
|
1245 |
+
|
1246 |
+
The question to start an AI chat.
|
1247 |
+
|
1248 |
+
#### stream: `str`
|
1249 |
+
|
1250 |
+
Indicates whether to output responses in a streaming way:
|
1251 |
+
|
1252 |
+
- `True`: Enable streaming.
|
1253 |
+
- `False`: (Default) Disable streaming.
|
1254 |
+
|
1255 |
+
### Returns
|
1256 |
+
|
1257 |
+
- A `Message` object containing the response to the question if `stream` is set to `False`
|
1258 |
+
- An iterator containing multiple `message` objects (`iter[Message]`) if `stream` is set to `True`
|
1259 |
+
|
1260 |
+
The following shows the attributes of a `Message` object:
|
1261 |
+
|
1262 |
+
#### id: `str`
|
1263 |
+
|
1264 |
+
The auto-generated message ID.
|
1265 |
+
|
1266 |
+
#### content: `str`
|
1267 |
+
|
1268 |
+
The content of the message. Defaults to `"Hi! I am your assistant, can I help you?"`.
|
1269 |
+
|
1270 |
+
#### reference: `list[Chunk]`
|
1271 |
+
|
1272 |
+
A list of `Chunk` objects representing references to the message, each containing the following attributes:
|
1273 |
+
|
1274 |
+
- `id` `str`
|
1275 |
+
The chunk ID.
|
1276 |
+
- `content` `str`
|
1277 |
+
The content of the chunk.
|
1278 |
+
- `image_id` `str`
|
1279 |
+
The ID of the snapshot of the chunk.
|
1280 |
+
- `document_id` `str`
|
1281 |
+
The ID of the referenced document.
|
1282 |
+
- `document_name` `str`
|
1283 |
+
The name of the referenced document.
|
1284 |
+
- `position` `list[str]`
|
1285 |
+
The location information of the chunk within the referenced document.
|
1286 |
+
- `knowledgebase_id` `str`
|
1287 |
+
The ID of the dataset to which the referenced document belongs.
|
1288 |
+
- `similarity` `float`
|
1289 |
+
A composite similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity.
|
1290 |
+
- `vector_similarity` `float`
|
1291 |
+
A vector similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity between vector embeddings.
|
1292 |
+
- `term_similarity` `float`
|
1293 |
+
A keyword similarity score of the chunk ranging from `0` to `1`, with a higher value indicating greater similarity between keywords.
|
1294 |
+
|
1295 |
+
|
1296 |
+
### Examples
|
1297 |
+
|
1298 |
+
```python
|
1299 |
+
from ragflow import RAGFlow
|
1300 |
+
|
1301 |
+
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
1302 |
+
assistant = rag_object.list_chats(name="Miss R")
|
1303 |
+
assistant = assistant[0]
|
1304 |
+
session = assistant.create_session()
|
1305 |
+
|
1306 |
+
print("\n==================== Miss R =====================\n")
|
1307 |
+
print(assistant.get_prologue())
|
1308 |
+
|
1309 |
+
while True:
|
1310 |
+
question = input("\n==================== User =====================\n> ")
|
1311 |
+
print("\n==================== Miss R =====================\n")
|
1312 |
+
|
1313 |
+
cont = ""
|
1314 |
+
for ans in session.ask(question, stream=True):
|
1315 |
+
print(answer.content[len(cont):], end='', flush=True)
|
1316 |
+
cont = answer.content
|
1317 |
```
|