86 lines
3.3 KiB
Python
86 lines
3.3 KiB
Python
"""Ten-minute real browser / local model session, sampled resource evidence."""
|
|
|
|
import asyncio
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import time
|
|
|
|
from playwright.async_api import async_playwright
|
|
|
|
OUT = pathlib.Path(__file__).resolve().parents[1] / "evidence"
|
|
|
|
|
|
async def main():
|
|
async with async_playwright() as p:
|
|
browser = await p.chromium.launch(
|
|
args=["--no-sandbox", "--autoplay-policy=no-user-gesture-required"]
|
|
)
|
|
context = await browser.new_context(ignore_https_errors=True)
|
|
page = await context.new_page()
|
|
errors = []
|
|
page.on("pageerror", lambda error: errors.append(str(error)))
|
|
await page.goto("https://192.168.200.12:8014")
|
|
await page.wait_for_function(
|
|
"document.querySelector('#status').textContent.includes('就绪')"
|
|
)
|
|
await page.click("#enter")
|
|
await page.wait_for_function(
|
|
"document.querySelector('#status').textContent.includes('正在听')", timeout=40000
|
|
)
|
|
start = time.monotonic()
|
|
samples = []
|
|
for index in range(15):
|
|
text = f"这是第{index + 1}次交谈。请只回复一句不超过十五个字的自然中文。"
|
|
await page.fill("#text", text)
|
|
await page.click("button[type=submit]")
|
|
for _tick in range(4):
|
|
await page.wait_for_timeout(10000)
|
|
state = await page.evaluate("""()=>({status:document.querySelector('#status').textContent,
|
|
videoTime:document.querySelector('#talk').currentTime,
|
|
frames:document.querySelector('#talk').getVideoPlaybackQuality().totalVideoFrames,
|
|
events:window.sampleEvents.slice(-3)})""")
|
|
gpu = subprocess.run(
|
|
[
|
|
"ssh",
|
|
"root@192.168.200.12",
|
|
"nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader,nounits",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
).stdout.strip()
|
|
sample = dict(
|
|
elapsed=round(time.monotonic() - start, 2), turn=index + 1, state=state, gpu=gpu
|
|
)
|
|
samples.append(sample)
|
|
(OUT / "soak-progress.json").write_text(
|
|
json.dumps(samples, ensure_ascii=False, indent=2)
|
|
)
|
|
print(
|
|
"soak",
|
|
index + 1,
|
|
"elapsed",
|
|
round(time.monotonic() - start),
|
|
"status",
|
|
state["status"],
|
|
"gpu",
|
|
gpu,
|
|
flush=True,
|
|
)
|
|
result = dict(
|
|
duration_seconds=round(time.monotonic() - start, 2),
|
|
samples=samples,
|
|
events=await page.evaluate("window.sampleEvents"),
|
|
pageerrors=errors,
|
|
scope="One logical session, peer retired each turn by cancellation design; 15 real LLM/TTS/avatar turns",
|
|
)
|
|
(OUT / "soak.json").write_text(json.dumps(result, ensure_ascii=False, indent=2))
|
|
await page.click("#back")
|
|
await page.wait_for_timeout(4000)
|
|
await browser.close()
|
|
print("SOAK COMPLETE", result["duration_seconds"], len(errors), flush=True)
|
|
|
|
|
|
asyncio.run(main())
|