docling-inference / scripts /mock_backend.py
mc0117's picture
init push
415196f
Raw
History Blame Contribute Delete
1.62 kB
#!/usr/bin/env python3
"""
Minimal mock backend that accepts POST /update and POST /finish and prints the body.
Run this, then set SYMBIOS_BACKEND_BASE_URL=http://localhost:9999 and trigger
a vectorize job to see progress and finish callbacks.
Usage:
python scripts/mock_backend.py
# or: .upload_venv/bin/python scripts/mock_backend.py
"""
import json
from http.server import HTTPServer, BaseHTTPRequestHandler
PORT = 9999
class Handler(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers.get("Content-Length", 0))
body = self.rfile.read(length) if length else b""
try:
data = json.loads(body.decode()) if body else {}
except Exception:
data = body.decode(errors="replace")
auth = self.headers.get("Authorization", "(none)")
print(f"[{self.command} {self.path}] Authorization: {auth}")
print(json.dumps(data, indent=2))
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b'{"ok": true}\n')
def log_message(self, format, *args):
pass # suppress default request log; we print above
def main():
server = HTTPServer(("", PORT), Handler)
print(f"Mock backend listening on http://localhost:{PORT}")
print(" POST /update - progress (doc_id, finished, total, message)")
print(" POST /finish - completion (status, vec_id, ...)")
print("Set SYMBIOS_BACKEND_BASE_URL=http://localhost:9999 and run a vectorize job.\n")
server.serve_forever()
if __name__ == "__main__":
main()