mirror of https://github.com/Mai-with-u/MaiBot.git
feat:添加主动发言相关api
parent
3a6dfbbe06
commit
6adc972e53
|
|
@ -107,6 +107,7 @@ class HeartFChatting:
|
|||
|
||||
self.last_active_time = time.time() # 记录上一次非noreply时间
|
||||
|
||||
self.question_probability_multiplier = 1
|
||||
self.questioned = False
|
||||
|
||||
|
||||
|
|
@ -192,7 +193,7 @@ class HeartFChatting:
|
|||
else:
|
||||
question_probability = 0.00003
|
||||
|
||||
question_probability = question_probability * global_config.chat.get_auto_chat_value(self.stream_id)
|
||||
question_probability = question_probability * global_config.chat.get_auto_chat_value(self.stream_id) * self.question_probability_multiplier
|
||||
|
||||
# print(f"{self.log_prefix} questioned: {self.questioned},len: {len(global_conflict_tracker.get_questions_by_chat_id(self.stream_id))}")
|
||||
if question_probability > 0 and not self.questioned and len(global_conflict_tracker.get_questions_by_chat_id(self.stream_id)) == 0: #长久没有回复,可以试试主动发言,提问概率随着时间增加
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ from .apis import (
|
|||
person_api,
|
||||
plugin_manage_api,
|
||||
send_api,
|
||||
auto_talk_api,
|
||||
register_plugin,
|
||||
get_logger,
|
||||
)
|
||||
|
|
@ -83,6 +84,7 @@ __all__ = [
|
|||
"person_api",
|
||||
"plugin_manage_api",
|
||||
"send_api",
|
||||
"auto_talk_api",
|
||||
"register_plugin",
|
||||
"get_logger",
|
||||
# 基础类
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from src.plugin_system.apis import (
|
|||
tool_api,
|
||||
frequency_api,
|
||||
mood_api,
|
||||
auto_talk_api,
|
||||
)
|
||||
from .logging_api import get_logger
|
||||
from .plugin_register_api import register_plugin
|
||||
|
|
@ -42,4 +43,5 @@ __all__ = [
|
|||
"tool_api",
|
||||
"frequency_api",
|
||||
"mood_api",
|
||||
"auto_talk_api",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
from src.common.logger import get_logger
|
||||
from src.chat.heart_flow.heartFC_chat import HeartFChatting
|
||||
from src.chat.heart_flow.heartflow import heartflow
|
||||
|
||||
logger = get_logger("auto_talk_api")
|
||||
|
||||
|
||||
def set_question_probability_multiplier(chat_id: str, multiplier: float) -> bool:
|
||||
"""
|
||||
设置指定 chat_id 的主动发言概率乘数。
|
||||
|
||||
返回:
|
||||
bool: 设置是否成功。仅当目标聊天为群聊(HeartFChatting)且存在时为 True。
|
||||
"""
|
||||
try:
|
||||
if not isinstance(chat_id, str):
|
||||
raise TypeError("chat_id 必须是 str")
|
||||
if not isinstance(multiplier, (int, float)):
|
||||
raise TypeError("multiplier 必须是数值类型")
|
||||
|
||||
chat = heartflow.heartflow_chat_list.get(chat_id)
|
||||
if chat is None:
|
||||
logger.warning(f"未找到 chat_id={chat_id} 的心流实例,无法设置乘数")
|
||||
return False
|
||||
|
||||
if not isinstance(chat, HeartFChatting):
|
||||
logger.warning(f"chat_id={chat_id} 非群聊(HeartFChatting),不支持设置主动发言乘数")
|
||||
return False
|
||||
|
||||
# 约束:不允许负值
|
||||
value = float(multiplier)
|
||||
if value < 0:
|
||||
value = 0.0
|
||||
|
||||
chat.question_probability_multiplier = value
|
||||
logger.info(f"[auto_talk_api] chat_id={chat_id} 主动发言乘数已设为 {value}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"设置主动发言乘数失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def get_question_probability_multiplier(chat_id: str) -> float:
|
||||
"""获取指定 chat_id 的主动发言概率乘数,未找到则返回 0。"""
|
||||
try:
|
||||
chat = heartflow.heartflow_chat_list.get(chat_id)
|
||||
if isinstance(chat, HeartFChatting):
|
||||
return float(getattr(chat, "question_probability_multiplier", 0.0))
|
||||
return 0.0
|
||||
except Exception:
|
||||
return 0.0
|
||||
Loading…
Reference in New Issue