IMJONEZZ commited on
Commit
6152ad5
·
1 Parent(s): e577af2

space: add /api/probe to verify live Warden generation end-to-end

Browse files
Files changed (1) hide show
  1. space/app.py +31 -1
space/app.py CHANGED
@@ -148,6 +148,36 @@ def whisper() -> dict:
148
  return {"line": random.choice(WHISPERS)}
149
 
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  @router.get("/")
152
  def landing() -> FileResponse:
153
  return FileResponse(STATIC / "index.html")
@@ -292,7 +322,7 @@ if __name__ == "__main__":
292
  fastapi_app.mount("/static", StaticFiles(directory=STATIC), name="static")
293
  # include_router appends; move our routes ahead of gradio's catch-alls.
294
  our = [r for r in fastapi_app.router.routes if getattr(r, "name", "") in {
295
- "status", "whisper", "landing", "play", "pty_bridge",
296
  }]
297
  for r in our:
298
  fastapi_app.router.routes.remove(r)
 
148
  return {"line": random.choice(WHISPERS)}
149
 
150
 
151
+ @router.get("/api/probe")
152
+ def probe(q: str = "A new process woke up in your machine. Greet it in one short line, in voice.") -> dict:
153
+ """Verification/health: ask the live Warden one line through the internal
154
+ llama-server. Confirms generation actually works end-to-end."""
155
+ import time
156
+
157
+ if not warden_ready():
158
+ return {"ok": False, "state": WARDEN_ERR}
159
+ body = json.dumps({
160
+ "messages": [
161
+ {"role": "system", "content": "You are the Warden, the malevolent operating system of SCRYPTOS. Terse, menacing, Unix-flavored."},
162
+ {"role": "user", "content": q},
163
+ ],
164
+ "max_tokens": 60,
165
+ "temperature": 0.6,
166
+ }).encode()
167
+ req = urllib.request.Request(
168
+ f"http://127.0.0.1:{LLAMA_PORT}/v1/chat/completions",
169
+ data=body, headers={"Content-Type": "application/json"},
170
+ )
171
+ t0 = time.time()
172
+ try:
173
+ with urllib.request.urlopen(req, timeout=150) as r:
174
+ data = json.loads(r.read())
175
+ line = data["choices"][0]["message"]["content"].strip()
176
+ return {"ok": True, "line": line, "seconds": round(time.time() - t0, 1)}
177
+ except Exception as err:
178
+ return {"ok": False, "error": f"{type(err).__name__}: {err}"}
179
+
180
+
181
  @router.get("/")
182
  def landing() -> FileResponse:
183
  return FileResponse(STATIC / "index.html")
 
322
  fastapi_app.mount("/static", StaticFiles(directory=STATIC), name="static")
323
  # include_router appends; move our routes ahead of gradio's catch-alls.
324
  our = [r for r in fastapi_app.router.routes if getattr(r, "name", "") in {
325
+ "status", "whisper", "probe", "landing", "play", "pty_bridge",
326
  }]
327
  for r in our:
328
  fastapi_app.router.routes.remove(r)