mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
feat: hello plugin support system prompt
This commit is contained in:
@@ -370,12 +370,9 @@ class LinkAISessionManager(SessionManager):
|
|||||||
|
|
||||||
class LinkAISession(ChatGPTSession):
|
class LinkAISession(ChatGPTSession):
|
||||||
def calc_tokens(self):
|
def calc_tokens(self):
|
||||||
try:
|
if not self.messages:
|
||||||
cur_tokens = super().calc_tokens()
|
return 0
|
||||||
except Exception as e:
|
return len(str(self.messages))
|
||||||
logger.debug("Exception when counting tokens precisely for query: {}".format(e))
|
|
||||||
cur_tokens = len(str(self.messages))
|
|
||||||
return cur_tokens
|
|
||||||
|
|
||||||
def discard_exceeding(self, max_tokens, cur_tokens=None):
|
def discard_exceeding(self, max_tokens, cur_tokens=None):
|
||||||
cur_tokens = self.calc_tokens()
|
cur_tokens = self.calc_tokens()
|
||||||
|
|||||||
@@ -184,8 +184,6 @@ 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: # 文字和图片消息
|
||||||
context["channel"] = e_context["channel"]
|
context["channel"] = e_context["channel"]
|
||||||
reply = super().build_reply_content(context.content, context)
|
reply = super().build_reply_content(context.content, context)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Hello(Plugin):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
|
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
|
||||||
logger.info("[Hello] inited")
|
logger.info("[Hello] inited")
|
||||||
|
self.config = super().load_config()
|
||||||
|
|
||||||
def on_handle_context(self, e_context: EventContext):
|
def on_handle_context(self, e_context: EventContext):
|
||||||
if e_context["context"].type not in [
|
if e_context["context"].type not in [
|
||||||
@@ -30,7 +31,8 @@ class Hello(Plugin):
|
|||||||
ContextType.PATPAT,
|
ContextType.PATPAT,
|
||||||
]:
|
]:
|
||||||
return
|
return
|
||||||
|
if not self.config or not self.config.get("use_character_desc"):
|
||||||
|
e_context["context"]["generate_breaked_by"] = EventAction.BREAK
|
||||||
if e_context["context"].type == ContextType.JOIN_GROUP:
|
if e_context["context"].type == ContextType.JOIN_GROUP:
|
||||||
if "group_welcome_msg" in conf():
|
if "group_welcome_msg" in conf():
|
||||||
reply = Reply()
|
reply = Reply()
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ class MJBot:
|
|||||||
context = e_context['context']
|
context = e_context['context']
|
||||||
if context.type == ContextType.TEXT:
|
if context.type == ContextType.TEXT:
|
||||||
cmd_list = context.content.split(maxsplit=1)
|
cmd_list = context.content.split(maxsplit=1)
|
||||||
|
if not cmd_list:
|
||||||
|
return None
|
||||||
if cmd_list[0].lower() == f"{trigger_prefix}mj":
|
if cmd_list[0].lower() == f"{trigger_prefix}mj":
|
||||||
return TaskType.GENERATE
|
return TaskType.GENERATE
|
||||||
elif cmd_list[0].lower() == f"{trigger_prefix}mju":
|
elif cmd_list[0].lower() == f"{trigger_prefix}mju":
|
||||||
|
|||||||
Reference in New Issue
Block a user