Skip to content

Commit a2be389

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix364
2 parents 35564d8 + af40be6 commit a2be389

File tree

75 files changed

+3452
-3714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3452
-3714
lines changed

admin/client/parser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
| search_on_datasets
9898
| get_chunk
9999
| list_chunks
100+
| insert_dataset_from_file
101+
| insert_metadata_from_file
100102
| create_chat_session
101103
| drop_chat_session
102104
| list_chat_sessions
@@ -207,10 +209,12 @@
207209
CHUNK: "CHUNK"i
208210
CHUNKS: "CHUNKS"i
209211
GET: "GET"i
212+
INSERT: "INSERT"i
210213
PAGE: "PAGE"i
211214
SIZE: "SIZE"i
212215
KEYWORDS: "KEYWORDS"i
213216
AVAILABLE: "AVAILABLE"i
217+
FILE: "FILE"i
214218
215219
login_user: LOGIN USER quoted_string ";"
216220
list_services: LIST SERVICES ";"
@@ -349,6 +353,10 @@
349353
parse_dataset_sync: PARSE DATASET quoted_string SYNC ";"
350354
parse_dataset_async: PARSE DATASET quoted_string ASYNC ";"
351355
356+
// Internal CLI for GO
357+
insert_dataset_from_file: INSERT DATASET FROM FILE quoted_string ";"
358+
insert_metadata_from_file: INSERT METADATA FROM FILE quoted_string ";"
359+
352360
identifier_list: identifier ("," identifier)*
353361
354362
identifier: WORD
@@ -750,6 +758,14 @@ def get_chunk(self, items):
750758
chunk_id = items[2].children[0].strip("'\"")
751759
return {"type": "get_chunk", "chunk_id": chunk_id}
752760

761+
def insert_dataset_from_file(self, items):
762+
file_path = items[4].children[0].strip("'\"")
763+
return {"type": "insert_dataset_from_file", "file_path": file_path}
764+
765+
def insert_metadata_from_file(self, items):
766+
file_path = items[4].children[0].strip("'\"")
767+
return {"type": "insert_metadata_from_file", "file_path": file_path}
768+
753769
def list_chunks(self, items):
754770
doc_id = items[4].children[0].strip("'\"")
755771
result = {"type": "list_chunks", "doc_id": doc_id}

admin/client/ragflow_client.py

Lines changed: 87 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -977,76 +977,13 @@ def list_user_chats(self, command):
977977
def create_user_chat(self, command):
978978
if self.server_type != "user":
979979
print("This command is only allowed in USER mode")
980-
'''
981-
description
982-
:
983-
""
984-
icon
985-
:
986-
""
987-
language
988-
:
989-
"English"
990-
llm_id
991-
:
992-
"glm-4-flash@ZHIPU-AI"
993-
llm_setting
994-
:
995-
{}
996-
name
997-
:
998-
"xx"
999-
prompt_config
1000-
:
1001-
{empty_response: "", prologue: "Hi! I'm your assistant. What can I do for you?", quote: true,…}
1002-
empty_response
1003-
:
1004-
""
1005-
keyword
1006-
:
1007-
false
1008-
parameters
1009-
:
1010-
[{key: "knowledge", optional: false}]
1011-
prologue
1012-
:
1013-
"Hi! I'm your assistant. What can I do for you?"
1014-
quote
1015-
:
1016-
true
1017-
reasoning
1018-
:
1019-
false
1020-
refine_multiturn
1021-
:
1022-
false
1023-
system
1024-
:
1025-
"You are an intelligent assistant. Your primary function is to answer questions based strictly on the provided knowledge base.\n\n **Essential Rules:**\n - Your answer must be derived **solely** from this knowledge base: `{knowledge}`.\n - **When information is available**: Summarize the content to give a detailed answer.\n - **When information is unavailable**: Your response must contain this exact sentence: \"The answer you are looking for is not found in the knowledge base!\"\n - **Always consider** the entire conversation history."
1026-
toc_enhance
1027-
:
1028-
false
1029-
tts
1030-
:
1031-
false
1032-
use_kg
1033-
:
1034-
false
1035-
similarity_threshold
1036-
:
1037-
0.2
1038-
top_n
1039-
:
1040-
8
1041-
vector_similarity_weight
1042-
:
1043-
0.3
1044-
'''
1045980
chat_name = command["chat_name"]
981+
default_models = self._get_default_models() or {}
1046982
payload = {
983+
"name": chat_name,
1047984
"description": "",
1048985
"icon": "",
1049-
"language": "English",
986+
"dataset_ids": [],
1050987
"llm_setting": {},
1051988
"prompt_config": {
1052989
"empty_response": "",
@@ -1064,16 +1001,24 @@ def create_user_chat(self, command):
10641001
"optional": False
10651002
}
10661003
],
1067-
"toc_enhance": False
1004+
"toc_enhance": False,
10681005
},
10691006
"similarity_threshold": 0.2,
10701007
"top_n": 8,
1071-
"vector_similarity_weight": 0.3
1008+
"top_k": 1024,
1009+
"vector_similarity_weight": 0.3,
1010+
"rerank_id": default_models.get("rerank_id", ""),
10721011
}
1073-
1074-
payload.update({"name": chat_name})
1075-
response = self.http_client.request("POST", "/dialog/set", json_body=payload, use_api_base=False,
1076-
auth_kind="web")
1012+
if default_models.get("llm_id"):
1013+
payload["llm_id"] = default_models["llm_id"]
1014+
1015+
response = self.http_client.request(
1016+
"POST",
1017+
"/chats",
1018+
json_body=payload,
1019+
use_api_base=True,
1020+
auth_kind="web",
1021+
)
10771022
res_json = response.json()
10781023
if response.status_code == 200 and res_json["code"] == 0:
10791024
print(f"Success to create chat: {chat_name}")
@@ -1158,9 +1103,14 @@ def drop_user_chat(self, command):
11581103
for elem in res_json:
11591104
if elem["name"] == chat_name:
11601105
to_drop_chat_ids.append(elem["id"])
1161-
payload = {"dialog_ids": to_drop_chat_ids}
1162-
response = self.http_client.request("POST", "/dialog/rm", json_body=payload, use_api_base=False,
1163-
auth_kind="web")
1106+
payload = {"ids": to_drop_chat_ids}
1107+
response = self.http_client.request(
1108+
"DELETE",
1109+
"/chats",
1110+
json_body=payload,
1111+
use_api_base=True,
1112+
auth_kind="web",
1113+
)
11641114
res_json = response.json()
11651115
if response.status_code == 200 and res_json["code"] == 0:
11661116
print(f"Success to drop chat: {chat_name}")
@@ -1520,6 +1470,48 @@ def get_chunk(self, command_dict):
15201470
else:
15211471
print(f"Fail to get chunk, code: {res_json['code']}, message: {res_json['message']}")
15221472

