Merge branch 'test'
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):
|
||||
@@ -72,6 +70,7 @@ class ASEngineClient:
|
||||
# ACK事件处理
|
||||
@self.sio.on('ack', namespace=self.namespace)
|
||||
def on_ack(data):
|
||||
print(f"Received ACK: {data}")
|
||||
ack_id = data.get('ack_id')
|
||||
if ack_id and ack_id in self.ack_events:
|
||||
print(f"Received ACK for message: {ack_id}")
|
||||
@@ -228,7 +227,7 @@ class ASEngineClient:
|
||||
self.sid = None
|
||||
print("Disconnected from server")
|
||||
|
||||
def send_text(self, route: str, text: str, id:str="", wait_for_ack: bool = False, timeout: int = 5) -> bool:
|
||||
def send_text(self, route: str, text: str, id:str="", wait_for_ack: bool = False, timeout: int = 5, return_event: bool = False) -> Any:
|
||||
"""
|
||||
发送文本消息
|
||||
:param route: 目标路由
|
||||
@@ -236,7 +235,8 @@ class ASEngineClient:
|
||||
:param id: 发送者ID
|
||||
:param wait_for_ack: 是否等待服务器ACK确认
|
||||
:param timeout: 等待ACK的超时时间(秒)
|
||||
:return: 是否发送成功(若wait_for_ack为True,则返回是否收到ACK)
|
||||
:param return_event: 是否返回事件对象和ack_id而不是等待ACK
|
||||
:return: 如果wait_for_ack为True且return_event为False,返回是否收到ACK;如果return_event为True,返回(event, ack_id);否则返回是否发送成功
|
||||
"""
|
||||
if not self.connected:
|
||||
print("Not connected to server")
|
||||
@@ -247,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
|
||||
|
||||
@@ -268,6 +261,10 @@ class ASEngineClient:
|
||||
event = Event()
|
||||
self.ack_events[ack_id] = event
|
||||
|
||||
# 如果需要返回事件对象,直接返回
|
||||
if return_event:
|
||||
return event, ack_id
|
||||
|
||||
# 等待ACK或超时
|
||||
received_ack = event.wait(timeout=timeout)
|
||||
|
||||
@@ -316,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
|
||||
@@ -384,7 +378,6 @@ class ASEngineClient:
|
||||
},
|
||||
namespace=self.namespace
|
||||
)
|
||||
print(f"Sent image file to route '{route}': {filename}")
|
||||
|
||||
# 如果不需要等待ACK,直接返回True
|
||||
if not wait_for_ack:
|
||||
@@ -428,6 +421,17 @@ class HSAEngineClient(ASEngineClient):
|
||||
super().__init__(server_url, namespace, id)
|
||||
self.chatmanager = chatmanager
|
||||
def loadmarkdown(self, fmd, fmdp, fsp):
|
||||
self.send_text('markdown-in', fmd, self.id, wait_for_ack=True)
|
||||
self.send_text('markdown-prompt-in', fmdp, self.id, wait_for_ack=True)
|
||||
self.send_text('score-prompt-in', fsp, self.id, wait_for_ack=True)
|
||||
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)
|
||||
timeout = 5 # 超时时间
|
||||
success1 = event1.wait(timeout=timeout)
|
||||
success2 = event2.wait(timeout=timeout)
|
||||
success3 = event3.wait(timeout=timeout)
|
||||
if ack_id1 in self.ack_events:
|
||||
del self.ack_events[ack_id1]
|
||||
if ack_id2 in self.ack_events:
|
||||
del self.ack_events[ack_id2]
|
||||
if ack_id3 in self.ack_events:
|
||||
del self.ack_events[ack_id3]
|
||||
return success1 and success2 and success3
|
||||
|
||||
@@ -129,8 +129,8 @@ class ChatManager:
|
||||
self.chapter_chain_now = chapter_index
|
||||
self.chapter_chain[chapter_index].Focus()
|
||||
|
||||
def load_next_chapter(self):
|
||||
print(f"now load next chapter markdown {self.chapter_chain_now}")
|
||||
def load_now_chapter(self):
|
||||
print(f"now load now chapter markdown {self.chapter_chain_now}")
|
||||
self.ase_client.loadmarkdown(self.chapter_chain[self.chapter_chain_now].chapter, self.chapter_chain[self.chapter_chain_now].chapter_prompt, self.chapter_chain[self.chapter_chain_now].score_prompt)
|
||||
self.load_code_in_markdown()
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@ def on_connect_to_ase(client, entry, init_data, **kwargs):
|
||||
}
|
||||
response = requests.post(clear_url, json=payload, headers=headers)
|
||||
response.raise_for_status() # 检查请求是否成功
|
||||
print(f"Clear user session successful: {response.json()}")
|
||||
except Exception as e:
|
||||
print(f"Error clearing user session: {e}")
|
||||
ase_client.chatmanager.load_next_chapter()
|
||||
ase_client.chatmanager.load_now_chapter()
|
||||
ase_client.send_text("chapter-start", "")
|
||||
namespace_entry.emit('message', "教案加载完毕", room=init_data['room'], namespace='/agent')
|
||||
|
||||
@@ -69,5 +68,5 @@ def receive_ase_chapter_score(client_entry, user_and_manager, data, init_data):
|
||||
chatmanager.scores[chatmanager.chapter_chain_now - 1] = data.get('data', None)
|
||||
else: chatmanager.scores.append(data.get('data', None))
|
||||
user.set_course_progress(chatmanager.chat_historys, chatmanager.scores, chatmanager.course_id, chatmanager.chapter_name, chatmanager.lesson_name)
|
||||
chatmanager.load_next_chapter()
|
||||
chatmanager.load_now_chapter()
|
||||
chatmanager.ase_client.send_text("chapter-start", "")
|
||||
|
||||
BIN
profile_stats
Normal file
BIN
profile_stats
Normal file
Binary file not shown.
BIN
profile_stats_extract
Normal file
BIN
profile_stats_extract
Normal file
Binary file not shown.
Reference in New Issue
Block a user