Skip to content

Commit

Permalink
add aici jsinit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jan 19, 2024
1 parent a248681 commit 38aa25b
Show file tree
Hide file tree
Showing 2 changed files with 554 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pyaici/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import argparse

from . import rest
from . import rest, jssrc
from . import add_cli_args, AiciRunner


Expand Down Expand Up @@ -103,6 +103,15 @@ def infer_args(cmd: argparse.ArgumentParser):
)


def save_file(name: str, content: str, force: bool):
if os.path.exists(name) and not force:
print(f"file {name} exists; use --force to overwrite")
return
with open(name, "w") as f:
f.write(content)
print(f"saved {name}")


def main_inner():
parser = argparse.ArgumentParser(
description="Upload an AICI Controller and completion request to rllm or vllm",
Expand All @@ -128,7 +137,10 @@ def main_inner():
""",
)
run_cmd.add_argument(
"aici_arg", metavar="FILE", nargs="?", help="file to pass to the AICI Controller"
"aici_arg",
metavar="FILE",
nargs="?",
help="file to pass to the AICI Controller",
)
infer_args(run_cmd)
run_cmd.add_argument(
Expand Down Expand Up @@ -194,6 +206,15 @@ def main_inner():
"build", metavar="FOLDER", help="path to rust project (folder with Cargo.toml)"
)

jsinit_cmd = subparsers.add_parser(
"jsinit",
help="intialize current folder for jsctrl",
description="Intialize a JavaScript/TypeScript folder for jsctrl.",
)
jsinit_cmd.add_argument(
"--force", "-f", action="store_true", help="overwrite existing files"
)

for cmd in [upload_cmd, build_cmd]:
cmd.add_argument(
"--tag",
Expand All @@ -211,6 +232,11 @@ def main_inner():
else:
rest.log_level = 3

if args.subcommand == "jsinit":
save_file("tsconfig.json", jssrc.tsconfig_json, args.force)
save_file("aici-types.d.ts", jssrc.aici_types_d_t, args.force)
sys.exit(0)

if args.subcommand == "benchrt":
AiciRunner.from_cli(args).bench()
sys.exit(0)
Expand Down Expand Up @@ -270,7 +296,9 @@ def main_inner():
elif fn.endswith(".json"):
aici_module = "declctrl-latest"
else:
cli_error("Can't determine AICI Controller type from file name: " + fn)
cli_error(
"Can't determine AICI Controller type from file name: " + fn
)
print(f"Running with tagged AICI Controller: {aici_module}")
if not aici_module:
cli_error("no AICI Controller specified to run")
Expand Down
Loading

0 comments on commit 38aa25b

Please sign in to comment.