mirror of
https://github.com/Zippland/Bubbles.git
synced 2026-03-04 07:47:48 +08:00
AI 路由开关
This commit is contained in:
@@ -172,6 +172,34 @@ class AIRouter:
|
|||||||
self.logger.error(f"AI路由器:处理异常 - {e}")
|
self.logger.error(f"AI路由器:处理异常 - {e}")
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
|
def _check_permission(self, ctx: MessageContext) -> bool:
|
||||||
|
"""
|
||||||
|
检查是否有权限使用AI路由功能
|
||||||
|
|
||||||
|
:param ctx: 消息上下文
|
||||||
|
:return: 是否有权限
|
||||||
|
"""
|
||||||
|
# 检查是否启用AI路由
|
||||||
|
ai_router_config = getattr(ctx.config, 'AI_ROUTER', {})
|
||||||
|
if not ai_router_config.get('enable', True):
|
||||||
|
self.logger.info("AI路由功能已禁用")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# 私聊始终允许
|
||||||
|
if not ctx.is_group:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# 群聊需要检查白名单
|
||||||
|
allowed_groups = ai_router_config.get('allowed_groups', [])
|
||||||
|
current_group = ctx.get_receiver()
|
||||||
|
|
||||||
|
if current_group in allowed_groups:
|
||||||
|
self.logger.info(f"群聊 {current_group} 在AI路由白名单中,允许使用")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.logger.info(f"群聊 {current_group} 不在AI路由白名单中,禁止使用")
|
||||||
|
return False
|
||||||
|
|
||||||
def dispatch(self, ctx: MessageContext) -> bool:
|
def dispatch(self, ctx: MessageContext) -> bool:
|
||||||
"""
|
"""
|
||||||
执行AI路由分发
|
执行AI路由分发
|
||||||
@@ -180,6 +208,11 @@ class AIRouter:
|
|||||||
"""
|
"""
|
||||||
print(f"[AI路由器] dispatch被调用,消息内容: {ctx.text}")
|
print(f"[AI路由器] dispatch被调用,消息内容: {ctx.text}")
|
||||||
|
|
||||||
|
# 检查权限
|
||||||
|
if not self._check_permission(ctx):
|
||||||
|
print("[AI路由器] 权限检查失败,返回False")
|
||||||
|
return False
|
||||||
|
|
||||||
# 获取AI路由决策
|
# 获取AI路由决策
|
||||||
success, decision = self.route(ctx)
|
success, decision = self.route(ctx)
|
||||||
print(f"[AI路由器] route返回 - success: {success}, decision: {decision}")
|
print(f"[AI路由器] route返回 - success: {success}, decision: {decision}")
|
||||||
|
|||||||
@@ -142,4 +142,8 @@ perplexity: # -----perplexity配置这行不填-----
|
|||||||
trigger_keyword: ask # 触发Perplexity服务的前置词
|
trigger_keyword: ask # 触发Perplexity服务的前置词
|
||||||
allow_all: false # 是否允许所有群聊和用户使用Perplexity,设为true时忽略下面的白名单配置
|
allow_all: false # 是否允许所有群聊和用户使用Perplexity,设为true时忽略下面的白名单配置
|
||||||
allowed_groups: [] # 允许使用Perplexity的群聊ID列表,例如:["123456789@chatroom", "123456789@chatroom"]
|
allowed_groups: [] # 允许使用Perplexity的群聊ID列表,例如:["123456789@chatroom", "123456789@chatroom"]
|
||||||
allowed_users: [] # 允许使用Perplexity的用户ID列表,例如:["wxid_123456789", "filehelper"]
|
allowed_users: [] # 允许使用Perplexity的用户ID列表,例如:["wxid_123456789", "filehelper"]
|
||||||
|
|
||||||
|
ai_router: # -----AI路由器配置-----
|
||||||
|
enable: true # 是否启用AI路由功能
|
||||||
|
allowed_groups: [] # 允许使用AI路由的群聊ID列表,例如:["123456789@chatroom", "123456789@chatroom"]
|
||||||
@@ -42,4 +42,6 @@ class Config(object):
|
|||||||
self.ALIYUN_IMAGE = yconfig.get("aliyun_image", {})
|
self.ALIYUN_IMAGE = yconfig.get("aliyun_image", {})
|
||||||
self.GEMINI_IMAGE = yconfig.get("gemini_image", {})
|
self.GEMINI_IMAGE = yconfig.get("gemini_image", {})
|
||||||
self.GEMINI = yconfig.get("gemini", {})
|
self.GEMINI = yconfig.get("gemini", {})
|
||||||
|
self.AI_ROUTER = yconfig.get("ai_router", {"enable": True, "allowed_groups": []})
|
||||||
|
self.MAX_HISTORY = yconfig.get("MAX_HISTORY", 300)
|
||||||
self.SEND_RATE_LIMIT = yconfig.get("send_rate_limit", 0)
|
self.SEND_RATE_LIMIT = yconfig.get("send_rate_limit", 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user