MCPcopy
hub / github.com/lightningpixel/modly / _run_comfy_workflow

Function _run_comfy_workflow

tools/modly-cli/agent.py:546–571  ·  view source on GitHub ↗
(args: argparse.Namespace)

Source from the content-addressed store, hash-verified

544
545
546def _run_comfy_workflow(args: argparse.Namespace) -> dict[str, Any]:
547 host = args.comfy_url.rstrip("/")
548 workflow = _load_comfy_workflow(args.workflow, host=host, timeout=args.request_timeout)
549 prompt = getattr(args, "prompt", None)
550 seed = getattr(args, "seed", None)
551 graph = _patch_comfy_workflow(workflow, prompt=prompt, seed=seed)
552 payload = json.dumps({"prompt": graph, "client_id": "modly-cli"}).encode("utf-8")
553 queued = _request_json("POST", f"{host}/prompt", timeout=args.request_timeout, data=payload, headers={"Content-Type": "application/json"})
554 prompt_id = queued.get("prompt_id") if isinstance(queued, dict) else None
555 if not prompt_id:
556 raise ModlyCliError(f"ComfyUI did not return prompt_id: {queued}")
557
558 deadline = time.monotonic() + args.timeout
559 history: dict[str, Any] = {}
560 while time.monotonic() < deadline:
561 data = _request_json("GET", f"{host}/history/{urllib.parse.quote(str(prompt_id))}", timeout=args.request_timeout)
562 if isinstance(data, dict) and str(prompt_id) in data:
563 history = data[str(prompt_id)] if isinstance(data[str(prompt_id)], dict) else {"raw": data[str(prompt_id)]}
564 break
565 if getattr(args, "progress", False) and not getattr(args, "quiet", False):
566 print(json.dumps({"phase": "comfy", "prompt_id": prompt_id, "status": "running"}), file=sys.stderr)
567 time.sleep(args.poll)
568 if not history:
569 raise ModlyCliError(f"Timed out waiting for ComfyUI prompt {prompt_id}", code="TIMEOUT")
570
571 return {"ok": True, "comfy_url": host, "workflow": args.workflow, "prompt_id": str(prompt_id), "history": history}
572
573
574def _iter_comfy_file_refs(value: Any) -> list[dict[str, Any]]:

Callers 2

_run_comfy_imageFunction · 0.85

Calls 4

_load_comfy_workflowFunction · 0.85
_patch_comfy_workflowFunction · 0.85
_request_jsonFunction · 0.85
ModlyCliErrorClass · 0.85

Tested by

no test coverage detected