去除广告
This commit is contained in:
@@ -14,6 +14,7 @@ from utils.decorator.plugin_decorators import plugin_stats_decorator
|
||||
from utils.robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||
from utils.decorator.points_decorator import plugin_points_cost
|
||||
from utils.media_downloader import MediaDownloader
|
||||
from utils.string_utils import remove_trailing_content
|
||||
|
||||
|
||||
class DifyPlugin(MessagePluginInterface):
|
||||
@@ -126,7 +127,8 @@ class DifyPlugin(MessagePluginInterface):
|
||||
if roomid and gbm.get_group_permission(roomid, Feature.AI_CAPABILITY) == PermissionStatus.DISABLED:
|
||||
return False, "没有权限"
|
||||
|
||||
self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", (roomid if roomid else sender), sender if roomid else "")
|
||||
self.message_util.send_text_msg("⏳AI 正在加油,请稍候… 😊", (roomid if roomid else sender),
|
||||
sender if roomid else "")
|
||||
# 获取查询内容
|
||||
query = parts[1].strip()
|
||||
|
||||
@@ -139,7 +141,8 @@ class DifyPlugin(MessagePluginInterface):
|
||||
try:
|
||||
# 调用Dify API获取回复
|
||||
response = self._chat_with_dify(session_id, user_id, query)
|
||||
|
||||
# 去除广告内容
|
||||
response = remove_trailing_content(response)
|
||||
# 发送回复
|
||||
if response:
|
||||
# 判断是否为本地文件路径
|
||||
@@ -159,6 +162,7 @@ class DifyPlugin(MessagePluginInterface):
|
||||
wcf.send_text(f"❌请求出错:{str(e)}", (roomid if roomid else sender), sender if roomid else "")
|
||||
return True, f"处理出错: {e}"
|
||||
|
||||
|
||||
def _chat_with_dify(self, session_id: str, user_id: str, query: str) -> Optional[str]:
|
||||
"""
|
||||
与Dify API交互获取回复
|
||||
|
||||
@@ -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
|
||||
@@ -126,7 +127,8 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
||||
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:
|
||||
# 生成总结
|
||||
@@ -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", {})
|
||||
|
||||
15
utils/string_utils.py
Normal file
15
utils/string_utils.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def remove_trailing_content(text, delimiter='---'):
|
||||
"""
|
||||
剔除文本中最后一个指定分隔符及其后面的内容。
|
||||
|
||||
参数:
|
||||
text (str): 输入的文本
|
||||
delimiter (str): 要查找的分隔符,默认为 '---'
|
||||
|
||||
返回:
|
||||
str: 剔除分隔符及其后面内容后的文本
|
||||
"""
|
||||
index = text.rfind(delimiter)
|
||||
if index != -1:
|
||||
return text[:index].strip()
|
||||
return text
|
||||
Reference in New Issue
Block a user