From 8ecd2dd2f3d7f08287df932d993180b1faf0c845 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sun, 20 Nov 2022 20:04:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20`=E5=91=BD=E4=BB=A4=E5=88=AB?= =?UTF-8?q?=E5=90=8D`=E5=A2=9E=E5=BC=BA=EF=BC=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=9C=A8`Web=20UI`=E4=B8=AD=E8=BF=9B=E8=A1=8C=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E4=BC=98=E5=8C=96=E7=BE=A4=E8=81=8A=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Learning_Chat/handler.py | 2 +- LittlePaimon/plugins/Learning_Chat/web_api.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/LittlePaimon/plugins/Learning_Chat/handler.py b/LittlePaimon/plugins/Learning_Chat/handler.py index 02a0807..86143ef 100644 --- a/LittlePaimon/plugins/Learning_Chat/handler.py +++ b/LittlePaimon/plugins/Learning_Chat/handler.py @@ -353,7 +353,7 @@ class LearningChat: return cmp(len(left_messages) / left_duration, len(right_messages) / right_duration) popularity: List[Tuple[int, List[ChatMessage]]] = sorted(total_messages.items(), - key=cmp_to_key(group_popularity_cmp)) + key=cmp_to_key(group_popularity_cmp), reverse=True) logger.debug('群聊学习', f'主动发言:群热度排行{">>".join([str(g[0]) for g in popularity])}') for group_id, messages in popularity: if len(messages) < 30: diff --git a/LittlePaimon/plugins/Learning_Chat/web_api.py b/LittlePaimon/plugins/Learning_Chat/web_api.py index a2866ed..d05d575 100644 --- a/LittlePaimon/plugins/Learning_Chat/web_api.py +++ b/LittlePaimon/plugins/Learning_Chat/web_api.py @@ -8,6 +8,11 @@ from LittlePaimon.plugins.Learning_Chat.models import ChatMessage, ChatContext, from LittlePaimon.web.api import BaseApiRouter from LittlePaimon.web.api.utils import authentication +try: + import jieba_fast as jieba +except ImportError: + import jieba + from .handler import LearningChat from .config import config_manager @@ -43,6 +48,7 @@ async def post_chat_global_config(data: dict): count=config_manager.config.learn_max_count) await ChatAnswer.filter(count__gt=config_manager.config.learn_max_count).update( count=config_manager.config.learn_max_count) + jieba.load_userdict(config_manager.config.dictionary) return { 'status': 0, 'msg': '保存成功'