mirror of https://github.com/Mai-with-u/MaiBot.git
commit
7bd6f54236
|
|
@ -89,6 +89,7 @@ class ChatBot:
|
||||||
group_id=event.group_id,
|
group_id=event.group_id,
|
||||||
user_id=event.user_id,
|
user_id=event.user_id,
|
||||||
message_id=event.message_id,
|
message_id=event.message_id,
|
||||||
|
user_cardname=sender_info['card'],
|
||||||
raw_message=str(event.original_message),
|
raw_message=str(event.original_message),
|
||||||
plain_text=event.get_plaintext(),
|
plain_text=event.get_plaintext(),
|
||||||
reply_message=event.reply,
|
reply_message=event.reply,
|
||||||
|
|
@ -145,6 +146,9 @@ class ChatBot:
|
||||||
willing_manager.change_reply_willing_sent(thinking_message.group_id)
|
willing_manager.change_reply_willing_sent(thinking_message.group_id)
|
||||||
|
|
||||||
response, emotion = await self.gpt.generate_response(message)
|
response, emotion = await self.gpt.generate_response(message)
|
||||||
|
|
||||||
|
if response is None:
|
||||||
|
thinking_message.interupt=True
|
||||||
|
|
||||||
# 如果生成了回复,发送并记录
|
# 如果生成了回复,发送并记录
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,13 @@ class BotConfig:
|
||||||
|
|
||||||
enable_advance_output: bool = False # 是否启用高级输出
|
enable_advance_output: bool = False # 是否启用高级输出
|
||||||
enable_kuuki_read: bool = True # 是否启用读空气功能
|
enable_kuuki_read: bool = True # 是否启用读空气功能
|
||||||
|
|
||||||
|
# 默认人设
|
||||||
|
PROMPT_PERSONALITY=[
|
||||||
|
"曾经是一个学习地质的女大学生,现在学习心理学和脑科学,你会刷贴吧,你正在浏览qq群",
|
||||||
|
"是一个女大学生,你有黑色头发,你会刷小红书, 你正在浏览qq群"
|
||||||
|
]
|
||||||
|
PROMPT_SCHEDULE_GEN="一个曾经学习地质,现在学习心理学和脑科学的女大学生,喜欢刷qq,贴吧,知乎和小红书"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_config_dir() -> str:
|
def get_config_dir() -> str:
|
||||||
|
|
|
||||||
|
|
@ -50,12 +50,19 @@ class ResponseGenerator:
|
||||||
model_response, emotion = await self._process_response(model_response)
|
model_response, emotion = await self._process_response(model_response)
|
||||||
if model_response:
|
if model_response:
|
||||||
print(f"为 '{model_response}' 获取到的情感标签为:{emotion}")
|
print(f"为 '{model_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]])
|
||||||
|
|
||||||
return model_response, emotion
|
return model_response, emotion
|
||||||
return None, []
|
return None, []
|
||||||
|
|
||||||
async def _generate_response_with_model(self, message: Message, model: LLM_request) -> Optional[str]:
|
async def _generate_response_with_model(self, message: Message, model: LLM_request) -> Optional[str]:
|
||||||
"""使用指定的模型生成回复"""
|
"""使用指定的模型生成回复"""
|
||||||
sender_name = message.user_nickname or f"用户{message.user_id}"
|
sender_name = message.user_nickname or f"用户{message.user_id}"
|
||||||
|
if message.user_cardname:
|
||||||
|
sender_name=f"[({message.user_id}){message.user_nickname}]{message.user_cardname}"
|
||||||
|
|
||||||
# 获取关系值
|
# 获取关系值
|
||||||
relationship_value = relationship_manager.get_relationship(message.user_id).relationship_value if relationship_manager.get_relationship(message.user_id) else 0.0
|
relationship_value = relationship_manager.get_relationship(message.user_id).relationship_value if relationship_manager.get_relationship(message.user_id) else 0.0
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from ...common.database import Database
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from .config import global_config
|
from .config import global_config
|
||||||
import urllib3
|
import urllib3
|
||||||
from .utils_user import get_user_nickname
|
from .utils_user import get_user_nickname,get_user_cardname
|
||||||
from .utils_cq import parse_cq_code
|
from .utils_cq import parse_cq_code
|
||||||
from .cq_code import cq_code_tool,CQCode
|
from .cq_code import cq_code_tool,CQCode
|
||||||
|
|
||||||
|
|
@ -27,6 +27,7 @@ class Message:
|
||||||
group_id: int = None
|
group_id: int = None
|
||||||
user_id: int = None
|
user_id: int = None
|
||||||
user_nickname: str = None # 用户昵称
|
user_nickname: str = None # 用户昵称
|
||||||
|
user_cardname: str=None # 用户群昵称
|
||||||
group_name: str = None # 群名称
|
group_name: str = None # 群名称
|
||||||
|
|
||||||
message_id: int = None
|
message_id: int = None
|
||||||
|
|
@ -58,6 +59,8 @@ class Message:
|
||||||
|
|
||||||
if not self.user_nickname:
|
if not self.user_nickname:
|
||||||
self.user_nickname = get_user_nickname(self.user_id)
|
self.user_nickname = get_user_nickname(self.user_id)
|
||||||
|
if not self.user_cardname:
|
||||||
|
self.user_cardname=get_user_cardname(self.user_id)
|
||||||
|
|
||||||
if not self.group_name:
|
if not self.group_name:
|
||||||
self.group_name = self.get_groupname(self.group_id)
|
self.group_name = self.get_groupname(self.group_id)
|
||||||
|
|
@ -71,7 +74,10 @@ class Message:
|
||||||
)
|
)
|
||||||
#将详细翻译为详细可读文本
|
#将详细翻译为详细可读文本
|
||||||
time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.time))
|
time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.time))
|
||||||
name = self.user_nickname or f"用户{self.user_id}"
|
try:
|
||||||
|
name = f"[({self.user_id}){self.user_nickname}]{self.user_cardname}"
|
||||||
|
except:
|
||||||
|
name = self.user_nickname or f"用户{self.user_id}"
|
||||||
content = self.processed_plain_text
|
content = self.processed_plain_text
|
||||||
self.detailed_plain_text = f"[{time_str}] {name}: {content}\n"
|
self.detailed_plain_text = f"[{time_str}] {name}: {content}\n"
|
||||||
|
|
||||||
|
|
@ -159,6 +165,7 @@ class Message_Thinking:
|
||||||
self.group_id = message.group_id
|
self.group_id = message.group_id
|
||||||
self.user_id = message.user_id
|
self.user_id = message.user_id
|
||||||
self.user_nickname = message.user_nickname
|
self.user_nickname = message.user_nickname
|
||||||
|
self.user_cardname = message.user_cardname
|
||||||
self.group_name = message.group_name
|
self.group_name = message.group_name
|
||||||
|
|
||||||
self.message_id = message_id
|
self.message_id = message_id
|
||||||
|
|
@ -167,6 +174,7 @@ class Message_Thinking:
|
||||||
self.thinking_text = "正在思考..."
|
self.thinking_text = "正在思考..."
|
||||||
self.time = int(time.time())
|
self.time = int(time.time())
|
||||||
self.thinking_time = 0
|
self.thinking_time = 0
|
||||||
|
self.interupt=False
|
||||||
|
|
||||||
def update_thinking_time(self):
|
def update_thinking_time(self):
|
||||||
self.thinking_time = round(time.time(), 2) - self.time
|
self.thinking_time = round(time.time(), 2) - self.time
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,11 @@ class MessageSendControl:
|
||||||
if isinstance(message, Message_Thinking):
|
if isinstance(message, Message_Thinking):
|
||||||
message.update_thinking_time()
|
message.update_thinking_time()
|
||||||
thinking_time = message.thinking_time
|
thinking_time = message.thinking_time
|
||||||
if thinking_time < 90: # 最少思考2秒
|
if message.interupt:
|
||||||
|
print(f"\033[1;34m[调试]\033[0m 思考不打算回复,移除")
|
||||||
|
queue.get_earliest_message()
|
||||||
|
return
|
||||||
|
elif thinking_time < 90: # 最少思考2秒
|
||||||
if int(thinking_time) % 15 == 0:
|
if int(thinking_time) % 15 == 0:
|
||||||
print(f"\033[1;34m[调试]\033[0m 消息正在思考中,已思考{thinking_time:.1f}秒")
|
print(f"\033[1;34m[调试]\033[0m 消息正在思考中,已思考{thinking_time:.1f}秒")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ class MessageStream:
|
||||||
"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg.time)),
|
"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(msg.time)),
|
||||||
"user_id": msg.user_id,
|
"user_id": msg.user_id,
|
||||||
"user_nickname": msg.user_nickname,
|
"user_nickname": msg.user_nickname,
|
||||||
|
"user_cardname": msg.user_cardname,
|
||||||
"message_id": msg.message_id,
|
"message_id": msg.message_id,
|
||||||
"raw_message": msg.raw_message,
|
"raw_message": msg.raw_message,
|
||||||
"processed_text": msg.processed_plain_text
|
"processed_text": msg.processed_plain_text
|
||||||
|
|
@ -126,14 +127,15 @@ class MessageStream:
|
||||||
# 从数据库中查询最近的消息
|
# 从数据库中查询最近的消息
|
||||||
recent_messages = list(db.db.messages.find(
|
recent_messages = list(db.db.messages.find(
|
||||||
{"group_id": self.group_id},
|
{"group_id": self.group_id},
|
||||||
{
|
# {
|
||||||
"time": 1,
|
# "time": 1,
|
||||||
"user_id": 1,
|
# "user_id": 1,
|
||||||
"user_nickname": 1,
|
# "user_nickname": 1,
|
||||||
"message_id": 1,
|
# # "user_cardname": 1,
|
||||||
"raw_message": 1,
|
# "message_id": 1,
|
||||||
"processed_text": 1
|
# "raw_message": 1,
|
||||||
}
|
# "processed_text": 1
|
||||||
|
# }
|
||||||
).sort("time", -1).limit(count))
|
).sort("time", -1).limit(count))
|
||||||
|
|
||||||
if not recent_messages:
|
if not recent_messages:
|
||||||
|
|
@ -143,16 +145,21 @@ class MessageStream:
|
||||||
from .message import Message
|
from .message import Message
|
||||||
messages = []
|
messages = []
|
||||||
for msg_data in recent_messages:
|
for msg_data in recent_messages:
|
||||||
msg = Message(
|
try:
|
||||||
time=msg_data["time"],
|
msg = Message(
|
||||||
user_id=msg_data["user_id"],
|
time=msg_data["time"],
|
||||||
user_nickname=msg_data.get("user_nickname", ""),
|
user_id=msg_data["user_id"],
|
||||||
message_id=msg_data["message_id"],
|
user_nickname=msg_data.get("user_nickname", ""),
|
||||||
raw_message=msg_data["raw_message"],
|
user_cardname=msg_data.get("user_cardname", ""),
|
||||||
processed_plain_text=msg_data.get("processed_text", ""),
|
message_id=msg_data["message_id"],
|
||||||
group_id=self.group_id
|
raw_message=msg_data["raw_message"],
|
||||||
)
|
processed_plain_text=msg_data.get("processed_text", ""),
|
||||||
messages.append(msg)
|
group_id=self.group_id
|
||||||
|
)
|
||||||
|
messages.append(msg)
|
||||||
|
except KeyError:
|
||||||
|
print("[WARNING] 数据库中存在无效的消息")
|
||||||
|
continue
|
||||||
|
|
||||||
return list(reversed(messages)) # 返回按时间正序的消息
|
return list(reversed(messages)) # 返回按时间正序的消息
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,14 +147,15 @@ class PromptBuilder:
|
||||||
is_bot_prompt = ''
|
is_bot_prompt = ''
|
||||||
|
|
||||||
#人格选择
|
#人格选择
|
||||||
|
personality=global_config.PROMPT_PERSONALITY
|
||||||
prompt_personality = ''
|
prompt_personality = ''
|
||||||
personality_choice = random.random()
|
personality_choice = random.random()
|
||||||
if personality_choice < 4/6: # 第一种人格
|
if personality_choice < 4/6: # 第一种人格
|
||||||
prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},现在学习心理学和脑科学,你会刷贴吧,你正在浏览qq群,{promt_info_prompt},
|
prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},{personality[0]},{promt_info_prompt},
|
||||||
现在请你给出日常且口语化的回复,平淡一些,尽量简短一些。{is_bot_prompt}
|
现在请你给出日常且口语化的回复,平淡一些,尽量简短一些。{is_bot_prompt}
|
||||||
请注意把握群里的聊天内容,不要刻意突出自身学科背景,不要回复的太有条理,可以有个性。'''
|
请注意把握群里的聊天内容,不要刻意突出自身学科背景,不要回复的太有条理,可以有个性。'''
|
||||||
elif personality_choice < 1: # 第二种人格
|
elif personality_choice < 1: # 第二种人格
|
||||||
prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},是一个女大学生,你有黑色头发,你会刷小红书, 你正在浏览qq群,{promt_info_prompt},
|
prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},{personality[1]},{promt_info_prompt},
|
||||||
|
|
||||||
现在请你给出日常且口语化的回复,请表现你自己的见解,不要一昧迎合,尽量简短一些。{is_bot_prompt}
|
现在请你给出日常且口语化的回复,请表现你自己的见解,不要一昧迎合,尽量简短一些。{is_bot_prompt}
|
||||||
请你表达自己的见解和观点。可以有个性。'''
|
请你表达自己的见解和观点。可以有个性。'''
|
||||||
|
|
@ -170,7 +171,7 @@ class PromptBuilder:
|
||||||
|
|
||||||
|
|
||||||
#额外信息要求
|
#额外信息要求
|
||||||
extra_info = '''但是记得回复平淡一些,简短一些,记住不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只需要输出回复内容就好,不要输出其他任何内容'''
|
extra_info = '''但是记得回复平淡一些,简短一些,尤其注意在没明确提到时不要过多提及自身的背景, 记住不要输出多余内容(包括前后缀,冒号和引号,括号,表情等),只需要输出回复内容就好,不要输出其他任何内容'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -195,9 +196,9 @@ class PromptBuilder:
|
||||||
prompt_personality_check = ''
|
prompt_personality_check = ''
|
||||||
extra_check_info=f"请注意把握群里的聊天内容的基础上,综合群内的氛围,例如,和{global_config.BOT_NICKNAME}相关的话题要积极回复,如果是at自己的消息一定要回复,如果自己正在和别人聊天一定要回复,其他话题如果合适搭话也可以回复,如果认为应该回复请输出yes,否则输出no,请注意是决定是否需要回复,而不是编写回复内容,除了yes和no不要输出任何回复内容。"
|
extra_check_info=f"请注意把握群里的聊天内容的基础上,综合群内的氛围,例如,和{global_config.BOT_NICKNAME}相关的话题要积极回复,如果是at自己的消息一定要回复,如果自己正在和别人聊天一定要回复,其他话题如果合适搭话也可以回复,如果认为应该回复请输出yes,否则输出no,请注意是决定是否需要回复,而不是编写回复内容,除了yes和no不要输出任何回复内容。"
|
||||||
if personality_choice < 4/6: # 第一种人格
|
if personality_choice < 4/6: # 第一种人格
|
||||||
prompt_personality_check = f'''你的网名叫{global_config.BOT_NICKNAME},曾经是一个学习地质的女大学生,现在学习心理学和脑科学,你会刷贴吧,你正在浏览qq群,{promt_info_prompt} {activate_prompt_check} {extra_check_info}'''
|
prompt_personality_check = f'''你的网名叫{global_config.BOT_NICKNAME},{personality[0]},{promt_info_prompt} {activate_prompt_check} {extra_check_info}'''
|
||||||
elif personality_choice < 1: # 第二种人格
|
elif personality_choice < 1: # 第二种人格
|
||||||
prompt_personality_check = f'''你的网名叫{global_config.BOT_NICKNAME},是一个女大学生,你有黑色头发,你会刷小红书, 你正在浏览qq群,{promt_info_prompt} {activate_prompt_check} {extra_check_info}'''
|
prompt_personality_check = f'''你的网名叫{global_config.BOT_NICKNAME},{personality[1]},{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{prompt_date}\n{chat_talking_prompt}\n{prompt_personality_check}"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ class MessageStorage:
|
||||||
"processed_plain_text": message.processed_plain_text,
|
"processed_plain_text": message.processed_plain_text,
|
||||||
"time": message.time,
|
"time": message.time,
|
||||||
"user_nickname": message.user_nickname,
|
"user_nickname": message.user_nickname,
|
||||||
|
"user_cardname": message.user_cardname,
|
||||||
"group_name": message.group_name,
|
"group_name": message.group_name,
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
"detailed_plain_text": message.detailed_plain_text,
|
"detailed_plain_text": message.detailed_plain_text,
|
||||||
|
|
@ -37,6 +38,7 @@ class MessageStorage:
|
||||||
"processed_plain_text": '[表情包]',
|
"processed_plain_text": '[表情包]',
|
||||||
"time": message.time,
|
"time": message.time,
|
||||||
"user_nickname": message.user_nickname,
|
"user_nickname": message.user_nickname,
|
||||||
|
"user_cardname": message.user_cardname,
|
||||||
"group_name": message.group_name,
|
"group_name": message.group_name,
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
"detailed_plain_text": message.detailed_plain_text,
|
"detailed_plain_text": message.detailed_plain_text,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,10 @@ def combine_messages(messages: List[Message]) -> str:
|
||||||
def db_message_to_str (message_dict: Dict) -> str:
|
def db_message_to_str (message_dict: Dict) -> str:
|
||||||
print(f"message_dict: {message_dict}")
|
print(f"message_dict: {message_dict}")
|
||||||
time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(message_dict["time"]))
|
time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(message_dict["time"]))
|
||||||
name = message_dict.get("user_nickname", "") or f"用户{message_dict['user_id']}"
|
try:
|
||||||
|
name="[(%s)%s]%s" % (message_dict['user_id'],message_dict.get("user_nickname", ""),message_dict.get("user_cardname", ""))
|
||||||
|
except:
|
||||||
|
name = message_dict.get("user_nickname", "") or f"用户{message_dict['user_id']}"
|
||||||
content = message_dict.get("processed_plain_text", "")
|
content = message_dict.get("processed_plain_text", "")
|
||||||
result = f"[{time_str}] {name}: {content}\n"
|
result = f"[{time_str}] {name}: {content}\n"
|
||||||
print(f"result: {result}")
|
print(f"result: {result}")
|
||||||
|
|
@ -114,7 +117,11 @@ def get_cloest_chat_from_db(db, length: int, timestamp: str):
|
||||||
chat_record = list(db.db.messages.find({"time": {"$gt": closest_time}, "group_id": group_id}).sort('time', 1).limit(length))
|
chat_record = list(db.db.messages.find({"time": {"$gt": closest_time}, "group_id": group_id}).sort('time', 1).limit(length))
|
||||||
for record in chat_record:
|
for record in chat_record:
|
||||||
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
||||||
chat_text += f'[{time_str}] {record["user_nickname"] or "用户" + str(record["user_id"])}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
try:
|
||||||
|
displayname="[(%s)%s]%s" % (record["user_id"],record["user_nickname"],record["user_cardname"])
|
||||||
|
except:
|
||||||
|
displayname=record["user_nickname"] or "用户" + str(record["user_id"])
|
||||||
|
chat_text += f'[{time_str}] {displayname}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
||||||
return chat_text
|
return chat_text
|
||||||
|
|
||||||
return [] # 如果没有找到记录,返回空列表
|
return [] # 如果没有找到记录,返回空列表
|
||||||
|
|
@ -135,14 +142,14 @@ def get_recent_group_messages(db, group_id: int, limit: int = 12) -> list:
|
||||||
# 从数据库获取最近消息
|
# 从数据库获取最近消息
|
||||||
recent_messages = list(db.db.messages.find(
|
recent_messages = list(db.db.messages.find(
|
||||||
{"group_id": group_id},
|
{"group_id": group_id},
|
||||||
{
|
# {
|
||||||
"time": 1,
|
# "time": 1,
|
||||||
"user_id": 1,
|
# "user_id": 1,
|
||||||
"user_nickname": 1,
|
# "user_nickname": 1,
|
||||||
"message_id": 1,
|
# "message_id": 1,
|
||||||
"raw_message": 1,
|
# "raw_message": 1,
|
||||||
"processed_text": 1
|
# "processed_text": 1
|
||||||
}
|
# }
|
||||||
).sort("time", -1).limit(limit))
|
).sort("time", -1).limit(limit))
|
||||||
|
|
||||||
if not recent_messages:
|
if not recent_messages:
|
||||||
|
|
@ -152,16 +159,20 @@ def get_recent_group_messages(db, group_id: int, limit: int = 12) -> list:
|
||||||
from .message import Message
|
from .message import Message
|
||||||
message_objects = []
|
message_objects = []
|
||||||
for msg_data in recent_messages:
|
for msg_data in recent_messages:
|
||||||
msg = Message(
|
try:
|
||||||
time=msg_data["time"],
|
msg = Message(
|
||||||
user_id=msg_data["user_id"],
|
time=msg_data["time"],
|
||||||
user_nickname=msg_data.get("user_nickname", ""),
|
user_id=msg_data["user_id"],
|
||||||
message_id=msg_data["message_id"],
|
user_nickname=msg_data.get("user_nickname", ""),
|
||||||
raw_message=msg_data["raw_message"],
|
message_id=msg_data["message_id"],
|
||||||
processed_plain_text=msg_data.get("processed_text", ""),
|
raw_message=msg_data["raw_message"],
|
||||||
group_id=group_id
|
processed_plain_text=msg_data.get("processed_text", ""),
|
||||||
)
|
group_id=group_id
|
||||||
message_objects.append(msg)
|
)
|
||||||
|
message_objects.append(msg)
|
||||||
|
except KeyError:
|
||||||
|
print("[WARNING] 数据库中存在无效的消息")
|
||||||
|
continue
|
||||||
|
|
||||||
# 按时间正序排列
|
# 按时间正序排列
|
||||||
message_objects.reverse()
|
message_objects.reverse()
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,9 @@ def get_user_nickname(user_id: int) -> str:
|
||||||
if int(user_id) == int(global_config.BOT_QQ):
|
if int(user_id) == int(global_config.BOT_QQ):
|
||||||
return global_config.BOT_NICKNAME
|
return global_config.BOT_NICKNAME
|
||||||
# print(user_id)
|
# print(user_id)
|
||||||
return relationship_manager.get_name(user_id)
|
return relationship_manager.get_name(user_id)
|
||||||
|
def get_user_cardname(user_id: int) -> str:
|
||||||
|
if int(user_id) == int(global_config.BOT_QQ):
|
||||||
|
return global_config.BOT_NICKNAME
|
||||||
|
# print(user_id)
|
||||||
|
return ''
|
||||||
|
|
@ -177,7 +177,11 @@ class Memory_graph:
|
||||||
chat_record = list(self.db.db.messages.find({"time": {"$gt": closest_time}, "group_id": group_id}).sort('time', 1).limit(length))
|
chat_record = list(self.db.db.messages.find({"time": {"$gt": closest_time}, "group_id": group_id}).sort('time', 1).limit(length))
|
||||||
for record in chat_record:
|
for record in chat_record:
|
||||||
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
||||||
chat_text += f'[{time_str}] {record["user_nickname"] or "用户" + str(record["user_id"])}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
try:
|
||||||
|
displayname="[(%s)%s]%s" % (record["user_id"],record["user_nickname"],record["user_cardname"])
|
||||||
|
except:
|
||||||
|
displayname=record["user_nickname"] or "用户" + str(record["user_id"])
|
||||||
|
chat_text += f'[{time_str}] {displayname}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
||||||
return chat_text
|
return chat_text
|
||||||
|
|
||||||
return [] # 如果没有找到记录,返回空列表
|
return [] # 如果没有找到记录,返回空列表
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,11 @@ class Memory_graph:
|
||||||
for record in chat_record:
|
for record in chat_record:
|
||||||
if record:
|
if record:
|
||||||
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
time_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(record['time'])))
|
||||||
chat_text += f'[{time_str}] {record["user_nickname"] or "用户" + str(record["user_id"])}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
try:
|
||||||
|
displayname="[(%s)%s]%s" % (record["user_id"],record["user_nickname"],record["user_cardname"])
|
||||||
|
except:
|
||||||
|
displayname=record["user_nickname"] or "用户" + str(record["user_id"])
|
||||||
|
chat_text += f'[{time_str}] {displayname}: {record["processed_plain_text"]}\n' # 添加发送者和时间信息
|
||||||
return chat_text
|
return chat_text
|
||||||
|
|
||||||
return [] # 如果没有找到记录,返回空列表
|
return [] # 如果没有找到记录,返回空列表
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class ScheduleGenerator:
|
||||||
|
|
||||||
elif read_only == False:
|
elif read_only == False:
|
||||||
print(f"{date_str}的日程不存在,准备生成新的日程。")
|
print(f"{date_str}的日程不存在,准备生成新的日程。")
|
||||||
prompt = f"""我是{global_config.BOT_NICKNAME},一个曾经学习地质,现在学习心理学和脑科学的女大学生,喜欢刷qq,贴吧,知乎和小红书,请为我生成{date_str}({weekday})的日程安排,包括:
|
prompt = f"""我是{global_config.BOT_NICKNAME},{global_config.PROMPT_SCHEDULE_GEN},请为我生成{date_str}({weekday})的日程安排,包括:
|
||||||
1. 早上的学习和工作安排
|
1. 早上的学习和工作安排
|
||||||
2. 下午的活动和任务
|
2. 下午的活动和任务
|
||||||
3. 晚上的计划和休息时间
|
3. 晚上的计划和休息时间
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue