去除广告
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):
|
||||
@@ -104,7 +105,7 @@ class DifyPlugin(MessagePluginInterface):
|
||||
return command in self._commands
|
||||
|
||||
@plugin_stats_decorator(plugin_name="Dify聊天")
|
||||
@plugin_points_cost(2, "AI聊天消耗积分",Feature.AI_CAPABILITY)
|
||||
@plugin_points_cost(2, "AI聊天消耗积分", Feature.AI_CAPABILITY)
|
||||
def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
@@ -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交互获取回复
|
||||
@@ -235,7 +239,7 @@ class DifyPlugin(MessagePluginInterface):
|
||||
|
||||
try:
|
||||
# 使用普通请求(非流式)
|
||||
response = requests.post(url, headers=headers, json=data, proxies=proxies,timeout=20)
|
||||
response = requests.post(url, headers=headers, json=data, proxies=proxies, timeout=20)
|
||||
|
||||
if response.status_code != 200:
|
||||
self.LOG.error(f"Dify API请求失败: {response.status_code} {response.text}")
|
||||
|
||||
Reference in New Issue
Block a user