1473+
# Internal
1474+
def insert_dataset_from_file(self, command_dict):
1475+
if self.server_type != "user":
1476+
print("This command is only allowed in USER mode")
1477+
return
1478+
1479+
file_path = command_dict["file_path"]
1480+
payload = {"file_path": file_path}
1481+
response = self.http_client.request("POST", "/kb/insert_from_file", json_body=payload,
1482+
use_api_base=False, auth_kind="web")
1483+
res_json = response.json()
1484+
if response.status_code == 200:
1485+
if res_json["code"] == 0:
1486+
print(f"Success to insert dataset from file: {file_path}")
1487+
if res_json.get("data"):
1488+
self._print_key_value(res_json["data"])
1489+
else:
1490+
print(f"Fail to insert dataset from file, code: {res_json['code']}, message: {res_json['message']}")
1491+
else:
1492+
print(f"Fail to insert dataset from file, code: {res_json['code']}, message: {res_json['message']}")
1493+
1494+
# Internal
1495+
def insert_metadata_from_file(self, command_dict):
1496+
if self.server_type != "user":
1497+
print("This command is only allowed in USER mode")
1498+
return
1499+
1500+
file_path = command_dict["file_path"]
1501+
payload = {"file_path": file_path}
1502+
response = self.http_client.request("POST", "/tenant/insert_metadata_from_file", json_body=payload,
1503+
use_api_base=False, auth_kind="web")
1504+
res_json = response.json()
1505+
if response.status_code == 200:
1506+
if res_json["code"] == 0:
1507+
print(f"Success to insert metadata from file: {file_path}")
1508+
if res_json.get("data"):
1509+
self._print_key_value(res_json["data"])
1510+
else:
1511+
print(f"Fail to insert metadata from file, code: {res_json['code']}, message: {res_json['message']}")
1512+
else:
1513+
print(f"Fail to insert metadata from file, code: {res_json['code']}, message: {res_json['message']}")
1514+
15231515
def list_chunks(self, command_dict):
15241516
if self.server_type != "user":
15251517
print("This command is only allowed in USER mode")
@@ -1622,17 +1614,27 @@ def _get_dataset_id(self, dataset_name: str):
16221614
def _list_chats(self, command):
16231615
iterations = command.get("iterations", 1)
16241616
if iterations > 1:
1625-
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
1626-
iterations=iterations)
1617+
response = self.http_client.request(
1618+
"GET",
1619+
"/chats",
1620+
use_api_base=True,
1621+
auth_kind="web",
1622+
iterations=iterations,
1623+
)
16271624
return response
16281625
else:
1629-
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
1630-
iterations=iterations)
1626+
response = self.http_client.request(
1627+
"GET",
1628+
"/chats",
1629+
use_api_base=True,
1630+
auth_kind="web",
1631+
iterations=iterations,
1632+
)
16311633
res_json = response.json()
16321634
if response.status_code == 200 and res_json["code"] == 0:
1633-
return res_json["data"]["dialogs"]
1635+
return res_json["data"]["chats"]
16341636
else:
1635-
print(f"Fail to list datasets, code: {res_json['code']}, message: {res_json['message']}")
1637+
print(f"Fail to list chats, code: {res_json['code']}, message: {res_json['message']}")
16361638
return None
16371639

16381640
def _get_default_models(self):
@@ -1903,6 +1905,10 @@ def run_command(client: RAGFlowClient, command_dict: dict):
19031905
return client.search_on_datasets(command_dict)
19041906
case "get_chunk":
19051907
return client.get_chunk(command_dict)
1908+
case "insert_dataset_from_file":
1909+
return client.insert_dataset_from_file(command_dict)
1910+
case "insert_metadata_from_file":
1911+
return client.insert_metadata_from_file(command_dict)
19061912
case "list_chunks":
19071913
return client.list_chunks(command_dict)
19081914
case "meta":

0 commit comments

Comments
 (0)