feat:回复温度现在会受到:人格-情绪-temp的链条影响;顺便修改了情绪激活度的取值

feat:回复温度现在会受到:人格-情绪-temp的链条影响;顺便修改了情绪激活度的取值
This commit is contained in:
SengokuCola
2025-04-09 22:50:21 +08:00
parent a41d0efe7a
commit f3d6e7cfa5
4 changed files with 79 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
import time
from random import random
import re
from typing import List
from ...memory_system.Hippocampus import HippocampusManager
from ...moods.moods import MoodManager
from ...config.config import global_config
@@ -18,6 +18,7 @@ from src.common.logger import get_module_logger, CHAT_STYLE_CONFIG, LogConfig
from ...chat.chat_stream import chat_manager
from ...person_info.relationship_manager import relationship_manager
from ...chat.message_buffer import message_buffer
from src.plugins.respon_info_catcher.info_catcher import info_catcher_manager
# 定义日志配置
chat_config = LogConfig(
@@ -58,7 +59,11 @@ class ReasoningChat:
return thinking_id
async def _send_response_messages(self, message, chat, response_set, thinking_id):
async def _send_response_messages(self,
message,
chat,
response_set:List[str],
thinking_id) -> MessageSending:
"""发送回复消息"""
container = message_manager.get_container(chat.stream_id)
thinking_message = None
@@ -77,6 +82,7 @@ class ReasoningChat:
message_set = MessageSet(chat, thinking_id)
mark_head = False
first_bot_msg = None
for msg in response_set:
message_segment = Seg(type="text", data=msg)
bot_message = MessageSending(
@@ -96,9 +102,12 @@ class ReasoningChat:
)
if not mark_head:
mark_head = True
first_bot_msg = bot_message
message_set.add_message(bot_message)
message_manager.add_message(message_set)
return first_bot_msg
async def _handle_emoji(self, message, chat, response):
"""处理表情包"""
if random() < global_config.emoji_chance:
@@ -231,12 +240,19 @@ class ReasoningChat:
thinking_id = await self._create_thinking_message(message, chat, userinfo, messageinfo)
timer2 = time.time()
timing_results["创建思考消息"] = timer2 - timer1
logger.debug(f"创建捕捉器thinking_id:{thinking_id}")
info_catcher = info_catcher_manager.get_info_catcher(thinking_id)
info_catcher.catch_decide_to_response(message)
# 生成回复
timer1 = time.time()
response_set = await self.gpt.generate_response(message)
response_set = await self.gpt.generate_response(message,thinking_id)
timer2 = time.time()
timing_results["生成回复"] = timer2 - timer1
info_catcher.catch_after_generate_response(timing_results["生成回复"])
if not response_set:
logger.info("为什么生成回复失败?")
@@ -244,9 +260,14 @@ class ReasoningChat:
# 发送消息
timer1 = time.time()
await self._send_response_messages(message, chat, response_set, thinking_id)
first_bot_msg = await self._send_response_messages(message, chat, response_set, thinking_id)
timer2 = time.time()
timing_results["发送消息"] = timer2 - timer1
info_catcher.catch_after_response(timing_results["发送消息"],response_set,first_bot_msg)
info_catcher.done_catch()
# 处理表情包
timer1 = time.time()

View File

@@ -8,6 +8,7 @@ from ...chat.message import MessageThinking
from .reasoning_prompt_builder import prompt_builder
from ...chat.utils import process_llm_response
from src.common.logger import get_module_logger, LogConfig, LLM_STYLE_CONFIG
from src.plugins.respon_info_catcher.info_catcher import info_catcher_manager
# 定义日志配置
llm_config = LogConfig(
@@ -37,7 +38,7 @@ class ResponseGenerator:
self.current_model_type = "r1" # 默认使用 R1
self.current_model_name = "unknown model"
async def generate_response(self, message: MessageThinking) -> Optional[Union[str, List[str]]]:
async def generate_response(self, message: MessageThinking,thinking_id:str) -> Optional[Union[str, List[str]]]:
"""根据当前模型类型选择对应的生成函数"""
# 从global_config中获取模型概率值并选择模型
if random.random() < global_config.MODEL_R1_PROBABILITY:
@@ -51,7 +52,7 @@ class ResponseGenerator:
f"{self.current_model_type}思考:{message.processed_plain_text[:30] + '...' if len(message.processed_plain_text) > 30 else message.processed_plain_text}"
) # noqa: E501
model_response = await self._generate_response_with_model(message, current_model)
model_response = await self._generate_response_with_model(message, current_model,thinking_id)
# print(f"raw_content: {model_response}")
@@ -64,8 +65,11 @@ class ResponseGenerator:
logger.info(f"{self.current_model_type}思考,失败")
return None
async def _generate_response_with_model(self, message: MessageThinking, model: LLM_request):
async def _generate_response_with_model(self, message: MessageThinking, model: LLM_request,thinking_id:str):
sender_name = ""
info_catcher = info_catcher_manager.get_info_catcher(thinking_id)
if message.chat_stream.user_info.user_cardname and message.chat_stream.user_info.user_nickname:
sender_name = (
f"[({message.chat_stream.user_info.user_id}){message.chat_stream.user_info.user_nickname}]"
@@ -90,6 +94,14 @@ class ResponseGenerator:
try:
content, reasoning_content, self.current_model_name = await model.generate_response(prompt)
info_catcher.catch_after_llm_generated(
prompt=prompt,
response=content,
reasoning_content=reasoning_content,
model_name=self.current_model_name)
except Exception:
logger.exception("生成回复时出错")
return None

View File

@@ -10,6 +10,8 @@ from ...chat.utils import process_llm_response
from src.common.logger import get_module_logger, LogConfig, LLM_STYLE_CONFIG
from src.plugins.respon_info_catcher.info_catcher import info_catcher_manager
from src.plugins.moods.moods import MoodManager
# 定义日志配置
llm_config = LogConfig(
# 使用消息发送专用样式
@@ -39,8 +41,12 @@ class ResponseGenerator:
logger.info(
f"思考:{message.processed_plain_text[:30] + '...' if len(message.processed_plain_text) > 30 else message.processed_plain_text}"
)
arousal_multiplier = MoodManager.get_instance().get_arousal_multiplier()
current_model = self.model_normal
current_model.temperature = 0.7 * arousal_multiplier #激活度越高,温度越高
model_response = await self._generate_response_with_model(message, current_model,thinking_id)
# print(f"raw_content: {model_response}")