去除广告

This commit is contained in:
liuwei
2025-04-15 17:28:32 +08:00
parent 7be1811c1c
commit b382bd8d4a
3 changed files with 33 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ from typing import Dict, Any, Tuple, Optional, List
import requests
from utils.string_utils import remove_trailing_content
from utils.wechat.message_to_db import MessageStorage
from utils.compress_chat_data import compress_chat_data
from plugin_common.message_plugin_interface import MessagePluginInterface
@@ -75,7 +76,7 @@ class MessageSummaryPlugin(MessagePluginInterface):
return True
@plugin_stats_decorator(plugin_name="群聊总结")
@plugin_points_cost(10, "群聊总结消耗积分",Feature.SUMMARY_CAPABILITY)
@plugin_points_cost(10, "群聊总结消耗积分", Feature.SUMMARY_CAPABILITY)
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
"""处理消息"""
try:
@@ -111,7 +112,7 @@ class MessageSummaryPlugin(MessagePluginInterface):
group_name = self._sanitize_group_name(group_name)
if wcf:
wcf.send_text("⏳群消息总结中… 😊", group_id)
# 创建线程异步处理总结生成和发送
summary_thread = threading.Thread(
target=self._async_generate_and_send_summary,
@@ -119,19 +120,20 @@ class MessageSummaryPlugin(MessagePluginInterface):
)
summary_thread.daemon = True # 设置为守护线程,主程序退出时线程也会退出
summary_thread.start()
return True, "异步总结已启动"
except Exception as e:
self.LOG.error(f"处理消息总结命令失败: {e}")
return False, None
def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str, message: Dict[str, Any]):
def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str,
message: Dict[str, Any]):
"""异步生成并发送总结"""
try:
# 生成总结
summary, image_path = self._generate_summary(chat_content, group_name)
# 发送总结结果
wcf = message.get("wcf")
if wcf:
@@ -199,6 +201,8 @@ class MessageSummaryPlugin(MessagePluginInterface):
# 提取回答内容
answer = response_data.get("answer", "")
# 去除广告内容pollinations.ai 的广告
answer = remove_trailing_content(answer)
spath = ""
# 提取token使用情况
metadata = response_data.get("metadata", {})