修复bug
This commit is contained in:
@@ -32,8 +32,6 @@ class ASEngineClient:
|
||||
|
||||
# ACK相关
|
||||
self.ack_events: Dict[str, Event] = {} # 存储ack_id和对应的Event对象
|
||||
|
||||
# 注册基础事件处理函数
|
||||
self._register_base_events()
|
||||
|
||||
def _register_base_events(self):
|
||||
@@ -249,20 +247,13 @@ class ASEngineClient:
|
||||
try:
|
||||
# 生成唯一ack_id
|
||||
ack_id = f"{id}_{datetime.now().strftime('%Y%m%d%H%M%S%f')}"
|
||||
|
||||
# 准备发送数据
|
||||
data = {
|
||||
'type': 'text',
|
||||
'data': text,
|
||||
'id': id,
|
||||
'ack_id': ack_id
|
||||
}
|
||||
|
||||
# 发送数据
|
||||
self.sio.emit(route, data, namespace=self.namespace)
|
||||
print(f"Sent text to route '{route}': {text[:20]}")
|
||||
|
||||
# 如果不需要等待ACK,直接返回True
|
||||
if not wait_for_ack:
|
||||
return True
|
||||
|
||||
@@ -322,9 +313,6 @@ class ASEngineClient:
|
||||
},
|
||||
namespace=self.namespace
|
||||
)
|
||||
|
||||
print(f"Sent voice file to route '{route}'")
|
||||
|
||||
# 如果不需要等待ACK,直接返回True
|
||||
if not wait_for_ack:
|
||||
return True
|
||||
@@ -390,7 +378,6 @@ class ASEngineClient:
|
||||
},
|
||||
namespace=self.namespace
|
||||
)
|
||||
print(f"Sent image file to route '{route}': {filename}")
|
||||
|
||||
# 如果不需要等待ACK,直接返回True
|
||||
if not wait_for_ack:
|
||||
@@ -434,22 +421,13 @@ class HSAEngineClient(ASEngineClient):
|
||||
super().__init__(server_url, namespace, id)
|
||||
self.chatmanager = chatmanager
|
||||
def loadmarkdown(self, fmd, fmdp, fsp):
|
||||
|
||||
now = time.time()
|
||||
# 并行发送三个消息,获取事件对象和ack_id
|
||||
event1, ack_id1 = self.send_text('markdown-in', fmd, self.id, wait_for_ack=True, return_event=True)
|
||||
event2, ack_id2 = self.send_text('markdown-prompt-in', fmdp, self.id, wait_for_ack=True, return_event=True)
|
||||
event3, ack_id3 = self.send_text('score-prompt-in', fsp, self.id, wait_for_ack=True, return_event=True)
|
||||
print(f"Load markdown time cost: {time.time() - now}")
|
||||
now = time.time()
|
||||
# 等待所有事件完成
|
||||
timeout = 5 # 超时时间
|
||||
success1 = event1.wait(timeout=timeout)
|
||||
success2 = event2.wait(timeout=timeout)
|
||||
success3 = event3.wait(timeout=timeout)
|
||||
print(f"Wait markdown time cost: {time.time() - now}")
|
||||
now = time.time()
|
||||
# 清理ACK事件
|
||||
if ack_id1 in self.ack_events:
|
||||
del self.ack_events[ack_id1]
|
||||
if ack_id2 in self.ack_events:
|
||||
|
||||
Reference in New Issue
Block a user