Skip to content

Commit

Permalink
feat: hello plugin support system prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
zhayujie committed Nov 29, 2023
1 parent 6e0d2f9 commit 865e4b5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
9 changes: 3 additions & 6 deletions bot/linkai/link_ai_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,9 @@ def session_reply(self, reply, session_id, total_tokens=None, query=None):

class LinkAISession(ChatGPTSession):
def calc_tokens(self):
try:
cur_tokens = super().calc_tokens()
except Exception as e:
logger.debug("Exception when counting tokens precisely for query: {}".format(e))
cur_tokens = len(str(self.messages))
return cur_tokens
if not self.messages:
return 0
return len(str(self.messages))

def discard_exceeding(self, max_tokens, cur_tokens=None):
cur_tokens = self.calc_tokens()
Expand Down
2 changes: 0 additions & 2 deletions channel/chat_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ def _generate_reply(self, context: Context, reply: Reply = Reply()) -> Reply:
reply = e_context["reply"]
if not e_context.is_pass():
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: # 文字和图片消息
context["channel"] = e_context["channel"]
reply = super().build_reply_content(context.content, context)
Expand Down
4 changes: 3 additions & 1 deletion plugins/hello/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self):
super().__init__()
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
logger.info("[Hello] inited")
self.config = super().load_config()

def on_handle_context(self, e_context: EventContext):
if e_context["context"].type not in [
Expand All @@ -30,7 +31,8 @@ def on_handle_context(self, e_context: EventContext):
ContextType.PATPAT,
]:
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 "group_welcome_msg" in conf():
reply = Reply()
Expand Down
2 changes: 2 additions & 0 deletions plugins/linkai/midjourney.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def judge_mj_task_type(self, e_context: EventContext):
context = e_context['context']
if context.type == ContextType.TEXT:
cmd_list = context.content.split(maxsplit=1)
if not cmd_list:
return None
if cmd_list[0].lower() == f"{trigger_prefix}mj":
return TaskType.GENERATE
elif cmd_list[0].lower() == f"{trigger_prefix}mju":
Expand Down

0 comments on commit 865e4b5

Please sign in to comment.