1
This commit is contained in:
SengokuCola
2025-03-05 00:24:46 +08:00
parent e74e128874
commit 4bf425521a
3 changed files with 24 additions and 18 deletions

View File

@@ -145,7 +145,8 @@ class MessageManager:
async def process_group_messages(self, group_id: int): async def process_group_messages(self, group_id: int):
"""处理群消息""" """处理群消息"""
print(f"\033[1;34m[调试]\033[0m 开始处理群{group_id}的消息") # if int(time.time() / 3) == time.time() / 3:
# print(f"\033[1;34m[调试]\033[0m 开始处理群{group_id}的消息")
container = self.get_container(group_id) container = self.get_container(group_id)
if container.has_messages(): if container.has_messages():
#最早的对象,可能是思考消息,也可能是发送消息 #最早的对象,可能是思考消息,也可能是发送消息

View File

@@ -37,9 +37,9 @@ class WillingManager:
current_willing *= 0.15 current_willing *= 0.15
print(f"表情包, 当前意愿: {current_willing}") print(f"表情包, 当前意愿: {current_willing}")
if interested_rate > 0.6: if interested_rate > 0.65:
print(f"兴趣度: {interested_rate}, 当前意愿: {current_willing}") print(f"兴趣度: {interested_rate}, 当前意愿: {current_willing}")
current_willing += interested_rate-0.45 current_willing += interested_rate-0.5
self.group_reply_willing[group_id] = min(current_willing, 3.0) self.group_reply_willing[group_id] = min(current_willing, 3.0)

View File

@@ -3,26 +3,28 @@ import sys
import numpy as np import numpy as np
import requests import requests
import time import time
from nonebot import get_driver from dotenv import load_dotenv
driver = get_driver()
config = driver.config
# 添加项目根目录到 Python 路径 # 添加项目根目录到 Python 路径
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")) root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
sys.path.append(root_path) sys.path.append(root_path)
from src.common.database import Database # 加载根目录下的env.edv文件
from src.plugins.chat.config import llm_config env_path = os.path.join(root_path, ".env.dev")
if not os.path.exists(env_path):
raise FileNotFoundError(f"配置文件不存在: {env_path}")
load_dotenv(env_path)
# 直接配置数据库连接信息 from src.common.database import Database
# 从环境变量获取配置
Database.initialize( Database.initialize(
host= config.MONGODB_HOST, host=os.getenv("MONGODB_HOST", "localhost"),
port= int(config.MONGODB_PORT), port=int(os.getenv("MONGODB_PORT", "27017")),
db_name= config.DATABASE_NAME, db_name=os.getenv("DATABASE_NAME", "maimai"),
username= config.MONGODB_USERNAME, username=os.getenv("MONGODB_USERNAME"),
password= config.MONGODB_PASSWORD, password=os.getenv("MONGODB_PASSWORD"),
auth_source=config.MONGODB_AUTH_SOURCE auth_source=os.getenv("MONGODB_AUTH_SOURCE", "admin")
) )
class KnowledgeLibrary: class KnowledgeLibrary:
@@ -30,6 +32,9 @@ class KnowledgeLibrary:
self.db = Database.get_instance() self.db = Database.get_instance()
self.raw_info_dir = "data/raw_info" self.raw_info_dir = "data/raw_info"
self._ensure_dirs() self._ensure_dirs()
self.api_key = os.getenv("SILICONFLOW_KEY")
if not self.api_key:
raise ValueError("SILICONFLOW_API_KEY 环境变量未设置")
def _ensure_dirs(self): def _ensure_dirs(self):
"""确保必要的目录存在""" """确保必要的目录存在"""
@@ -44,7 +49,7 @@ class KnowledgeLibrary:
"encoding_format": "float" "encoding_format": "float"
} }
headers = { headers = {
"Authorization": f"Bearer {llm_config.SILICONFLOW_API_KEY}", "Authorization": f"Bearer {self.api_key}",
"Content-Type": "application/json" "Content-Type": "application/json"
} }
@@ -74,7 +79,7 @@ class KnowledgeLibrary:
content = f.read() content = f.read()
# 按1024字符分段 # 按1024字符分段
segments = [content[i:i+300] for i in range(0, len(content), 300)] segments = [content[i:i+400] for i in range(0, len(content), 400)]
# 处理每个分段 # 处理每个分段
for segment in segments: for segment in segments: