The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Add Comfy API console tips (#17052)
guill8baf68d53d75
diff --git a/app/product_tips.py b/app/product_tips.pynew file mode 100644index 000000000..f6a8c82af--- /dev/null+++ b/app/product_tips.py@@ -0,0 +1,33 @@+"""Console tips for Comfy-Org developer products: one startup line and at most one of each job hint per process.++Plain ASCII on purpose: Windows consoles may still use cp1252.+"""++COMFY_API_STARTUP_TIP = "ComfyUI is developed by Comfy Org. We also offer commercial products to deploy ComfyUI as scalable cloud endpoints. Visit platform.comfy.org/ascii for more information."++COMFY_API_JOB_HINT = "ComfyUI is developed by Comfy Org. We also offer commercial products to deploy ComfyUI as scalable cloud endpoints. Visit platform.comfy.org/ascii-job for more information."+++def tips_enabled(args, environ) -> bool:+ return not (+ args.disable_product_tips+ or args.dont_print_server+ or args.windows_standalone_build+ or args.quick_test_for_ci+ or environ.get("COMFYUI_DISABLE_PRODUCT_TIPS", "").strip().lower() in ("1", "true", "yes")+ or environ.get("CI", "").strip().lower() in ("1", "true")+ )+++_shown_job_hints = set()+++def get_relevant_job_hint(args, environ, success: bool, extra_data: dict) -> str | None:+ """The hint to log after a finished job, or None. Each hint is shown at most once per process."""+ if not tips_enabled(args, environ) or not success:+ return None+ hint = COMFY_API_JOB_HINT if "client_id" not in extra_data else None+ if hint is None or hint in _shown_job_hints:+ return None+ _shown_job_hints.add(hint)+ return hintdiff --git a/comfy/cli_args.py b/comfy/cli_args.pyindex 135a89900..bd605a703 100644--- a/comfy/cli_args.py+++ b/comfy/cli_args.py@@ -210,6 +210,7 @@ parser.add_argument("--mmap-torch-files", action="store_true", help="Use mmap whparser.add_argument("--disable-mmap", action="store_true", help="Don't use mmap when loading safetensors.")parser.add_argument("--dont-print-server", action="store_true", help="Don't print server output.")+parser.add_argument("--disable-product-tips", action="store_true", help="Hide console tips about new products from Comfy-Org. Same as setting the env var COMFYUI_DISABLE_PRODUCT_TIPS=1.")parser.add_argument("--quick-test-for-ci", action="store_true", help="Quick test for CI.")parser.add_argument("--windows-standalone-build", action="store_true", help="Windows standalone build: Enable convenient things that most people using the standalone windows build will probably enjoy (like auto opening the page on startup and turning on the assets system; --disable-assets turns it off).")diff --git a/execution.py b/execution.pyindex 305f1dbb7..3d67a4627 100644--- a/execution.py+++ b/execution.py@@ -785,6 +785,7 @@ class PromptExecutor:while not execution_list.is_empty():node_id, error, ex = await execution_list.stage_node_execution()if error is not None:+ self.success = Falseself.handle_execution_error(prompt_id, dynamic_prompt.original_prompt, current_outputs, executed, error, ex)breakdiff --git a/main.py b/main.pyindex 8494d5839..e66d9c0c3 100644--- a/main.py+++ b/main.py@@ -18,6 +18,7 @@ import folder_pathsimport timefrom comfy.cli_args import enables_dynamic_vramfrom app import governance+from app import product_tipsfrom app.logger import setup_loggerconsole_log_level = get_console_log_level(args.verbose)file_log_outputs = get_file_log_outputs(args.verbose)@@ -408,6 +409,10 @@ def prompt_worker(q, server_instance, asset_manager):else:logging.info("Prompt executed in {:.2f} seconds".format(execution_time), extra={'color': 'green'})+ job_hint = product_tips.get_relevant_job_hint(args, os.environ, e.success, extra_data)+ if job_hint is not None:+ logging.info(job_hint)+flags = q.get_flags()free_memory = flags.get("free_memory", False)@@ -682,6 +687,8 @@ if __name__ == "__main__":event_loop, prompt_server, start_all_func = start_comfyui()try:x = start_all_func()+ if product_tips.tips_enabled(args, os.environ):+ logging.info(product_tips.COMFY_API_STARTUP_TIP)app.logger.print_startup_warnings()event_loop.run_until_complete(x)except KeyboardInterrupt:diff --git a/tests-unit/app_test/product_tips_test.py b/tests-unit/app_test/product_tips_test.pynew file mode 100644index 000000000..d5e1428ed--- /dev/null+++ b/tests-unit/app_test/product_tips_test.py@@ -0,0 +1,49 @@+import argparse++import pytest++from app import product_tips+++def _args(**overrides):+ flags = dict(disable_product_tips=False, dont_print_server=False, windows_standalone_build=False, quick_test_for_ci=False)+ flags.update(overrides)+ return argparse.Namespace(**flags)+++def test_startup_tip_is_single_ascii_line():+ assert product_tips.COMFY_API_STARTUP_TIP.isascii()+ assert "\n" not in product_tips.COMFY_API_STARTUP_TIP+++def test_tips_enabled_by_default():+ assert product_tips.tips_enabled(_args(), {})+ assert product_tips.tips_enabled(_args(), {"CI": "0", "COMFYUI_DISABLE_PRODUCT_TIPS": "0"})++[email protected]("flag", ["disable_product_tips", "dont_print_server", "windows_standalone_build", "quick_test_for_ci"])+def test_tips_disabled_by_flag(flag):+ assert not product_tips.tips_enabled(_args(**{flag: True}), {})++[email protected]("environ", [+ {"COMFYUI_DISABLE_PRODUCT_TIPS": "1"},+ {"COMFYUI_DISABLE_PRODUCT_TIPS": "True"},+ {"COMFYUI_DISABLE_PRODUCT_TIPS": "YES"},+ {"CI": "1"},+ {"CI": "true"},+])+def test_tips_disabled_by_env(environ):+ assert not product_tips.tips_enabled(_args(), environ)+++def test_job_hint_once_and_only_for_headless_success(monkeypatch):+ monkeypatch.setattr(product_tips, "_shown_job_hints", set())+ get = product_tips.get_relevant_job_hint+ assert get(_args(disable_product_tips=True), {}, True, {}) is None+ assert get(_args(), {"CI": "1"}, True, {}) is None+ assert get(_args(), {}, False, {}) is None+ assert get(_args(), {}, True, {"client_id": "abc"}) is None+ assert get(_args(), {}, True, {}) == product_tips.COMFY_API_JOB_HINT+ assert get(_args(), {}, True, {}) is None+ assert product_tips.COMFY_API_JOB_HINT.isascii()diff --git a/tests/execution/test_execution.py b/tests/execution/test_execution.pyindex 6778fbb77..beaf90564 100644--- a/tests/execution/test_execution.py+++ b/tests/execution/test_execution.py@@ -787,6 +787,14 @@ class TestExecution:except Exception as e:assert 'prompt_id' in e.args[0], f"Did not get back a proper error message: {e}"assert e.args[0]['node_id'] == generator.id, "Error should have been on the generator node"+ prompt_id = e.args[0]['prompt_id']++ for _ in range(100):+ history = client.get_history(prompt_id)+ if prompt_id in history:+ break+ time.sleep(0.1)+ assert history[prompt_id]['status']['status_str'] == 'error'def test_missing_node_error(self, client: ComfyClient, builder: GraphBuilder):g = builder