fix many bug
This commit is contained in:
@@ -25,6 +25,12 @@ class ASEngineClient:
|
||||
# 存储路由和对应的回调函数
|
||||
self.routes: Dict[str, Dict[str, Callable]] = {}
|
||||
|
||||
self._on_connect_callback = None
|
||||
self._on_connect_callback_entry=None
|
||||
self._on_connect_callback_initData=None
|
||||
|
||||
|
||||
|
||||
# 注册基础事件处理函数
|
||||
self._register_base_events()
|
||||
|
||||
@@ -36,7 +42,9 @@ class ASEngineClient:
|
||||
self.connected = True
|
||||
self.sid = self.sio.get_sid(namespace=self.namespace)
|
||||
print(f"Connected to server. SID: {self.sid}")
|
||||
|
||||
if self._on_connect_callback is not None:
|
||||
self._on_connect_callback(self._on_connect_callback_entry, self._on_connect_callback_initData)
|
||||
|
||||
# 断开连接事件
|
||||
@self.sio.on('disconnect', namespace=self.namespace)
|
||||
def on_disconnect():
|
||||
@@ -55,6 +63,14 @@ class ASEngineClient:
|
||||
def on_response(data):
|
||||
print(f"Received response: {data}")
|
||||
|
||||
def register_on_connect_entry(self, callback: Callable, entry: Any, init_data: Any)->bool:
|
||||
if not callable(callback):
|
||||
return False
|
||||
self._on_connect_callback = callback
|
||||
self._on_connect_callback_entry=entry
|
||||
self._on_connect_callback_initData=init_data
|
||||
|
||||
|
||||
def register_route_with_entry(self, route: str,
|
||||
callback: Optional[Callable] = None,
|
||||
entry: Any = None,
|
||||
@@ -138,7 +154,8 @@ class ASEngineClient:
|
||||
# 等待连接建立
|
||||
start_time = time.time()
|
||||
while not self.connected and (time.time() - start_time) < timeout:
|
||||
time.sleep(0.1)
|
||||
print(f"Connecting To {self.server_url}")
|
||||
time.sleep(0.2)
|
||||
return self.connected
|
||||
except Exception as e:
|
||||
print(f"Connection failed: {e}")
|
||||
@@ -264,8 +281,9 @@ class ASEngineClient:
|
||||
|
||||
|
||||
class HSAEngineClient(ASEngineClient):
|
||||
def __init__(self, server_url: str, namespace: str, id:str):
|
||||
def __init__(self, server_url: str, namespace: str, id:str, chatmanager):
|
||||
super().__init__(server_url, namespace, id)
|
||||
self.chatmanager = chatmanager
|
||||
def loadmarkdown(self, fmd, fmdp, fsp):
|
||||
self.send_text('markdown-in', fmd, self.id)
|
||||
self.send_text('markdown-prompt-in', fmdp, self.id)
|
||||
|
||||
Reference in New Issue
Block a user