mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-01-19 01:21:01 +08:00
feat: make plugin compatible with LINKAI in most cases
This commit is contained in:
@@ -34,7 +34,11 @@ class LinkAIBot(Bot):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# load config
|
# load config
|
||||||
app_code = conf().get("linkai_app_code")
|
if context.get("generate_breaked_by"):
|
||||||
|
logger.info(f"[LINKAI] won't set appcode because a plugin ({context['generate_breaked_by']}) affected the context")
|
||||||
|
app_code = None
|
||||||
|
else:
|
||||||
|
app_code = conf().get("linkai_app_code")
|
||||||
linkai_api_key = conf().get("linkai_api_key")
|
linkai_api_key = conf().get("linkai_api_key")
|
||||||
|
|
||||||
session_id = context["session_id"]
|
session_id = context["session_id"]
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ class ChatChannel(Channel):
|
|||||||
reply = e_context["reply"]
|
reply = e_context["reply"]
|
||||||
if not e_context.is_pass():
|
if not e_context.is_pass():
|
||||||
logger.debug("[WX] ready to handle context: type={}, content={}".format(context.type, context.content))
|
logger.debug("[WX] ready to handle context: type={}, content={}".format(context.type, context.content))
|
||||||
|
if e_context.is_break():
|
||||||
|
context["generate_breaked_by"] = e_context["breaked_by"]
|
||||||
if context.type == ContextType.TEXT or context.type == ContextType.IMAGE_CREATE: # 文字和图片消息
|
if context.type == ContextType.TEXT or context.type == ContextType.IMAGE_CREATE: # 文字和图片消息
|
||||||
reply = super().build_reply_content(context.content, context)
|
reply = super().build_reply_content(context.content, context)
|
||||||
elif context.type == ContextType.VOICE: # 语音消息
|
elif context.type == ContextType.VOICE: # 语音消息
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class Dungeon(Plugin):
|
|||||||
if e_context["context"].type != ContextType.TEXT:
|
if e_context["context"].type != ContextType.TEXT:
|
||||||
return
|
return
|
||||||
bottype = Bridge().get_bot_type("chat")
|
bottype = Bridge().get_bot_type("chat")
|
||||||
if bottype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]:
|
if bottype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI]:
|
||||||
return
|
return
|
||||||
bot = Bridge().get_bot("chat")
|
bot = Bridge().get_bot("chat")
|
||||||
content = e_context["context"].content[:]
|
content = e_context["context"].content[:]
|
||||||
|
|||||||
@@ -50,3 +50,6 @@ class EventContext:
|
|||||||
|
|
||||||
def is_pass(self):
|
def is_pass(self):
|
||||||
return self.action == EventAction.BREAK_PASS
|
return self.action == EventAction.BREAK_PASS
|
||||||
|
|
||||||
|
def is_break(self):
|
||||||
|
return self.action == EventAction.BREAK or self.action == EventAction.BREAK_PASS
|
||||||
|
|||||||
@@ -285,9 +285,9 @@ class Godcmd(Plugin):
|
|||||||
ok, result = False, "请提供一个GPT模型"
|
ok, result = False, "请提供一个GPT模型"
|
||||||
elif cmd == "gpt_model":
|
elif cmd == "gpt_model":
|
||||||
user_data = conf().get_user_data(user)
|
user_data = conf().get_user_data(user)
|
||||||
model = conf().get('model')
|
model = conf().get("model")
|
||||||
if 'gpt_model' in user_data:
|
if "gpt_model" in user_data:
|
||||||
model = user_data['gpt_model']
|
model = user_data["gpt_model"]
|
||||||
ok, result = True, "你的GPT模型为" + str(model)
|
ok, result = True, "你的GPT模型为" + str(model)
|
||||||
elif cmd == "reset_gpt_model":
|
elif cmd == "reset_gpt_model":
|
||||||
try:
|
try:
|
||||||
@@ -320,7 +320,7 @@ class Godcmd(Plugin):
|
|||||||
load_config()
|
load_config()
|
||||||
ok, result = True, "配置已重载"
|
ok, result = True, "配置已重载"
|
||||||
elif cmd == "resetall":
|
elif cmd == "resetall":
|
||||||
if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]:
|
if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI]:
|
||||||
channel.cancel_all_session()
|
channel.cancel_all_session()
|
||||||
bot.sessions.clear_all_session()
|
bot.sessions.clear_all_session()
|
||||||
ok, result = True, "重置所有会话成功"
|
ok, result = True, "重置所有会话成功"
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ class PluginManager:
|
|||||||
logger.debug("Plugin %s triggered by event %s" % (name, e_context.event))
|
logger.debug("Plugin %s triggered by event %s" % (name, e_context.event))
|
||||||
instance = self.instances[name]
|
instance = self.instances[name]
|
||||||
instance.handlers[e_context.event](e_context, *args, **kwargs)
|
instance.handlers[e_context.event](e_context, *args, **kwargs)
|
||||||
|
if e_context.is_break():
|
||||||
|
e_context["breaked_by"] = name
|
||||||
|
logger.debug("Plugin %s breaked event %s" % (name, e_context.event))
|
||||||
return e_context
|
return e_context
|
||||||
|
|
||||||
def set_plugin_priority(self, name: str, priority: int):
|
def set_plugin_priority(self, name: str, priority: int):
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Role(Plugin):
|
|||||||
if e_context["context"].type != ContextType.TEXT:
|
if e_context["context"].type != ContextType.TEXT:
|
||||||
return
|
return
|
||||||
btype = Bridge().get_bot_type("chat")
|
btype = Bridge().get_bot_type("chat")
|
||||||
if btype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]:
|
if btype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI]:
|
||||||
return
|
return
|
||||||
bot = Bridge().get_bot("chat")
|
bot = Bridge().get_bot("chat")
|
||||||
content = e_context["context"].content[:]
|
content = e_context["context"].content[:]
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class Tool(Plugin):
|
|||||||
const.CHATGPT,
|
const.CHATGPT,
|
||||||
const.OPEN_AI,
|
const.OPEN_AI,
|
||||||
const.CHATGPTONAZURE,
|
const.CHATGPTONAZURE,
|
||||||
|
const.LINKAI,
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user