Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
Skip gateway models file write when only date changed (#786)
Louis Choquelaeb37a0e4492
diff --git a/pipelex/cli/dev_cli/commands/check_gateway_models_cmd.py b/pipelex/cli/dev_cli/commands/check_gateway_models_cmd.pyindex e9319d0ca..b94f4da1e 100644--- a/pipelex/cli/dev_cli/commands/check_gateway_models_cmd.py+++ b/pipelex/cli/dev_cli/commands/check_gateway_models_cmd.py@@ -13,6 +13,7 @@ from pipelex.cli.dev_cli.commands.gateway_models_generator import (fetch_gateway_model_specs,generate_reference_markdown,generate_reference_pure_markdown,+ normalize_for_comparison,)from pipelex.cli.dev_cli.commands.update_gateway_models_cmd import (GATEWAY_MODELS_PLAIN_REFERENCE_PATH,@@ -25,12 +26,6 @@ if TYPE_CHECKING:from rich.console import Console-def _normalize_for_comparison(content: str) -> str:- """Remove timestamp line for comparison since it changes every generation."""- lines = content.split("\n")- return "\n".join(line for line in lines if not line.startswith("> Last updated:"))--def check_gateway_models_cmd(show_diff: bool = True, quiet: bool = False) -> None:"""Verify that the Pipelex Gateway models reference files are up-to-date.@@ -127,8 +122,8 @@ def check_gateway_models_cmd(show_diff: bool = True, quiet: bool = False) -> Nonsys.exit(1)# Compare content (ignoring timestamp line for comparison)- html_matches = _normalize_for_comparison(existing_html_content) == _normalize_for_comparison(expected_html_content)- plain_matches = _normalize_for_comparison(existing_plain_content) == _normalize_for_comparison(expected_plain_content)+ html_matches = normalize_for_comparison(existing_html_content) == normalize_for_comparison(expected_html_content)+ plain_matches = normalize_for_comparison(existing_plain_content) == normalize_for_comparison(expected_plain_content)if html_matches and plain_matches:# No differences found in either filediff --git a/pipelex/cli/dev_cli/commands/gateway_models_generator.py b/pipelex/cli/dev_cli/commands/gateway_models_generator.pyindex 7dca89bd5..87b87d229 100644--- a/pipelex/cli/dev_cli/commands/gateway_models_generator.py+++ b/pipelex/cli/dev_cli/commands/gateway_models_generator.py@@ -27,6 +27,12 @@ PREFERRED_INPUT_ORDER = ["text", "images", "image", "pdf"]PREFERRED_OUTPUT_ORDER = ["text", "structured", "image", "pages"]+def normalize_for_comparison(content: str) -> str:+ """Remove timestamp line for comparison since it changes every generation."""+ lines = content.split("\n")+ return "\n".join(line for line in lines if not line.startswith("> Last updated:"))++def fetch_gateway_model_specs() -> BackendModelSpecs:"""Fetch model specifications from Pipelex Gateway remote config.diff --git a/pipelex/cli/dev_cli/commands/update_gateway_models_cmd.py b/pipelex/cli/dev_cli/commands/update_gateway_models_cmd.pyindex c51ffa8d2..aea891b7a 100644--- a/pipelex/cli/dev_cli/commands/update_gateway_models_cmd.py+++ b/pipelex/cli/dev_cli/commands/update_gateway_models_cmd.py@@ -12,6 +12,7 @@ from pipelex.cli.dev_cli.commands.gateway_models_generator import (fetch_gateway_model_specs,generate_reference_markdown,generate_reference_pure_markdown,+ normalize_for_comparison,)from pipelex.hub import get_consolefrom pipelex.system.pipelex_service.exceptions import RemoteConfigFetchError, RemoteConfigValidationError@@ -71,6 +72,36 @@ def update_gateway_models_cmd(quiet: bool = False) -> None:markdown_content = generate_reference_markdown(model_specs)plain_markdown_content = generate_reference_pure_markdown(model_specs)+ # Count models for reporting+ model_count = sum(1 for key in model_specs if key != "defaults" and ".rules" not in key and isinstance(model_specs[key], dict))++ # Skip writing if the only change is the timestamp (avoids noisy diffs in PRs)+ if GATEWAY_MODELS_REFERENCE_PATH.exists() and GATEWAY_MODELS_PLAIN_REFERENCE_PATH.exists():+ try:+ existing_html = GATEWAY_MODELS_REFERENCE_PATH.read_text(encoding="utf-8")+ existing_plain = GATEWAY_MODELS_PLAIN_REFERENCE_PATH.read_text(encoding="utf-8")+ except OSError:+ pass # File disappeared or is unreadable — fall through and rewrite+ else:+ html_unchanged = normalize_for_comparison(existing_html) == normalize_for_comparison(markdown_content)+ plain_unchanged = normalize_for_comparison(existing_plain) == normalize_for_comparison(plain_markdown_content)+ if html_unchanged and plain_unchanged:+ if quiet:+ console.print(f"[green]✓ Gateway models update: UP-TO-DATE[/green] ({model_count} models, no changes)")+ else:+ up_to_date_panel = Panel(+ f"[green]✓[/green] Reference files are already up-to-date (skipped write)\n\n"+ f"[dim]HTML-styled: {GATEWAY_MODELS_REFERENCE_PATH}[/dim]\n"+ f"[dim]Plain text: {GATEWAY_MODELS_PLAIN_REFERENCE_PATH}[/dim]\n"+ f"[dim]Models: {model_count}[/dim]",+ title="[bold green]Gateway Models Update: UP-TO-DATE[/bold green]",+ border_style="green",+ padding=(1, 2),+ )+ console.print(up_to_date_panel)+ console.print()+ return+# Ensure parent directory existsGATEWAY_MODELS_REFERENCE_PATH.parent.mkdir(parents=True, exist_ok=True)@@ -78,9 +109,6 @@ def update_gateway_models_cmd(quiet: bool = False) -> None:GATEWAY_MODELS_REFERENCE_PATH.write_text(markdown_content, encoding="utf-8")GATEWAY_MODELS_PLAIN_REFERENCE_PATH.write_text(plain_markdown_content, encoding="utf-8")- # Count models for reporting- model_count = sum(1 for key in model_specs if key != "defaults" and ".rules" not in key and isinstance(model_specs[key], dict))-if quiet:console.print(f"[green]✓ Gateway models update: PASSED[/green] ({model_count} models)")else: