后端处理分组问题
This commit is contained in:
@@ -68,18 +68,57 @@ class ChatConsumer(AsyncWebsocketConsumer):
|
||||
|
||||
print(" - Sending message to server.", flush=True)
|
||||
websocket.send(text_data)
|
||||
# with open("websocket_messages.txt", "w", encoding="utf-8") as file:
|
||||
|
||||
import re
|
||||
current_agent = "User"
|
||||
while True:
|
||||
message = websocket.recv()
|
||||
message = message.decode("utf-8") if isinstance(message, bytes) else message
|
||||
|
||||
print(message, end="", flush=True)
|
||||
import re
|
||||
cleaned_string = re.sub(r'\x1b\[[0-?]*[ -/]*[@-~]', '', message)
|
||||
# file.write(cleaned_string)
|
||||
|
||||
# 通过 WebSocket 消费者发送消息
|
||||
asyncio.run(self.send(text_data=cleaned_string))
|
||||
cleaned_string = re.sub(r'\x1b\[[0-?]*[ -/]*[@-~]', '', message)
|
||||
# match = re.findall(r"(\w+)\s*\(to\s+(\w+)\)", cleaned_string)
|
||||
# print(match)
|
||||
# if len(match)==1:
|
||||
# current_agent = match[0][0] if current_agent != match[0][0] else current_agent
|
||||
# print(f"A: {match[0][0]}, B: {match[0][1]}")
|
||||
if "Next speaker" in cleaned_string:
|
||||
match = re.search(r"Next\s+speaker:\s+(\w+)", cleaned_string)
|
||||
current_agent = match.group(1)
|
||||
else:
|
||||
if cleaned_string == "\n--------------------------------------------------------------------------------\n":
|
||||
continue
|
||||
if cleaned_string == "\n********************************************************************************\n":
|
||||
continue
|
||||
if cleaned_string == "Starting a new chat....\n":
|
||||
continue
|
||||
if cleaned_string == "\n>>>>>>>> USING AUTO REPLY...\n":
|
||||
continue
|
||||
match = re.findall(r"(\w+)\s*\(to\s+(\w+)\)", cleaned_string)
|
||||
if len(match)==1:
|
||||
continue
|
||||
|
||||
if current_agent in ['Outer_Retrieval_Admin', 'Outer_Generate_Admin', 'Outer_Converter_Admin']:
|
||||
current_agent = current_agent.replace('Outer_', '')
|
||||
if current_agent in ['vector_code_executor']:
|
||||
continue
|
||||
|
||||
if current_agent == 'User':
|
||||
group_name = 'Planner'
|
||||
if current_agent in ['vector_searcher','vector_code_executor', 'graphrag_searcher', 'graphrag_code_executor', 'web_searcher', 'web_summary', 'Outer_Retrieval_Admin']:
|
||||
group_name = 'Retrieval'
|
||||
if current_agent in ['structure_scientist','property_scientist', 'application_scientist', 'synthesis_scientist', 'scheme_critic', 'Outer_Generate_Admin']:
|
||||
group_name = 'Generator'
|
||||
if current_agent in ['scheme_converter','converter_critic', 'mergrid_ploter', 'scheme_code_writer', 'scheme_code_critic', 'Outer_Converter_Admin']:
|
||||
group_name = 'Converter'
|
||||
if current_agent in ['experiment_executor','expriment_code_writer', 'data_collector', 'collector_code_writer', 'Outer_Executor_Admin']:
|
||||
group_name = 'Executor'
|
||||
if current_agent in ['analysis_executor','analysis_pl_uv', 'analysis_picturer', 'Experiment_Optimizer', 'optimizer_critic', 'Outer_Analysis_Admin']:
|
||||
group_name = 'Optimizer'
|
||||
|
||||
content = {"group_name": group_name, "agent_name": current_agent.replace("_", " ").title(), "content": cleaned_string}
|
||||
# 通过 WebSocket 消费者发送消息
|
||||
asyncio.run(self.send(text_data=json.dumps(content)))
|
||||
|
||||
# if "TERMINATE" in message:
|
||||
# print(" - Received TERMINATE message. Exiting.", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user