mirror of
https://git.squeakyrat.moe/faggot-chan/
synced 2026-11-05 02:45:45 +01:00
no one reads this
This commit is contained in:
1 parent
49ea1dd86f
commit
bdd7d1f57c
1 file changed
+21
-25
+21
-25
@@ -1,11 +1,9 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#all of this is vibecoded but i read it and it's okay
|
|
||||||
"""
|
"""
|
||||||
run this in a colab cell to stand up main.py + a public wss:// tunnel to it.
|
run this in a colab cell to stand up main.py + a public wss:// tunnel to it.
|
||||||
session is ephemeral — restart the notebook, get a new url, re-paste it
|
session is ephemeral — restart the notebook, get a new url, re-paste it
|
||||||
into your bot.py-side config/connection.txt.
|
into your bot.py-side config/connection.txt.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
@@ -56,16 +54,13 @@ def ensure_auth_token() -> str:
|
|||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
def ensure_params_and_prompt():
|
def ensure_params():
|
||||||
# main.py needs both of these to exist — if this is a fresh colab instance
|
# main.py is stateless — system_prompt comes over the wire in every payload from bot.py.
|
||||||
# and you haven't uploaded them yet, stop here and add them first.
|
# params.json is the one thing it actually reads off its own disk (ollama.chat options
|
||||||
|
# aren't sent in the payload), so that's the only file that has to exist here.
|
||||||
params_file = CONFIG_DIR / "params.json"
|
params_file = CONFIG_DIR / "params.json"
|
||||||
prompt_file = CONFIG_DIR / "system_prompt.txt"
|
if not params_file.exists():
|
||||||
missing = [f.name for f in (params_file, prompt_file) if not f.exists()]
|
raise SystemExit(f"missing params.json in {CONFIG_DIR} — upload it before running this")
|
||||||
if missing:
|
|
||||||
raise SystemExit(
|
|
||||||
f"missing {', '.join(missing)} in {CONFIG_DIR} — upload them before running this"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def start_main():
|
def start_main():
|
||||||
@@ -82,44 +77,45 @@ def start_tunnel() -> str:
|
|||||||
run("dpkg -i cloudflared.deb")
|
run("dpkg -i cloudflared.deb")
|
||||||
|
|
||||||
print("\n-- opening tunnel to localhost:8765 --")
|
print("\n-- opening tunnel to localhost:8765 --")
|
||||||
proc = subprocess.Popen(
|
# logging to a real file instead of a PIPE — a pipe's read end lives in this python
|
||||||
|
# process, so once this script exits the pipe's reader disappears and cloudflared
|
||||||
|
# gets SIGPIPE on its next log write and dies. a file has no reader to lose.
|
||||||
|
log_path = SCRIPT_DIR / "cloudflared.log"
|
||||||
|
log_file = open(log_path, "w")
|
||||||
|
subprocess.Popen(
|
||||||
"cloudflared tunnel --url http://localhost:8765",
|
"cloudflared tunnel --url http://localhost:8765",
|
||||||
shell=True,
|
shell=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=log_file,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True,
|
|
||||||
bufsize=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
url = None
|
url = None
|
||||||
deadline = time.time() + 30
|
deadline = time.time() + 30
|
||||||
for line in proc.stdout:
|
while time.time() < deadline:
|
||||||
print(line, end="")
|
text = log_path.read_text(encoding="utf-8", errors="ignore")
|
||||||
match = re.search(r"https://[a-zA-Z0-9\-]+\.trycloudflare\.com", line)
|
match = re.search(r"https://[a-zA-Z0-9\-]+\.trycloudflare\.com", text)
|
||||||
if match:
|
if match:
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
break
|
break
|
||||||
if time.time() > deadline:
|
time.sleep(1)
|
||||||
break
|
|
||||||
|
|
||||||
if not url:
|
if not url:
|
||||||
raise SystemExit("couldn't find the tunnel url in cloudflared's output, check the log above")
|
raise SystemExit(f"couldn't find the tunnel url, check {log_path}")
|
||||||
|
|
||||||
wss_url = url.replace("https://", "wss://")
|
return url.replace("https://", "wss://")
|
||||||
return wss_url
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
install_ollama()
|
install_ollama()
|
||||||
pull_models()
|
pull_models()
|
||||||
install_python_deps()
|
install_python_deps()
|
||||||
ensure_params_and_prompt()
|
ensure_params()
|
||||||
token = ensure_auth_token()
|
token = ensure_auth_token()
|
||||||
start_main()
|
start_main()
|
||||||
time.sleep(3) # let main.py bind its port before the tunnel tries to reach it
|
time.sleep(3) # let main.py bind its port before the tunnel tries to reach it
|
||||||
wss_url = start_tunnel()
|
wss_url = start_tunnel()
|
||||||
|
|
||||||
print("\n" + "=" * 60) #wtf is this shit claude
|
print("\n" + "=" * 60)
|
||||||
print("paste these into setup_wizard.py on the bot.py side:")
|
print("paste these into setup_wizard.py on the bot.py side:")
|
||||||
print(f" address: {wss_url}")
|
print(f" address: {wss_url}")
|
||||||
print(f" token: {token}")
|
print(f" token: {token}")
|
||||||
|
|||||||
Reference in new issue
Block a user