diff --git a/aws_doc_sdk_examples_tools/scripts/make_prompts.py b/aws_doc_sdk_examples_tools/scripts/make_prompts.py new file mode 100644 index 0000000..6506217 --- /dev/null +++ b/aws_doc_sdk_examples_tools/scripts/make_prompts.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python + +import argparse +import logging +import os +from pathlib import Path +from typing import Dict, List + +from aws_doc_sdk_examples_tools.doc_gen import DocGen, Snippet + +# Setup logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +def make_doc_gen(root: Path) -> DocGen: + """Create and return a DocGen instance from the given root directory.""" + doc_gen = DocGen.from_root(root) + doc_gen.collect_snippets() + return doc_gen + + +def write_prompts(snippets: Dict[str, Snippet], out: Path) -> None: + """Write each snippet's code into a separate Markdown file.""" + out.mkdir(parents=True, exist_ok=True) + for snippet_id, snippet in snippets.items(): + snippet_path = out / f"{snippet_id}.md" + snippet_path.write_text(snippet.code, encoding="utf-8") + + +def setup_ailly(system_prompts: List[str], out: Path) -> None: + """Create the .aillyrc configuration file.""" + fence = "---" + options = {"isolated": "true"} + options_block = "\n".join(f"{key}: {value}" for key, value in options.items()) + prompts_block = "\n".join(system_prompts) + + content = f"{fence}\n{options_block}\n{fence}\n{prompts_block}" + + aillyrc_path = out / ".aillyrc" + aillyrc_path.parent.mkdir(parents=True, exist_ok=True) + aillyrc_path.write_text(content, encoding="utf-8") + + +def parse_prompts_arg(values: List[str]) -> List[str]: + """Parse system prompts from a list of strings or file paths.""" + prompts = [] + for value in values: + if os.path.isfile(value): + with open(value, "r", encoding="utf-8") as f: + prompts.append(f.read()) + else: + prompts.append(value) + return prompts + + +def main(doc_gen_root: Path, system_prompts: List[str], out: str = ".ailly_prompts") -> None: + """Generate prompts and configuration files for Ailly.""" + out_path = Path(out) + setup_ailly(system_prompts, out_path) + + doc_gen = make_doc_gen(doc_gen_root) + write_prompts(doc_gen.snippets, out_path) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Write Ailly prompts for DocGen snippets and parse the results." + ) + parser.add_argument( + "--doc-gen-root", required=True, + help="Path to a DocGen ready project." + ) + parser.add_argument( + "--system-prompts", nargs="+", required=True, + help="List of prompt strings or file paths to store in a .aillyrc file." + ) + parser.add_argument( + "--out", + default=".ailly_prompts", + help="Directory where Ailly prompt files will be written. Defaults to '.ailly_prompts'." + ) + + args = parser.parse_args() + + doc_gen_root = Path(args.doc_gen_root) + system_prompts = parse_prompts_arg(args.system_prompts) + main(doc_gen_root, system_prompts, out=args.out) diff --git a/aws_doc_sdk_examples_tools/scripts/policy.json.example.md b/aws_doc_sdk_examples_tools/scripts/policy.json.example.md new file mode 100644 index 0000000..da7a414 --- /dev/null +++ b/aws_doc_sdk_examples_tools/scripts/policy.json.example.md @@ -0,0 +1,20 @@ +# Example generated IAM policy descriptions +``` +[ + { + "title": "Allows Amazon SNS to send messages to an Amazon SQS dead-letter queue", + "title_abbrev": "Allows SNS to SQS messages", + "description": "This resource-based policy allows Amazon SNS to send messages to a specific Amazon SQS dead-letter queue. The policy grants the SNS service principal permission to perform the SQS:SendMessage action on the queue named [MyDeadLetterQueue], but only when the source ARN matches the specified SNS topic [MyTopic]. This policy would be attached to the SQS queue to enable it to receive messages from the SNS topic when message delivery fails. Replace [us-east-2] with your specific AWS Region." + }, + { + "title": "Allows managing log delivery and related resources", + "title_abbrev": "Allows log delivery management", + "description": "This identity-based policy allows managing CloudWatch Logs delivery configurations and related resources. The policy grants permissions to create, get, update, delete, and list log deliveries, as well as manage resource policies for a specific log group [SampleLogGroupName]. It also allows creating service-linked roles, tagging Firehose delivery streams, and managing bucket policies for a specific S3 bucket [bucket-name]. Replace [region] and [account-id] with your specific AWS Region and account ID, and [bucket-name] with your actual S3 bucket name." + }, + { + "title": "Allows Amazon SNS to send messages to an SQS dead-letter queue", + "title_abbrev": "SNS to SQS permissions", + "description": "This resource-based policy allows Amazon SNS to send messages to a specific Amazon SQS queue that serves as a dead-letter queue. The policy grants the SNS service permission to perform the SQS:SendMessage action on the queue named [MyDeadLetterQueue] in the [us-east-2] Region. The policy includes a condition that restricts this permission to messages originating from the SNS topic named [MyTopic] in the same Region and account." + } +] +``` \ No newline at end of file