Files
dfj 40656fd046 Initial commit: OpenCode vLLM autostart plugin and launchers
- Desktop plugin: on-demand vLLM model start, eject, media budgets
- WSL-native twin plugin for WSL project sessions
- Launchers for Qwen3.6 35B-A3B, Qwen3.8 27B (uncensored/fast), Agents-A1
- Config templates, diagnostics, video-processor workaround
2026-11-01 00:18:38 +01:00

34 lines
1.4 KiB
Python

import json, urllib.request, time, sys
BASE = "http://127.0.0.1:8000"
# discover served model
m = json.loads(urllib.request.urlopen(BASE + "/v1/models", timeout=15).read())
MODEL = m["data"][0]["id"]
print("model:", MODEL)
def ask(prompt, n=128, temperature=0.7):
body = json.dumps({
"model": MODEL, "messages": [{"role": "user", "content": prompt}],
"max_tokens": n, "temperature": temperature,
"chat_template_kwargs": {"enable_thinking": False},
}).encode()
req = urllib.request.Request(BASE + "/v1/chat/completions", data=body,
headers={"Content-Type": "application/json"})
t0 = time.time()
r = urllib.request.urlopen(req, timeout=300)
dt = time.time() - t0
j = json.loads(r.read())
return dt, j["usage"]["completion_tokens"], j["choices"][0]["message"].get("content")
# warm
dt, tok, _ = ask("Hi", 8)
print(f"warmup : {dt:.2f}s {tok}tok")
for label, prompt, n in [
("chat ", "Write a short paragraph about why the sky is blue.", 120),
("code ", "Write a Python function `fib(n)` with a docstring and a usage example. Concise.", 200),
("json ", 'Return JSON only: {"name": "...", "age": 0, "city": "..."} for a fictional person named Ada.', 120),
]:
dt, tok, txt = ask(prompt, n)
print(f"{label}: {dt:5.2f}s {tok:3d}tok -> {tok/dt:6.1f} tok/s")
print(" ", (txt or "")[:160].replace("\n", " "))