Revert "Refa: Chats /chat API to RESTFul (#13871)" (#13877)

### What problem does this PR solve?

This reverts commit 1a608ac411.

### Type of change

- [x] Other (please describe):
This commit is contained in:
Liu An
2026-04-01 11:05:29 +08:00
committed by GitHub
parent 1a608ac411
commit b1d28b5898
52 changed files with 3584 additions and 2044 deletions

View File

@@ -977,13 +977,76 @@ class RAGFlowClient:
def create_user_chat(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
'''
description
:
""
icon
:
""
language
:
"English"
llm_id
:
"glm-4-flash@ZHIPU-AI"
llm_setting
:
{}
name
:
"xx"
prompt_config
:
{empty_response: "", prologue: "Hi! I'm your assistant. What can I do for you?", quote: true,…}
empty_response
:
""
keyword
:
false
parameters
:
[{key: "knowledge", optional: false}]
prologue
:
"Hi! I'm your assistant. What can I do for you?"
quote
:
true
reasoning
:
false
refine_multiturn
:
false
system
:
"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."
toc_enhance
:
false
tts
:
false
use_kg
:
false
similarity_threshold
:
0.2
top_n
:
8
vector_similarity_weight
:
0.3
'''
chat_name = command["chat_name"]
default_models = self._get_default_models() or {}
payload = {
"name": chat_name,
"description": "",
"icon": "",
"dataset_ids": [],
"language": "English",
"llm_setting": {},
"prompt_config": {
"empty_response": "",
@@ -1001,24 +1064,16 @@ class RAGFlowClient:
"optional": False
}
],
"toc_enhance": False,
"toc_enhance": False
},
"similarity_threshold": 0.2,
"top_n": 8,
"top_k": 1024,
"vector_similarity_weight": 0.3,
"rerank_id": default_models.get("rerank_id", ""),
"vector_similarity_weight": 0.3
}
if default_models.get("llm_id"):
payload["llm_id"] = default_models["llm_id"]
response = self.http_client.request(
"POST",
"/chats",
json_body=payload,
use_api_base=True,
auth_kind="web",
)
payload.update({"name": chat_name})
response = self.http_client.request("POST", "/dialog/set", json_body=payload, use_api_base=False,
auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json["code"] == 0:
print(f"Success to create chat: {chat_name}")
@@ -1103,14 +1158,9 @@ class RAGFlowClient:
for elem in res_json:
if elem["name"] == chat_name:
to_drop_chat_ids.append(elem["id"])
payload = {"ids": to_drop_chat_ids}
response = self.http_client.request(
"DELETE",
"/chats",
json_body=payload,
use_api_base=True,
auth_kind="web",
)
payload = {"dialog_ids": to_drop_chat_ids}
response = self.http_client.request("POST", "/dialog/rm", json_body=payload, use_api_base=False,
auth_kind="web")
res_json = response.json()
if response.status_code == 200 and res_json["code"] == 0:
print(f"Success to drop chat: {chat_name}")
@@ -1572,27 +1622,17 @@ class RAGFlowClient:
def _list_chats(self, command):
iterations = command.get("iterations", 1)
if iterations > 1:
response = self.http_client.request(
"GET",
"/chats",
use_api_base=True,
auth_kind="web",
iterations=iterations,
)
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
iterations=iterations)
return response
else:
response = self.http_client.request(
"GET",
"/chats",
use_api_base=True,
auth_kind="web",
iterations=iterations,
)
response = self.http_client.request("POST", "/dialog/next", use_api_base=False, auth_kind="web",
iterations=iterations)
res_json = response.json()
if response.status_code == 200 and res_json["code"] == 0:
return res_json["data"]["chats"]
return res_json["data"]["dialogs"]
else:
print(f"Fail to list chats, code: {res_json['code']}, message: {res_json['message']}")
print(f"Fail to list datasets, code: {res_json['code']}, message: {res_json['message']}")
return None
def _get_default_models(self):