add some logger
This commit is contained in:
@@ -433,31 +433,20 @@ class HSAEngineClient(ASEngineClient):
|
||||
super().__init__(server_url, namespace, id)
|
||||
self.chatmanager = chatmanager
|
||||
def loadmarkdown(self, fmd, fmdp, fsp):
|
||||
# 保存app实例以便在回调中使用
|
||||
app = self.chatmanager.app
|
||||
|
||||
def log_info(message):
|
||||
"""安全的日志记录函数,确保在任何线程中都能使用"""
|
||||
try:
|
||||
with app.app_context():
|
||||
app.logger.info(message)
|
||||
except Exception as e:
|
||||
print(f"Log error: {e}")
|
||||
print(f"Message: {message}")
|
||||
|
||||
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)
|
||||
log_info(f"Load markdown time cost: {time.time() - now}")
|
||||
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)
|
||||
log_info(f"Wait markdown time cost: {time.time() - now}")
|
||||
print(f"Wait markdown time cost: {time.time() - now}")
|
||||
now = time.time()
|
||||
# 清理ACK事件
|
||||
if ack_id1 in self.ack_events:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ def on_connect_to_ase(client, entry, init_data, **kwargs):
|
||||
response.raise_for_status() # 检查请求是否成功
|
||||
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')
|
||||
|
||||
@@ -68,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", "")
|
||||
|
||||
Reference in New Issue
Block a user