fix: 增加设置模板,优化emotion,优化压缩

This commit is contained in:
tcmofashi
2025-03-07 01:06:36 +08:00
parent 71e851fbd4
commit 0ebd241077
4 changed files with 9 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ ban_words = [
[emoji] [emoji]
check_interval = 120 # 检查表情包的时间间隔 check_interval = 120 # 检查表情包的时间间隔
register_interval = 10 # 注册表情包的时间间隔 register_interval = 10 # 注册表情包的时间间隔
check_prompt = "不要包含违反公序良俗的内容" # 表情包过滤要求
[cq_code] [cq_code]
enable_pic_translate = false enable_pic_translate = false

View File

@@ -163,12 +163,6 @@ class ChatBot:
message_manager.add_message(message_set) message_manager.add_message(message_set)
bot_response_time = tinking_time_point 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: if random() < global_config.emoji_chance:
emoji_path = await emoji_manager.get_emoji_for_text(response) emoji_path = await emoji_manager.get_emoji_for_text(response)
@@ -196,6 +190,12 @@ class ChatBot:
# reply_message_id=message.message_id # reply_message_id=message.message_id
) )
message_manager.add_message(bot_message) 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) # willing_manager.change_reply_willing_after_sent(event.group_id)

View File

@@ -160,27 +160,6 @@ class EmojiManager:
logger.error(f"获取表情包失败: {str(e)}") logger.error(f"获取表情包失败: {str(e)}")
return None 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: async def _get_emoji_discription(self, image_base64: str) -> str:
"""获取表情包的标签""" """获取表情包的标签"""
try: try:
@@ -208,7 +187,7 @@ class EmojiManager:
async def _get_kimoji_for_text(self, text:str): async def _get_kimoji_for_text(self, text:str):
try: 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) content, _ = await self.lm.generate_response_async(prompt)
logger.info(f"输出描述: {content}") logger.info(f"输出描述: {content}")
@@ -319,7 +298,6 @@ class EmojiManager:
logger.info(f"其不满足过滤规则,被剔除 {check}") logger.info(f"其不满足过滤规则,被剔除 {check}")
continue continue
logger.info(f"check通过 {check}") logger.info(f"check通过 {check}")
tag = await self._get_emoji_tag(image_base64)
embedding = get_embedding(discription) embedding = get_embedding(discription)
if discription is not None: if discription is not None:
# 准备数据库记录 # 准备数据库记录
@@ -328,7 +306,6 @@ class EmojiManager:
'path': image_path, 'path': image_path,
'embedding':embedding, 'embedding':embedding,
'discription': discription, 'discription': discription,
'tag':tag,
'timestamp': int(time.time()) 'timestamp': int(time.time())
} }

View File

@@ -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): for frame_idx in range(img.n_frames):
img.seek(frame_idx) img.seek(frame_idx)
new_frame = img.copy() 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) frames.append(new_frame)
# 保存到缓冲区 # 保存到缓冲区