feat:移除mood,但是加入mood_api
This commit is contained in:
@@ -77,10 +77,6 @@ class HeartFCMessageReceiver:
|
|||||||
|
|
||||||
heartflow_chat: HeartFChatting = await heartflow.get_or_create_heartflow_chat(chat.stream_id) # type: ignore
|
heartflow_chat: HeartFChatting = await heartflow.get_or_create_heartflow_chat(chat.stream_id) # type: ignore
|
||||||
|
|
||||||
if global_config.mood.enable_mood:
|
|
||||||
chat_mood = mood_manager.get_mood_by_chat_id(heartflow_chat.stream_id)
|
|
||||||
asyncio.create_task(chat_mood.update_mood_by_message(message))
|
|
||||||
|
|
||||||
# 3. 日志记录
|
# 3. 日志记录
|
||||||
mes_name = chat.group_info.group_name if chat.group_info else "私聊"
|
mes_name = chat.group_info.group_name if chat.group_info else "私聊"
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,21 @@ def init_prompt():
|
|||||||
Prompt(
|
Prompt(
|
||||||
"""
|
"""
|
||||||
{chat_talking_prompt}
|
{chat_talking_prompt}
|
||||||
|
以上是群里正在进行的聊天记录
|
||||||
|
|
||||||
|
{identity_block}
|
||||||
|
你先前的情绪状态是:{mood_state}
|
||||||
|
你的情绪特点是:{emotion_style}
|
||||||
|
|
||||||
|
现在,请你根据先前的情绪状态和现在的聊天内容,总结推断你现在的情绪状态
|
||||||
|
请只输出新的情绪状态,不要输出其他内容:
|
||||||
|
""",
|
||||||
|
"get_mood_prompt",
|
||||||
|
)
|
||||||
|
|
||||||
|
Prompt(
|
||||||
|
"""
|
||||||
|
{chat_talking_prompt}
|
||||||
以上是群里最近的聊天记录
|
以上是群里最近的聊天记录
|
||||||
|
|
||||||
{identity_block}
|
{identity_block}
|
||||||
@@ -140,6 +155,61 @@ class ChatMood:
|
|||||||
|
|
||||||
self.last_change_time = message_time
|
self.last_change_time = message_time
|
||||||
|
|
||||||
|
async def get_mood(self) -> str:
|
||||||
|
self.regression_count = 0
|
||||||
|
|
||||||
|
current_time = time.time()
|
||||||
|
|
||||||
|
logger.info(f"{self.log_prefix} 获取情绪状态")
|
||||||
|
message_list_before_now = get_raw_msg_by_timestamp_with_chat_inclusive(
|
||||||
|
chat_id=self.chat_id,
|
||||||
|
timestamp_start=self.last_change_time,
|
||||||
|
timestamp_end=current_time,
|
||||||
|
limit=int(global_config.chat.max_context_size / 3),
|
||||||
|
limit_mode="last",
|
||||||
|
)
|
||||||
|
|
||||||
|
chat_talking_prompt = build_readable_messages(
|
||||||
|
message_list_before_now,
|
||||||
|
replace_bot_name=True,
|
||||||
|
timestamp_mode="normal_no_YMD",
|
||||||
|
read_mark=0.0,
|
||||||
|
truncate=True,
|
||||||
|
show_actions=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
bot_name = global_config.bot.nickname
|
||||||
|
if global_config.bot.alias_names:
|
||||||
|
bot_nickname = f",也有人叫你{','.join(global_config.bot.alias_names)}"
|
||||||
|
else:
|
||||||
|
bot_nickname = ""
|
||||||
|
|
||||||
|
identity_block = f"你的名字是{bot_name}{bot_nickname}"
|
||||||
|
|
||||||
|
prompt = await global_prompt_manager.format_prompt(
|
||||||
|
"get_mood_prompt",
|
||||||
|
chat_talking_prompt=chat_talking_prompt,
|
||||||
|
identity_block=identity_block,
|
||||||
|
mood_state=self.mood_state,
|
||||||
|
emotion_style=global_config.personality.emotion_style,
|
||||||
|
)
|
||||||
|
|
||||||
|
response, (reasoning_content, _, _) = await self.mood_model.generate_response_async(
|
||||||
|
prompt=prompt, temperature=0.7
|
||||||
|
)
|
||||||
|
if global_config.debug.show_prompt:
|
||||||
|
logger.info(f"{self.log_prefix} prompt: {prompt}")
|
||||||
|
logger.info(f"{self.log_prefix} response: {response}")
|
||||||
|
logger.info(f"{self.log_prefix} reasoning_content: {reasoning_content}")
|
||||||
|
|
||||||
|
logger.info(f"{self.log_prefix} 情绪状态更新为: {response}")
|
||||||
|
|
||||||
|
self.mood_state = response
|
||||||
|
|
||||||
|
self.last_change_time = current_time
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
async def regress_mood(self):
|
async def regress_mood(self):
|
||||||
message_time = time.time()
|
message_time = time.time()
|
||||||
message_list_before_now = get_raw_msg_by_timestamp_with_chat_inclusive(
|
message_list_before_now = get_raw_msg_by_timestamp_with_chat_inclusive(
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from src.plugin_system.apis import (
|
|||||||
send_api,
|
send_api,
|
||||||
tool_api,
|
tool_api,
|
||||||
frequency_api,
|
frequency_api,
|
||||||
|
mood_api,
|
||||||
)
|
)
|
||||||
from .logging_api import get_logger
|
from .logging_api import get_logger
|
||||||
from .plugin_register_api import register_plugin
|
from .plugin_register_api import register_plugin
|
||||||
@@ -40,4 +41,5 @@ __all__ = [
|
|||||||
"register_plugin",
|
"register_plugin",
|
||||||
"tool_api",
|
"tool_api",
|
||||||
"frequency_api",
|
"frequency_api",
|
||||||
|
"mood_api",
|
||||||
]
|
]
|
||||||
|
|||||||
16
src/plugin_system/apis/mood_api.py
Normal file
16
src/plugin_system/apis/mood_api.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import asyncio
|
||||||
|
import traceback
|
||||||
|
import time
|
||||||
|
from typing import Optional, Union, Dict, List, TYPE_CHECKING, Tuple
|
||||||
|
|
||||||
|
from src.chat.message_receive import message
|
||||||
|
from src.common.logger import get_logger
|
||||||
|
from src.mood.mood_manager import mood_manager
|
||||||
|
|
||||||
|
logger = get_logger("mood_api")
|
||||||
|
|
||||||
|
|
||||||
|
async def get_mood_by_chat_id(chat_id: str) -> Optional[float]:
|
||||||
|
chat_mood = mood_manager.get_mood_by_chat_id(chat_id)
|
||||||
|
mood = asyncio.create_task(chat_mood.get_mood())
|
||||||
|
return mood
|
||||||
@@ -86,7 +86,7 @@ enable_mood = true # 是否启用情绪系统
|
|||||||
mood_update_threshold = 1 # 情绪更新阈值,越高,更新越慢
|
mood_update_threshold = 1 # 情绪更新阈值,越高,更新越慢
|
||||||
|
|
||||||
[emoji]
|
[emoji]
|
||||||
emoji_chance = 0.6 # 麦麦激活表情包动作的概率
|
emoji_chance = 0.4 # 麦麦激活表情包动作的概率
|
||||||
max_reg_num = 100 # 表情包最大注册数量
|
max_reg_num = 100 # 表情包最大注册数量
|
||||||
do_replace = true # 开启则在达到最大数量时删除(替换)表情包,关闭则达到最大数量时不会继续收集表情包
|
do_replace = true # 开启则在达到最大数量时删除(替换)表情包,关闭则达到最大数量时不会继续收集表情包
|
||||||
check_interval = 10 # 检查表情包(注册,破损,删除)的时间间隔(分钟)
|
check_interval = 10 # 检查表情包(注册,破损,删除)的时间间隔(分钟)
|
||||||
|
|||||||
Reference in New Issue
Block a user