generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 16
Add runner for iam update agent #163
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,102 +1,74 @@ | ||
| # Ailly Prompt Workflow | ||
|
|
||
| This project provides three scripts to **generate** Ailly prompts, **run** them, **parse** the results, and **update** a DocGen instance. | ||
|
|
||
| ## Overview | ||
|
|
||
| 1. **Generate** Ailly prompts from DocGen snippets (`make_prompts.py`). | ||
| 2. **Run** the Ailly CLI on the generated prompts (`npx @ailly/cli`). | ||
| 3. **Parse** the Ailly outputs into structured JSON (`parse_json_files.py`). | ||
| 4. **Update** your DocGen project with the parsed results (`update_doc_gen.py`). | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.8+ | ||
| - Node.js & npm (for `npx`) | ||
| This project automates the process of generating, running, parsing, and applying [Ailly](https://www.npmjs.com/package/@ailly/cli) prompt outputs to an AWS DocGen project. It combines all steps into one streamlined command using a single Python script. | ||
|
|
||
| --- | ||
|
|
||
| ## Step 1: Generate Ailly prompts | ||
|
|
||
| Use `make_prompts.py` to create a directory of Markdown files and a `.aillyrc` configuration file. | ||
| ## 📦 Overview | ||
|
|
||
| ```bash | ||
| python make_prompts.py \ | ||
| --doc-gen-root /path/to/your/docgen/project \ | ||
| --system-prompts "You are a helpful assistant..." \ | ||
| --out .ailly_prompts | ||
| ``` | ||
| This tool: | ||
| 1. **Generates** Ailly prompts from DocGen snippets. | ||
| 2. **Runs** Ailly CLI to get enhanced metadata. | ||
| 3. **Parses** Ailly responses into structured JSON. | ||
| 4. **Updates** your DocGen examples with the new metadata. | ||
|
|
||
| **Arguments:** | ||
| - `--doc-gen-root`: Path to your DocGen project root. | ||
| - `--system-prompts`: One or more system prompts, either as strings or file paths. | ||
| - `--out`: (Optional) Output directory. Defaults to `.ailly_prompts`. | ||
| All of this is done with one command. | ||
|
|
||
| --- | ||
|
|
||
| ## Step 2: Run Ailly CLI | ||
| ## ✅ Prerequisites | ||
|
|
||
| Run Ailly on the generated prompts: | ||
|
|
||
| ```bash | ||
| npx @ailly/cli --root .ailly_prompts | ||
| ``` | ||
|
|
||
| This will create `{file}.ailly.md` output files in the `.ailly_prompts` directory (or whatever output directory you specified). | ||
| - Python 3.8+ | ||
| - Node.js and npm (for `npx`) | ||
| - A DocGen project directory | ||
|
|
||
| --- | ||
|
|
||
| ## Step 3: Parse Ailly output | ||
| ## 🚀 Usage | ||
|
|
||
| Parse the `{name}.ailly.md` files into JSON using `parse_json_files.py`: | ||
| From your project root, run: | ||
|
|
||
| ```bash | ||
| python parse_json_files.py .ailly_prompts/*.ailly.md --out example_updates.json | ||
| python -m aws_doc_sdk_examples_tools.agent.bin.main \ | ||
| /path/to/your/docgen/project \ | ||
| --system-prompts path/to/system_prompt.txt | ||
| ``` | ||
|
|
||
| **Arguments:** | ||
| - Positional: List of files to parse (e.g., `*.ailly.md`). | ||
| - `--out`: (Optional) Path for the JSON output. Defaults to `out.json`. | ||
| ### 🔧 Arguments | ||
|
|
||
| Run `python -m aws_doc_sdk_examples_tools.agent.bin.main --help` for more info. | ||
|
|
||
| --- | ||
|
|
||
| ## Step 4: Update DocGen with Ailly results | ||
| ## 🗂 What This Does | ||
|
|
||
| Use `update_doc_gen.py` to load the parsed data back into your `DocGen` project: | ||
| Under the hood, this script: | ||
|
|
||
| ```bash | ||
| python update_doc_gen.py \ | ||
| --doc-gen-root /path/to/your/docgen/project \ | ||
| --updates-path example_updates.json | ||
| ``` | ||
| 1. Creates a directory `.ailly_iam_policy` containing: | ||
| - One Markdown file per snippet. | ||
| - A `.aillyrc` configuration file. | ||
|
|
||
| **Arguments:** | ||
| - `--doc-gen-root`: Path to the root of your DocGen project. | ||
| - `--updates-path`: JSON file generated in Step 3 (default: `example_updates.json`). | ||
| 2. Runs `npx @ailly/cli` to generate `.ailly.md` outputs. | ||
|
|
||
| This will update the `title`, `title_abbrev`, and `synopsis` fields in the corresponding DocGen examples. | ||
| 3. Parses the Ailly `.ailly.md` files into a single `iam_updates.json` file. | ||
|
|
||
| 4. Updates each matching `Example` in the DocGen instance with: | ||
| - `title` | ||
| - `title_abbrev` | ||
| - `synopsis` | ||
|
|
||
| --- | ||
|
|
||
| ## Example Full Workflow | ||
| ## 💡 Example | ||
|
|
||
| ```bash | ||
| # Step 1: Generate prompts | ||
| python make_prompts.py \ | ||
| --doc-gen-root ~/projects/aws-docgen-root \ | ||
| --system-prompts system_prompt.txt \ | ||
| --out .ailly_prompts | ||
|
|
||
| # Step 2: Run Ailly | ||
| npx @ailly/cli --root .ailly_prompts | ||
|
|
||
| # Step 3: Parse results | ||
| python parse_json_files.py .ailly_prompts/*.ailly.md --out example_updates.json | ||
|
|
||
| # Step 4: Update DocGen | ||
| python update_doc_gen.py \ | ||
| --doc-gen-root ~/projects/aws-docgen-root \ | ||
| --updates-path example_updates.json | ||
| python -m aws_doc_sdk_examples_tools.agent.bin.main \ | ||
| ~/projects/AWSIAMPolicyExampleReservoir \ | ||
| --system-prompts prompts/system_prompt.txt | ||
| ``` | ||
|
|
||
| This will: | ||
| - Write prompts and config to `.ailly_iam_policy/` | ||
| - Run Ailly and capture results | ||
| - Parse and save output as `.ailly_iam_policy/iam_updates.json` | ||
| - Apply updates to your DocGen examples |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from pathlib import Path | ||
| from subprocess import run | ||
| from typing import List | ||
|
|
||
| import typer | ||
|
|
||
| from aws_doc_sdk_examples_tools.agent.make_prompts import main as make_prompts | ||
| from aws_doc_sdk_examples_tools.agent.parse_json_files import main as parse_json_files | ||
| from aws_doc_sdk_examples_tools.agent.update_doc_gen import main as update_doc_gen | ||
|
|
||
| app = typer.Typer() | ||
|
|
||
| AILLY_DIR = ".ailly_iam_policy" | ||
| AILLY_DIR_PATH = Path(AILLY_DIR) | ||
| IAM_UPDATES_PATH = AILLY_DIR_PATH / "iam_updates.json" | ||
|
|
||
|
|
||
| def get_ailly_files(dir: Path): | ||
| return [ | ||
| file | ||
| for file in dir.iterdir() | ||
| if file.is_file() and file.name.endswith(".ailly.md") | ||
| ] | ||
cpyle0819 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @app.command() | ||
| def update(iam_tributary_root: str, system_prompts: List[str] = []): | ||
| doc_gen_root = Path(iam_tributary_root) | ||
| make_prompts( | ||
| doc_gen_root=doc_gen_root, system_prompts=system_prompts, out=AILLY_DIR_PATH | ||
| ) | ||
| run(["npx", "@ailly/cli", "--root", AILLY_DIR]) | ||
| file_paths = get_ailly_files(AILLY_DIR_PATH) | ||
| parse_json_files(file_paths=file_paths, out=IAM_UPDATES_PATH) | ||
| update_doc_gen(doc_gen_root=doc_gen_root, iam_updates_path=IAM_UPDATES_PATH) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app() | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ PyYAML==6.0.1 | |
| requests==2.32.0 | ||
| types-PyYAML==6.0.12.12 | ||
| yamale==4.0.4 | ||
| typer==0.15.3 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.