Spaces:
Sleeping
Sleeping
Adarsh Kumar commited on
Delete smoke_test.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879#!/usr/bin/env python3"""Small end-to-end check for a running local or Hugging Face deployment."""from __future__ import annotations
import jsonimport sys
import httpx
def check(name: str, condition: bool, detail: str = "") -> None: mark = "✓" if condition else "✗" print(f"{mark} {name}{': ' + detail if detail else ''}") if not condition: raise SystemExit(1)
def main() -> None: base = (sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:7860").rstrip("/") model = sys.argv[2] if len(sys.argv) > 2 else "osaii/faster-experimental"
with httpx.Client(timeout=120, follow_redirects=True) as client: health = client.get(f"{base}/healthz") check("health", health.status_code == 200 and health.json().get("ok") is True)
models = client.get( f"{base}/v1/models", headers={"Authorization": "Bearer public"} ) model_data = models.json().get("data", []) if models.status_code == 200 else [] ids = [item.get("id") for item in model_data if isinstance(item, dict)] check("models", models.status_code == 200 and bool(ids), f"{len(ids)} available") check("selected model exists", model in ids, model)
payload = { "model": model, "stream": False, "messages": [{"role": "user", "content": "Reply with exactly: OK"}], } reply = client.post( f"{base}/v1/chat/completions", headers={"Authorization": "Bearer public"}, json=payload, ) try: answer = reply.json()["choices"][0]["message"] except Exception: answer = {} check("JSON chat", reply.status_code == 200 and bool(answer), reply.text[:160])
payload["stream"] = True payload["stream_options"] = {"include_usage": True} chunks = 0 done = False with client.stream( "POST", f"{base}/v1/chat/completions", headers={"Authorization": "Bearer public"}, json=payload, ) as stream: check( "SSE content type", stream.headers.get("content-type", "").startswith("text/event-stream"), ) for line in stream.iter_lines(): if not line.startswith("data: "): continue if line[6:] == "[DONE]": done = True else: json.loads(line[6:]) chunks += 1 check("SSE chunks", chunks > 0, str(chunks)) check("SSE done marker", done)
print("\nAll smoke checks passed.")
if __name__ == "__main__": main()smoke_test.pyDeleted-79