Skip to content

Commit 1a608ac

Browse files
authored
Refa: Chats /chat API to RESTFul (#13871)
### What problem does this PR solve? Chats /chat API to RESTFul. ### Type of change - [x] Refactoring
1 parent 00b62dd commit 1a608ac

Some content is hidden

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

52 files changed

+2013
-3553
lines changed

admin/client/ragflow_client.py

Lines changed: 41 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}")
@@ -1622,17 +1572,27 @@ def _get_dataset_id(self, dataset_name: str):
16221572
def _list_chats(self, command):
16231573
iterations = command.get("iterations", 1)
16241574
if iterations > 1:
1625-
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
1626-
iterations=iterations)
1575+
response = self.http_client.request(
1576+
"GET",
1577+
"/chats",
1578+
use_api_base=True,
1579+
auth_kind="web",
1580+
iterations=iterations,
1581+
)
16271582
return response
16281583
else:
1629-
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
1630-
iterations=iterations)
1584+
response = self.http_client.request(
1585+
"GET",
1586+
"/chats",
1587+
use_api_base=True,
1588+
auth_kind="web",
1589+
iterations=iterations,
1590+
)
16311591
res_json = response.json()
16321592
if response.status_code == 200 and res_json["code"] == 0:
1633-
return res_json["data"]["dialogs"]
1593+
return res_json["data"]["chats"]
16341594
else:
1635-
print(f"Fail to list datasets, code: {res_json['code']}, message: {res_json['message']}")
1595+
print(f"Fail to list chats, code: {res_json['code']}, message: {res_json['message']}")
16361596
return None
16371597

16381598
def _get_default_models(self):

0 commit comments

Comments
 (0)