mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
[fix] (code review)
This commit is contained in:
@@ -148,8 +148,8 @@ class BaseAnalyzer(ABC):
|
||||
data_objects = self.create_data_objects(regex_data)
|
||||
return data_objects, token_usage
|
||||
else:
|
||||
# 最后的降级方案
|
||||
logger.warning(f"{self.get_data_type()}正则表达式提取失败,返回空列表")
|
||||
# 最后的降级方案 - 两种方法都失败
|
||||
logger.error(f"{self.get_data_type()}分析失败: JSON解析和正则表达式提取均未成功,返回空列表")
|
||||
return [], token_usage
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -39,7 +39,7 @@ class GoldenQuoteAnalyzer(BaseAnalyzer):
|
||||
构建金句分析提示词
|
||||
|
||||
Args:
|
||||
messages: 圣经的文本消息列表
|
||||
messages: 群聊的文本消息列表
|
||||
|
||||
Returns:
|
||||
提示词字符串
|
||||
|
||||
@@ -56,8 +56,8 @@ class TopicAnalyzer(BaseAnalyzer):
|
||||
text = content.get("data", {}).get("text", "").strip()
|
||||
if text and len(text) > 2 and not text.startswith("/"):
|
||||
# 清理消息内容
|
||||
text = text.replace('"', '"').replace('"', '"')
|
||||
text = text.replace(''', "'").replace(''', "'")
|
||||
text = text.replace('“', '"').replace('”', '"')
|
||||
text = text.replace('‘', "'").replace('’', "'")
|
||||
text = text.replace('\n', ' ').replace('\r', ' ')
|
||||
text = text.replace('\t', ' ')
|
||||
text = re.sub(r'[\x00-\x1f\x7f-\x9f]', '', text)
|
||||
|
||||
@@ -127,19 +127,4 @@ class LLMAnalyzer:
|
||||
修复后的JSON文本
|
||||
"""
|
||||
return fix_json(text)
|
||||
|
||||
def _extract_topics_with_regex(self, result_text: str, max_topics: int) -> List[SummaryTopic]:
|
||||
"""
|
||||
向后兼容的话题正则提取方法
|
||||
现在委托给json_utils模块处理
|
||||
|
||||
Args:
|
||||
result_text: 需要提取的文本
|
||||
max_topics: 最大话题数量
|
||||
|
||||
Returns:
|
||||
话题对象列表
|
||||
"""
|
||||
|
||||
topics_data = extract_topics_with_regex(result_text, max_topics)
|
||||
return [SummaryTopic(**topic) for topic in topics_data]
|
||||
|
||||
@@ -62,8 +62,14 @@ def fix_json(text: str) -> str:
|
||||
# 1. 修复缺失的逗号
|
||||
text = re.sub(r'}\s*{', '}, {', text)
|
||||
|
||||
# 2. 确保字段名有引号
|
||||
text = re.sub(r'([{,]\s*)([a-zA-Z_][a-zA-Z0-9_]*)\s*:', r'\1"\2":', text)
|
||||
# 2. 确保字段名有引号(仅在对象开始或逗号后,避免破坏字符串值)
|
||||
def quote_field_names(match):
|
||||
prefix = match.group(1)
|
||||
key = match.group(2)
|
||||
return f'{prefix}"{key}":'
|
||||
|
||||
# 只在 { 或 , 后面匹配字段名,避免在字符串值中误匹配
|
||||
text = re.sub(r'([{,]\s*)([a-zA-Z_][a-zA-Z0-9_]*)\s*:', quote_field_names, text)
|
||||
|
||||
# 3. 移除多余的逗号
|
||||
text = re.sub(r',\s*}', '}', text)
|
||||
|
||||
Reference in New Issue
Block a user