diff --git a/config/bot_config_template.toml b/config/bot_config_template.toml index bc4ac18e3..afc2b5079 100644 --- a/config/bot_config_template.toml +++ b/config/bot_config_template.toml @@ -20,6 +20,7 @@ ban_words = [ [emoji] check_interval = 120 # 检查表情包的时间间隔 register_interval = 10 # 注册表情包的时间间隔 +check_prompt = "不要包含违反公序良俗的内容" # 表情包过滤要求 [cq_code] enable_pic_translate = false diff --git a/src/plugins/chat/bot.py b/src/plugins/chat/bot.py index 89c15b388..add9bf978 100644 --- a/src/plugins/chat/bot.py +++ b/src/plugins/chat/bot.py @@ -163,12 +163,6 @@ class ChatBot: message_manager.add_message(message_set) bot_response_time = tinking_time_point - emotion = await self.gpt._get_emotion_tags(raw_content) - print(f"为 '{response}' 获取到的情感标签为:{emotion}") - valuedict={ - 'happy':0.5,'angry':-1,'sad':-0.5,'surprised':0.5,'disgusted':-1.5,'fearful':-0.25,'neutral':0.25 - } - await relationship_manager.update_relationship_value(message.user_id, relationship_value=valuedict[emotion[0]]) if random() < global_config.emoji_chance: emoji_path = await emoji_manager.get_emoji_for_text(response) @@ -196,6 +190,12 @@ class ChatBot: # reply_message_id=message.message_id ) message_manager.add_message(bot_message) + emotion = await self.gpt._get_emotion_tags(raw_content) + print(f"为 '{response}' 获取到的情感标签为:{emotion}") + valuedict={ + 'happy':0.5,'angry':-1,'sad':-0.5,'surprised':0.5,'disgusted':-1.5,'fearful':-0.25,'neutral':0.25 + } + await relationship_manager.update_relationship_value(message.user_id, relationship_value=valuedict[emotion[0]]) # willing_manager.change_reply_willing_after_sent(event.group_id) diff --git a/src/plugins/chat/emoji_manager.py b/src/plugins/chat/emoji_manager.py index ede0d7135..cec454e4d 100644 --- a/src/plugins/chat/emoji_manager.py +++ b/src/plugins/chat/emoji_manager.py @@ -160,27 +160,6 @@ class EmojiManager: logger.error(f"获取表情包失败: {str(e)}") return None - async def _get_emoji_tag(self, image_base64: str) -> str: - """获取表情包的标签""" - try: - prompt = '这是一个表情包,请从"happy", "angry", "sad", "surprised", "disgusted", "fearful", "neutral"中选出1个情感标签。只输出标签,不要输出其他任何内容,只输出情感标签就好' - - content, _ = await self.llm.generate_response_for_image(prompt, image_base64) - tag_result = content.strip().lower() - - valid_tags = ["happy", "angry", "sad", "surprised", "disgusted", "fearful", "neutral"] - for tag_match in valid_tags: - if tag_match in tag_result or tag_match == tag_result: - return tag_match - print(f"\033[1;33m[警告]\033[0m 无效的标签: {tag_result}, 跳过") - - except Exception as e: - print(f"\033[1;31m[错误]\033[0m 获取标签失败: {str(e)}") - return "neutral" - - print(f"\033[1;32m[调试信息]\033[0m 使用默认标签: neutral") - return "neutral" # 默认标签 - async def _get_emoji_discription(self, image_base64: str) -> str: """获取表情包的标签""" try: @@ -208,7 +187,7 @@ class EmojiManager: async def _get_kimoji_for_text(self, text:str): try: - prompt = f'这是{global_config.BOT_NICKNAME}将要发送的消息内容:\n{text}\n若要为其配上表情包,请你输出这个表情包应该表达怎样的情感,应该给人什么样的感觉,不要太简洁也不要太长,注意不要输出任何对内容的分析内容,只输出\"一种什么样的感觉\"中间的形容词部分。' + prompt = f'这是{global_config.BOT_NICKNAME}将要发送的消息内容:\n{text}\n若要为其配上表情包,请你输出这个表情包应该表达怎样的情感,应该给人什么样的感觉,不要太简洁也不要太长,注意不要输出任何对消息内容的分析内容,只输出\"一种什么样的感觉\"中间的形容词部分。' content, _ = await self.lm.generate_response_async(prompt) logger.info(f"输出描述: {content}") @@ -319,7 +298,6 @@ class EmojiManager: logger.info(f"其不满足过滤规则,被剔除 {check}") continue logger.info(f"check通过 {check}") - tag = await self._get_emoji_tag(image_base64) embedding = get_embedding(discription) if discription is not None: # 准备数据库记录 @@ -328,7 +306,6 @@ class EmojiManager: 'path': image_path, 'embedding':embedding, 'discription': discription, - 'tag':tag, 'timestamp': int(time.time()) } diff --git a/src/plugins/chat/utils_image.py b/src/plugins/chat/utils_image.py index 922ab5228..9a7ef789a 100644 --- a/src/plugins/chat/utils_image.py +++ b/src/plugins/chat/utils_image.py @@ -252,7 +252,7 @@ def compress_base64_image_by_scale(base64_data: str, target_size: int = 0.8 * 10 for frame_idx in range(img.n_frames): img.seek(frame_idx) new_frame = img.copy() - new_frame = new_frame.resize((new_width, new_height), Image.Resampling.LANCZOS) + new_frame = new_frame.resize((new_width//4, new_height//4), Image.Resampling.LANCZOS) # 动图折上折 frames.append(new_frame) # 保存到缓冲区