ASengine id

This commit is contained in:
CakeCN
2025-09-13 13:40:13 +08:00
parent 33fc4fdc53
commit b75f002cf7
2 changed files with 16 additions and 13 deletions

View File

@@ -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)

View File

@@ -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',