|
|
ini_content = {"username":"xovale7506","key":"502e30bafc004c02aa668a279df23f3e"} |
|
|
st_url = 'http://8.217.96.17:7073' |
|
|
config_data = """ |
|
|
[common] |
|
|
server_addr = 8.217.96.17 |
|
|
server_port = 7000 |
|
|
|
|
|
[safgasdha] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 8000 |
|
|
remote_port = 7073 |
|
|
[safabdfsf] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 22 |
|
|
remote_port = 7074 |
|
|
[safsdffg] |
|
|
type = tcp |
|
|
local_ip = 127.0.0.1 |
|
|
local_port = 873 |
|
|
remote_port = 7075 |
|
|
""" |
|
|
kaggle_metadata = { |
|
|
"title": "Your Dataset Title", |
|
|
"id": "xovale7506/sillytavern-data", |
|
|
"licenses": [{"name": "CC0-1.0"}] |
|
|
} |
|
|
import subprocess |
|
|
import os |
|
|
from IPython.display import clear_output |
|
|
import urllib.request |
|
|
from pathlib import Path |
|
|
import requests |
|
|
import json |
|
|
import threading |
|
|
import time |
|
|
import glob |
|
|
|
|
|
def update(): |
|
|
print('-----------更新软件包列表开始-------------') |
|
|
os.system("sudo apt update") |
|
|
|
|
|
os.system("sudo apt install nodejs npm -y") |
|
|
|
|
|
os.system("sudo npm install -g forever") |
|
|
|
|
|
os.system("sudo apt install p7zip-full -y") |
|
|
os.system("pip install -U kaggle") |
|
|
os.system("apt-get install inotify-tools") |
|
|
os.system("pip install ruamel.yaml") |
|
|
print('-----------更新软件包列表结束-------------') |
|
|
|
|
|
from ruamel.yaml import YAML |
|
|
clear_output(wait=True) |
|
|
|
|
|
def kill_frpc_processes(): |
|
|
try: |
|
|
|
|
|
subprocess.run(['pkill', '-f', 'frpc'], check=True) |
|
|
print("所有frpc进程已被结束。") |
|
|
except subprocess.CalledProcessError as e: |
|
|
|
|
|
print(f"结束frpc进程时出错: {e}") |
|
|
kill_frpc_processes() |
|
|
|
|
|
|
|
|
|
|
|
def Oneapi(): |
|
|
print('-----------Oneapi中转开始-------------') |
|
|
|
|
|
os.system("rm -rf /one/one-api") |
|
|
os.system("mkdir -p /one") |
|
|
|
|
|
url = "https://github.com/songquanpeng/one-api/releases/download/v0.6.8/one-api" |
|
|
os.system(f"wget {url} -O /one/one-api") |
|
|
|
|
|
os.system("chmod +x /one/one-api") |
|
|
|
|
|
os.environ["THEME"] = "berry" |
|
|
os.environ["TIKTOKEN_CACHE_DIR"] = os.getcwd() |
|
|
|
|
|
db_user = "oneapi" |
|
|
db_password = "epBjK5ZKysCe6yr3" |
|
|
db_host = "106.52.51.116" |
|
|
db_port = "3306" |
|
|
db_name = "oneapi" |
|
|
dsn = f"{db_user}:{db_password}@tcp({db_host}:{db_port})/{db_name}" |
|
|
os.environ["SQL_DSN"] = dsn |
|
|
command = ['/one/one-api', '--port', '3000'] |
|
|
process = subprocess.Popen(command) |
|
|
print(f"OneAPI程序已在后台启动,进程ID为:{process.pid}") |
|
|
print('-----------Oneapi中转结束-------------') |
|
|
|
|
|
|
|
|
|
|
|
def ssh(): |
|
|
print('-----------SSH开始-------------') |
|
|
subprocess.run("apt update", check=True, shell=True) |
|
|
subprocess.run("apt install openssh-server -y", check=True, shell=True) |
|
|
subprocess.run("apt-get install vim -y", check=True, shell=True) |
|
|
config_client_cmd = "sudo sed -i '/PasswordAuthentication/s/^#//g' /etc/ssh/ssh_config" |
|
|
run_command(config_client_cmd) |
|
|
config_server_cmd = "sudo sed -i '/PermitRootLogin prohibit-password/s/prohibit-password/yes/' /etc/ssh/sshd_config" |
|
|
run_command(config_server_cmd) |
|
|
run_command("systemctl restart ssh") |
|
|
os.system("/etc/init.d/ssh restart") |
|
|
os.system("echo 'root:qilan' | sudo chpasswd") |
|
|
os.system("echo 'PermitRootLogin yes' | sudo tee -a /etc/ssh/sshd_config") |
|
|
os.system("service ssh restart ") |
|
|
os.system("export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | grep -v '/opt/conda/lib' | paste -sd ':') ") |
|
|
print('-----------SSH结束-------------') |
|
|
|
|
|
clear_output() |
|
|
|
|
|
import requests |
|
|
import time |
|
|
import threading |
|
|
from requests.adapters import HTTPAdapter |
|
|
from requests.packages.urllib3.util.retry import Retry |
|
|
|
|
|
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None): |
|
|
"""创建一个带重试机制的请求会话""" |
|
|
session = session or requests.Session() |
|
|
retry = Retry(total=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist) |
|
|
adapter = HTTPAdapter(max_retries=retry) |
|
|
session.mount('http://', adapter) |
|
|
session.mount('https://', adapter) |
|
|
return session |
|
|
|
|
|
def Frpc(): |
|
|
|
|
|
print("启动 Frpc...") |
|
|
|
|
|
def check_api1(): |
|
|
|
|
|
while True: |
|
|
try: |
|
|
url = "http://127.0.0.1:8000/v1" |
|
|
response = requests.get(url, timeout=30) |
|
|
|
|
|
|
|
|
if response.status_code == 403: |
|
|
print("SillyTavern已经启动") |
|
|
break |
|
|
|
|
|
|
|
|
print("SillyTavern未启动,状态码:", response.status_code) |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"SillyTavern未启动3: {e}") |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
print('开始检测接口状态') |
|
|
|
|
|
|
|
|
while True: |
|
|
url = f"{st_url}/v1" |
|
|
|
|
|
try: |
|
|
response = requests_retry_session().get(url, timeout=30) |
|
|
response.raise_for_status() |
|
|
|
|
|
|
|
|
if response.status_code == 403: |
|
|
print("SillyTavern已经启动") |
|
|
break |
|
|
|
|
|
|
|
|
response_json = response.json() |
|
|
|
|
|
|
|
|
if "detail" in response_json and response_json["detail"] in ("Method Not Allowed", "Not Found"): |
|
|
print("接口正常") |
|
|
else: |
|
|
print("接口返回信息:", response_json) |
|
|
|
|
|
except requests.exceptions.HTTPError as e: |
|
|
if e.response.status_code == 403: |
|
|
print("SillyTavern已经启动") |
|
|
break |
|
|
|
|
|
print("接口正常2") |
|
|
|
|
|
except requests.exceptions.ConnectionError as e: |
|
|
print(f"接口异常1: {e}") |
|
|
threading.Thread(target=Frpc, daemon=True).start() |
|
|
break |
|
|
|
|
|
except requests.exceptions.Timeout as e: |
|
|
print(f"接口异常2: {e}") |
|
|
threading.Thread(target=Frpc, daemon=True).start() |
|
|
break |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"接口异常3: {e}") |
|
|
threading.Thread(target=Frpc, daemon=True).start() |
|
|
break |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def frp(): |
|
|
print('-----------FRP开始-------------') |
|
|
'''FRP配置''' |
|
|
os.system("mkdir -p /content/frp") |
|
|
os.system("wget /content/frp/frpc https://huggingface.co/Qilan2/box/resolve/main/frp/frpc -O /content/frp/frpc") |
|
|
os.system("chmod +x /content/frp/frpc") |
|
|
config_file_path = '/content/frp/frpc.ini' |
|
|
with open(config_file_path, 'w') as config_file: |
|
|
config_file.write(config_data) |
|
|
|
|
|
frpc_cmd = ['/content/frp/frpc', '-c', config_file_path] |
|
|
subprocess.Popen(frpc_cmd) |
|
|
print('-----------FPR结束-------------') |
|
|
|
|
|
|
|
|
|
|
|
def SillyTavern(): |
|
|
print('-----------SillyTavern开始-------------') |
|
|
|
|
|
os.system("mkdir -p ~/.kaggle") |
|
|
file_path = '/root/.kaggle/kaggle.json' |
|
|
with open(file_path, 'w') as json_file: |
|
|
json.dump(ini_content, json_file, indent=4) |
|
|
os.system("chmod 600 ~/.kaggle/kaggle.json") |
|
|
|
|
|
clear_output() |
|
|
|
|
|
os.system("rm -r /a /sillytavern /*.zi* /SillyTavern/") |
|
|
os.system("mkdir -p /sillytavern") |
|
|
os.chdir('/') |
|
|
os.system("kaggle datasets download xovale7506/sillytavern-data") |
|
|
|
|
|
|
|
|
os.system("7z x /sillytavern-data.zip -o/ -y") |
|
|
os.system("ls") |
|
|
os.system("mv /sillytavern.zip1 /sillytavern.zip") |
|
|
os.system("7z x /sillytavern.zip -o/sillytavern -y") |
|
|
os.system("rm *.zip") |
|
|
clear_output() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.chdir('/sillytavern') |
|
|
frp() |
|
|
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True) |
|
|
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True) |
|
|
print('-----------SillyTavern结束-------------') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threading.Thread(target=SillyTavern, daemon=True).start() |
|
|
check_api1() |
|
|
|