Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Ailly at 1.2.5-rc1 with windows working for 2 engineers #6257

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
meyertst-aws marked this conversation as resolved.
Show resolved Hide resolved


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
Loading