From b75f002cf786c11a8c4bc6dbf5765f23c961779f Mon Sep 17 00:00:00 2001 From: CakeCN Date: Sat, 13 Sep 2025 13:40:13 +0800 Subject: [PATCH] ASengine id --- Html/apps/extension_ase/ase_client/client.py | 27 +++++++++++--------- Html/apps/sockets/namespaces.py | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Html/apps/extension_ase/ase_client/client.py b/Html/apps/extension_ase/ase_client/client.py index 6c2c93d..bcb7ab1 100644 --- a/Html/apps/extension_ase/ase_client/client.py +++ b/Html/apps/extension_ase/ase_client/client.py @@ -8,7 +8,7 @@ from typing import Dict, Callable, Any, Optional from functools import partial class ASEngineClient: - def __init__(self, server_url: str, namespace: str): + def __init__(self, server_url: str, namespace: str, id:str): """ 初始化客户端 :param server_url: 服务器URL,例如 'http://localhost:5000' @@ -16,6 +16,7 @@ class ASEngineClient: """ self.server_url = server_url self.namespace = namespace + self.id = id self.sid = None self.connected = False @@ -153,7 +154,7 @@ class ASEngineClient: self.sid = None print("Disconnected from server") - def send_text(self, route: str, text: str) -> bool: + def send_text(self, route: str, text: str, id:str) -> bool: """ 发送文本消息 :param route: 目标路由 @@ -166,14 +167,14 @@ class ASEngineClient: try: - self.sio.emit(route, {'type': 'text', 'data': text}, namespace=self.namespace) + self.sio.emit(route, {'type': 'text', 'data': text, 'id': id}, namespace=self.namespace) print(f"Sent text to route '{route}': {text}") return True except Exception as e: print(f"Failed to send text to route '{route}': {e}") return False - def send_voice(self, route: str, voice_data: bytes) -> bool: + def send_voice(self, route: str, voice_data: bytes, id:str) -> bool: """ 发送语音数据 :param route: 目标路由 @@ -195,7 +196,8 @@ class ASEngineClient: 'type': 'audio', 'data': voice_data, 'timestamp': int(time.time() * 1000), - 'sampleRate': 16000 + 'sampleRate': 16000, + 'id': id }, namespace=self.namespace ) @@ -207,7 +209,7 @@ class ASEngineClient: print(f"Failed to send voice to route '{route}': {e}") return False - def send_image(self, route: str, file_path: str) -> bool: + def send_image(self, route: str, file_path: str, id:str) -> bool: """ 发送图片文件 :param route: 目标路由 @@ -237,7 +239,8 @@ class ASEngineClient: route, { 'type': 'image', - 'data': image_data + 'data': image_data, + 'id': id }, namespace=self.namespace ) @@ -262,10 +265,10 @@ class ASEngineClient: class HSAEngineClient(ASEngineClient): - def __init__(self, server_url: str, namespace: str): - super().__init__(server_url, namespace) + def __init__(self, server_url: str, namespace: str, id:str): + super().__init__(server_url, namespace, id) def loadmarkdown(self, fmd, fmdp, fsp): - self.send_text('markdown-in', fmd) - self.send_text('markdown-prompt-in', fmdp) - self.send_text('score-prompt-in', fsp) + self.send_text('markdown-in', fmd, self.id) + self.send_text('markdown-prompt-in', fmdp, self.id) + self.send_text('score-prompt-in', fsp, self.id) diff --git a/Html/apps/sockets/namespaces.py b/Html/apps/sockets/namespaces.py index d31457d..515ef1a 100644 --- a/Html/apps/sockets/namespaces.py +++ b/Html/apps/sockets/namespaces.py @@ -56,7 +56,7 @@ class AgentNamespace(Namespace): print(f'User connected with session user_uuid: {user_uuid}') user_uuid2chatmanager = ex["user_uuid2chatmanager"] user_uuid2ase_client = ex["user_uuid2ase_client"] - user_uuid2ase_client[user_uuid] = HSAEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"]) + user_uuid2ase_client[user_uuid] = HSAEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"],id=user_id) user_uuid2ase_client[user_uuid].connect() user_uuid2ase_client[user_uuid].register_route_with_entry( route='dialog',