Fixed the Issue Where the Host Information was not Displayed
This commit is contained in:
28
app.py
28
app.py
@@ -377,35 +377,43 @@ def parse_forum_log_line(line):
|
||||
"""解析forum.log行内容,提取对话信息"""
|
||||
import re
|
||||
|
||||
# 匹配格式: [时间] [来源] 内容
|
||||
pattern = r'\[(\d{2}:\d{2}:\d{2})\]\s*\[([A-Z]+)\]\s*(.*)'
|
||||
# 匹配格式: [时间] [来源] 内容(来源允许大小写及空格)
|
||||
pattern = r'\[(\d{2}:\d{2}:\d{2})\]\s*\[([^\]]+)\]\s*(.*)'
|
||||
match = re.match(pattern, line)
|
||||
|
||||
if match:
|
||||
timestamp, source, content = match.groups()
|
||||
if not match:
|
||||
return None
|
||||
|
||||
timestamp, raw_source, content = match.groups()
|
||||
source = raw_source.strip().upper()
|
||||
|
||||
# 过滤掉系统消息和空内容
|
||||
if source == 'SYSTEM' or not content.strip():
|
||||
return None
|
||||
|
||||
# 只处理三个Engine的消息
|
||||
if source not in ['QUERY', 'INSIGHT', 'MEDIA']:
|
||||
# 支持三个Agent和主持人
|
||||
if source not in ['QUERY', 'INSIGHT', 'MEDIA', 'HOST']:
|
||||
return None
|
||||
|
||||
# 解码日志中的转义换行,保留多行格式
|
||||
cleaned_content = content.replace('\\n', '\n').replace('\\r', '').strip()
|
||||
|
||||
# 根据来源确定消息类型和发送者
|
||||
if source == 'HOST':
|
||||
message_type = 'host'
|
||||
sender = 'Forum Host'
|
||||
else:
|
||||
message_type = 'agent'
|
||||
sender = f'{source} Engine'
|
||||
sender = f'{source.title()} Engine'
|
||||
|
||||
return {
|
||||
'type': message_type,
|
||||
'sender': sender,
|
||||
'content': content.strip(),
|
||||
'content': cleaned_content,
|
||||
'timestamp': timestamp,
|
||||
'source': source
|
||||
}
|
||||
|
||||
return None
|
||||
|
||||
# Forum日志监听器
|
||||
# 存储每个客户端的历史日志发送位置
|
||||
forum_log_positions = {}
|
||||
|
||||
Reference in New Issue
Block a user