Merge branch 'chieribot' into c1

pull/541/head
XBC_D2O 2025-03-12 22:24:52 +08:00 committed by GitHub
commit 63cf348ef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 45 additions and 29 deletions

View File

@ -9,7 +9,7 @@ from nonebot.typing import T_State
from ...common.database import Database
from ..moods.moods import MoodManager # 导入情绪管理器
from ..schedule.schedule_generator import bot_schedule
# from ..schedule.schedule_generator import bot_schedule
from ..utils.statistic import LLMStatistics
from .bot import chat_bot
from .config import global_config
@ -70,8 +70,8 @@ async def start_background_tasks():
# 只启动表情包管理任务
asyncio.create_task(emoji_manager.start_periodic_check(interval_MINS=global_config.EMOJI_CHECK_INTERVAL))
await bot_schedule.initialize()
bot_schedule.print_schedule()
# await bot_schedule.initialize()
# bot_schedule.print_schedule()
@driver.on_startup

View File

@ -1,6 +1,9 @@
import re
import time
from random import random
import asyncio
from loguru import logger
from nonebot.adapters.onebot.v11 import (
Bot,
@ -149,9 +152,16 @@ class ChatBot:
logger.debug(f"{message.processed_plain_text}的激活度:{interested_rate}")
# logger.info(f"\033[1;32m[主题识别]\033[0m 使用{global_config.topic_extract}主题: {topic}")
await self.storage.store_message(message, chat, topic[0] if topic else None)
is_mentioned = is_mentioned_bot_in_message(message)
if is_mentioned:
#如果被@等待下文10秒
await asyncio.sleep(10)
logger.info(f"被@,等待下文")
reply_probability = await willing_manager.change_reply_willing_received(
chat_stream=chat,
topic=topic[0] if topic else None,
@ -159,6 +169,8 @@ class ChatBot:
config=global_config,
is_emoji=message.is_emoji,
interested_rate=interested_rate,
)
current_willing = willing_manager.get_willing(chat_stream=chat)

View File

@ -176,6 +176,7 @@ class CQCode:
return None
def translate_image(self) -> Optional[str]:
"""处理图片类型的CQ码返回base64字符串"""
if "url" not in self.params:

View File

@ -177,7 +177,6 @@ class EmojiManager:
logger.error(f"获取表情包失败: {str(e)}")
return None
async def _get_emoji_discription(self, image_base64: str) -> str:
"""获取表情包的标签使用image_manager的描述生成功能"""

View File

@ -6,7 +6,7 @@ from loguru import logger
from ...common.database import Database
from ..memory_system.memory import hippocampus, memory_graph
from ..moods.moods import MoodManager
from ..schedule.schedule_generator import bot_schedule
#from ..schedule.schedule_generator import bot_schedule
from .config import global_config
from .utils import get_embedding, get_recent_group_detailed_plain_text
from .chat_stream import chat_manager
@ -54,10 +54,10 @@ class PromptBuilder:
mood_prompt = mood_manager.get_prompt()
# 日程构建
current_date = time.strftime("%Y-%m-%d", time.localtime())
current_time = time.strftime("%H:%M:%S", time.localtime())
bot_schedule_now_time, bot_schedule_now_activity = bot_schedule.get_current_task()
prompt_date = f'''今天是{current_date},现在是{current_time},你今天的日程是:\n{bot_schedule.today_schedule}\n你现在正在{bot_schedule_now_activity}\n'''
# current_date = time.strftime("%Y-%m-%d", time.localtime())
# current_time = time.strftime("%H:%M:%S", time.localtime())
# bot_schedule_now_time, bot_schedule_now_activity = bot_schedule.get_current_task()
# prompt_date = f'''今天是{current_date},现在是{current_time},你今天的日程是:\n{bot_schedule.today_schedule}\n你现在正在{bot_schedule_now_activity}\n'''
# 知识构建
start_time = time.time()
@ -143,17 +143,19 @@ class PromptBuilder:
else:
prompt_in_group=f"你正在{chat_stream.platform}上和{sender_name}私聊"
if personality_choice < probability_1: # 第一种人格
prompt_personality += f'''{personality[0]}, 你正在浏览qq群,{promt_info_prompt},
现在请你给出日常且口语化的回复平淡一些尽量简短一些{keywords_reaction_prompt}
请注意把握群里的聊天内容不要刻意突出自身学科背景不要回复的太有条理可以有个性'''
现在请你给出日常且口语化的回复{keywords_reaction_prompt}
请注意把握群里的聊天内容回复可以有个性'''
elif personality_choice < probability_1 + probability_2: # 第二种人格
prompt_personality += f'''{personality[1]}, 你正在浏览qq群{promt_info_prompt},
现在请你给出日常且口语化的回复请表现你自己的见解不要一昧迎合尽量简短一些{keywords_reaction_prompt}
你表达自己的见解和观点可以有个性'''
现在请你给出日常且口语化的回复{keywords_reaction_prompt}
注意把握群里的聊天内容回复可以有个性'''
else: # 第三种人格
prompt_personality += f'''{personality[2]}, 你正在浏览qq群{promt_info_prompt},
现在请你给出日常且口语化的回复请表现你自己的见解不要一昧迎合尽量简短一些{keywords_reaction_prompt}
请你表达自己的见解和观点可以有个性'''
现在请你给出日常且口语化的回复{keywords_reaction_prompt}
请注意把握群里的聊天内容回复可以有个性'''
# 中文高手(新加的好玩功能)
prompt_ger = ''
@ -161,16 +163,16 @@ class PromptBuilder:
prompt_ger += '你喜欢用倒装句'
if random.random() < 0.02:
prompt_ger += '你喜欢用反问句'
if random.random() < 0.01:
prompt_ger += '你喜欢用文言文'
#if random.random() < 0.01:
# prompt_ger += '你喜欢用文言文'
# 额外信息要求
extra_info = '''但是记得回复平淡一些,简短一些,尤其注意在没明确提到时不要过多提及自身的背景, 不要直接回复别人发的表情包,记住不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只需要输出回复内容就好,不要输出其他任何内容'''
extra_info = '''尤其注意在没明确提到时不要过多提及自身的背景, 回答平淡一点,不要直接回复别人发的表情包,记住不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只需要输出回复内容就好,不要输出其他任何内容'''
# 合并prompt
prompt = ""
prompt += f"{prompt_info}\n"
prompt += f"{prompt_date}\n"
#prompt += f"{prompt_date}\n"
prompt += f"{chat_talking_prompt}\n"
prompt += f"{prompt_personality}\n"
prompt += f"{prompt_ger}\n"
@ -187,16 +189,16 @@ class PromptBuilder:
else: # 第三种人格
prompt_personality_check = f'''你的网名叫{global_config.BOT_NICKNAME}{personality[2]}, 你正在浏览qq群{promt_info_prompt} {activate_prompt_check} {extra_check_info}'''
prompt_check_if_response = f"{prompt_info}\n{prompt_date}\n{chat_talking_prompt}\n{prompt_personality_check}"
prompt_check_if_response = f"{prompt_info}\n{chat_talking_prompt}\n{prompt_personality_check}"
#{prompt_date}\n
return prompt, prompt_check_if_response
def _build_initiative_prompt_select(self, group_id, probability_1=0.8, probability_2=0.1):
current_date = time.strftime("%Y-%m-%d", time.localtime())
current_time = time.strftime("%H:%M:%S", time.localtime())
bot_schedule_now_time, bot_schedule_now_activity = bot_schedule.get_current_task()
prompt_date = f'''今天是{current_date},现在是{current_time},你今天的日程是:\n{bot_schedule.today_schedule}\n你现在正在{bot_schedule_now_activity}\n'''
#bot_schedule_now_time, bot_schedule_now_activity = bot_schedule.get_current_task()
prompt_date = f'''今天是{current_date},现在是{current_time}\n'''
#,你今天的日程是:\n{bot_schedule.today_schedule}\n你现在正在{bot_schedule_now_activity}
chat_talking_prompt = ''
if group_id:
chat_talking_prompt = get_recent_group_detailed_plain_text(self.db, group_id,

View File

@ -226,10 +226,10 @@ def split_into_sentences_w_remove_punctuation(text: str) -> List[str]:
text_no_1 = ''
for letter in text:
# print(f"当前字符: {letter}")
if letter in ['!', '', '?', '']:
# print(f"当前字符: {letter}, 随机数: {random.random()}")
if random.random() < split_strength:
letter = ''
# if letter in ['!', '', '?', '']:
# # print(f"当前字符: {letter}, 随机数: {random.random()}")
# if random.random() < split_strength:
# letter = ''
if letter in ['', '']:
# print(f"当前字符: {letter}, 随机数: {random.random()}")
if random.random() < 1 - split_strength:

View File

@ -893,6 +893,7 @@ config = driver.config
start_time = time.time()
Database.initialize(
uri=os.getenv("MONGODB_URI"),
host=os.getenv("MONGODB_HOST", "127.0.0.1"),
port=int(os.getenv("MONGODB_PORT", "27017")),
@ -900,6 +901,7 @@ Database.initialize(
username=os.getenv("MONGODB_USERNAME"),
password=os.getenv("MONGODB_PASSWORD"),
auth_source=os.getenv("MONGODB_AUTH_SOURCE"),
)
# 创建记忆图
memory_graph = Memory_graph()

View File

@ -50,7 +50,7 @@ class ScheduleGenerator:
async def generate_daily_schedule(self, target_date: datetime.datetime = None, read_only: bool = False) -> Dict[
str, str]:
return '忘了', None
date_str = target_date.strftime("%Y-%m-%d")
weekday = target_date.strftime("%A")