forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tools: Ailly at 1.2.5-rc1 with windows working for 2 engineers (awsdo…
…cs#6257) * Ailly at 1.2.5-rc1 with windows working for 2 engineers
- Loading branch information
1 parent
fd26a8a
commit 726d759
Showing
4 changed files
with
733 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
|
@@ -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(): | ||
|
@@ -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", | ||
|
@@ -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__": | ||
|
Oops, something went wrong.