Cookbook Pipeline
"""End-to-end: fetch a cookbook recipe, validate it, save it, optionally submit.
Run:
python examples/03_cookbook_pipeline.py groot groot_finetune/groot_finetune
OSMO_TARGET_POOL=my-pool python examples/03_cookbook_pipeline.py groot groot_finetune/groot_finetune
"""
from __future__ import annotations
import json
import os
import sys
import tempfile
from strands_osmo import (
osmo_cookbook_fetch,
osmo_workflow_submit,
osmo_workflow_validate,
)
def main() -> None:
category = sys.argv[1] if len(sys.argv) > 1 else "groot"
recipe = sys.argv[2] if len(sys.argv) > 2 else "groot_finetune/groot_finetune"
local_root = os.getenv("OSMO_COOKBOOK_ROOT", "../OSMO/cookbook")
print(f"=== osmo_cookbook_fetch({category}/{recipe}) ===")
fetched = osmo_cookbook_fetch(
category=category, recipe=recipe, local_root=local_root,
)
if fetched.get("status") != "success":
print(json.dumps(fetched, indent=2, default=str))
return
yaml_text = fetched["content"][0]["text"]
out_path = tempfile.NamedTemporaryFile(
prefix="osmo-recipe-", suffix=".yaml", delete=False, mode="w",
)
out_path.write(yaml_text)
out_path.close()
print(f"saved → {out_path.name} ({len(yaml_text)} chars)")
print("\n=== osmo_workflow_validate ===")
validate = osmo_workflow_validate(workflow_yaml=out_path.name)
print(validate["content"][0]["text"][:300])
pool = os.getenv("OSMO_TARGET_POOL", "")
if not pool or validate.get("status") != "success":
print("\nDry-run only.")
return
print(f"\n=== osmo_workflow_submit(..., pool={pool}) ===")
submitted = osmo_workflow_submit(workflow_yaml=out_path.name, pool=pool)
print(json.dumps(submitted, indent=2, default=str))
if __name__ == "__main__":
main()