Merge pull request #96 from jiajiu123/debug
feat: Windows 部署脚本,toml 格式检测;chore: 文件结构
This commit is contained in:
@@ -3,4 +3,6 @@ __pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
mongodb
|
||||
napcat
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -19,6 +19,8 @@ __pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
llm_statistics.txt
|
||||
mongodb
|
||||
napcat
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
输入消息,推理内容,flag,username,timestamp
|
||||
显示内容,,,,2025-02-18 16:50:53.643238
|
||||
|
6
run.bat
Normal file
6
run.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
chcp 65001
|
||||
REM python -m venv venv
|
||||
call venv\Scripts\activate.bat
|
||||
REM pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple --upgrade -r requirements.txt
|
||||
python run.py
|
||||
122
run.py
Normal file
122
run.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import subprocess
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def extract_files(zip_path, target_dir):
|
||||
"""
|
||||
解压
|
||||
|
||||
Args:
|
||||
zip_path: 源ZIP压缩包路径(需确保是有效压缩包)
|
||||
target_dir: 目标文件夹路径(会自动创建不存在的目录)
|
||||
"""
|
||||
# 打开ZIP压缩包(上下文管理器自动处理关闭)
|
||||
with zipfile.ZipFile(zip_path) as zip_ref:
|
||||
# 通过第一个文件路径推断顶层目录名(格式如:top_dir/)
|
||||
top_dir = zip_ref.namelist()[0].split("/")[0] + "/"
|
||||
|
||||
# 遍历压缩包内所有文件条目
|
||||
for file in zip_ref.namelist():
|
||||
# 跳过目录条目,仅处理文件
|
||||
if file.startswith(top_dir) and not file.endswith("/"):
|
||||
# 截取顶层目录后的相对路径(如:sub_dir/file.txt)
|
||||
rel_path = file[len(top_dir) :]
|
||||
|
||||
# 创建目标目录结构(含多级目录)
|
||||
os.makedirs(
|
||||
os.path.dirname(f"{target_dir}/{rel_path}"),
|
||||
exist_ok=True, # 忽略已存在目录的错误
|
||||
)
|
||||
|
||||
# 读取压缩包内文件内容并写入目标路径
|
||||
with open(f"{target_dir}/{rel_path}", "wb") as f:
|
||||
f.write(zip_ref.read(file))
|
||||
|
||||
|
||||
def run_cmd(command: str, open_new_window: bool = False):
|
||||
"""
|
||||
运行 cmd 命令
|
||||
|
||||
Args:
|
||||
command (str): 指定要运行的命令
|
||||
open_new_window (bool): 指定是否新建一个 cmd 窗口运行
|
||||
"""
|
||||
creationflags = 0
|
||||
if open_new_window:
|
||||
creationflags = subprocess.CREATE_NEW_CONSOLE
|
||||
subprocess.Popen(
|
||||
[
|
||||
"cmd.exe",
|
||||
"/c",
|
||||
command,
|
||||
],
|
||||
creationflags=creationflags,
|
||||
)
|
||||
|
||||
|
||||
def run_maimbot():
|
||||
run_cmd(r"napcat\NapCatWinBootMain.exe 10001", False)
|
||||
run_cmd(
|
||||
r"mongodb\bin\mongod.exe --dbpath=" + os.getcwd() + r"\mongodb\db --port 27017",
|
||||
True,
|
||||
)
|
||||
run_cmd("nb run", True)
|
||||
|
||||
|
||||
def install_mongodb():
|
||||
"""
|
||||
安装 MongoDB
|
||||
"""
|
||||
print("下载 MongoDB")
|
||||
resp = requests.get(
|
||||
"https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-latest.zip",
|
||||
stream=True,
|
||||
)
|
||||
total = int(resp.headers.get("content-length", 0)) # 计算文件大小
|
||||
with open("mongodb.zip", "w+b") as file, tqdm( # 展示下载进度条,并解压文件
|
||||
desc="mongodb.zip",
|
||||
total=total,
|
||||
unit="iB",
|
||||
unit_scale=True,
|
||||
unit_divisor=1024,
|
||||
) as bar:
|
||||
for data in resp.iter_content(chunk_size=1024):
|
||||
size = file.write(data)
|
||||
bar.update(size)
|
||||
extract_files("mongodb.zip", "mongodb")
|
||||
print("MongoDB 下载完成")
|
||||
os.remove("mongodb.zip")
|
||||
|
||||
|
||||
def install_napcat():
|
||||
run_cmd("start https://github.com/NapNeko/NapCatQQ/releases", True)
|
||||
print("请检查弹出的浏览器窗口,点击**第一个**蓝色的“Win64无头” 下载 napcat")
|
||||
napcat_filename = input(
|
||||
"下载完成后请把文件复制到此文件夹,并将**不包含后缀的文件名**输入至此窗口,如 NapCat.32793.Shell:"
|
||||
)
|
||||
extract_files(napcat_filename + ".zip", "napcat")
|
||||
print("NapCat 安装完成")
|
||||
os.remove(napcat_filename + ".zip")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.system("cls")
|
||||
choice = input(
|
||||
"请输入要进行的操作:\n"
|
||||
"1.首次安装\n"
|
||||
"2.运行麦麦\n"
|
||||
"3.运行麦麦并启动可视化推理界面\n"
|
||||
)
|
||||
os.system("cls")
|
||||
if choice == "1":
|
||||
install_napcat()
|
||||
install_mongodb()
|
||||
elif choice == "2":
|
||||
run_maimbot()
|
||||
elif choice == "3":
|
||||
run_maimbot()
|
||||
run_cmd("python src/gui/reasoning_gui.py", True)
|
||||
@@ -85,7 +85,11 @@ class BotConfig:
|
||||
config = cls()
|
||||
if os.path.exists(config_path):
|
||||
with open(config_path, "rb") as f:
|
||||
toml_dict = tomli.load(f)
|
||||
try:
|
||||
toml_dict = tomli.load(f)
|
||||
except(tomli.TOMLDecodeError) as e:
|
||||
logger.critical(f"配置文件bot_config.toml填写有误,请检查第{e.lineno}行第{e.colno}处:{e.msg}")
|
||||
exit(1)
|
||||
|
||||
if 'personality' in toml_dict:
|
||||
personality_config=toml_dict['personality']
|
||||
|
||||
Reference in New Issue
Block a user