Add ability to run small scripts from the ui and added a merge lora script

This commit is contained in:
Jaret Burkett
2026-05-18 14:33:47 -06:00
parent ec58dcde92
commit 6ecaf679dc
14 changed files with 984 additions and 52 deletions

46
ui_scripts/test_script.py Normal file
View File

@@ -0,0 +1,46 @@
"""Example UI script invoked via POST /api/scripts.
The API streams stdout/stderr back to the caller. To return structured data,
print a single JSON object on the final line of stdout — the route parses it
into the `result` field of the response.
"""
import argparse
import json
import sys
import time
def main() -> int:
parser = argparse.ArgumentParser(description="Example ui_scripts entry point.")
parser.add_argument("--message", default="hello", help="Message to echo back.")
parser.add_argument(
"--count", type=int, default=3, help="Number of log lines to emit."
)
parser.add_argument(
"--delay", type=float, default=0.0, help="Seconds to sleep between log lines."
)
parser.add_argument(
"--fail", action="store_true", help="Exit non-zero to demo failure handling."
)
args = parser.parse_args()
for i in range(args.count):
print(f"[{i + 1}/{args.count}] {args.message}", flush=True)
if args.delay > 0:
time.sleep(args.delay)
if args.fail:
print("intentional failure", file=sys.stderr, flush=True)
return 1
# Final line: JSON payload the API surfaces as `result`.
print(
json.dumps({"message": args.message, "count": args.count, "ok": True}),
flush=True,
)
return 0
if __name__ == "__main__":
sys.exit(main())