Fix create / drop chat session syntax (#13279)

### What problem does this PR solve?

This pull request refactors the chat session creation and deletion logic
in both the parser and client code to use unique session IDs instead of
session names. It also updates the corresponding command syntax and
payloads, ensuring more robust and unambiguous session management.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-02-28 14:18:21 +08:00
committed by GitHub
parent d9d4825079
commit 32ec950ca8
2 changed files with 14 additions and 15 deletions

View File

@ -284,7 +284,7 @@ list_user_agents: LIST AGENTS ";"
list_user_chats: LIST CHATS ";"
create_user_chat: CREATE CHAT quoted_string ";"
drop_user_chat: DROP CHAT quoted_string ";"
create_chat_session: CREATE CHAT quoted_string SESSION quoted_string ";"
create_chat_session: CREATE CHAT quoted_string SESSION ";"
drop_chat_session: DROP CHAT quoted_string SESSION quoted_string ";"
list_chat_sessions: LIST CHAT quoted_string SESSIONS ";"
chat_on_session: CHAT quoted_string ON quoted_string SESSION quoted_string ";"
@ -591,13 +591,12 @@ class RAGFlowCLITransformer(Transformer):
def create_chat_session(self, items):
chat_name = items[2].children[0].strip("'\"")
session_name = items[4].children[0].strip("'\"")
return {"type": "create_chat_session", "chat_name": chat_name, "session_name": session_name}
return {"type": "create_chat_session", "chat_name": chat_name}
def drop_chat_session(self, items):
chat_name = items[2].children[0].strip("'\"")
session_name = items[4].children[0].strip("'\"")
return {"type": "drop_chat_session", "chat_name": chat_name, "session_name": session_name}
session_id = items[4].children[0].strip("'\"")
return {"type": "drop_chat_session", "chat_name": chat_name, "session_id": session_id}
def list_chat_sessions(self, items):
chat_name = items[2].children[0].strip("'\"")

View File

@ -15,6 +15,7 @@
#
import json
import time
import uuid
from typing import Any, List, Optional
import multiprocessing as mp
from concurrent.futures import ProcessPoolExecutor, as_completed
@ -907,29 +908,28 @@ class RAGFlowClient:
if self.server_type != "user":
print("This command is only allowed in USER mode")
chat_name = command["chat_name"]
session_name = command["session_name"]
dialog_id = self._get_chat_id_by_name(chat_name)
if dialog_id is None:
return
conversation_id = str(uuid.uuid4()).replace("-", "")
payload = {
"conversation_id": "",
"conversation_id": conversation_id,
"is_new": True,
"name": session_name,
"dialog_id": dialog_id
}
response = self.http_client.request("POST", "/conversation/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 session '{session_name}' for chat: {chat_name}")
print(f"Success to create chat session for chat: {chat_name}")
else:
print(f"Fail to create chat session '{session_name}' for chat {chat_name}, code: {res_json['code']}, message: {res_json['message']}")
print(f"Fail to create chat session for chat {chat_name}, code: {res_json['code']}, message: {res_json['message']}")
def drop_chat_session(self, command):
if self.server_type != "user":
print("This command is only allowed in USER mode")
chat_name = command["chat_name"]
session_name = command["session_name"]
session_id = command["session_id"]
dialog_id = self._get_chat_id_by_name(chat_name)
if dialog_id is None:
return
@ -938,19 +938,19 @@ class RAGFlowClient:
return
to_drop_session_ids = []
for session in sessions:
if session["name"] == session_name:
if session["id"] == session_id:
to_drop_session_ids.append(session["id"])
if not to_drop_session_ids:
print(f"Chat session '{session_name}' not found in chat '{chat_name}'")
print(f"Chat session '{session_id}' not found in chat '{chat_name}'")
return
payload = {"conversation_ids": to_drop_session_ids}
response = self.http_client.request("POST", "/conversation/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 session '{session_name}' from chat: {chat_name}")
print(f"Success to drop chat session '{session_id}' from chat: {chat_name}")
else:
print(f"Fail to drop chat session '{session_name}' from chat {chat_name}, code: {res_json['code']}, message: {res_json['message']}")
print(f"Fail to drop chat session '{session_id}' from chat {chat_name}, code: {res_json['code']}, message: {res_json['message']}")
def list_chat_sessions(self, command):
if self.server_type != "user":