Skip to content

Commit

Permalink
Tools: Ailly at 1.2.5-rc1 with windows working for 2 engineers (awsdo…
Browse files Browse the repository at this point in the history
…cs#6257)

* Ailly at 1.2.5-rc1 with windows working for 2 engineers
  • Loading branch information
DavidSouther authored and AMZ-brandon committed Mar 19, 2024
1 parent fd26a8a commit 726d759
Show file tree
Hide file tree
Showing 4 changed files with 733 additions and 698 deletions.
45 changes: 24 additions & 21 deletions .tools/ailly/ailly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@
# AILLY = "@ailly/[email protected]"
AILLY = "@ailly/cli"

# Throughout this wrapper, `subprocess.run(shell=True)` is used for Windows
# support in running node, npm, and npx. While this script is already run in a
# shell, so shell escaping already rather involves being on the other side of
# the airtight hatchway, care is taken to only write strings defined in this file
# itself into the subprocess. If a security auditor just ran a SASL and thinks
# this is a thing that's a problem, please bring a proof of exploit.

def check(cmd: str):
run = subprocess.run(cmd, shell=True, capture_output=True)
run.check_returncode()


# Ensure `npx` is available
def ensure_npx():
check("node --version")
check(f"npm install {AILLY}")
check(f"npx {AILLY} --help")
subprocess.run(["npx", AILLY, "--version"], shell=True)
"""Ensure `npx` is available in this system."""
subprocess.run(
["node", "--version"], shell=True, capture_output=True
).check_returncode()
subprocess.run(
["npm", "install", AILLY], shell=True, capture_output=True
).check_returncode()
subprocess.run(
["npx", AILLY, "--help"], shell=True, capture_output=True
).check_returncode()
subprocess.run(["npx", AILLY, "--version"], shell=True).check_returncode()


def prepare_scouts(example: Path):
Expand All @@ -43,21 +51,21 @@ def prepare_scouts(example: Path):
# --plugin file://${PWD}/plugin.mjs \
# --root ../../<example> \
# --out ../../<example>/.scouts/[target language] \
# --prompt "Translate to [target language]. [Additional instructions]"
def run_ailly(source: str, example: Path, target: str, instructions: str = ""):
# --prompt "Translate to [target language]."
def run_ailly(source: str, example: Path, target: str):
base = Path(__file__).parent
engine = ["--engine", "bedrock"]
plugin = ["--plugin", (base / "plugin.mjs").as_uri()]
root = ["--root", example]
out = ["--out", example / ".scouts" / target]
prompt = [
"--prompt",
f"Translate the final block of code from {source} to {target} programming language. {instructions}",
f"Translate the final block of code from {source} to {target} programming language.",
]
logging.info("Converting %s to %s", example, target)
args = ["npx", AILLY, *engine, *plugin, *root, *out, *prompt, "--isolated"]
args = ["npx", AILLY, *engine, *plugin, *root, *out, *prompt, "--isolated", "."]
print("cd '" + str(base) + "' ; " + " ".join(f"'{str(arg)}'" for arg in args))
subprocess.run(args, cwd=base)
subprocess.run(args, cwd=base, shell=True)


def main():
Expand All @@ -74,11 +82,6 @@ def main():
default="s3",
help="The targeted service. Choose from: %(choices)s.",
)
parser.add_argument(
"--additional-prompt",
default="",
help="Additional instructions to provide for the LLM.",
)
parser.add_argument(
"--verbose",
action="store_true",
Expand Down Expand Up @@ -109,14 +112,14 @@ def main():
example = (
Path(__file__).parent.parent.parent
/ args.language
# / "example_code"
/ "example_code"
/ args.service
)
if args.clean:
prepare_scouts(example)

for target in targets:
run_ailly(args.language, example, target, instructions=args.additional_prompt)
run_ailly(args.language, example, target)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 726d759

Please sign in to comment.